

At the very least, you will need to start the message with a magic number which you change if any detail which is not described internally is altered.įrom the above you will obviously see that it is non-trivial. the schema of the data being transmitted.

You might also need to consider what each field represents, i.e. an array in Pascal terms).ĭ) Choosing a format to embed the offset of the start of each field etc. So the problem boils down to four things:Ī) Knowing the encoding and locale of a string.ī) Knowing the size and endianness of an integer or real.Ĭ) Qualifying these with a count if necessary to represent there being multiple associated elements (i.e. to get the bytes representing a character sequence but instead relying on the language facilities to manipulate a string. Serialisation and deserialisation have been dealt with many times before, and these obviously include consideration of fetching and storing your data: your program should not be trying to go to the heap etc. The key here is that you are trying to /serialise/ (and later /deserialise/) data, and since you are sending binary data which cannot be explicitly terminated you need to embed /offsets/ and/or /lengths/ in the message. I think it might be useful to change a couple of bits of terminology. Simple padding would be enough, the more simple the better. And the bitness of the "pointers"/references interfere here. So sender and receiver side need to have the exact same binary representation. On the receiver side this is reversed, namely the heap data for the string or array is allocated and the data moved, so the record fields can be easily accessed in the receiver function just using the record fields. The reference of the dynamic type to the heap data is then replaced with the offset value of the data written in the message. I already wrote a procedure using RTTI moving the heap part into the message directly behind the record. For basic types with fixed length it works well, but the dynamic types (ansistring, arrays) have the data on the heap. The record contains the data I want to communicate. In short: For a TCP communication I want to apply a record to a byte array (the TCP message) via pointer. The background of my question can be read here:
