Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
astarte_bson.h File Reference

Astarte BSON deserialization functions. More...

#include "astarte.h"
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for astarte_bson.h:

Go to the source code of this file.

Functions

const void * astarte_bson_key_lookup (const char *key, const void *document, uint8_t *type) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_lookup' function " "in astarte_bson_deserializer.h")))
 Look up the key from the document and return a pointer to the appropriate entry. More...
 
const void * astarte_bson_first_item (const void *document) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_first_element' function " "in astarte_bson_deserializer.h")))
 Get a pointer to the first item in a document's list. More...
 
void * astarte_bson_next_item (const void *document, const void *current_item) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_next_element' function " "in astarte_bson_deserializer.h")))
 Get a pointer to the next item in a document's list. More...
 
const char * astarte_bson_key (const void *item) __attribute__((deprecated("Please use the deserialization functions in astarte_bson_deserializer.h")))
 Get a pointer to the string containing an element name. More...
 
const char * astarte_bson_value_to_string (const void *value_ptr, uint32_t *len) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_string' function " "in astarte_bson_deserializer.h")))
 Parse a BSON string and return a pointer to the beginning of the UTF-8 string. More...
 
const char * astarte_bson_value_to_binary (const void *value_ptr, uint32_t *len) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_binary' function " "in astarte_bson_deserializer.h")))
 Parse a BSON binary and return a pointer to the beginning of the byte array. More...
 
const void * astarte_bson_value_to_document (const void *value_ptr, uint32_t *len) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_document' function " "in astarte_bson_deserializer.h")))
 Parse a BSON document and return a pointer to the beginning of the document. More...
 
int8_t astarte_bson_value_to_int8 (const void *value_ptr) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_bool' function " "in astarte_bson_deserializer.h")))
 Cast the input element to a int8. More...
 
int32_t astarte_bson_value_to_int32 (const void *value_ptr) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_int32' function " "in astarte_bson_deserializer.h")))
 Cast the input element to a int32. More...
 
int64_t astarte_bson_value_to_int64 (const void *value_ptr) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_int64' function " "in astarte_bson_deserializer.h")))
 Cast the input element to a int64. More...
 
double astarte_bson_value_to_double (const void *value_ptr) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_element_to_double' function " "in astarte_bson_deserializer.h")))
 Cast the input element to a double. More...
 
bool astarte_bson_check_validity (const void *document, unsigned int file_size) __attribute__((deprecated("Please use the 'astarte_bson_deserializer_check_validity' function " "in astarte_bson_deserializer.h")))
 Perform some checks on the validity of the BSON. More...
 
uint32_t astarte_bson_document_size (const void *document) __attribute__((deprecated("Please use the deserialization functions in astarte_bson_deserializer.h")))
 Get the size of the document. More...
 

Detailed Description

Astarte BSON deserialization functions.

This library follows the v1.1 of the BSON standard, but does not provide support for the full specification, only for a smaller subset. For more information regarding the BSON format specifications see: https://bsonspec.org/spec.html.

Function Documentation

◆ astarte_bson_check_validity()

bool astarte_bson_check_validity ( const void *  document,
unsigned int  file_size 
)

Perform some checks on the validity of the BSON.

Note
This function performs a very rough validation check. It is quite possible a malformed bson file would still pass this check.
Deprecated, call astarte_bson_deserializer_check_validity() instead.
Parameters
[in]documentDocument for which to calculate the size.
[in]file_sizeSize of the allocated buffer containing document.
Returns
True when BSON file is valid, false otherwise.

◆ astarte_bson_document_size()

uint32_t astarte_bson_document_size ( const void *  document)

Get the size of the document.

Note
Deprecated, use the functions contained in astarte_bson_deserializer.h instead.
Parameters
[in]documentDocument for which to calculate the size.
Returns
Size of the document.

◆ astarte_bson_first_item()

const void* astarte_bson_first_item ( const void *  document)

Get a pointer to the first item in a document's list.

N.B. The return value points to the beginning of the element, to the element type.

Note
Deprecated, call astarte_bson_deserializer_first_element() instead.
Parameters
[in]documentDocument containing the list.
Returns
Pointer to the first element. NULL when no next element exists.

◆ astarte_bson_key()

const char* astarte_bson_key ( const void *  item)

Get a pointer to the string containing an element name.

Note
Deprecated, use the functions contained in astarte_bson_deserializer.h instead.
Parameters
[in]itemPointer to the element from which the key should be extracted.
Returns
Pointer to the beginning of the name of the element.

◆ astarte_bson_key_lookup()

const void* astarte_bson_key_lookup ( const char *  key,
const void *  document,
uint8_t *  type 
)

Look up the key from the document and return a pointer to the appropriate entry.

This function loops over all the elements in the document's list and return a pointer to the first element with a name matching the specified key. N.B. The return value points to the content of the element, past the element type and name.

Note
Deprecated, call astarte_bson_deserializer_element_lookup() instead.
Parameters
[in]keyString representing the key to find in the document.
[in]documentDocument to use for the search.
[out]typeReturned element type, see 'astarte_bson_types.h' for its possible values.
Returns
Pointer to the content of the element matched by the key. NULL when the key has not been matched or the BSON file is malformed.

◆ astarte_bson_next_item()

void* astarte_bson_next_item ( const void *  document,
const void *  current_item 
)

Get a pointer to the next item in a document's list.

N.B. The return value points to the beginning of the element, to the element type.

Note
Deprecated, call astarte_bson_deserializer_next_element() instead.
Parameters
[in]documentDocument containing the list.
[in]current_itemPointer to the current element.
Returns
Pointer to the next element. NULL when no next element exists.

◆ astarte_bson_value_to_binary()

const char* astarte_bson_value_to_binary ( const void *  value_ptr,
uint32_t *  len 
)

Parse a BSON binary and return a pointer to the beginning of the byte array.

Note
Deprecated, call astarte_bson_deserializer_element_to_binary() instead.
Parameters
[in]value_ptrPointer to the value to parse.
[out]lenSize of the parsed byte array.
Returns
Pointer to the beginning of the byte array.

◆ astarte_bson_value_to_document()

const void* astarte_bson_value_to_document ( const void *  value_ptr,
uint32_t *  len 
)

Parse a BSON document and return a pointer to the beginning of the document.

This function does not perform actual parsing, using the original pointer as a document would work in the exact same way.

Note
Deprecated, call astarte_bson_deserializer_element_to_document() instead.
Parameters
[in]value_ptrPointer to the value to parse.
[out]lenSize of the document.
Returns
Pointer to the beginning of the document.

◆ astarte_bson_value_to_double()

double astarte_bson_value_to_double ( const void *  value_ptr)

Cast the input element to a double.

Note
Deprecated, call astarte_bson_deserializer_element_to_double() instead.
Parameters
[in]value_ptrPointer to the value to parse.
Returns
Casted value.

◆ astarte_bson_value_to_int32()

int32_t astarte_bson_value_to_int32 ( const void *  value_ptr)

Cast the input element to a int32.

Note
Deprecated, call astarte_bson_deserializer_element_to_int32() instead.
Parameters
[in]value_ptrPointer to the value to parse.
Returns
Casted value.

◆ astarte_bson_value_to_int64()

int64_t astarte_bson_value_to_int64 ( const void *  value_ptr)

Cast the input element to a int64.

Note
Deprecated, call astarte_bson_deserializer_element_to_int64() instead.
Parameters
[in]value_ptrPointer to the value to parse.
Returns
Casted value.

◆ astarte_bson_value_to_int8()

int8_t astarte_bson_value_to_int8 ( const void *  value_ptr)

Cast the input element to a int8.

This function does not perform actual parsing, performing a manual casting would work in the same way.

Note
Deprecated, call astarte_bson_deserializer_element_to_bool() instead.
Parameters
[in]value_ptrPointer to the value to parse.
Returns
Casted value.

◆ astarte_bson_value_to_string()

const char* astarte_bson_value_to_string ( const void *  value_ptr,
uint32_t *  len 
)

Parse a BSON string and return a pointer to the beginning of the UTF-8 string.

Note
Deprecated, call astarte_bson_deserializer_element_to_string() instead.
Parameters
[in]value_ptrPointer to the value to parse.
[out]lenSize of the parsed string.
Returns
Pointer to the begginning of the UTF-8 string.