Crate cbor_data[][src]

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

ArrayWriter

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

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.

DictWriter

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

NoOutput

Marker type for builders that only append to a provided vector

SingleBuilder

Builder for the single value of a dict key.

SingleResult

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

Tags
WithOutput

Marker type for builders that emit an owned value

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

CborOutput

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

Encoder

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

Visitor

Visitor for the structure of a CBOR item.

Writer

Low-level primitives for emitting CBOR items.