jam.utils.codec.primitives.bools module
Boolean codec implementation for JAM protocol.
Implements encoding and decoding of boolean values according to the JAM specification. Booleans are encoded as a single byte with 0 for False and 1 for True.
- class jam.utils.codec.primitives.bools.BooleanCodec[source]
-
Codec for boolean values.
Encoding scheme: - False -> b’’ - True -> b’00’
Any non-zero value is decoded as True for robustness.
- encode_size(value: bool) int[source]
Calculate size needed to encode a boolean value.
- Parameters:
value – Boolean to encode
- Returns:
Always returns 1 as booleans are encoded as a single byte
- encode_into(value: bool, buffer: bytearray, offset: int = 0) int[source]
Encode a boolean value into the provided buffer.
- Parameters:
value – Boolean to encode
buffer – Target buffer
offset – Starting position in buffer
- Returns:
Number of bytes written (always 1)
- Raises:
EncodeError – If the buffer is too small or value is invalid type
- static decode_from(buffer: bytes | bytearray | memoryview, offset: int = 0) Tuple[bool, int][source]
Decode a boolean value from the provided buffer.
- Parameters:
buffer – Source buffer
offset – Starting position in buffer
- Returns:
Tuple of (decoded boolean, bytes read)
- Raises:
DecodeError – If the buffer is too small