Decoding¶
The following diagram illustrates the relationship among different parts of libcbor from the decoding standpoint.
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Client application │
│ │
│ ┌────────────────────────────────────────────┘
│ │ ↕
│ │ ┌──────────────────────────────────────────┐
│ │ │ │
│ │ │ Manipulation routines │
│ │ │ │
│ ┌─────────────────────────────────────┘ └──────────────────────────────────────────┘
│ │ ↑ ↑ ↑ ↑
│ │ │ │ ┌─────────────╫──────────┬───────────────────┴─┐
│ │ │ CDS │ ║ │ │
│ │ │ │ PDS ║ PDS PDS
│ │ ↓ ↓ ↓ ↓ ↓ ↓
│ │ ┌─────────────────┐ ┌────────────────────┐ ┌────────────────────────────┐
│ │ │ │ │ │ │ │
│ │ │ Custom driver │ ↔ │ Streaming driver │ ↔ │ Default driver │ ↔ CD
│ │ │ │ │ │ │ │
└───────────┘ └─────────────────┘ └────────────────────┘ └────────────────────────────┘
↕ ↕ ↕ ↕
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Stateless event─driven decoder │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
(PSD = Provided Data Structures, CDS = Custom Data Structures)
This section will deal with the API that is labeled as the “Default driver” in the diagram. That is, routines that decode complete libcbor data items
-
cbor_item_t *
cbor_load
(cbor_data source, size_t source_size, struct cbor_load_result *result)¶ Loads data item from a buffer.
- Return
- new CBOR item or
NULL
on failure. In that case,result
contains location and description of the error. - Parameters
source
: The buffersource_size
:result[out]
: Result indicator. CBOR_ERR_NONE on success
Associated data structures¶
-
enum
cbor_error_code
¶ Possible decoding errors.
Values:
-
CBOR_ERR_NONE
¶
-
CBOR_ERR_NOTENOUGHDATA
¶
-
CBOR_ERR_NODATA
¶
-
CBOR_ERR_MALFORMATED
¶
-
CBOR_ERR_MEMERROR
¶ Memory error - item allocation failed.
Is it too big for your allocator?
-
CBOR_ERR_SYNTAXERROR
¶ Stack parsing algorithm failed.
-
-
struct
cbor_load_result
¶ High-level decoding result.
Public Members
-
struct cbor_error cbor_load_result
error
¶ Error indicator.
-
size_t cbor_load_result
read
¶ Number of bytes read.
-
struct cbor_error cbor_load_result
-
struct
cbor_error
¶ High-level decoding error.
Public Members
-
size_t cbor_error
position
¶ Aproximate position.
-
cbor_error_code cbor_error
code
¶ Description.
-
size_t cbor_error