Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
|
Astarte BSON serializer functions. More...
Go to the source code of this file.
Data Structures | |
struct | astarte_byte_array_t |
struct | astarte_bson_serializer_t |
Functions | |
void | astarte_bson_serializer_init (struct astarte_bson_serializer_t *bs) |
initialize given BSON serializer. More... | |
void | astarte_bson_serializer_destroy (struct astarte_bson_serializer_t *bs) |
destroy given BSON serializer. More... | |
const void * | astarte_bson_serializer_get_document (const struct astarte_bson_serializer_t *bs, int *size) |
return bson serializer internal buffer. More... | |
astarte_err_t | astarte_bson_serializer_write_document (const struct astarte_bson_serializer_t *bs, void *out_buf, int out_buf_len, int *out_doc_size) |
copy bson serializer internal buffer to a different buffer. More... | |
int | astarte_bson_serializer_document_size (const struct astarte_bson_serializer_t *bs) |
return document size More... | |
void | astarte_bson_serializer_append_end_of_document (struct astarte_bson_serializer_t *bs) |
append end of document marker. More... | |
void | astarte_bson_serializer_append_double (struct astarte_bson_serializer_t *bs, const char *name, double value) |
append a double value More... | |
void | astarte_bson_serializer_append_int32 (struct astarte_bson_serializer_t *bs, const char *name, int32_t value) |
append an int32 value More... | |
void | astarte_bson_serializer_append_int64 (struct astarte_bson_serializer_t *bs, const char *name, int64_t value) |
append an int64 value More... | |
void | astarte_bson_serializer_append_binary (struct astarte_bson_serializer_t *bs, const char *name, const void *value, int size) |
append a binary blob value More... | |
void | astarte_bson_serializer_append_string (struct astarte_bson_serializer_t *bs, const char *name, const char *string) |
append an UTF-8 string More... | |
void | astarte_bson_serializer_append_datetime (struct astarte_bson_serializer_t *bs, const char *name, uint64_t epoch_millis) |
append a date time value More... | |
void | astarte_bson_serializer_append_boolean (struct astarte_bson_serializer_t *bs, const char *name, bool value) |
append a boolean value More... | |
void | astarte_bson_serializer_append_document (struct astarte_bson_serializer_t *bs, const char *name, const void *document) |
append a sub-BSON document. More... | |
void | astarte_bson_serializer_append_double_array (struct astarte_bson_serializer_t *bs, const char *name, const double *double_array, int count) |
append a double array More... | |
void | astarte_bson_serializer_append_int32_array (struct astarte_bson_serializer_t *bs, const char *name, const int32_t *int32_array, int count) |
append an int32 array More... | |
void | astarte_bson_serializer_append_int64_array (struct astarte_bson_serializer_t *bs, const char *name, const int64_t *int64_array, int count) |
append an int64 array More... | |
void | astarte_bson_serializer_append_string_array (struct astarte_bson_serializer_t *bs, const char *name, const char *const *string_array, int count) |
append a string array More... | |
void | astarte_bson_serializer_append_binary_array (struct astarte_bson_serializer_t *bs, const char *name, const void *const *binary_array, const int *sizes, int count) |
append a binary blob array More... | |
void | astarte_bson_serializer_append_datetime_array (struct astarte_bson_serializer_t *bs, const char *name, const int64_t *epoch_millis_array, int count) |
append a date time array More... | |
void | astarte_bson_serializer_append_boolean_array (struct astarte_bson_serializer_t *bs, const char *name, const bool *boolean_array, int count) |
append a boolean array More... | |
Astarte BSON serializer functions.
void astarte_bson_serializer_append_binary | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const void * | value, | ||
int | size | ||
) |
append a binary blob value
This function appends a binary blob to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | the buffer that holds the binary blob. |
binary | blob size in bytes. |
void astarte_bson_serializer_append_binary_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const void *const * | binary_array, | ||
const int * | sizes, | ||
int | count | ||
) |
append a binary blob array
This function appends a binary blob array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
binarty_array | an array of binary blobs (void *). |
sizes | an array with the sizes of each binary in binary_array parameter. |
count | the number of items stored in binary_array. |
void astarte_bson_serializer_append_boolean | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
bool | value | ||
) |
append a boolean value
This function appends a boolean value to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | 0 as false value, not 0 as true value. |
void astarte_bson_serializer_append_boolean_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const bool * | boolean_array, | ||
int | count | ||
) |
append a boolean array
This function appends a boolean array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
boolean_array | an array of stdbool booleans. |
count | the number of items stored in boolean_array. |
void astarte_bson_serializer_append_datetime | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
uint64_t | epoch_millis | ||
) |
append a date time value
This function appends a date time value to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | a 64 bits unsigned integer storing date time in milliseconds since epoch. |
void astarte_bson_serializer_append_datetime_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const int64_t * | epoch_millis_array, | ||
int | count | ||
) |
append a date time array
This function appends a date time array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
epoch_millis_array | an array of 64 bits unsigned integer storing date time in milliseconds since epoch. |
count | the number of items stored in epoch_millis_array. |
void astarte_bson_serializer_append_document | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const void * | document | ||
) |
append a sub-BSON document.
This function appends a BSON subdocument to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
document | a valid BSON document (that has been already terminated). |
void astarte_bson_serializer_append_double | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
double | value | ||
) |
append a double value
This function appends a double value to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | a double floating point value. |
void astarte_bson_serializer_append_double_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const double * | double_array, | ||
int | count | ||
) |
append a double array
This function appends a double array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
double_array | an array of doubles. |
count | the number of items stored in double_array. |
void astarte_bson_serializer_append_end_of_document | ( | struct astarte_bson_serializer_t * | bs | ) |
append end of document marker.
BSON document MUST be manually terminated with an end of document marker.
bs | a astarte_bson_serializer_t. |
void astarte_bson_serializer_append_int32 | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
int32_t | value | ||
) |
append an int32 value
This function appends an int32 value to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | a 32 bits signed integer value. |
void astarte_bson_serializer_append_int32_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const int32_t * | int32_array, | ||
int | count | ||
) |
append an int32 array
This function appends an int32 array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
int32_array | an array of signed 32 bit integers. |
count | the number of items stored in int32_array. |
void astarte_bson_serializer_append_int64 | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
int64_t | value | ||
) |
append an int64 value
This function appends an int64 value to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | a 64 bits signed integer value. |
void astarte_bson_serializer_append_int64_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const int64_t * | int64_array, | ||
int | count | ||
) |
append an int64 array
This function appends an int64 array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
int64_array | an array of signed 64 bit integers. |
count | the number of items stored in int64_array. |
void astarte_bson_serializer_append_string | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const char * | string | ||
) |
append an UTF-8 string
This function appends an UTF-8 string to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
value | a 0 terminated UTF-8 string. |
void astarte_bson_serializer_append_string_array | ( | struct astarte_bson_serializer_t * | bs, |
const char * | name, | ||
const char *const * | string_array, | ||
int | count | ||
) |
append a string array
This function appends a string array to the document. Stored value can be fetched using given key.
bs | a astarte_bson_serializer_t. |
name | BSON key, which is a C string. |
string_array | an array of 0 terminated UTF-8 strings. |
count | the number of items stored in string_array. |
void astarte_bson_serializer_destroy | ( | struct astarte_bson_serializer_t * | bs | ) |
destroy given BSON serializer.
This function has to be called to destroy and free astarte_bson_serializer_t memory.
bs | an astarte_bson_serializer_t that will be destroyed. |
int astarte_bson_serializer_document_size | ( | const struct astarte_bson_serializer_t * | bs | ) |
return document size
This function returns BSON document size in bytes.
bs | a astarte_bson_serializer_t. |
const void* astarte_bson_serializer_get_document | ( | const struct astarte_bson_serializer_t * | bs, |
int * | size | ||
) |
return bson serializer internal buffer.
This function might be used to get internal buffer without any data copy. Returned buffer will be invalid after serializer destruction.
bs | a astarte_bson_serializer_t. |
void astarte_bson_serializer_init | ( | struct astarte_bson_serializer_t * | bs | ) |
initialize given BSON serializer.
This function has to be called to initialize and allocate memory for astarte_bson_serializer_t.
bs | an astarte_bson_serializer_t that will be initialized. |
astarte_err_t astarte_bson_serializer_write_document | ( | const struct astarte_bson_serializer_t * | bs, |
void * | out_buf, | ||
int | out_buf_len, | ||
int * | out_doc_size | ||
) |
copy bson serializer internal buffer to a different buffer.
This function should be used to get a copy of the BSON document data. end of document should be called before calling this function.
bs | a astarte_bson_serializer_t. |
out_buf | destination buffer. |
out_buf_len | destination buffer length. |
out_doc_size | BSON document size (that is <= out_buf_len). |