KNX IoT
KNX IoT Point API stack implementation
|
request and response payload handling in cbor More...
#include "deps/tinycbor/src/cbor.h"
#include "oc_helpers.h"
#include "util/oc_memb.h"
#include <oc_config.h>
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | oc_rep_s |
parsed entry of a cbor object This represents a link list of response values one can iterate over the responses to find values by More... | |
Macros | |
#define | OC_PRETTY_PRINT_TAB_CHARACTER " " |
Tab character(s) used for oc_rep_to_json function when doing pretty_print. More... | |
#define | oc_rep_add_boolean(parent, value) g_err |= cbor_encode_boolean(&parent##_array, value) |
Add an bool value to a parent array. More... | |
#define | oc_rep_add_byte_string(parent, value, value_len) g_err |= cbor_encode_byte_string(&parent##_array, value, value_len) |
Add a byte string value to a parent array. More... | |
#define | oc_rep_add_double(parent, value) g_err |= cbor_encode_double(&parent##_array, value) |
Add an double value to a parent array. More... | |
#define | oc_rep_add_float(parent, value) g_err |= cbor_encode_float(&parent##_array, value) |
Add an float value to a parent array. More... | |
#define | oc_rep_add_int(parent, value) g_err |= cbor_encode_int(&parent##_array, value) |
Add an int value to a parent array. More... | |
#define | oc_rep_add_text_string(parent, value) |
Add a text string value to a parent array. More... | |
#define | oc_rep_array(name) &name##_array |
Get a pointer to the cbor array object with the given name More... | |
#define | oc_rep_begin_array(parent, name) |
This macro is unlikely to be used by outside the library. More... | |
#define | oc_rep_begin_links_array() |
#define | oc_rep_begin_object(parent, key) |
#define | oc_rep_begin_root() g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength) |
Begin the root (without map). More... | |
#define | oc_rep_begin_root_object() g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength) |
Begin the root object. More... | |
#define | oc_rep_close_array(parent, key) oc_rep_end_array(&parent##_map, key) |
Close the array object. More... | |
#define | oc_rep_close_object(parent, key) oc_rep_end_object(&parent##_map, key) |
Close the object. More... | |
#define | oc_rep_end_array(parent, name) |
End the array object. More... | |
#define | oc_rep_end_links_array() g_err |= cbor_encoder_close_container(&g_encoder, &links_array) |
#define | oc_rep_end_object(parent, key) |
This macro has been replaced with oc_rep_begin_object. More... | |
#define | oc_rep_end_root_object() g_err |= cbor_encoder_close_container(&g_encoder, &root_map) |
End the root object. More... | |
#define | oc_rep_i_set_bool_array(object, key, values, length) |
Add a boolean array with values of length to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_boolean(object, key, value) |
Add an boolean value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_byte_string(object, key, value, length) |
Add an byte array value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_double(object, key, value) |
Add a double value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_double_array(object, key, values, length) |
Add a double array with values of length to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_float(object, key, value) |
Add a float value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_float_array(object, key, values, length) |
Add a float array with values of length to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_float_array(object, key, values, length) |
Add a float array with values of length to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_int(object, key, value) |
Add an integer value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_int_array(object, key, values, length) |
Add an integer array with values of length to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_key(parent, key) |
End users are very unlikely to use this macro. More... | |
#define | oc_rep_i_set_string_array(object, key, values) |
Add a string array using an oc_string_array_t as values to the cbor object under the integer key name. More... | |
#define | oc_rep_i_set_text_string(object, key, value) |
Add an string value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_i_set_uint(object, key, value) |
Add an unsigned integer value to the cbor object under the integer key name Example: More... | |
#define | oc_rep_object(name) &name##_map |
Get a pointer to the cbor object with the given name More... | |
#define | oc_rep_object_array_begin_item(key) oc_rep_begin_object(&key##_array, key) |
Begin a cbor object for an array of cbor objects. More... | |
#define | oc_rep_object_array_end_item(key) oc_rep_end_object(&key##_array, key) |
End the cbor object for the key array of cbor objects. More... | |
#define | oc_rep_object_array_start_item(key) oc_rep_object_array_begin_item(key) |
This macro has been replaced with oc_rep_object_array_begin_item. More... | |
#define | oc_rep_open_array(parent, key) |
Open a cbor array object belonging to parent object under the key name. More... | |
#define | oc_rep_open_object(parent, key) |
Open a cbor object belonging to parent object under the key name. More... | |
#define | oc_rep_set_array(object, key) oc_rep_open_array(object, key) |
This macro has been replaced with oc_rep_open_array. More... | |
#define | oc_rep_set_bool_array(object, key, values, length) |
Add a boolean array with values of length to the cbor object under the key name. More... | |
#define | oc_rep_set_boolean(object, key, value) |
Add an boolean value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_byte_string(object, key, value, length) |
Add an byte array value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_double(object, key, value) |
Add a double value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_double_array(object, key, values, length) |
Add a double array with values of length to the cbor object under the key name. More... | |
#define | oc_rep_set_float(object, key, value) |
Add a float value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_float_array(object, key, values, length) |
Add a float array with values of length to the cbor object under the key name. More... | |
#define | oc_rep_set_float_array(object, key, values, length) |
Add a float array with values of length to the cbor object under the key name. More... | |
#define | oc_rep_set_int(object, key, value) |
Add an integer value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_int_array(object, key, values, length) |
Add an integer array with values of length to the cbor object under the key name. More... | |
#define | oc_rep_set_key(parent, key) |
End users are very unlikely to use this macro. More... | |
#define | oc_rep_set_object(object, key) oc_rep_open_object(object, key) |
This macro has been replaced with oc_rep_open_object. More... | |
#define | oc_rep_set_string_array(object, key, values) |
Add a string array using an oc_string_array_t as values to the cbor object under the key name. More... | |
#define | oc_rep_set_text_string(object, key, value) |
Add an string value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_text_string_no_tag(object, value) |
Add an string value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_uint(object, key, value) |
Add an unsigned integer value to the cbor object under the key name Example: More... | |
#define | oc_rep_set_value_boolean(parent, value) g_err |= cbor_encode_boolean(&parent##_map, value) |
#define | oc_rep_set_value_byte_string(parent, value, value_len) g_err |= cbor_encode_byte_string(&parent##_map, value, value_len) |
#define | oc_rep_set_value_double(parent, value) g_err |= cbor_encode_double(&parent##_map, value) |
#define | oc_rep_set_value_float(parent, value) g_err |= cbor_encode_float(&parent##_map, value) |
#define | oc_rep_set_value_int(parent, value) g_err |= cbor_encode_int(&parent##_map, value) |
#define | oc_rep_set_value_text_string(parent, value) |
#define | oc_rep_start_array(parent, name) oc_rep_begin_array(parent, name) |
This macro has been replaced with oc_rep_begin_array. More... | |
#define | oc_rep_start_links_array() oc_rep_begin_links_array() |
#define | oc_rep_start_object(parent, key) oc_rep_begin_object(parent, key) |
This macro has been replaced with oc_rep_begin_object. More... | |
Typedefs | |
typedef struct oc_rep_s | oc_rep_t |
parsed entry of a cbor object This represents a link list of response values one can iterate over the responses to find values by More... | |
Functions | |
void | oc_free_rep (oc_rep_t *rep) |
int | oc_parse_rep (const uint8_t *payload, int payload_size, oc_rep_t **value_list) |
void | oc_print_rep_as_json (oc_rep_t *rep, bool pretty_print) |
prints the response tree as JSON to the output pretty_print: true: nicely formatted JSON on multiple lines false: JSON formatted on a single line More... | |
int | oc_rep_add_line_size_to_buffer (const char *line, int len) |
add a line to the response buffer note updates the occupied size in the response buffer More... | |
int | oc_rep_add_line_to_buffer (const char *line) |
add a line to the response buffer note updates the occupied size in the response buffer More... | |
void | oc_rep_encode_raw (const uint8_t *data, size_t len) |
Encode raw data, as if it was already encoded. More... | |
void | oc_rep_encode_raw_encoder (CborEncoder *encoder, const uint8_t *data, size_t len) |
Encode raw data, as if it was already encoded. More... | |
bool | oc_rep_get_bool (oc_rep_t *rep, const char *key, bool *value) |
Read a boolean value from an oc_rep_t More... | |
bool | oc_rep_get_bool_array (oc_rep_t *rep, const char *key, bool **value, size_t *size) |
Read an boolean array value from an oc_rep_t More... | |
bool | oc_rep_get_byte_string (oc_rep_t *rep, const char *key, char **value, size_t *size) |
Read a byte string value from an oc_rep_t More... | |
bool | oc_rep_get_byte_string_array (oc_rep_t *rep, const char *key, oc_string_array_t *value, size_t *size) |
Read an byte string array value from an oc_rep_t More... | |
CborError | oc_rep_get_cbor_errno (void) |
Called after any oc_rep_set_* , oc_rep_start_* , oc_rep_begin_* , oc_rep_end_* , oc_rep_add_* , oc_rep_open_* , and oc_rep_close_* macros to check if an error occurred while executing the commands. More... | |
bool | oc_rep_get_double (oc_rep_t *rep, const char *key, double *value) |
Read a double value from an oc_rep_t More... | |
bool | oc_rep_get_double_array (oc_rep_t *rep, const char *key, double **value, size_t *size) |
Read an double array value from an oc_rep_t More... | |
int | oc_rep_get_encoded_payload_size (void) |
Get the size of the cbor encoded data. More... | |
const uint8_t * | oc_rep_get_encoder_buf (void) |
Get the buffer pointer at the start of the encoded cbor data. More... | |
bool | oc_rep_get_float (oc_rep_t *rep, const char *key, float *value) |
Read a float value from an oc_rep_t More... | |
bool | oc_rep_get_float_array (oc_rep_t *rep, const char *key, float **value, size_t *size) |
Read an float array value from an oc_rep_t More... | |
bool | oc_rep_get_int (oc_rep_t *rep, const char *key, int64_t *value) |
Read an integer from an oc_rep_t More... | |
bool | oc_rep_get_int_array (oc_rep_t *rep, const char *key, int64_t **value, size_t *size) |
Read an integer array value from an oc_rep_t More... | |
bool | oc_rep_get_mixed_array (oc_rep_t *rep, const char *key, oc_rep_t **value) |
Read a mixed array value from an oc_rep_t More... | |
bool | oc_rep_get_object (oc_rep_t *rep, const char *key, oc_rep_t **value) |
Read a object value from an oc_rep_t More... | |
bool | oc_rep_get_object_array (oc_rep_t *rep, const char *key, oc_rep_t **value) |
Read a object array value from an oc_rep_t More... | |
bool | oc_rep_get_string (oc_rep_t *rep, const char *key, char **value, size_t *size) |
Read a text string value from an oc_rep_t More... | |
bool | oc_rep_get_string_array (oc_rep_t *rep, const char *key, oc_string_array_t *value, size_t *size) |
Read a string array value from an oc_rep_t More... | |
bool | oc_rep_i_get_bool (oc_rep_t *rep, int key, bool *value) |
Read a boolean value from an oc_rep_t with key as integer. More... | |
bool | oc_rep_i_get_bool_array (oc_rep_t *rep, int key, bool **value, size_t *size) |
Read an boolean array value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_byte_string (oc_rep_t *rep, int key, char **value, size_t *size) |
Read a byte string value from an oc_rep_t with an integer key. More... | |
bool | oc_rep_i_get_byte_string_array (oc_rep_t *rep, int key, oc_string_array_t *value, size_t *size) |
Read an byte string array value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_double (oc_rep_t *rep, int key, double *value) |
Read a double value from an oc_rep_t More... | |
bool | oc_rep_i_get_double_array (oc_rep_t *rep, int key, double **value, size_t *size) |
Read an double array value from an oc_rep_t with an integer key. More... | |
bool | oc_rep_i_get_float (oc_rep_t *rep, int key, float *value) |
Read a float value from an oc_rep_t More... | |
bool | oc_rep_i_get_float_array (oc_rep_t *rep, int key, float **value, size_t *size) |
Read an float array value from an oc_rep_t with an integer key. More... | |
bool | oc_rep_i_get_int (oc_rep_t *rep, int key, int64_t *value) |
Read an integer from an oc_rep_t with an integer as key. More... | |
bool | oc_rep_i_get_int_array (oc_rep_t *rep, int key, int64_t **value, size_t *size) |
Read an integer array value from an oc_rep_t with an integer key. More... | |
bool | oc_rep_i_get_mixed_array (oc_rep_t *rep, int key, oc_rep_t **value) |
Read a mixed array value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_object (oc_rep_t *rep, int key, oc_rep_t **value) |
Read a object value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_object_array (oc_rep_t *rep, int key, oc_rep_t **value) |
Read a object array value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_string (oc_rep_t *rep, int key, char **value, size_t *size) |
Read a text string value from an oc_rep_t with integer key. More... | |
bool | oc_rep_i_get_string_array (oc_rep_t *rep, int key, oc_string_array_t *value, size_t *size) |
Read a string array value from an oc_rep_t with integer key. More... | |
void | oc_rep_new (uint8_t *payload, int size) |
Initialize the buffer used to hold the cbor encoded data. More... | |
void | oc_rep_set_pool (struct oc_memb *rep_objects_pool) |
size_t | oc_rep_to_json (oc_rep_t *rep, char *buf, size_t buf_size, bool pretty_print) |
Convert an oc_rep_t to JSON encoded string. More... | |
size_t | py_oc_rep_to_json (oc_rep_t *rep, char *buf, size_t buf_size, bool pretty_print) |
Variables | |
CborEncoder | g_encoder |
int | g_err |
CborEncoder | links_array |
CborEncoder | root_map |
request and response payload handling in cbor
Definition in file oc_rep.h.
#define OC_PRETTY_PRINT_TAB_CHARACTER " " |
#define oc_rep_add_boolean | ( | parent, | |
value | |||
) | g_err |= cbor_encode_boolean(&parent##_array, value) |
Add an bool
value
to a parent
array.
Using oc_rep_add_boolean can be used when the number of items is calculated at run time or for some reason it is not know till after calling oc_rep_open_array.
If the size of the bool
array is already known oc_rep_set_bool_array
should be used.
Example: To build the an object with the following cbor value
{ "flip": [ false, false, true, false, false ] }
The following code could be used:
#define oc_rep_add_byte_string | ( | parent, | |
value, | |||
value_len | |||
) | g_err |= cbor_encode_byte_string(&parent##_array, value, value_len) |
Add a byte string value
to a parent
array.
Currently the only way to make an array of byte strings is using this macro
Example:
To build the an object with the following cbor value note, base64 encoding used to represent binary array data
{ "barray": [ "AAECAwQFBg==", "AQECAwUIEyE0VYk=", "AAD/AAA=" ] }
The following code could be used:
#define oc_rep_add_double | ( | parent, | |
value | |||
) | g_err |= cbor_encode_double(&parent##_array, value) |
Add an double
value
to a parent
array.
Using oc_rep_add_double can be useful when the number of items is calculated at run time or for some reason is not know till after calling oc_rep_open_array.
If the size of the double
array is already known oc_rep_set_double_array
should be used.
Example:
To build the an object with the following cbor value
{ "math_constants": [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_add_float | ( | parent, | |
value | |||
) | g_err |= cbor_encode_float(&parent##_array, value) |
Add an float
value
to a parent
array.
Using oc_rep_add_float can be useful when the number of items is calculated at run time or for some reason is not know till after calling oc_rep_open_array.
If the size of the float
array is already known oc_rep_set_float_array
should be used.
Example:
To build the an object with the following cbor value
{ "math_constants": [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_add_int | ( | parent, | |
value | |||
) | g_err |= cbor_encode_int(&parent##_array, value) |
Add an int
value
to a parent
array.
Using oc_rep_add_int can be useful when the number of items is calculated at run time or for some reason it not know till after calling oc_rep_open_array.
If the size of the int
array is already known oc_rep_set_int_array
should be used.
Example: To build the an object with the following cbor value
{ "fibonacci": [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ] }
The following code could be used:
#define oc_rep_add_text_string | ( | parent, | |
value | |||
) |
Add a text string value
to a parent
array.
Currently the only way to make an array of text strings is using this macro
Example:
To build the an object with the following cbor value
{ "quotes": [ "Do not take life too seriously. You will never get out of it alive.", "All generalizations are false, including this one.", "Those who believe in telekinetics, raise my hand.", "I refuse to join any club that would have me as a member." ] }
The following code could be used:
#define oc_rep_array | ( | name | ) | &name##_array |
#define oc_rep_begin_array | ( | parent, | |
name | |||
) |
This macro is unlikely to be used by outside the library.
Begin a cbor array object with name
belonging to parent
object. Items can then be added to the array till oc_rep_end_array is called.
Since no functions exist to retrieve an array object without a key it is unlikely this macro will be used without using oc_rep_set_key first. Most likely oc_rep_open_array will be used to create an array object with a key.
Example: To build the an object with the following cbor value
{ "fibonacci": [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ] }
The following code could be used:
See oc_rep_add_int to see an example using the recommended way to do the same thing using oc_rep_open_array
and oc_rep_close_array
instead.
#define oc_rep_begin_links_array | ( | ) |
#define oc_rep_begin_object | ( | parent, | |
key | |||
) |
#define oc_rep_begin_root | ( | ) | g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength) |
Begin the root (without map).
Items can be added to the root object till oc_rep_end_root_object is called
#define oc_rep_begin_root_object | ( | ) | g_err |= cbor_encoder_create_map(&g_encoder, &root_map, CborIndefiniteLength) |
Begin the root object.
Items can be added to the root object till oc_rep_end_root_object is called
#define oc_rep_close_array | ( | parent, | |
key | |||
) | oc_rep_end_array(&parent##_map, key) |
Close the array object.
No additional items can be added to the array after this is called.
#define oc_rep_close_object | ( | parent, | |
key | |||
) | oc_rep_end_object(&parent##_map, key) |
Close the object.
No additional items can be added to the object after this is called.
#define oc_rep_end_array | ( | parent, | |
name | |||
) |
End the array object.
No additional items can be added to the array after this is called.
#define oc_rep_end_object | ( | parent, | |
key | |||
) |
This macro has been replaced with oc_rep_begin_object.
#define oc_rep_end_root_object | ( | ) | g_err |= cbor_encoder_close_container(&g_encoder, &root_map) |
End the root object.
Items can no longer be added to the root object.
#define oc_rep_i_set_bool_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a boolean array with values
of length
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 4 : [ false, false, true, false, false ] }
The following code could be used:
#define oc_rep_i_set_boolean | ( | object, | |
key, | |||
value | |||
) |
Add an boolean value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 3: false }
The following code could be used:
#define oc_rep_i_set_byte_string | ( | object, | |
key, | |||
value, | |||
length | |||
) |
Add an byte array value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value Note using base64 encoding in the following example string.
{ 3 : "AAECAwQF" }
The following code could be used:
#define oc_rep_i_set_double | ( | object, | |
key, | |||
value | |||
) |
Add a double value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 5 : 3.14159 }
The following code could be used:
#define oc_rep_i_set_double_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a double array with values
of length
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 6 : [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_i_set_float | ( | object, | |
key, | |||
value | |||
) |
Add a float value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 5 : 3.14159 }
The following code could be used:
#define oc_rep_i_set_float_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a float array with values
of length
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 6 : [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_i_set_float_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a float array with values
of length
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 6 : [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_i_set_int | ( | object, | |
key, | |||
value | |||
) |
Add an integer value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 5 : 42 }
The following code could be used:
#define oc_rep_i_set_int_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add an integer array with values
of length
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 3 : [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ] }
The following code could be used:
#define oc_rep_i_set_key | ( | parent, | |
key | |||
) |
End users are very unlikely to use this macro.
This will add a key
as integer to a parent
object.
This is almost always followed by oc_rep_begin_array to build an array when the number of items being placed in the array are not known before the end of the array.
See oc_rep_begin_array for example code
#define oc_rep_i_set_string_array | ( | object, | |
key, | |||
values | |||
) |
Add a string array using an oc_string_array_t as values
to the cbor object
under the integer key
name.
Example:
To build the an object with the following cbor value
{ 4 : [ "Do not take life too seriously. You will never get out of it alive.", "All generalizations are false, including this one.", "Those who believe in telekinetics, raise my hand.", "I refuse to join any club that would have me as a member." ] }
The following code could be used:
#define oc_rep_i_set_text_string | ( | object, | |
key, | |||
value | |||
) |
Add an string value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 4 : "Hello, world!" }
The following code could be used:
#define oc_rep_i_set_uint | ( | object, | |
key, | |||
value | |||
) |
Add an unsigned integer value
to the cbor object
under the integer key
name Example:
To build the an object with the following cbor value
{ 5: 42 }
The following code could be used:
Note: when the cbor object is converted to a oc_rep_the data type will be encoded as an OC_REP_INT. There is no way for a client to know that the server sent the INT as an unsigned value.
#define oc_rep_object | ( | name | ) | &name##_map |
#define oc_rep_object_array_begin_item | ( | key | ) | oc_rep_begin_object(&key##_array, key) |
Begin a cbor object for an array of cbor objects.
The key
is the name of the array object.
Example:
To build the an object with the following cbor value
{ "space2001": [ {"name": "Dave Bowman", "job": "astronaut"}, {"name": "Frank Poole", "job": "astronaut"}, {"name": "Hal 9000", "job": "AI computer"} ] }
The following code could be used:
#define oc_rep_object_array_end_item | ( | key | ) | oc_rep_end_object(&key##_array, key) |
#define oc_rep_object_array_start_item | ( | key | ) | oc_rep_object_array_begin_item(key) |
This macro has been replaced with oc_rep_object_array_begin_item.
#define oc_rep_open_array | ( | parent, | |
key | |||
) |
Open a cbor array object belonging to parent
object under the key
name.
Items can then be added to the array till oc_rep_close_array is called.
Most common array types such as int
, bool
, double
, float
and strings
have specific macros for handling those array types. This macro will mostly be used to make arrays where the length is unknown ahead of time or to make an array of other objects.
For and example of this macro being used see oc_rep_object_array_begin_item.
#define oc_rep_open_object | ( | parent, | |
key | |||
) |
Open a cbor object belonging to parent
object under the key
name.
Items can then be added to the array till oc_rep_close_object is called.
Example:
To build the an object with the following cbor value
{ "my_object": { "a": 1 "b": false "c": "three" } }
The following code could be used:
#define oc_rep_set_array | ( | object, | |
key | |||
) | oc_rep_open_array(object, key) |
This macro has been replaced with oc_rep_open_array.
#define oc_rep_set_bool_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a boolean array with values
of length
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "flip": [ false, false, true, false, false ] }
The following code could be used:
#define oc_rep_set_boolean | ( | object, | |
key, | |||
value | |||
) |
Add an boolean value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "door_open": false }
The following code could be used:
#define oc_rep_set_byte_string | ( | object, | |
key, | |||
value, | |||
length | |||
) |
Add an byte array value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value Note using base64 encoding in the following example string.
{ "byte_string_key": "AAECAwQF" }
The following code could be used:
#define oc_rep_set_double | ( | object, | |
key, | |||
value | |||
) |
Add a double value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "pi": 3.14159 }
The following code could be used:
#define oc_rep_set_double_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a double array with values
of length
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "math_constants": [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_set_float | ( | object, | |
key, | |||
value | |||
) |
Add a float value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "pi": 3.14159 }
The following code could be used:
#define oc_rep_set_float_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a float array with values
of length
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "math_constants": [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_set_float_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add a float array with values
of length
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "math_constants": [ 3.14159, 2.71828, 1.414121, 1.61803 ] }
The following code could be used:
#define oc_rep_set_int | ( | object, | |
key, | |||
value | |||
) |
Add an integer value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "power": 42 }
The following code could be used:
#define oc_rep_set_int_array | ( | object, | |
key, | |||
values, | |||
length | |||
) |
Add an integer array with values
of length
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "fibonacci": [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ] }
The following code could be used:
#define oc_rep_set_key | ( | parent, | |
key | |||
) |
End users are very unlikely to use this macro.
This will add a key
to a parent
object.
This is almost always followed by oc_rep_begin_array to build an array when the number of items being placed in the array are not known before the end of the array.
See oc_rep_begin_array for example code
#define oc_rep_set_object | ( | object, | |
key | |||
) | oc_rep_open_object(object, key) |
This macro has been replaced with oc_rep_open_object.
#define oc_rep_set_string_array | ( | object, | |
key, | |||
values | |||
) |
Add a string array using an oc_string_array_t as values
to the cbor object
under the key
name.
Example:
To build the an object with the following cbor value
{ "quotes": [ "Do not take life too seriously. You will never get out of it alive.", "All generalizations are false, including this one.", "Those who believe in telekinetics, raise my hand.", "I refuse to join any club that would have me as a member." ] }
The following code could be used:
#define oc_rep_set_text_string | ( | object, | |
key, | |||
value | |||
) |
Add an string value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "greeting": "Hello, world!" }
The following code could be used:
#define oc_rep_set_text_string_no_tag | ( | object, | |
value | |||
) |
Add an string value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "Hello, world!" }
The following code could be used:
#define oc_rep_set_uint | ( | object, | |
key, | |||
value | |||
) |
Add an unsigned integer value
to the cbor object
under the key
name Example:
To build the an object with the following cbor value
{ "power": 42 }
The following code could be used:
Note: when the cbor object is converted to a oc_rep_the data type will be encoded as an OC_REP_INT. There is no way for a client to know that the server sent the INT as an unsigned value.
#define oc_rep_set_value_text_string | ( | parent, | |
value | |||
) |
#define oc_rep_start_array | ( | parent, | |
name | |||
) | oc_rep_begin_array(parent, name) |
This macro has been replaced with oc_rep_begin_array.
#define oc_rep_start_object | ( | parent, | |
key | |||
) | oc_rep_begin_object(parent, key) |
This macro has been replaced with oc_rep_begin_object.
parsed entry of a cbor object This represents a link list of response values one can iterate over the responses to find values by
void oc_print_rep_as_json | ( | oc_rep_t * | rep, |
bool | pretty_print | ||
) |
prints the response tree as JSON to the output pretty_print: true: nicely formatted JSON on multiple lines false: JSON formatted on a single line
rep | the response tree |
pretty_print | true: nicely formatted json |
int oc_rep_add_line_size_to_buffer | ( | const char * | line, |
int | len | ||
) |
add a line to the response buffer note updates the occupied size in the response buffer
line | data to be added |
len | the length of the line data to be added |
int oc_rep_add_line_to_buffer | ( | const char * | line | ) |
add a line to the response buffer note updates the occupied size in the response buffer
line | data to be added |
void oc_rep_encode_raw | ( | const uint8_t * | data, |
size_t | len | ||
) |
Encode raw data, as if it was already encoded.
using the global encoder.
data | Pointer to data to be encoded. Will be copied into the global buffer. |
len | Length of data. |
void oc_rep_encode_raw_encoder | ( | CborEncoder * | encoder, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Encode raw data, as if it was already encoded.
encoder | The encoder to be used. |
data | Pointer to data to be encoded. Will be copied into the global buffer. |
len | Length of data. |
bool oc_rep_get_bool | ( | oc_rep_t * | rep, |
const char * | key, | ||
bool * | value | ||
) |
Read a boolean value from an oc_rep_t
Example:
rep | oc_rep_t to read boolean value from |
key | the key name for the boolean value |
value | the return boolean value |
bool oc_rep_get_bool_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
bool ** | value, | ||
size_t * | size | ||
) |
Read an boolean array value from an oc_rep_t
Example:
rep | oc_rep_t to boolean array value from |
key | the key name for the boolean array value |
value | the return boolean array value |
size | the size of the boolean array |
bool oc_rep_get_byte_string | ( | oc_rep_t * | rep, |
const char * | key, | ||
char ** | value, | ||
size_t * | size | ||
) |
Read a byte string value from an oc_rep_t
Example:
rep | oc_rep_t to read byte string value from |
key | the key name for the byte string value |
value | the return byte string value |
size | the size of the byte string |
bool oc_rep_get_byte_string_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
oc_string_array_t * | value, | ||
size_t * | size | ||
) |
Read an byte string array value from an oc_rep_t
Example:
rep | oc_rep_t to byte string array value from |
key | the key name for the byte string array value |
value | the return byte string array value |
size | the size of the byte string array |
CborError oc_rep_get_cbor_errno | ( | void | ) |
Called after any oc_rep_set_*
, oc_rep_start_*
, oc_rep_begin_*
, oc_rep_end_*
, oc_rep_add_*
, oc_rep_open_*
, and oc_rep_close_*
macros to check if an error occurred while executing the commands.
If the value returned is anything other than CborNoError
then one of the oc_rep_*
macros failed.
The error returned is not automatically cleared. To clear the error set g_err to CborNoError
.
bool oc_rep_get_double | ( | oc_rep_t * | rep, |
const char * | key, | ||
double * | value | ||
) |
Read a double value from an oc_rep_t
Example:
rep | oc_rep_t to read double value from |
key | the key name for the double value |
value | the return double value |
bool oc_rep_get_double_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
double ** | value, | ||
size_t * | size | ||
) |
Read an double array value from an oc_rep_t
Example:
rep | oc_rep_t to double array value from |
key | the key name for the double array value |
value | the return double array value |
size | the size of the double array |
int oc_rep_get_encoded_payload_size | ( | void | ) |
Get the size of the cbor encoded data.
This can be used to check if the cbor encode data will fit inside the payload buffer. If the payload buffer is too small -1 is returned.
const uint8_t* oc_rep_get_encoder_buf | ( | void | ) |
Get the buffer pointer at the start of the encoded cbor data.
This is used when parsing the encoded cbor data to an oc_rep_t. It is unlikely to be used outside the stack library.
bool oc_rep_get_float | ( | oc_rep_t * | rep, |
const char * | key, | ||
float * | value | ||
) |
Read a float value from an oc_rep_t
Example:
rep | oc_rep_t to read float value from |
key | the key name for the float value |
value | the return float value |
bool oc_rep_get_float_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
float ** | value, | ||
size_t * | size | ||
) |
Read an float array value from an oc_rep_t
Example:
rep | oc_rep_t to float array value from |
key | the key name for the float array value |
value | the return float array value |
size | the size of the float array |
bool oc_rep_get_int | ( | oc_rep_t * | rep, |
const char * | key, | ||
int64_t * | value | ||
) |
Read an integer from an oc_rep_t
Example:
rep | oc_rep_t to read int value from |
key | the key name for the integer value |
value | the return integer value |
bool oc_rep_get_int_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
int64_t ** | value, | ||
size_t * | size | ||
) |
Read an integer array value from an oc_rep_t
Example:
rep | oc_rep_t to integer array value from |
key | the key name for the integer array value |
value | the return integer array value |
size | the size of the integer array |
Read a mixed array value from an oc_rep_t
Calling the returned value an array is a misnomer. The value actually returned is a linked list of oc_rep_t objects. The linked list must be walked to see each item in the mixed array.
Example:
rep | oc_rep_t to read mixed array value from |
key | the key name for the mixed array value |
value | the return mixed array value |
Read a object value from an oc_rep_t
Example:
rep | oc_rep_t to read object value from |
key | the key name for the object value |
value | the return object value |
Read a object array value from an oc_rep_t
Calling the returned value an array is a misnomer. The value actually returned is a linked list of oc_rep_t objects. The linked list must be walked to see each item in the object array.
Example:
rep | oc_rep_t to read object array value from |
key | the key name for the object array value |
value | the return object array value |
bool oc_rep_get_string | ( | oc_rep_t * | rep, |
const char * | key, | ||
char ** | value, | ||
size_t * | size | ||
) |
Read a text string value from an oc_rep_t
Example:
rep | oc_rep_t to read string value from |
key | the key name for the string value |
value | the return string value |
size | the size of the string |
bool oc_rep_get_string_array | ( | oc_rep_t * | rep, |
const char * | key, | ||
oc_string_array_t * | value, | ||
size_t * | size | ||
) |
Read a string array value from an oc_rep_t
Example:
rep | oc_rep_t to string array value from |
key | the key name for the string array value |
value | the return string array value |
size | the size of the string array |
bool oc_rep_i_get_bool | ( | oc_rep_t * | rep, |
int | key, | ||
bool * | value | ||
) |
Read a boolean value from an oc_rep_t
with key as integer.
Example:
rep | oc_rep_t to read boolean value from |
key | the integer key name for the boolean value |
value | the return boolean value |
bool oc_rep_i_get_bool_array | ( | oc_rep_t * | rep, |
int | key, | ||
bool ** | value, | ||
size_t * | size | ||
) |
Read an boolean array value from an oc_rep_t
with integer key.
Example:
rep | oc_rep_t to boolean array value from |
key | the key name for the boolean array value |
value | the return boolean array value |
size | the size of the boolean array |
bool oc_rep_i_get_byte_string | ( | oc_rep_t * | rep, |
int | key, | ||
char ** | value, | ||
size_t * | size | ||
) |
Read a byte string value from an oc_rep_t
with an integer key.
Example:
rep | oc_rep_t to read byte string value from |
key | the key name for the byte string value |
value | the return byte string value |
size | the size of the byte string |
bool oc_rep_i_get_byte_string_array | ( | oc_rep_t * | rep, |
int | key, | ||
oc_string_array_t * | value, | ||
size_t * | size | ||
) |
Read an byte string array value from an oc_rep_t
with integer key.
Example:
rep | oc_rep_t to byte string array value from |
key | the key name for the byte string array value |
value | the return byte string array value |
size | the size of the byte string array |
bool oc_rep_i_get_double | ( | oc_rep_t * | rep, |
int | key, | ||
double * | value | ||
) |
Read a double value from an oc_rep_t
Example:
rep | oc_rep_t to read double value from |
key | the key name for the double value, as integer |
value | the return double value |
bool oc_rep_i_get_double_array | ( | oc_rep_t * | rep, |
int | key, | ||
double ** | value, | ||
size_t * | size | ||
) |
Read an double array value from an oc_rep_t
with an integer key.
Example:
rep | oc_rep_t to double array value from |
key | the key name for the double array value |
value | the return double array value |
size | the size of the double array |
bool oc_rep_i_get_float | ( | oc_rep_t * | rep, |
int | key, | ||
float * | value | ||
) |
Read a float value from an oc_rep_t
Example:
rep | oc_rep_t to read float value from |
key | the key name for the float value, as integer |
value | the return float value |
bool oc_rep_i_get_float_array | ( | oc_rep_t * | rep, |
int | key, | ||
float ** | value, | ||
size_t * | size | ||
) |
Read an float array value from an oc_rep_t
with an integer key.
Example:
rep | oc_rep_t to float array value from |
key | the key name for the float array value |
value | the return float array value |
size | the size of the float array |
bool oc_rep_i_get_int | ( | oc_rep_t * | rep, |
int | key, | ||
int64_t * | value | ||
) |
Read an integer from an oc_rep_t
with an integer as key.
Example:
rep | oc_rep_t to read int value from |
key | the key name for the integer value |
value | the return integer value |
bool oc_rep_i_get_int_array | ( | oc_rep_t * | rep, |
int | key, | ||
int64_t ** | value, | ||
size_t * | size | ||
) |
Read an integer array value from an oc_rep_t
with an integer key.
Example:
rep | oc_rep_t to integer array value from |
key | the key name for the integer array value |
value | the return integer array value |
size | the size of the integer array |
Read a mixed array value from an oc_rep_t
with integer key.
Calling the returned value an array is a misnomer. The value actually returned is a linked list of oc_rep_t objects. The linked list must be walked to see each item in the mixed array.
Example:
rep | oc_rep_t to read mixed array value from |
key | the key name for the mixed array value |
value | the return mixed array value |
Read a object value from an oc_rep_t
with integer key.
Example:
rep | oc_rep_t to read object value from |
key | the key name for the object value |
value | the return object value |
Read a object array value from an oc_rep_t
with integer key.
Calling the returned value an array is a misnomer. The value actually returned is a linked list of oc_rep_t objects. The linked list must be walked to see each item in the object array.
Example:
rep | oc_rep_t to read object array value from |
key | the key name for the object array value |
value | the return object array value |
bool oc_rep_i_get_string | ( | oc_rep_t * | rep, |
int | key, | ||
char ** | value, | ||
size_t * | size | ||
) |
Read a text string value from an oc_rep_t
with integer key.
Example:
rep | oc_rep_t to read string value from |
key | the key name for the string value |
value | the return string value |
size | the size of the string |
bool oc_rep_i_get_string_array | ( | oc_rep_t * | rep, |
int | key, | ||
oc_string_array_t * | value, | ||
size_t * | size | ||
) |
Read a string array value from an oc_rep_t
with integer key.
Example:
rep | oc_rep_t to string array value from |
key | the key name for the string array value |
value | the return string array value |
size | the size of the string array |
void oc_rep_new | ( | uint8_t * | payload, |
int | size | ||
) |
Initialize the buffer used to hold the cbor encoded data.
Unlikely to be used by outside the stack library.
[in] | payload | pointer to payload buffer |
[in] | size | the size of the payload buffer |
size_t oc_rep_to_json | ( | oc_rep_t * | rep, |
char * | buf, | ||
size_t | buf_size, | ||
bool | pretty_print | ||
) |
Convert an oc_rep_t to JSON encoded string.
An oc_rep_t that is NULL or empty will return as an empty JSON object "{}".
All binary data will be encoded to a string using base64 encoding.
Converting binary data to a base64 encoded string is only done if the buf
can hold the entire base64 string. If the resulting base64 string would overflow the buffer nothing is placed in the buffer.
The function will not write more than buf_size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available. Thus, a return value of buf_size or more means that the output was truncated.
NOTE: if the key is an integer, the key will be printed as string e.g. "5". integers with value 0 will not be framed.
[in] | rep | the oc_rep_t object to be converted to JSON |
[out] | buf | a char array that will hold the JSON encoded string. |
[in] | buf_size | the size of the passed in char array |
[in] | pretty_print | if true extra white space and new lines will be added to the output making it more human readable. Note return value will differ if pretty_print value is changed. |
Example: