CBORConfig¶
cbor_model.CBORConfig
dataclass
¶
Configuration options for CBORModel instances.
Attributes:
| Name | Type | Description |
|---|---|---|
encoding |
Literal['map', 'array']
|
Whether to encode the model as a CBOR map (keyed by
|
tag |
int | None
|
Wrap the encoded model in a CBOR tag with this tag number.
|
canonical |
bool
|
Use canonical CBOR encoding (deterministic key ordering
and minimal integer encoding). Defaults to |
encoders |
CBOREncoders
|
Custom encoders for types not natively supported by
cbor2. Keys are Python types; values are callables that
convert an instance of that type to a cbor2-encodable value
(e.g. |
unknown_keys |
Literal['forbid', 'ignore']
|
Behavior for unknown CBOR map keys during validation.
|
Source code in src/cbor_model/_config.py
canonical = False
class-attribute
instance-attribute
¶
Whether to use canonical CBOR encoding. Defaults to False.
encoders = field(default_factory=dict)
class-attribute
instance-attribute
¶
Custom encoders for types that are not natively supported by cbor2. The keys should be types, and the values should be callables that take an instance of the type and return a value that can be encoded by cbor2 (e.g. a string, int, list, dict, etc.).
encoding = 'map'
class-attribute
instance-attribute
¶
Whether to encode the model as a CBOR map (key-value pairs) or array (positional). Defaults to "map".
tag = None
class-attribute
instance-attribute
¶
Wrap the CBORModel in a CBOR Tag on serialization.
unknown_keys = 'ignore'
class-attribute
instance-attribute
¶
How to handle unknown keys in map-encoded CBOR payloads on validation.
"forbid" raises an error, "ignore" drops the keys.