API#
- class bstruct.Array(length: int)[source]#
Special annotation class to specify the length of an array.
- class bstruct.CustomEncoding(target: type[T], format: str, decode_attributes: Callable[[Iterator[Union[bool, bytes, int]], Literal['big', 'little']], T], encode_attributes: Callable[[T, list[Union[bool, bytes, int]], Literal['big', 'little']], None])[source]#
- static create(target: type[T], fields: Iterable[_NativeEncoding[Any]], decode_attributes: Callable[[Iterator[Union[bool, bytes, int]], Literal['big', 'little']], T], encode_attributes: Callable[[T, list[Union[bool, bytes, int]], Literal['big', 'little']], None]) CustomEncoding[T][source]#
- class bstruct.Encoding(target: type[T], format: str, decode_attributes: Callable[[Iterator[Union[bool, bytes, int]], Literal['big', 'little']], T], encode_attributes: Callable[[T, list[Union[bool, bytes, int]], Literal['big', 'little']], None])[source]#
- decode(data: bytes, byteorder: Literal['big', 'little'] = 'little') T[source]#
Decode an instance of cls from the provided data. The size of data must exactly match the size of cls.
- decode_all(data: bytes, byteorder: Literal['big', 'little'] = 'little') Iterator[T][source]#
Decode multiple instances of cls. The size of data must be an integer multiple of the size of S.
- encode(value: T, byteorder: Literal['big', 'little'] = 'little') bytes[source]#
Encode the value according to the provided byteorder.
- get_struct(byteorder: Literal['big', 'little']) Struct[source]#
Return the underlying struct.Struct instance used to (un)pack the binary data.
- read(buffer: BufferedIOBase, byteorder: Literal['big', 'little'] = 'little') T[source]#
Read and decode an instance of cls from the buffer.
- read_many(buffer: BufferedIOBase, count: int, byteorder: Literal['big', 'little'] = 'little') list[T][source]#
Read and decode count instances of cls from the buffer.
- class bstruct.Encodings[source]#
- I80F48 = <bstruct.CustomEncoding object>#
- bool: _NativeEncoding[bool] = <bstruct._NativeEncoding object>#
- f16 = <bstruct._NativeEncoding object>#
- f32 = <bstruct._NativeEncoding object>#
- f64 = <bstruct._NativeEncoding object>#
- i128 = <bstruct.CustomEncoding object>#
- i16 = <bstruct._NativeEncoding object>#
- i256 = <bstruct.CustomEncoding object>#
- i32 = <bstruct._NativeEncoding object>#
- i64 = <bstruct._NativeEncoding object>#
- i8 = <bstruct._NativeEncoding object>#
- u128 = <bstruct.CustomEncoding object>#
- u16 = <bstruct._NativeEncoding object>#
- u256 = <bstruct.CustomEncoding object>#
- u32 = <bstruct._NativeEncoding object>#
- u64 = <bstruct._NativeEncoding object>#
- u8 = <bstruct._NativeEncoding object>#