bzflag
bzflag copied to clipboard
Consistent String packing
Currently there are no less than 6 different string packing methods inside protocol messages:
- Fixed Size Strings
- C style, Null Terminated variable length strings
- C style, Non-Terminated variable length strings that use the entire buffer length
- Pascal style variable length strings that use a byte for length
- Pascal style variable length strings that use a unsigned short (2 bytes) for length
- Pascal style variable length strings that use a unsigned long (4 bytes) for length
Null terminated, or Pascal Long should be the standard if it is desired for strings to be able to span multiple TCP packets (over 1020 bytes). Pascal Short is fine if every message must fit in a single packet. All strings should be UTF8 encoded.
(From @JeffM2501)
Here's a vote for Pascal short. :)
The message buffer already has it's own size checking mechanism, so null terminated is viable. there is no additional error checking features provided by a separate string length.
The protocol supports messages over the size of a single packet, so short may be limiting. This may be more important if Unicode is eventually supported.