tvl-depot/users/Profpatsch/netstring
Profpatsch 222016a174 feat(users/Profpatsch/netstring): add README
Change-Id: I2b5e74f376ac2212ec12fd85267e115621095639
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2432
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
2021-01-23 15:33:50 +00:00
..
default.nix feat(users/Profpatsch/netstring): add rust to_netstring 2021-01-23 15:33:50 +00:00
README.md feat(users/Profpatsch/netstring): add README 2021-01-23 15:33:50 +00:00
tests.nix feat(users/Profpatsch/netstring): add rust to_netstring 2021-01-23 15:33:50 +00:00

Netstring

Netstrings are a djb invention. They are intended as a serialization format. Instead of inline control characters like \n or \0 to signal the end of a string, they use a run-length encoding given as the number of bytes, encoded in ASCII, at the beginning of the string.

hello -> 5:hello,
foo! -> 4:foo!,
こんにちは -> 15:こんにちは,

They can be used to encode e.g. lists by simply concatenating and reading them in one-by-one.

If you need a more complex encoding, you could start encoding e.g. tuples as netstrings-in-netstrings, or you could use netencode instead, which is what-if-json-but-netstrings, and takes the idea of netstrings to their logical conclusion.

Resources:

Spec: http://cr.yp.to/proto/netstrings.txt Wiki: https://en.wikipedia.org/wiki/Netstring