I have two protos like lets say
Message1 and Message2.
I will get these proto messages. I want to serialize them but append the serialized bytes to a single byte array. What is the proper way to do this?
I mean from the resultant byte array, the consumer should be able to deserialize the two messages. Do I need to add some kind of metadata like
Message1 -> 1
Message2 -> 2
Then when I append the bytes obtained for the individual serialized messages(Message1 and Message2 in this case) to something
result = [1] ,[len of bytearray of message1] [bytearray for message1], [2], [len of bytearray for message2], [bytearray for message2]
and then send the bytearray. At the consumer end they will read the first byte as the message type, the second 4 bytes for the message length and based upon that read the first message bytearray and so on.
How about if I want to serialize them to json. Do I still need to do some kind of encoding?
Also lets simplify the question. If I have to add multiple instances of the same message in a single byte array, what would be the ideal way to do it?