binobj.varints module¶
Serializers and deserializers for variable-length integers.
- class EncodingInfo(encode: Callable[[int], bytes], decode: Callable[[BinaryIO], int], endian: typing_extensions.Literal[little, big], signed: bool)¶
Bases:
object
Information describing a variable-length integer encoding.
- decode: Callable[[BinaryIO], int]¶
A function used to deserialize a variable-length integer from a stream.
- endian: typing_extensions.Literal[little, big]¶
The endianness the string is stored in.
- INTEGER_ENCODING_MAP = {<VarIntEncoding.COMPACT_INDICES: 'compact'>: EncodingInfo(encode=<function encode_integer_compact>, decode=<function decode_integer_compact>, endian='big', signed=True), <VarIntEncoding.LEB128: 'leb128'>: EncodingInfo(encode=<function encode_integer_leb128>, decode=<function decode_integer_leb128>, endian='little', signed=True), <VarIntEncoding.ULEB128: 'uleb128'>: EncodingInfo(encode=<function encode_integer_uleb128>, decode=<function decode_integer_uleb128>, endian='little', signed=False), <VarIntEncoding.VLQ: 'vlq'>: EncodingInfo(encode=<function encode_integer_vlq>, decode=<function decode_integer_vlq>, endian='big', signed=False)}¶
A mapping of encoding enums to encode/decode functions.
- class VarIntEncoding(value)¶
Bases:
Enum
All available encoding schemes for variable-length integers.
- COMPACT_INDICES = 'compact'¶
Signed big-endian integer in modified VLQ format.
- decode_integer_compact(stream: BinaryIO) int ¶
Decode an integer with signed VLQ encoding.
- Parameters:
stream (BinaryIO) – The stream to read from.
- Returns:
The decoded integer.
- Return type:
- decode_integer_leb128(stream: BinaryIO) int ¶
Decode a signed LEB128-encoded integer from the given stream.
- Parameters:
stream (BinaryIO) – The stream to read from.
- Returns:
The decoded integer.
- Return type:
- decode_integer_uleb128(stream: BinaryIO) int ¶
Decode an unsigned LEB128-encoded integer from the given stream.
- Parameters:
stream (BinaryIO) – The stream to read from.
- Returns:
The decoded integer.
- Return type:
- decode_integer_vlq(stream: BinaryIO) int ¶
Decode an unsigned VLQ-encoded integer from the given stream.
- Parameters:
stream (BinaryIO) – The stream to read from.
- Returns:
The decoded integer.
- Return type: