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 type
cbor_error_code
¶ Possible decoding errors.
Values:
Memory error - item allocation failed.
Is it too big for your allocator?
Stack parsing algorithm failed.
- struct
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
- struct
High-level decoding error.
Public Members
-
size_t
cbor_error::
position
¶ Aproximate position.
-
cbor_error_code
cbor_error::
code
¶ Description.
-
size_t