5 ms·
Turbo/Borland Pascal used a NUL-optional string format of length (byte IIRC) followed by data. [0] Java IIRC also uses a length-oriented format for string cons
by cgabios 11y ago
Turbo/Borland Pascal used a NUL-optional string format of length (byte IIRC) followed by data. [0]
Java IIRC also uses a length-oriented format for string constants in .class files. [1] It's been a while since I wrote a .java to MIPS asm compiler in C++ from scratch (don't ask).
This is because real-world strings may contain 0 to N NULs and escaping them is too much of a PITA for serialized formats, so it's easier and common to do things like TYPE LENGTH DATA de/serialization. For modern, efficient binary de/ser, check out binc and msgpack [2,3].
0: http://math.uww.edu/~harrisb/courses/cs171/strings.html http://math.uww.edu/~harrisb/courses/cs171/strings.html
1: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7 https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.ht...
2: http://msgpack.org/ http://msgpack.org/
3: https://github.com/ugorji/binc/blob/master/SPEC.md https://github.com/ugorji/binc/blob/master/SPEC.md
- salgernon 11y agoAnother option for dealing with nuls in a string: http://en.m.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing http://en.m.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuf... Basically eliminates a null in a byte stream so it can be used as a terminator.