BitReader#

class BitReader(*args, **kwargs)#

BitReader provides a bit reader that can read any number of bits from a memory buffer. It provides functions for reading any number of bits into 8, 16, 32 and 64 bit variables.

Methods#

class BitReader
free() None#

Frees a BitReader instance, which was previously allocated by new().

get_bits_uint16(nbits: int) Tuple[bool, int]#

Read nbits bits into val and update the current position.

Parameters:

nbits – number of bits to read

get_bits_uint32(nbits: int) Tuple[bool, int]#

Read nbits bits into val and update the current position.

Parameters:

nbits – number of bits to read

get_bits_uint64(nbits: int) Tuple[bool, int]#

Read nbits bits into val and update the current position.

Parameters:

nbits – number of bits to read

get_bits_uint8(nbits: int) Tuple[bool, int]#

Read nbits bits into val and update the current position.

Parameters:

nbits – number of bits to read

get_pos() int#

Returns the current position of a BitReader instance in bits.

get_remaining() int#

Returns the remaining number of bits of a BitReader instance.

get_size() int#

Returns the total number of bits of a BitReader instance.

init(data: list[int]) None#

Initializes a BitReader instance to read from data. This function can be called on already initialized instances.

Parameters:

data – data from which the bit reader should read

peek_bits_uint16(nbits: int) Tuple[bool, int]#

Read nbits bits into val but keep the current position.

Parameters:

nbits – number of bits to read

peek_bits_uint32(nbits: int) Tuple[bool, int]#

Read nbits bits into val but keep the current position.

Parameters:

nbits – number of bits to read

peek_bits_uint64(nbits: int) Tuple[bool, int]#

Read nbits bits into val but keep the current position.

Parameters:

nbits – number of bits to read

peek_bits_uint8(nbits: int) Tuple[bool, int]#

Read nbits bits into val but keep the current position.

Parameters:

nbits – number of bits to read

set_pos(pos: int) bool#

Sets the new position of a BitReader instance to pos in bits.

Parameters:

pos – The new position in bits

skip(nbits: int) bool#

Skips nbits bits of the BitReader instance.

Parameters:

nbits – the number of bits to skip

skip_to_byte() bool#

Skips until the next byte.

Fields#

class BitReader
bit#

Bit position in the current byte

byte#

Current byte position

data#
Data from which the bit reader will

read

size#

Size of data in bytes