Crate cbor_data[][src]

Expand description

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

Structs

Builder for an array value, used by write_array_ret().

Wrapper around a byte slice that allows parsing as CBOR value.

Builder for a single CBOR value.

Wrapper around a vector of bytes, for parsing as CBOR.

Representation of a possibly tagged CBOR data item.

Builder for a dict value, used by write_dict_rec().

Marker type for builders that only append to a provided vector

Builder for the single value of a dict key.

Result value of using a SingleBuilder proving that it has been used.

Marker type for builders that emit an owned value

Enums

Lifted navigation structure for a CborValue.

Low-level representation of major type 7 values.

Low-level decoded form of a CBOR item. Use CborValue for inspecting values.

Traits

Marker trait to distinguish a builder that emits an owned value from one that appends to a vector

High-level encoding functions to write values in their canonical format.

Visitor for the structure of a CBOR item.

Low-level primitives for emitting CBOR items.