[−][src]Crate cbor_data
A library for using CBOR as in-memory representation for working with dynamically shaped data.
For the details on the data format see RFC 7049. It is normally meant to be used as a data interchange format that models a superset of the JSON features while employing a more compact binary representation. As such, the data representation is biased towards smaller in-memory size and not towards fastest data access speed.
This library presents a range of tradeoffs when using this data format. You can just use the bits you get from the wire or from a file, without paying any initial overhead but with the possibility of panicking during access and panicking when extracting (byte) strings encoded with indefinite size. Or you can validate and canonicalise the bits before using them, removing the possibility of panics and guaranteeing that indexing into the data will never allocate.
Regarding performance you should keep in mind that arrays and dictionaries are encoded as flat juxtaposition of its elements, meaning that indexing will have to decode items as it skips over them.
Regarding the interpretation of parsed data you have the option of inspecting the particular
encoding (by pattern matching on CborValue
) or extracting the information
you need using the API methods. In the latter case, many binary representations may yield the
same value, e.g. when asking for an integer the result may stem from a non-optimal encoding
(like writing 57 as 64-bit value) or from a BigDecimal with mantissa 570 and exponent -1.
Modules
constants |
Structs
ArrayBuilder | Builder for an array value, used by |
ArrayWriter | Builder for an array value, used by |
Cbor | Wrapper around a byte slice that allows parsing as CBOR value. |
CborBuilder | Builder for a single CBOR value. |
CborOwned | Wrapper around a vector of bytes, for parsing as CBOR. |
CborValue | Representation of a possibly tagged CBOR data item. |
DictBuilder | Builder for a dict value, used by |
DictValueBuilder | DSL helper for creating dictionary entries using |
DictValueWriter | DSL helper for creating dictionary entries using |
DictWriter | Builder for a dict value, used by |
Enums
CborObject | Lifted navigation structure for a CborValue. |
Literal | Low-level representation of major type 7 values. |
ValueKind | Low-level decoded form of a CBOR item. Use CborValue for inspecting values. |
Traits
Encoder | High-level encoding functions to write values in their canonical format. |