cbor-data 0.4.2

A library for using CBOR as in-memory representation for working with dynamically shaped data
Documentation

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.