First off, I saw Java equivalent of Python's struct.pack?... this is a clarification.
I am new to Java and trying to mirror some of the techniques that I have used in Python. I am trying to send data over the network, and want to ensure I know what it looks like. In python, I would use struct.pack. For example:
data = struct.pack('i', 10)
data += "Some string"
data += struct.pack('i', 500)
print(data)
That would print the packed portions in byte order with the string in plaintext in the middle.
I tried to replicate that with ByteBuffer:
String somestring = "Some string";
ByteBuffer buffer = ByteBuffer.allocate(100);
buffer.putInt(10);
buffer.put(somestring.getbytes());
buffer.putInt(500);
System.out.println(buffer.array());
What part am I not understanding?