KPN Things Device SDK
cbor.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define SENML_BVER_LABEL   -1
 
#define SENML_CBOR_BN_LABEL   -2
 
#define SENML_CBOR_BT_LABEL   -3
 
#define SENML_CBOR_BU_LABEL   -4
 
#define SENML_CBOR_BV_LABEL   -5
 
#define SENML_CBOR_BS_LABEL   -16
 
#define SENML_CBOR_N_LABEL   0
 
#define SENML_CBOR_U_LABEL   1
 
#define SENML_CBOR_V_LABEL   2
 
#define SENML_CBOR_VS_LABEL   3
 
#define SENML_CBOR_VB_LABEL   4
 
#define SENML_CBOR_S_LABEL   5
 
#define SENML_CBOR_T_LABEL   6
 
#define SENML_CBOR_UT_LABEL   7
 
#define SENML_CBOR_VD_LABEL   8
 
#define THINGSML_CBOR_I_LABEL   23
 
#define CBOR_TYPE_MASK   0xE0 /* top 3 bits */
 
#define CBOR_INFO_MASK   0x1F /* low 5 bits */
 
#define CBOR_UINT8_FOLLOWS   24 /* 0x18 */
 
#define CBOR_UINT16_FOLLOWS   25 /* 0x19 */
 
#define CBOR_UINT32_FOLLOWS   26 /* 0x1a */
 
#define CBOR_UINT64_FOLLOWS   27 /* 0x1b */
 
#define CBOR_BYTE_FOLLOWS   24 /* indicator that the next byte is part of this item */
 
#define CBOR_UINT   0x00 /* type 0 */
 
#define CBOR_NEGINT   0x20 /* type 1 */
 
#define CBOR_BYTES   0x40 /* type 2 */
 
#define CBOR_TEXT   0x60 /* type 3 */
 
#define CBOR_ARRAY   0x80 /* type 4 */
 
#define CBOR_MAP   0xA0 /* type 5 */
 
#define CBOR_TAG   0xC0 /* type 6 */
 
#define CBOR_7   0xE0 /* type 7 (float and other types) */
 
#define CBOR_VAR_FOLLOWS   31 /* 0x1f */
 
#define CBOR_DATETIME_STRING_FOLLOWS   0
 
#define CBOR_DATETIME_EPOCH_FOLLOWS   1
 
#define CBOR_FALSE   (CBOR_7 | 20)
 
#define CBOR_TRUE   (CBOR_7 | 21)
 
#define CBOR_NULL   (CBOR_7 | 22)
 
#define CBOR_UNDEFINED   (CBOR_7 | 23)
 
#define CBOR_FLOAT16   (CBOR_7 | 25)
 
#define CBOR_FLOAT32   (CBOR_7 | 26)
 
#define CBOR_FLOAT64   (CBOR_7 | 27)
 
#define CBOR_BREAK   (CBOR_7 | 31)
 
#define CBOR_TYPE   (peekChar() & CBOR_TYPE_MASK)
 

Functions

bool is_lossless_to_half_float (double value)
 
bool is_lossless_to_float (double value)
 
size_t cbor_serialize_array (size_t array_length)
 Serialize array of length array_length. More...
 
size_t cbor_serialize_map (size_t map_length)
 Serialize map of length map_length. More...
 
size_t cbor_serialize_int (int val)
 Serializes an integer. More...
 
size_t cbor_serialize_unicode_string (const char *val)
 Serializes a unicode string. More...
 
size_t cbor_serialize_double (double val)
 Serializes a double precision floating point value. More...
 
size_t cbor_serialize_float (float val)
 Serializes a single precision floating point value. More...
 
size_t cbor_serialize_half_float (float val)
 Serializes a half precision floating point value. More...
 
size_t cbor_serialize_bool (bool val)
 Serializes a boolean value. More...
 
size_t cbor_serialize_byte_string (const char *val, int length)
 Serializes a byte string. More...
 
size_t decode_int (uint64_t *val)
 
size_t cbor_deserialize_int64_t (int64_t *val)
 Deserialize signed 64 bit values from stream to val. More...
 
size_t cbor_deserialize_uint64_t (uint64_t *val)
 Deserialize unsigned 64 bit values from stream to val. More...
 
size_t cbor_at_break ()
 check that the char at the current position is a break char More...
 
size_t cbor_deserialize_float_half (float *val)
 
size_t cbor_deserialize_float (float *val)
 
size_t cbor_deserialize_double (double *val)
 

Macro Definition Documentation

◆ CBOR_7

#define CBOR_7   0xE0 /* type 7 (float and other types) */

◆ CBOR_ARRAY

#define CBOR_ARRAY   0x80 /* type 4 */

◆ CBOR_BREAK

#define CBOR_BREAK   (CBOR_7 | 31)

◆ CBOR_BYTE_FOLLOWS

#define CBOR_BYTE_FOLLOWS   24 /* indicator that the next byte is part of this item */

◆ CBOR_BYTES

#define CBOR_BYTES   0x40 /* type 2 */

◆ CBOR_DATETIME_EPOCH_FOLLOWS

#define CBOR_DATETIME_EPOCH_FOLLOWS   1

◆ CBOR_DATETIME_STRING_FOLLOWS

#define CBOR_DATETIME_STRING_FOLLOWS   0

◆ CBOR_FALSE

#define CBOR_FALSE   (CBOR_7 | 20)

◆ CBOR_FLOAT16

#define CBOR_FLOAT16   (CBOR_7 | 25)

◆ CBOR_FLOAT32

#define CBOR_FLOAT32   (CBOR_7 | 26)

◆ CBOR_FLOAT64

#define CBOR_FLOAT64   (CBOR_7 | 27)

◆ CBOR_INFO_MASK

#define CBOR_INFO_MASK   0x1F /* low 5 bits */

◆ CBOR_MAP

#define CBOR_MAP   0xA0 /* type 5 */

◆ CBOR_NEGINT

#define CBOR_NEGINT   0x20 /* type 1 */

◆ CBOR_NULL

#define CBOR_NULL   (CBOR_7 | 22)

◆ CBOR_TAG

#define CBOR_TAG   0xC0 /* type 6 */

◆ CBOR_TEXT

#define CBOR_TEXT   0x60 /* type 3 */

◆ CBOR_TRUE

#define CBOR_TRUE   (CBOR_7 | 21)

◆ CBOR_TYPE

#define CBOR_TYPE   (peekChar() & CBOR_TYPE_MASK)

◆ CBOR_TYPE_MASK

#define CBOR_TYPE_MASK   0xE0 /* top 3 bits */

◆ CBOR_UINT

#define CBOR_UINT   0x00 /* type 0 */

◆ CBOR_UINT16_FOLLOWS

#define CBOR_UINT16_FOLLOWS   25 /* 0x19 */

◆ CBOR_UINT32_FOLLOWS

#define CBOR_UINT32_FOLLOWS   26 /* 0x1a */

◆ CBOR_UINT64_FOLLOWS

#define CBOR_UINT64_FOLLOWS   27 /* 0x1b */

◆ CBOR_UINT8_FOLLOWS

#define CBOR_UINT8_FOLLOWS   24 /* 0x18 */

◆ CBOR_UNDEFINED

#define CBOR_UNDEFINED   (CBOR_7 | 23)

◆ CBOR_VAR_FOLLOWS

#define CBOR_VAR_FOLLOWS   31 /* 0x1f */

◆ SENML_BVER_LABEL

#define SENML_BVER_LABEL   -1

◆ SENML_CBOR_BN_LABEL

#define SENML_CBOR_BN_LABEL   -2

◆ SENML_CBOR_BS_LABEL

#define SENML_CBOR_BS_LABEL   -16

◆ SENML_CBOR_BT_LABEL

#define SENML_CBOR_BT_LABEL   -3

◆ SENML_CBOR_BU_LABEL

#define SENML_CBOR_BU_LABEL   -4

◆ SENML_CBOR_BV_LABEL

#define SENML_CBOR_BV_LABEL   -5

◆ SENML_CBOR_N_LABEL

#define SENML_CBOR_N_LABEL   0

◆ SENML_CBOR_S_LABEL

#define SENML_CBOR_S_LABEL   5

◆ SENML_CBOR_T_LABEL

#define SENML_CBOR_T_LABEL   6

◆ SENML_CBOR_U_LABEL

#define SENML_CBOR_U_LABEL   1

◆ SENML_CBOR_UT_LABEL

#define SENML_CBOR_UT_LABEL   7

◆ SENML_CBOR_V_LABEL

#define SENML_CBOR_V_LABEL   2

◆ SENML_CBOR_VB_LABEL

#define SENML_CBOR_VB_LABEL   4

◆ SENML_CBOR_VD_LABEL

#define SENML_CBOR_VD_LABEL   8

◆ SENML_CBOR_VS_LABEL

#define SENML_CBOR_VS_LABEL   3

◆ THINGSML_CBOR_I_LABEL

#define THINGSML_CBOR_I_LABEL   23

Function Documentation

◆ cbor_at_break()

size_t cbor_at_break ( )

check that the char at the current position is a break char

Returns
1 if all ok, 0 if no break char was found.

◆ cbor_deserialize_double()

size_t cbor_deserialize_double ( double *  val)

◆ cbor_deserialize_float()

size_t cbor_deserialize_float ( float *  val)

◆ cbor_deserialize_float_half()

size_t cbor_deserialize_float_half ( float *  val)

◆ cbor_deserialize_int64_t()

size_t cbor_deserialize_int64_t ( int64_t *  val)

Deserialize signed 64 bit values from stream to val.

Parameters
[out]valPointer to destination array
Returns
Number of bytes read from stream

◆ cbor_deserialize_uint64_t()

size_t cbor_deserialize_uint64_t ( uint64_t *  val)

Deserialize unsigned 64 bit values from stream to val.

Parameters
[out]valPointer to destination array
Returns
Number of bytes read from stream

◆ cbor_serialize_array()

size_t cbor_serialize_array ( size_t  array_length)

Serialize array of length array_length.

Basic usage:

cbor_serialize_array(2); // array of length 2 follows
cbor_serialize_int(1)); // write item 1
cbor_serialize_int(2)); // write item 2
size_t cbor_serialize_int(int val)
Serializes an integer.
Definition: cbor.cpp:321
size_t cbor_serialize_array(size_t array_length)
Serialize array of length array_length.
Definition: cbor.cpp:309
Note
You have to make sure to serialize the correct amount of items. If you exceed the length array_length, items will just be appened as normal
Parameters
[in]array_lengthLength of the array of items which follows
Returns
Number of bytes written to stream stream

◆ cbor_serialize_bool()

size_t cbor_serialize_bool ( bool  val)

Serializes a boolean value.

Parameters
[in]valThe boolean value to serialize
Returns
Number of bytes written to stream stream

◆ cbor_serialize_byte_string()

size_t cbor_serialize_byte_string ( const char *  val,
int  length 
)

Serializes a byte string.

Parameters
[in]valThe byte string start pointer
[in]lengthThe length of the string
Returns
Number of bytes written to stream stream

◆ cbor_serialize_double()

size_t cbor_serialize_double ( double  val)

Serializes a double precision floating point value.

Parameters
[in]valThe double to serialize
Returns
Number of bytes written to stream stream

◆ cbor_serialize_float()

size_t cbor_serialize_float ( float  val)

Serializes a single precision floating point value.

Parameters
[in]valThe float to serialize
Returns
Number of bytes written to stream stream

◆ cbor_serialize_half_float()

size_t cbor_serialize_half_float ( float  val)

Serializes a half precision floating point value.

Parameters
[in]valThe float to serialize
Returns
Number of bytes written to stream stream

◆ cbor_serialize_int()

size_t cbor_serialize_int ( int  val)

Serializes an integer.

Parameters
[in]valThe integer to serialize
Returns
Number of bytes written to stream stream

◆ cbor_serialize_map()

size_t cbor_serialize_map ( size_t  map_length)

Serialize map of length map_length.

Basic usage:

cbor_serialize_map(2); // map of length 2 follows
cbor_serialize_int(1)); // write key 1
cbor_serialize_byte_string("1")); // write value 1
cbor_serialize_int(2)); // write key 2
cbor_serialize_byte_string("2")); // write value 2
size_t cbor_serialize_byte_string(const char *val, int length)
Serializes a byte string.
Definition: cbor.cpp:457
size_t cbor_serialize_map(size_t map_length)
Serialize map of length map_length.
Definition: cbor.cpp:315
Parameters
map_lengthLength of the map of items which follows
Returns
Number of bytes written to stream stream

◆ cbor_serialize_unicode_string()

size_t cbor_serialize_unicode_string ( const char *  val)

Serializes a unicode string.

                 string
Parameters
[out]valThe zero-terminated unicode string to serialize.
Returns
Number of bytes written to stream stream

◆ decode_int()

size_t decode_int ( uint64_t *  val)

◆ is_lossless_to_float()

bool is_lossless_to_float ( double  value)

◆ is_lossless_to_half_float()

bool is_lossless_to_half_float ( double  value)