- class cbor2.decoder.CBORDecoder(fp, tag_hook=None, object_hook=None, str_errors='strict')
The CBORDecoder class implements a fully featured CBOR decoder with several extensions for handling shared references, big integers, rational numbers and so on. Typically the class is not used directly, but the
loads()functions are called to indirectly construct and use the class.
tag_hook – callable that takes 2 arguments: the decoder instance, and the
CBORTagto be decoded. This callback is invoked for any tags for which there is no built-in decoder. The return value is substituted for the
CBORTagobject in the deserialized output
object_hook – callable that takes 2 arguments: the decoder instance, and a dictionary. This callback is invoked for each deserialized
dictobject. The return value is substituted for the dict in the deserialized output.
Decode the next value from the stream.
CBORDecodeError – if there is any problem decoding the stream
Wrap the given bytestring as a file and call
decode()with it as the argument.
This method was intended to be used from the
tag_hookhook when an object needs to be decoded separately from the rest but while still taking advantage of the shared value registry.
- property immutable
Used by decoders to check if the calling context requires an immutable type. Object_hook or tag_hook should raise an exception if this flag is set unless the result can be safely used as a dict key.
Read bytes from the data stream.
amount (int) – the number of bytes to read
Set the shareable value for the last encountered shared value marker, if any. If the current shared index is
None, nothing is done.
value – the shared value
the shared value to permit chaining
- cbor2.decoder.load(fp, **kwargs)
Deserialize an object from an open file.
fp – the input file (any file-like object)
kwargs – keyword arguments passed to
the deserialized object