Decoding¶
Another way to decode data using libcbor is to specify a callbacks that will be invoked when upon finding certain items in the input. This API is provided by
-
struct cbor_decoder_result cbor_stream_decode(cbor_data buffer, size_t buffer_size, const struct cbor_callbacks *callbacks, void *context)¶
Stateless decoder.
Will try parsing the
buffer
and will invoke the appropriate callback on success. Decodes one item at a time. No memory allocations occur.- param buffer:
Input buffer
- param buffer_size:
Length of the buffer
- param callbacks:
The callback bundle
- param context:
An arbitrary pointer to allow for maintaining context.
Usage example: https://github.com/PJK/libcbor/blob/master/examples/streaming_parser.c
The callbacks are defined by
-
struct cbor_callbacks¶
Callback bundle — passed to the decoder.
Public Members
-
cbor_int8_callback uint8¶
Unsigned int.
-
cbor_int16_callback uint16¶
Unsigned int.
-
cbor_int32_callback uint32¶
Unsigned int.
-
cbor_int64_callback uint64¶
Unsigned int.
-
cbor_int64_callback negint64¶
Negative int.
-
cbor_int32_callback negint32¶
Negative int.
-
cbor_int16_callback negint16¶
Negative int.
-
cbor_int8_callback negint8¶
Negative int.
-
cbor_simple_callback byte_string_start¶
Definite byte string.
-
cbor_string_callback byte_string¶
Indefinite byte string start.
-
cbor_string_callback string¶
Definite string.
-
cbor_simple_callback string_start¶
Indefinite string start.
-
cbor_simple_callback indef_array_start¶
Definite array.
-
cbor_collection_callback array_start¶
Indefinite array.
-
cbor_simple_callback indef_map_start¶
Definite map.
-
cbor_collection_callback map_start¶
Indefinite map.
-
cbor_int64_callback tag¶
Tags.
-
cbor_float_callback float2¶
Half float.
-
cbor_float_callback float4¶
Single float.
-
cbor_double_callback float8¶
Double float.
-
cbor_simple_callback undefined¶
Undef.
-
cbor_simple_callback null¶
Null.
-
cbor_bool_callback boolean¶
Bool.
-
cbor_simple_callback indef_break¶
Indefinite item break.
-
cbor_int8_callback uint8¶
When building custom sets of callbacks, feel free to start from
-
const struct cbor_callbacks cbor_empty_callbacks¶
Dummy callback bundle - does nothing.
Callback types definition¶
-
typedef void (*cbor_int8_callback)(void*, uint8_t)¶
Callback prototype.
-
typedef void (*cbor_int16_callback)(void*, uint16_t)¶
Callback prototype.
-
typedef void (*cbor_int32_callback)(void*, uint32_t)¶
Callback prototype.
-
typedef void (*cbor_int64_callback)(void*, uint64_t)¶
Callback prototype.
-
typedef void (*cbor_simple_callback)(void*)¶
Callback prototype.
-
typedef void (*cbor_string_callback)(void*, cbor_data, size_t)¶
Callback prototype.
-
typedef void (*cbor_collection_callback)(void*, size_t)¶
Callback prototype.
-
typedef void (*cbor_float_callback)(void*, float)¶
Callback prototype.
-
typedef void (*cbor_double_callback)(void*, double)¶
Callback prototype.
-
typedef void (*cbor_bool_callback)(void*, bool)¶
Callback prototype.