I need to construct a Java byte array out of mixed data types, but I don't know how to do this. These are my types:
byte version = 1; // at offset 0 short message_length = // the size of the byte message I am constructing here, at offset 1 short sub_version = 15346; // at offset 3 byte message_id = 2; // at offset 5 int flag1 = 10; // at offset 6 int flag2 = 0; // at offset 10 int flag3 = 0; // at offset 14 int flag4 = 0; // at offset 18 String message = "the quick brown fox jumps over the lazy dog"; // at offset 22
I know for the String, I can use
I know for the int values, I can use
I know for the short values, I can use
And the byte values are already bytes, I am just not sure of how to combine all of these into a single byte array. I have read about
Is this the correct process, I just convert all the data to bytes, and start "concatenating" the byte array with arraycopy?
I am communicating with some distant server I have no control over, and this is the message process they require.