CborReader
- class cometa.cbor.cbor_reader.CborReader(ptr)[source]
Bases:
objectRepresents a reader for parsing Concise Binary Object Representation (CBOR) encoded data.
This class provides a stream-like interface to decode CBOR data items sequentially.
- property refcount: int
Returns the number of active references to the underlying C object.
- property remaining_bytes: int
Returns the number of unread bytes remaining in the buffer.
- property last_error: str
Returns the last error message recorded for this reader.
- classmethod from_bytes(data)[source]
Creates a CborReader from raw bytes.
- Parameters:
data (bytes) – The CBOR encoded data.
- Return type:
- classmethod from_hex(hex_string)[source]
Creates a CborReader from a hexadecimal string.
- Parameters:
hex_string (str) – The hex-encoded CBOR data.
- Return type:
- peek_state()[source]
Inspects the type of the next CBOR token without consuming it.
- Returns:
The state enum indicating the next token type.
- Return type:
- skip_value()[source]
Skips the next CBOR data item completely (including nested items).
- Return type:
None
- read_encoded_value()[source]
Reads the next CBOR data item as-is and returns the raw bytes.
- Return type:
bytes
- read_array_len()[source]
Reads the start of an array.
- Returns:
The number of elements in the array, or None if it is indefinite-length.
- Return type:
int | None
- read_array_end()[source]
Consumes the ‘break’ code ending an indefinite-length array.
- Return type:
None
- read_map_len()[source]
Reads the start of a map.
- Returns:
The number of pairs in the map, or None if it is indefinite-length.
- Return type:
int | None
- read_map_end()[source]
Consumes the ‘break’ code ending an indefinite-length map.
- Return type:
None
- read_simple_value()[source]
Reads a simple value (e.g., boolean, null, or undefined).
- Returns:
The simple value.
- Return type:
int
- read_str()[source]
Reads a text string (Major type 3). Returns a string (decoded UTF-8).
- Return type:
str
- peek_tag()[source]
Peeks at the next semantic tag without consuming it.
- Returns:
The tag value if present.
- Return type:
int
- __init__(ptr)[source]
Internal constructor. Use factories like from_bytes or from_hex.
- Return type:
None