You determine the packet size by adding up the amount of bytes the payload will use and if the packet size is not fixed you use -1 (max payload size of 256) or -2 (unsigned short max value)
byte – 1
short – 2
int – 4
long – 8
double – 8
example
out.writeShort(column); // 2
out.writeByte(4); // 1
out.writeShort(slot); // 2
out.writeShort(id + 1); // 2
out.writeByte(1); // 1
packet size will be 8
Original credits: Spooky from r-s
https://www.rune-server.ee/runescape-development/rs2-server/help/647849-packet-sizes.html#post5297545