ubjsc
0.5
Enterprise-grade C library for manipulating UBJSON
|
Incremental parser of bytestream to ubjson primitives. More...
Go to the source code of this file.
Data Structures | |
struct | ubjs_parser_settings |
Settings for parser. More... | |
struct | ubjs_parser_context |
User-provided context - callbacks and userdata. More... | |
Typedefs | |
typedef struct ubjs_parser | ubjs_parser |
Parser itself. | |
typedef struct ubjs_parser_context | ubjs_parser_context |
User-provided context - callbacks and userdata. | |
typedef struct ubjs_parser_settings | ubjs_parser_settings |
Parser settings. | |
typedef struct ubjs_parser_error | ubjs_parser_error |
Holder for parser errors. | |
typedef void(* | ubjs_parser_context_parsed) (ubjs_parser_context *context, ubjs_prmtv *primitive) |
Callback to be executed just when parser parsed a first-citizen primitive. More... | |
typedef void(* | ubjs_parser_context_error) (ubjs_parser_context *context, ubjs_parser_error *error) |
Callback when encountered a parsing error. More... | |
typedef void(* | ubjs_parser_context_free) (ubjs_parser_context *) |
Callback when parser is about to be free-d. More... | |
Functions | |
UBJS_EXPORT ubjs_result | ubjs_parser_error_get_message_length (ubjs_parser_error *this, unsigned int *plength) |
Gets the error message's length. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_error_get_message_text (ubjs_parser_error *this, char *text) |
Copies the error message's content to provided array. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_new (ubjs_library *lib, ubjs_parser_settings *settings, ubjs_parser_context *context, ubjs_parser **pthis) |
Creates new parser. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_free (ubjs_parser **pthis) |
Frees the parser. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_get_context (ubjs_parser *this, ubjs_parser_context **pcontext) |
Gets user context from the parser. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_get_settings (ubjs_parser *this, ubjs_parser_settings **psettings) |
Gets settings from the parser. More... | |
UBJS_EXPORT ubjs_result | ubjs_parser_parse (ubjs_parser *this, uint8_t *data, unsigned int len) |
Parses the incoming data. More... | |
Incremental parser of bytestream to ubjson primitives.
This file describes ubjs_parser structure, that parses incoming bytes and produces ubjs_prmtv object.
typedef void(* ubjs_parser_context_error) (ubjs_parser_context *context, ubjs_parser_error *error) |
Callback when encountered a parsing error.
The current call to ubjs_parser_parse will return UR_ERROR. The parser is still functional, but it remains at last valid state, before the error appeared.
context | Context object you passed to ubjs_parser_new. |
error | Error. |
typedef void(* ubjs_parser_context_free) (ubjs_parser_context *) |
Callback when parser is about to be free-d.
Here you can cleanup your userdata.
context | Context object you passed to ubjs_parser_new. |
typedef void(* ubjs_parser_context_parsed) (ubjs_parser_context *context, ubjs_prmtv *primitive) |
Callback to be executed just when parser parsed a first-citizen primitive.
You should ubjs_prmtv_free(&primitive) by yourself.
context | Context object you passed to ubjs_parser_new. |
primitive | Newly parsed primitive. |
UBJS_EXPORT ubjs_result ubjs_parser_error_get_message_length | ( | ubjs_parser_error * | this, |
unsigned int * | plength | ||
) |
UBJS_EXPORT ubjs_result ubjs_parser_error_get_message_text | ( | ubjs_parser_error * | this, |
char * | text | ||
) |
Copies the error message's content to provided array.
Target array must be preallocated. Before the call, you may want to ubjs_parser_error_get_message_length and allocate the target array.
this | Error. |
text | Target array. |
References MARKER_ARRAY_BEGIN, MARKER_ARRAY_END, MARKER_CHAR, MARKER_FALSE, MARKER_FLOAT32, MARKER_FLOAT64, MARKER_HPN, MARKER_INT16, MARKER_INT32, MARKER_INT64, MARKER_INT8, MARKER_NOOP, MARKER_NULL, MARKER_OBJECT_BEGIN, MARKER_OBJECT_END, MARKER_OPTIMIZE_COUNT, MARKER_OPTIMIZE_TYPE, MARKER_STR, MARKER_TRUE, MARKER_UINT8, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_parser_free | ( | ubjs_parser ** | pthis | ) |
Frees the parser.
The call to context->free will occur here. After this, *pthis will be equal to 0.
pthis | Pointer to the parser. |
References ubjs_library::free_f, UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_parser_get_context | ( | ubjs_parser * | this, |
ubjs_parser_context ** | pcontext | ||
) |
UBJS_EXPORT ubjs_result ubjs_parser_get_settings | ( | ubjs_parser * | this, |
ubjs_parser_settings ** | psettings | ||
) |
UBJS_EXPORT ubjs_result ubjs_parser_new | ( | ubjs_library * | lib, |
ubjs_parser_settings * | settings, | ||
ubjs_parser_context * | context, | ||
ubjs_parser ** | pthis | ||
) |
Creates new parser.
lib | Library handle. |
settings | Settings. Can be 0. |
context | User context. |
pthis | Pointer to where put newly created parser. |
References ubjs_library::alloc_f, ubjs_glue_array_builder::build_f, ubjs_parser_context::error, ubjs_parser_context::free, ubjs_glue_array_builder::free_f, ubjs_parser_context::parsed, ubjs_glue_array_builder::set_value_free_f, ubjs_glue_array_array_builder_new(), UR_ERROR, and UR_OK.
UBJS_EXPORT ubjs_result ubjs_parser_parse | ( | ubjs_parser * | this, |
uint8_t * | data, | ||
unsigned int | len | ||
) |
Parses the incoming data.
This may produce the call (or calls) to context->parsed with just-parsed primitive, or context->error, or none of them.
In case there are many primitives parsed in single ubjs_parser_parse call, these many calls to context->parsed will be issues for each new primitive.
In case there is too little data to issue any callback, this method will not issue any callback.
If len == 0, this method does nothing and simply returns UR_OK.
this | Parser. |
data | Incoming data. |
len | Length of the data. |
References ubjs_library::alloc_f, ubjs_glue_array_iterator::free_f, ubjs_library::free_f, ubjs_glue_array_iterator::get_f, ubjs_glue_array::get_length_f, ubjs_glue_array_iterator::next_f, ubjs_prmtv_debug_string_copy(), ubjs_prmtv_debug_string_get_length(), ubjs_prmtv_free(), ubjs_prmtv_get_type(), ubjs_prmtv_int16_get(), ubjs_prmtv_int32_get(), ubjs_prmtv_int8_get(), ubjs_prmtv_uint8_get(), UFALSE, UOT_INT16, UOT_INT32, UOT_INT8, UOT_UINT8, UR_ERROR, UR_OK, and UTRUE.