The friendly Operating System for the Internet of Things
ubjson.h File Reference

Headers for the UBJSON module. More...

Detailed Description

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
+ Include dependency graph for ubjson.h:

Go to the source code of this file.

Data Structures

struct  ubjson_cookie
 See ubjson_cookie_t. More...
 

Typedefs

typedef struct ubjson_cookie ubjson_cookie_t
 A cookie passed between the read and write functions. More...
 
typedef ssize_t(* ubjson_read_t) (ubjson_cookie_t *__restrict cookie, void *buf, size_t max_len)
 Method called by ubjson_read() to get more data. More...
 
typedef ubjson_read_callback_result_t(* ubjson_read_callback_t) (ubjson_cookie_t *__restrict cookie, ubjson_type_t type1, ssize_t content1, ubjson_type_t type2, ssize_t content2)
 Method called by ubjson_read() to denote the next element in the structure. More...
 
typedef ssize_t(* ubjson_write_t) (ubjson_cookie_t *__restrict cookie, const void *buf, size_t len)
 Method called by ubjson_write_null() and friends. More...
 

Enumerations

enum  ubjson_type_t {
  UBJSON_ABSENT, UBJSON_TYPE_NULL, UBJSON_TYPE_NOOP, UBJSON_TYPE_BOOL,
  UBJSON_TYPE_INT32, UBJSON_TYPE_INT64, UBJSON_TYPE_FLOAT, UBJSON_TYPE_DOUBLE,
  UBJSON_TYPE_STRING, UBJSON_ENTER_ARRAY, UBJSON_ENTER_OBJECT, UBJSON_INDEX,
  UBJSON_KEY
}
 Status code of ubjson_read(), ubjson_read_array() and ubjson_read_object() callback. More...
 
enum  ubjson_int32_type_t { UBJSON_INT32_INT8, UBJSON_INT32_UINT8, UBJSON_INT32_INT16, UBJSON_INT32_INT32 }
 Length of the UBJSON_TYPE_INT32 datum. More...
 
enum  ubjson_read_callback_result_t {
  UBJSON_OKAY, UBJSON_ABORTED, UBJSON_INVALID_DATA, UBJSON_PREMATURELY_ENDED,
  UBJSON_SIZE_ERROR
}
 Return value of ubjson_read_callback_t and ubjson_read() More...
 

Functions

ubjson_read_callback_result_t ubjson_read_next (ubjson_cookie_t *__restrict cookie)
 Used to read with a setup cookie. More...
 
static ubjson_read_callback_result_t ubjson_read (ubjson_cookie_t *__restrict cookie, ubjson_read_t read, ubjson_read_callback_t callback)
 The entry function to read UBJSON serialized data. More...
 
ubjson_read_callback_result_t ubjson_peek_value (ubjson_cookie_t *__restrict cookie, ubjson_type_t *type, ssize_t *content)
 Use in a callback if type1 is UBJSON_KEY or UBJSON_INDEX. More...
 
ssize_t ubjson_get_i32 (ubjson_cookie_t *__restrict cookie, ssize_t content, int32_t *dest)
 Call if type1 of the callback was UBJSON_TYPE_INT32. More...
 
ssize_t ubjson_get_i64 (ubjson_cookie_t *__restrict cookie, ssize_t content, int64_t *dest)
 Call if type1 of the callback was UBJSON_TYPE_INT64. More...
 
ssize_t ubjson_get_string (ubjson_cookie_t *__restrict cookie, ssize_t content, void *dest)
 Call if type1 of the callback was UBJSON_TYPE_STRING. More...
 
static ssize_t ubjson_get_bool (ubjson_cookie_t *__restrict cookie, ssize_t content, bool *dest)
 Call if type1 of the callback was UBJSON_TYPE_BOOL. More...
 
static ssize_t ubjson_get_float (ubjson_cookie_t *__restrict cookie, ssize_t content, float *dest)
 Call if type1 of the callback was UBJSON_TYPE_FLOAT. More...
 
static ssize_t ubjson_get_double (ubjson_cookie_t *__restrict cookie, ssize_t content, double *dest)
 Call if type1 of the callback was UBJSON_TYPE_DOUBLE. More...
 
ubjson_read_callback_result_t ubjson_read_array (ubjson_cookie_t *__restrict cookie)
 Call if type1 of the callback was UBJSON_ENTER_ARRAY. More...
 
ubjson_read_callback_result_t ubjson_read_object (ubjson_cookie_t *__restrict cookie)
 Call if type1 of the callback was UBJSON_ENTER_OBJECT. More...
 
static void ubjson_write_init (ubjson_cookie_t *__restrict cookie, ubjson_write_t write_fun)
 The first call when you serialize data to UBJSON. More...
 
ssize_t ubjson_write_null (ubjson_cookie_t *__restrict cookie)
 Write a null value. More...
 
ssize_t ubjson_write_noop (ubjson_cookie_t *__restrict cookie)
 Write a no-operation value. More...
 
ssize_t ubjson_write_bool (ubjson_cookie_t *__restrict cookie, bool value)
 Write a boolean value. More...
 
ssize_t ubjson_write_i32 (ubjson_cookie_t *__restrict cookie, int32_t value)
 Write an integer value. More...
 
ssize_t ubjson_write_i64 (ubjson_cookie_t *__restrict cookie, int64_t value)
 Write an integer value. More...
 
ssize_t ubjson_write_float (ubjson_cookie_t *__restrict cookie, float value)
 Write a floating point value. More...
 
ssize_t ubjson_write_double (ubjson_cookie_t *__restrict cookie, double value)
 Write a floating point value. More...
 
ssize_t ubjson_write_string (ubjson_cookie_t *__restrict cookie, const void *value, size_t len)
 Write a string or blob. More...
 
ssize_t ubjson_open_array (ubjson_cookie_t *__restrict cookie)
 Open an array. More...
 
ssize_t ubjson_open_array_len (ubjson_cookie_t *__restrict cookie, size_t len)
 Open an array with a known length. More...
 
ssize_t ubjson_close_array (ubjson_cookie_t *__restrict cookie)
 Close an array that was opened with ubjson_open_array(). More...
 
ssize_t ubjson_open_object (ubjson_cookie_t *__restrict cookie)
 Open an object. More...
 
ssize_t ubjson_open_object_len (ubjson_cookie_t *__restrict cookie, size_t len)
 Open an object with a known length. More...
 
ssize_t ubjson_write_key (ubjson_cookie_t *__restrict cookie, const void *value, size_t len)
 Write a key inside an object. More...
 
ssize_t ubjson_close_object (ubjson_cookie_t *__restrict cookie)
 Close an array that was opened with ubjson_open_object(). More...