Reader¶
The Reader class allows binary data to be read and parsed as a stream of bits with a bit position.
- class Reader(bits, pos=0)¶
Wraps a
BitsorMutableBitsobject and a bit position to allow reading and parsing as a stream of bits.Methods:
read(): Read from the current bit position, and interpret according to the given format.peek(): Peek from the current bit position, and interpret according to the given format without changing the pos.parse(): Parse a fieldtype from the current bit position, returning the number of bits parsed.
Properties:
bits: TheBitsorMutableBitsobject.pos: The current bit position to read and parse from.
- parse(f, /)¶
Parse a fieldtype from the current bit position, returning the number of bits parsed.
- read(dtype, /)¶
Read from the current bit position, and interpret according to the given
Dtype.- Return type:
Any|tuple[Any] |list[Any|tuple[Any]]
- property bits: Bits | MutableBits¶
Get or set the
BitsorMutableBitsobject associated with theReader.Changing this object may invalidate the bit position, but it’s left to the user to manage this.
- Returns:
The current bits object.
- Raises:
ValueError – If the provided value is not a valid type.
- property pos: int¶
Get or set the current bit position.
This should be a positive int, but no attempt is made to check if the position is valid before it is used.
- Returns:
The current bit position.
- Raises:
ValueError – If set to a value that is not an integer.