In java I have put one byte like this. How do I reserve next 3 bytes? I heard that it’s better to pack data in multiples of 4 bytes
final byte PACKET_TYPE = 3;
bBuffer.put(PACKET_TYPE);
Also, if I want to fix a string data field as 48 bytes then how do I handle if string data is less than 48 bytes? I don’t want to add the size of string…
Thanks in advance…
In a word, padding:
For a fixed-width string field, you could pad with null bytes (a byte of 0), assuming, of course, that the string itself will never contain such bytes.