3 ms·
Why? When is this a useful thing?
by lambda 13y ago
Why? When is this a useful thing?
- chris_wot 13y agoI once had to decode an ASCII based datastream that was encoded something like this: * the first 14 characters were the length of the data stream in ASCII, padded with 0 * after this came the records - each record started with the size of the record, including the record header * the record then had each field start with a letter that indicated what sort of record it was - integer, float, character, variable string - all were encoded in ASCII * variable records were the letter "V", then a 14 byte length Yes, the format was awful. But you asked when that would be useful. There's your answer.
- nostrademons 13y agoYou could still do this even if strings were encoded in UTF-8. Just define the length of the record to be the length in bytes. This is why most modern programming & serialization languages (Go, Python 3, Protocol Buffers, Cap'n Proto) define separate byte[] and string types. Some things are just binary data and should be treated as such. Other things are encodings of world languages and should also be treated as such.
- masklinn 13y agoYou don't show how O(1) random access is useful here. You show a standard length-prefixed stream encoding.