bencode inspired tight self describing serialization format
the bendncode format specification
definitions
- leb128: store arbitrary size integers as multiples of 7 bits, with 8th bit as continuation
- sleb128: similar but you write the sign bit at the end
decoding steps
as this is a self descriptive format, you need not know what it must become to read what it is.
the first step of any decode, is to read the tag out. none of the possible variants have a closing tag, merely an opening tag.
\x0(False) and\x1(True) map straight to a booleani(Int) uses thesleb128encoding as definedu(Uint) uses theleb128encodingf(Float) simply encodes 4 bytesd(Double) encodes 8 bytesz(None) means none, andSomemeans read the next tagl(List) is encoded asleb128(len),tagged contents, and are not necessarily homogenous.s(String) is encoded asleb128(len), followed bylenbytes.m(Map) is encoded asleb128(len),kₙ,vₙ, ..
enum tags
- all enums are, immediately after their tag, encoded with their index(
leb128) v, for newtype variant, is encoded as simply the actual type (which is tagged).x, unit variant, has no further steps.y, struct variant, is encoded identically toMap.n, tuple variant, is encoded identically toList.