I am creating an application for mobile phone which sends the acceleration measurements through TCP connection to the server.
I would like to reduce the message length as much as possible but in the same time I would like to make it the current format possible to extend without a lot of pain on modifying receiver parsing mechanism.
At the beginning I send a string in a following format:
##measurementTime#AccelerationX#AccelerationY#AccelerationZ
butsoon after the implementation I added to the message some other data and I realized it will take a lot of time if I will have to modify the format frequently.
I was thinking about the XML, but it adds a lot of load which of course I would like to avoid (the measurements are sent every 100-250 ms).
One recommendation is sending simple key name / value pairs if you need to stick completely to an ASCII text type stream. The key name is used to describe the name of the field that each value conveys similar to original proposal:
Alternatively, you can send data in a binary tagged format such as this:
where tagCodeNum is perhaps a byte or word and length is a byte or word depending on your needs. The idea of this format is that the receiver can recognize fields that it understands by the code number and then can also skip tags it doesn’t know how to decode. In this way, the encoding becomes extensible. If you need multiple tags grouped into logical messages, I would wrap a group of these binary coded tags in an overall message hierarchy:
Where the tag above is a replication of the previous tag construction described above and length describes the byte length of all the tags combined together.
Note: If you think about this structure, not a whole lot different than an XML type structure but it is a lot more concise and constrained so that it is nearly trivial to decode.