API
The data API is centered around cbor_item_t
, a generic handle for any CBOR item. There are functions to
create items,
set items’ data,
parse serialized data into items,
manage, move, and links item together.
The single most important thing to keep in mind is: cbor_item_t
is an opaque type and should only be manipulated using the appropriate functions! Think of it as an object.
The libcbor API closely follows the semantics outlined by CBOR standard. This part of the documentation provides a short overview of the CBOR constructs, as well as a general introduction to the libcbor API. Remaining reference can be found in the following files structured by data types.
The API is designed to allow both very tight control & flexibility and general convenience with sane defaults. [1] For example, client with very specific requirements (constrained environment, custom application protocol built on top of CBOR, etc.) may choose to take full control (and responsibility) of memory and data structures management by interacting directly with the decoder. Other clients might want to take control of specific aspects (streamed collections, hash maps storage), but leave other responsibilities to libcbor. More general clients might prefer to be abstracted away from all aforementioned details and only be presented complete data structures.
- libcbor provides
stateless encoders and decoders
encoding and decoding drivers, routines that coordinate encoding and decoding of complex structures
data structures to represent and transform CBOR structures
routines for building and manipulating these structures
utilities for inspection and debugging
- Types of items
- Memory management and reference counting
- Decoding
- Encoding
- Streaming Decoding
cbor_stream_decode()
cbor_callbacks
uint8
uint16
uint32
uint64
negint64
negint32
negint16
negint8
byte_string_start
byte_string
string
string_start
indef_array_start
array_start
indef_map_start
map_start
tag
float2
float4
float8
undefined
null
boolean
indef_break
cbor_empty_callbacks
- Callback types definition
- Streaming Encoding
cbor_encode_uint8()
cbor_encode_uint16()
cbor_encode_uint32()
cbor_encode_uint64()
cbor_encode_uint()
cbor_encode_negint8()
cbor_encode_negint16()
cbor_encode_negint32()
cbor_encode_negint64()
cbor_encode_negint()
cbor_encode_bytestring_start()
cbor_encode_indef_bytestring_start()
cbor_encode_string_start()
cbor_encode_indef_string_start()
cbor_encode_array_start()
cbor_encode_indef_array_start()
cbor_encode_map_start()
cbor_encode_indef_map_start()
cbor_encode_tag()
cbor_encode_bool()
cbor_encode_null()
cbor_encode_undef()
cbor_encode_half()
cbor_encode_single()
cbor_encode_double()
cbor_encode_break()
cbor_encode_ctrl()
- Types 0 & 1 – Positive and negative integers
- Type 2 – Byte strings
- Type 3 – UTF-8 strings
- Type 4 – Arrays
- Type 5 – Maps
- Type 6 – Semantic tags
- Type 7 – Floats & control tokens