51 if (source_size == 0) {
60 .creation_failed =
false,
67 if (source_size > result->read) {
69 source + result->read,
70 source_size - result->read,
76 .position = result->read
81 switch (decode_result.
status) {
85 result->read += decode_result.
read;
112 }
while (stack.
size > 0);
119 result->error.position = result->read;
123 while (stack.
size > 0) {
139 default:
return NULL;
168 return _cbor_copy_int(item,
false);
170 return _cbor_copy_int(item,
true);
234 return _cbor_copy_float_ctrl(item);
240 #if CBOR_PRETTY_PRINTER 242 #include <inttypes.h> 247 #define __STDC_FORMAT_MACROS 249 static int _pow(
int b,
int ex)
251 if (ex == 0)
return 1;
253 while (--ex > 0) res *= b;
257 static void _cbor_nested_describe(
cbor_item_t *item, FILE *out,
int indent)
259 setlocale(LC_ALL,
"");
262 fprintf(out,
"%*s[CBOR_TYPE_UINT] ", indent,
" ");
268 fprintf(out,
"%*s[CBOR_TYPE_NEGINT] ", indent,
" ");
270 fprintf(out,
"Value: -%"PRIu64
" -1\n",
cbor_get_int(item));
274 fprintf(out,
"%*s[CBOR_TYPE_BYTESTRING] ", indent,
" ");
277 "Indefinite, with %zu chunks:\n",
280 _cbor_nested_describe(
286 "Definite, length %zuB\n",
292 fprintf(out,
"%*s[CBOR_TYPE_STRING] ", indent,
" ");
295 "Indefinite, with %zu chunks:\n",
298 _cbor_nested_describe(
304 "Definite, length %zuB, %zu codepoints\n",
310 fprintf(out,
"%*s", indent + 4,
" ");
318 fprintf(out,
"%*s[CBOR_TYPE_ARRAY] ", indent,
" ");
321 "Definite, size: %zu\n",
325 "Indefinite, size: %zu\n",
330 _cbor_nested_describe(
337 fprintf(out,
"%*s[CBOR_TYPE_MAP] ", indent,
" ");
340 "Definite, size: %zu\n",
344 "Indefinite, size: %zu\n",
349 _cbor_nested_describe(
353 _cbor_nested_describe(
361 fprintf(out,
"%*s[CBOR_TYPE_TAG] ", indent,
" ");
367 fprintf(out,
"%*s[CBOR_TYPE_FLOAT_CTRL] ", indent,
" ");
372 fprintf(out,
"Undefined\n");
374 fprintf(out,
"Null\n");
388 _cbor_nested_describe(item, out, 0);
Malformed or reserved MTB/value.
cbor_item_t * cbor_build_uint8(uint8_t value)
Constructs a new positive integer.
void cbor_builder_float4_callback(void *context, float value)
High-level decoding result.
bool cbor_bytestring_is_definite(const cbor_item_t *item)
Is the byte string definite?
bool syntax_error
Stack expectation mismatch.
uint64_t cbor_get_int(const cbor_item_t *item)
Extracts the integer value.
Stack handle - contents and size.
double cbor_float_get_float(const cbor_item_t *item)
Get the float value represented as double.
cbor_item_t * cbor_build_stringn(const char *val, size_t length)
Creates a new string and initializes it.
void cbor_builder_byte_string_callback(void *context, cbor_data data, size_t length)
void cbor_builder_uint32_callback(void *context, uint32_t value)
cbor_int_width cbor_int_get_width(const cbor_item_t *item)
Queries the integer width.
Internal use - ctrl and special values.
unsigned char * cbor_string_handle(const cbor_item_t *item)
Get the handle to the underlying string.
cbor_item_t * cbor_new_indefinite_bytestring()
Creates a new indefinite byte string.
cbor_item_t * cbor_new_indefinite_string()
Creates a new indefinite string.
cbor_item_t * cbor_build_float2(float value)
Constructs a new float.
void cbor_builder_uint8_callback(void *context, uint8_t value)
void cbor_decref(cbor_item_t **item_ref)
Decreases the reference count by one, deallocating the item if needed.
cbor_int8_callback uint8
Unsigned int.
size_t cbor_bytestring_chunk_count(const cbor_item_t *item)
Get the number of chunks this string consist of.
cbor_item_t ** cbor_string_chunks_handle(const cbor_item_t *item)
Get the handle to the array of chunks.
void cbor_builder_uint64_callback(void *context, uint64_t value)
void cbor_builder_tag_callback(void *context, uint64_t value)
void cbor_builder_float2_callback(void *context, float value)
void cbor_builder_indef_break_callback(void *context)
void cbor_builder_negint8_callback(void *context, uint8_t value)
struct _cbor_stack _cbor_stack_init()
size_t cbor_map_size(const cbor_item_t *item)
Get the number of pairs.
cbor_item_t * cbor_build_ctrl(uint8_t value)
Constructs a ctrl item.
cbor_item_t ** cbor_bytestring_chunks_handle(const cbor_item_t *item)
Get the handle to the array of chunks.
bool cbor_bytestring_is_indefinite(const cbor_item_t *item)
Is the byte string indefinite?
cbor_item_t * cbor_new_indefinite_array()
Create new indefinite array.
void cbor_builder_negint16_callback(void *context, uint16_t value)
7 - decimals and special values (true, false, nil, ...)
uint32_t cbor_get_uint32(const cbor_item_t *item)
Extracts the integer value.
void cbor_mark_negint(cbor_item_t *item)
Marks the integer item as a negative integer.
High-level decoding context.
Simple pair of items for use in maps.
void cbor_builder_undefined_callback(void *context)
cbor_error_code code
Description.
cbor_item_t * cbor_build_uint32(uint32_t value)
Constructs a new positive integer.
void _cbor_stack_pop(struct _cbor_stack *stack)
bool cbor_array_is_definite(const cbor_item_t *item)
Is the array definite?
cbor_item_t * cbor_build_float4(float value)
Constructs a new float.
void cbor_builder_null_callback(void *context)
High-level decoding error.
uint16_t cbor_get_uint16(const cbor_item_t *item)
Extracts the integer value.
struct cbor_error error
Error indicator.
bool cbor_is_null(const cbor_item_t *item)
Does this item represent null
bool cbor_array_push(cbor_item_t *array, cbor_item_t *pushee)
Append to the end.
cbor_item_t * cbor_copy(cbor_item_t *item)
Deep copy of an item.
void cbor_builder_string_start_callback(void *context)
void cbor_builder_array_start_callback(void *context, size_t size)
size_t cbor_string_chunk_count(const cbor_item_t *item)
Get the number of chunks this string consist of.
void cbor_builder_string_callback(void *context, cbor_data data, size_t length)
size_t cbor_array_size(const cbor_item_t *item)
Get the number of members.
bool cbor_bytestring_add_chunk(cbor_item_t *item, cbor_item_t *chunk)
Appends a chunk to the bytestring.
cbor_item_t * cbor_build_uint16(uint16_t value)
Constructs a new positive integer.
uint8_t cbor_get_uint8(const cbor_item_t *item)
Extracts the integer value.
float cbor_float_get_float4(const cbor_item_t *item)
Get a single precision float.
uint64_t cbor_get_uint64(const cbor_item_t *item)
Extracts the integer value.
uint8_t cbor_ctrl_value(const cbor_item_t *item)
Reads the control value.
void cbor_builder_indef_array_start_callback(void *context)
Streaming decoder result.
cbor_float_width cbor_float_get_width(const cbor_item_t *item)
Get the float width.
const unsigned char * cbor_data
cbor_item_t * cbor_load(cbor_data source, size_t source_size, struct cbor_load_result *result)
Loads data item from a buffer.
struct _cbor_stack * stack
cbor_item_t * cbor_build_uint64(uint64_t value)
Constructs a new positive integer.
bool cbor_map_is_definite(const cbor_item_t *item)
Is this map definite?
float cbor_float_get_float2(const cbor_item_t *item)
Get a half precision float.
cbor_item_t * cbor_build_float8(double value)
Constructs a new float.
cbor_item_t * cbor_move(cbor_item_t *item)
Provides CPP-like move construct.
void cbor_builder_negint32_callback(void *context, uint32_t value)
double cbor_float_get_float8(const cbor_item_t *item)
Get a double precision float.
bool cbor_is_bool(const cbor_item_t *item)
Is the item an a boolean?
enum cbor_decoder_status status
The result.
void cbor_builder_negint64_callback(void *context, uint64_t value)
Callback bundle – passed to the decoder.
bool cbor_is_undef(const cbor_item_t *item)
Does this item represent undefined
void cbor_builder_float8_callback(void *context, double value)
cbor_type cbor_typeof(const cbor_item_t *item)
Get the type of the item.
Stack parsing algorithm failed.
Not enough data - mismatch with MTB.
size_t cbor_string_codepoint_count(const cbor_item_t *item)
The number of codepoints in this string.
bool cbor_ctrl_is_bool(const cbor_item_t *item)
Is this ctrl item a boolean?
bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk)
Appends a chunk to the string.
bool cbor_string_is_definite(const cbor_item_t *item)
Is the string definite?
unsigned char * cbor_bytestring_handle(const cbor_item_t *item)
Get the handle to the binary data.
cbor_item_t * cbor_new_definite_array(size_t size)
Create new definite array.
void cbor_builder_map_start_callback(void *context, size_t size)
void cbor_builder_boolean_callback(void *context, bool value)
bool cbor_float_ctrl_is_ctrl(const cbor_item_t *item)
Is this a ctrl value?
size_t cbor_string_length(const cbor_item_t *item)
Returns the length of the underlying string.
cbor_item_t * cbor_new_indefinite_map()
Create a new indefinite map.
void cbor_builder_uint16_callback(void *context, uint16_t value)
bool cbor_map_add(cbor_item_t *item, struct cbor_pair pair)
Add a pair to the map.
cbor_item_t * cbor_build_bytestring(cbor_data handle, size_t length)
Creates a new byte string and initializes it.
void cbor_builder_byte_string_start_callback(void *context)
struct cbor_pair * cbor_map_handle(const cbor_item_t *item)
Get the pairs storage.
cbor_item_t * cbor_new_definite_map(size_t size)
Create a new definite map.
cbor_item_t * cbor_array_get(const cbor_item_t *item, size_t index)
Get item by index.
void cbor_builder_indef_map_start_callback(void *context)
size_t cbor_bytestring_length(const cbor_item_t *item)
Returns the length of the binary data.
Memory error - item allocation failed.
size_t read
Number of bytes read.
Buffer manipulation problem.
struct _cbor_stack_record * top
struct cbor_decoder_result cbor_stream_decode(cbor_data source, size_t source_size, const struct cbor_callbacks *callbacks, void *context)
Stateless decoder.
cbor_item_t ** cbor_array_handle(const cbor_item_t *item)
Get the array contents.
bool cbor_string_is_indefinite(const cbor_item_t *item)
Is the string indefinite?
bool creation_failed
Callback creating the last item has failed.