I’d like to take plain ASCII text, such as JSON, and serialize it to be transferred over the wire in binary. I’d like to add an unsigned 4-byte header to this binary that will have the size of the JSON “object” to make it easier to deserialize on the server.
In PHP this would be done using the pack() and unpack() family of methods. I’d like to be able to do the same using ANSI C.
If you already have the json string, you don’t need to convert to anything. Just prepend the length and send it.