53 else if (size <= UINT8_MAX)
55 else if (size <= UINT16_MAX)
57 else if (size <= UINT32_MAX)
92 size_t indef_bytestring_size = 2;
98 return indef_bytestring_size;
107 size_t indef_string_size = 2;
113 return indef_string_size;
165 size_t* buffer_size) {
168 if (serialized_size == 0) {
169 if (buffer_size != NULL) *buffer_size = 0;
173 if (*buffer == NULL) {
174 if (buffer_size != NULL) *buffer_size = 0;
180 if (buffer_size != NULL) *buffer_size = serialized_size;
185 size_t buffer_size) {
204 size_t buffer_size) {
223 size_t buffer_size) {
228 if (written > 0 && (buffer_size - written >= length)) {
230 return written + length;
237 if (written == 0)
return 0;
240 for (
size_t i = 0; i < chunk_count; i++) {
242 chunks[i], buffer + written, buffer_size - written);
243 if (chunk_written == 0)
return 0;
244 written += chunk_written;
247 size_t break_written =
249 if (break_written == 0)
return 0;
250 return written + break_written;
255 size_t buffer_size) {
260 if (written && (buffer_size - written >= length)) {
262 return written + length;
269 if (written == 0)
return 0;
272 for (
size_t i = 0; i < chunk_count; i++) {
274 buffer_size - written);
275 if (chunk_written == 0)
return 0;
276 written += chunk_written;
279 size_t break_written =
281 if (break_written == 0)
return 0;
282 return written + break_written;
287 size_t buffer_size) {
297 if (written == 0)
return 0;
299 for (
size_t i = 0; i < size; i++) {
300 size_t item_written =
301 cbor_serialize(*(handle++), buffer + written, buffer_size - written);
302 if (item_written == 0)
return 0;
303 written += item_written;
310 size_t break_written =
312 if (break_written == 0)
return 0;
313 return written + break_written;
318 size_t buffer_size) {
329 if (written == 0)
return 0;
331 for (
size_t i = 0; i < size; i++) {
332 size_t item_written =
334 if (item_written == 0) {
337 written += item_written;
339 buffer_size - written);
340 if (item_written == 0)
return 0;
341 written += item_written;
348 size_t break_written =
350 if (break_written == 0)
return 0;
351 return written + break_written;
356 size_t buffer_size) {
359 if (written == 0)
return 0;
362 buffer + written, buffer_size - written);
363 if (item_written == 0)
return 0;
364 return written + item_written;
368 size_t buffer_size) {
_cbor_malloc_t _cbor_malloc
bool cbor_array_is_indefinite(const cbor_item_t *item)
Is the array indefinite?
size_t cbor_array_size(const cbor_item_t *item)
Get the number of members.
cbor_item_t ** cbor_array_handle(const cbor_item_t *item)
Get the array contents.
bool cbor_array_is_definite(const cbor_item_t *item)
Is the array definite?
bool cbor_bytestring_is_definite(const cbor_item_t *item)
Is the byte string definite?
bool cbor_bytestring_is_indefinite(const cbor_item_t *item)
Is the byte string indefinite?
size_t cbor_bytestring_length(const cbor_item_t *item)
Returns the length of the binary data.
cbor_item_t ** cbor_bytestring_chunks_handle(const cbor_item_t *item)
Get the handle to the array of chunks.
size_t cbor_bytestring_chunk_count(const cbor_item_t *item)
Get the number of chunks this string consist of.
unsigned char * cbor_bytestring_handle(const cbor_item_t *item)
Get the handle to the binary data.
bool cbor_isa_string(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_negint(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_tag(const cbor_item_t *item)
Does the item have the appropriate major type?
cbor_item_t * cbor_move(cbor_item_t *item)
Provides CPP-like move construct.
bool cbor_isa_uint(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_float_ctrl(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_array(const cbor_item_t *item)
Does the item have the appropriate major type?
cbor_type cbor_typeof(const cbor_item_t *item)
Get the type of the item.
bool cbor_isa_bytestring(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_map(const cbor_item_t *item)
Does the item have the appropriate major type?
#define _CBOR_UNREACHABLE
@ CBOR_TYPE_FLOAT_CTRL
7 - decimals and special values (true, false, nil, ...)
@ CBOR_TYPE_UINT
0 - positive integers
@ CBOR_TYPE_BYTESTRING
2 - byte strings
@ CBOR_TYPE_STRING
3 - strings
@ CBOR_TYPE_NEGINT
1 - negative integers
@ CBOR_TYPE_ARRAY
4 - arrays
@ CBOR_FLOAT_32
Single float.
@ CBOR_FLOAT_16
Half float.
@ CBOR_FLOAT_0
Internal use - ctrl and special values.
size_t cbor_encode_negint16(uint16_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_ctrl(uint8_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_map_start(size_t length, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_tag(uint64_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_negint64(uint64_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_indef_map_start(unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_array_start(size_t length, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_uint8(uint8_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_half(float value, unsigned char *buffer, size_t buffer_size)
Encodes a half-precision float.
size_t cbor_encode_indef_bytestring_start(unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_double(double value, unsigned char *buffer, size_t buffer_size)
Encodes a double precision float.
size_t cbor_encode_indef_array_start(unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_uint16(uint16_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_uint64(uint64_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_negint32(uint32_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_string_start(size_t length, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_uint32(uint32_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_negint8(uint8_t value, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_bytestring_start(size_t length, unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_break(unsigned char *buffer, size_t buffer_size)
size_t cbor_encode_single(float value, unsigned char *buffer, size_t buffer_size)
Encodes a single precision float.
size_t cbor_encode_indef_string_start(unsigned char *buffer, size_t buffer_size)
cbor_float_width cbor_float_get_width(const cbor_item_t *item)
Get the float width.
double cbor_float_get_float8(const cbor_item_t *item)
Get a double precision float.
uint8_t cbor_ctrl_value(const cbor_item_t *item)
Reads the control value.
float cbor_float_get_float2(const cbor_item_t *item)
Get a half precision float.
float cbor_float_get_float4(const cbor_item_t *item)
Get a single precision float.
uint32_t cbor_get_uint32(const cbor_item_t *item)
Extracts the integer value.
uint16_t cbor_get_uint16(const cbor_item_t *item)
Extracts the integer value.
uint8_t cbor_get_uint8(const cbor_item_t *item)
Extracts the integer value.
cbor_int_width cbor_int_get_width(const cbor_item_t *item)
Queries the integer width.
uint64_t cbor_get_uint64(const cbor_item_t *item)
Extracts the integer value.
bool cbor_map_is_definite(const cbor_item_t *item)
Is this map definite?
struct cbor_pair * cbor_map_handle(const cbor_item_t *item)
Get the pairs storage.
size_t cbor_map_size(const cbor_item_t *item)
Get the number of pairs.
bool cbor_map_is_indefinite(const cbor_item_t *item)
Is this map indefinite?
size_t _cbor_safe_signaling_add(size_t a, size_t b)
Adds a and b, propagating zeros and returning 0 on overflow.
size_t cbor_serialize_string(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a string.
size_t cbor_serialized_size(const cbor_item_t *item)
Compute the length (in bytes) of the item when serialized using cbor_serialize.
size_t cbor_serialize_float_ctrl(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a.
size_t cbor_serialize(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize the given item.
size_t cbor_serialize_tag(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a tag.
size_t cbor_serialize_negint(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a negint.
size_t cbor_serialize_bytestring(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a bytestring.
size_t cbor_serialize_array(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize an array.
size_t cbor_serialize_uint(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize an uint.
size_t cbor_serialize_map(const cbor_item_t *item, unsigned char *buffer, size_t buffer_size)
Serialize a map.
size_t _cbor_encoded_header_size(uint64_t size)
How many bytes will a tag for a nested item of a given size take when encoded.
size_t cbor_serialize_alloc(const cbor_item_t *item, unsigned char **buffer, size_t *buffer_size)
Serialize the given item, allocating buffers as needed.
const uint64_t kMaxEmbeddedInt
Largest integer that can be encoded as embedded in the item leading byte.
size_t cbor_string_length(const cbor_item_t *item)
Returns the length of the underlying string in bytes.
bool cbor_string_is_indefinite(const cbor_item_t *item)
Is the string indefinite?
bool cbor_string_is_definite(const cbor_item_t *item)
Is the string definite?
cbor_item_t ** cbor_string_chunks_handle(const cbor_item_t *item)
Get the handle to the array of chunks.
unsigned char * cbor_string_handle(const cbor_item_t *item)
Get the handle to the underlying string.
size_t cbor_string_chunk_count(const cbor_item_t *item)
Get the number of chunks this string consist of.
Simple pair of items for use in maps.