View Source Riot.Util.Varint.LEB128 (Riot LoR v1.1.1)
More on LEB128:
- https://en.wikipedia.org/wiki/LEB128
- https://wiki.vg/Protocol#VarInt_and_VarLong
- https://developers.google.com/protocol-buffers/docs/encoding#varints
Other LEB128 implementations:
- protobuf (Python):
- decode: https://github.com/protocolbuffers/protobuf/blob/75eff10d81233d3d08ce5ded215e526c1fcace88/python/google/protobuf/internal/decoder.py#L107-L120
- encode: https://github.com/protocolbuffers/protobuf/blob/75eff10d81233d3d08ce5ded215e526c1fcace88/python/google/protobuf/internal/encoder.py#L375-L382
- Golang:
Link to this section Summary
Functions
Decodes all varint sequences
Decodes the next varint sequence
Encode an integer to a varint sequence
Link to this section Functions
Decodes all varint sequences
examples
Examples
iex> Riot.Util.Varint.LEB128.decode_all(<<8, 172, 2, 151, 195, 6>>)
{[8, 300, 106903], "", 6}
Decodes the next varint sequence
examples
Examples
iex> {_, rest, _} = Riot.Util.Varint.LEB128.decode_next(<<8, 172, 2>>)
{8, <<172, 2>>, 1}
iex> Riot.Util.Varint.LEB128.decode_next(rest)
{300, "", 2}
Encode an integer to a varint sequence
examples
Examples
iex> Riot.Util.Varint.LEB128.encode(999)
<<231, 7>>