Module len

Module len 

Source
Expand description

§Variable-Length Integer Encoding

This encoding ensures that smaller integer values need fewer bytes to encode. Support types are L2 and L3, both are encoded in little endian.

By default, L3 (u22) is used to encode length (integer) for record. But you override it by setting L2 (u15) in features flag.

Encoding algorithm is very straightforward, reserving one or two most significant bits of the first byte to encode rest of the length.

§L2
MSBLengthUsable BitsRange
0170..127
12150..32767
§L3
MSBLengthUsable BitsRange
0170..127
102140..16383
113220..4194303

For example, Binary representation of 0x_C0DE is 0x_11_00000011_011110

L3(0x_C0DE) is encoded in 3 bytes:

1st byte: 11_011110      # MSB is 11, so read next 2 bytes
2nd byte:        11
3rd byte:        11

Another example, L3(107) is encoded in just 1 byte:

1st byte: 0_1101011      # MSB is 0, So we don't have to read extra bytes.

Re-exports§

pub use L3 as Len;

Structs§

L2
L3