Diffusion C API  6.7.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cbor.h File Reference

Utilities for handling CBOR-encoded data. More...

Data Structures

struct  cbor_parser_s
 
union  CBOR_VALUE_UNION_T
 
struct  cbor_val_s
 A CBOR value/token as returned by cbor_next_val(). More...
 
struct  cbor_generator_s
 A CBOR generator is a wrapper for encoded data and the length of that data. More...
 

Macros

#define CBOR_VAL_FALSE
 Initial byte which maps to a JSON "false" value.
 
#define CBOR_VAL_TRUE
 Initial byte which maps to a JSON "true" value.
 
#define CBOR_VAL_NULL
 Initial byte which maps to a JSON "null" value.
 
#define CBOR_VAL_UNDEFINED
 Initial byte which maps to a JSON "undefined" value.
 
#define CBOR_VAL_BREAK
 Initial byte indicating the termination of a indefinte-length collection.
 

Typedefs

typedef struct cbor_val_s CBOR_VAL_T
 A CBOR value/token as returned by cbor_next_val().
 
typedef struct cbor_generator_s CBOR_GENERATOR_T
 A CBOR generator is a wrapper for encoded data and the length of that data. More...
 

Enumerations

enum  CBOR_TYPE_T
 CBOR major types.
 

Functions

CBOR_PARSER_Tcbor_parser_create (const char *data, size_t len)
 Create a CBOR parser. More...
 
void cbor_parser_free (CBOR_PARSER_T *parser)
 Free memory associated with a CBOR parser. More...
 
CBOR_VAL_Tcbor_next_val (CBOR_PARSER_T *parser)
 Get the next available token from a CBOR parser. More...
 
void cbor_val_free (CBOR_VAL_T *val)
 Free memory associated with a CBOR_VAL_T. More...
 
CBOR_GENERATOR_Tcbor_generator_create ()
 Creates a generator to be used for encoding CBOR data. More...
 
void cbor_generator_free (CBOR_GENERATOR_T *generator)
 Free memory associated with a CBOR generator. More...
 
int cbor_write_uint (CBOR_GENERATOR_T *generator, uint64_t val)
 Encode an unsigned integer value into the smallest possible CBOR encoding. More...
 
int cbor_write_negint (CBOR_GENERATOR_T *generator, int64_t val)
 Encode an negative integer value into the smallest possible CBOR encoding. More...
 
int cbor_write_byte_string (CBOR_GENERATOR_T *generator, const char *bytes, int64_t len)
 Encode a stream of bytes as CBOR. More...
 
int cbor_write_text_string (CBOR_GENERATOR_T *generator, const char *bytes, int64_t len)
 Encode a stream of bytes as CBOR. More...
 
int cbor_write_array (CBOR_GENERATOR_T *generator, int64_t size)
 Encode an array start marker as CBOR. More...
 
int cbor_write_map (CBOR_GENERATOR_T *generator, int64_t size)
 Encode a map start marker as CBOR. More...
 
int cbor_write_float (CBOR_GENERATOR_T *generator, double val)
 Encode a floating point value in CBOR format. More...
 
int cbor_write_break (CBOR_GENERATOR_T *generator)
 Encode a "break" value in CBOR format, for terminating indefinite-length CBOR collections. More...
 
int cbor_write_false (CBOR_GENERATOR_T *generator)
 Encode a "false" value in CBOR format. More...
 
int cbor_write_true (CBOR_GENERATOR_T *generator)
 Encode a "true" value in CBOR format. More...
 
int cbor_write_null (CBOR_GENERATOR_T *generator)
 Encode a "null" value in CBOR format. More...
 
int cbor_write_undefined (CBOR_GENERATOR_T *generator)
 Encode an "undefined" value in CBOR format. More...
 

Detailed Description

Utilities for handling CBOR-encoded data.

Copyright © 2017, 2021 Push Technology Ltd., All Rights Reserved.

Use is subject to license terms.

NOTICE: All information contained herein is, and remains the property of Push Technology. The intellectual and technical concepts contained herein are proprietary to Push Technology and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.

Typedef Documentation

A CBOR generator is a wrapper for encoded data and the length of that data.

Once all items have been written to the generator, the encoded data can be accessed directly from the structure.

Function Documentation

CBOR_GENERATOR_T* cbor_generator_create ( )

Creates a generator to be used for encoding CBOR data.

Return values
Anew CBOR generator, or NULL on error.
void cbor_generator_free ( CBOR_GENERATOR_T generator)

Free memory associated with a CBOR generator.

Parameters
generatorThe CBOR generator to be freed.
CBOR_VAL_T* cbor_next_val ( CBOR_PARSER_T parser)

Get the next available token from a CBOR parser.

Parameters
parserA pointer to a CBOR parser.
Returns
A pointer to a CBOR_VAL_T containing details about the next token, or NULL if there are no more tokens to read.
CBOR_PARSER_T* cbor_parser_create ( const char *  data,
size_t  len 
)

Create a CBOR parser.

Parameters
dataA pointer to CBOR-encoded data. The data is not copied and must be available during the lifetime of the parser.
lenLength of the CBOR-encoded data.
Returns
A pointer to a CBOR_PARSER_T, or NULL if data is NULL.
void cbor_parser_free ( CBOR_PARSER_T parser)

Free memory associated with a CBOR parser.

Parameters
parserA pointer to a CBOR_PARSER_T. If NULL, this function has no effect.
void cbor_val_free ( CBOR_VAL_T val)

Free memory associated with a CBOR_VAL_T.

Parameters
valA pointer to a CBOR_VAL_T structure, or NULL.
int cbor_write_array ( CBOR_GENERATOR_T generator,
int64_t  size 
)

Encode an array start marker as CBOR.

A marker denoting an indefinte-length array can be written using this function by setting len to -1. It is neccessary to call cbor_write_break() once the data items inside an array of this type have been written.

Parameters
generatorThe CBOR generator to encode into.
sizeThe length of the array to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_break ( CBOR_GENERATOR_T generator)

Encode a "break" value in CBOR format, for terminating indefinite-length CBOR collections.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
Returns
0 on success, or -1 on error.
int cbor_write_byte_string ( CBOR_GENERATOR_T generator,
const char *  bytes,
int64_t  len 
)

Encode a stream of bytes as CBOR.

A marker denoting an indefinte-length byte string can be written using this function by setting len to -1. It is neccessary to call cbor_write_break() once the data items inside a byte string of this type has been written.

Parameters
generatorThe CBOR generator to encode into.
bytesA pointer to the bytes to be encoded.
lenThe length of the bytes to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_false ( CBOR_GENERATOR_T generator)

Encode a "false" value in CBOR format.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
Returns
0 on success, or -1 on error.
int cbor_write_float ( CBOR_GENERATOR_T generator,
double  val 
)

Encode a floating point value in CBOR format.

Automatically detects the smallest possible encoding to use.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
valThe value to be encoded.
Returns
0 on success, or -1 on error.
int cbor_write_map ( CBOR_GENERATOR_T generator,
int64_t  size 
)

Encode a map start marker as CBOR.

The length of a map is equal to the number of key/value pairs that it contains.

A marker denoting an indefinte-length map can be written using this function by setting len to -1. It is neccessary to call cbor_write_break() once the data items inside a map of this type have been written.

Parameters
generatorThe CBOR generator to encode into.
sizeThe length of the map to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_negint ( CBOR_GENERATOR_T generator,
int64_t  val 
)

Encode an negative integer value into the smallest possible CBOR encoding.

Parameters
generatorThe CBOR generator to encode into.
valThe value to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_null ( CBOR_GENERATOR_T generator)

Encode a "null" value in CBOR format.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
Returns
0 on success, or -1 on error.
int cbor_write_text_string ( CBOR_GENERATOR_T generator,
const char *  bytes,
int64_t  len 
)

Encode a stream of bytes as CBOR.

A marker denoting an indefinte-length text string can be written using this function by setting len to -1. It is neccessary to call cbor_write_break() once the data items inside a text string of this type have been written.

Parameters
generatorThe CBOR generator to encode into.
bytesA pointer to the bytes to be encoded.
lenThe length of the bytes to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_true ( CBOR_GENERATOR_T generator)

Encode a "true" value in CBOR format.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
Returns
0 on success, or -1 on error.
int cbor_write_uint ( CBOR_GENERATOR_T generator,
uint64_t  val 
)

Encode an unsigned integer value into the smallest possible CBOR encoding.

Parameters
generatorThe CBOR generator to encode into.
valThe value to be encoded.
Returns
0 on success or -1 on error.
int cbor_write_undefined ( CBOR_GENERATOR_T generator)

Encode an "undefined" value in CBOR format.

Parameters
generatorThe CBOR generator to which the encoded value is appended.
Returns
0 on success, or -1 on error.