ubjsc  0.4-dev
Enterprise-grade C library for manipulating UBJSON
Data Structures | Typedefs | Functions
ubjs_parser.h File Reference

Incremental parser of bytestream to ubjson primitives. More...

#include "ubjs_common.h"
#include "ubjs_primitives.h"
Include dependency graph for ubjs_parser.h:
This graph shows which files directly or indirectly include this file:

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...
 

Detailed Description

Incremental parser of bytestream to ubjson primitives.

This file describes ubjs_parser structure, that parses incoming bytes and produces ubjs_prmtv object.

Since
0.2

Typedef Documentation

§ ubjs_parser_context_error

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.

Parameters
contextContext object you passed to ubjs_parser_new.
errorError.

§ ubjs_parser_context_free

typedef void(* ubjs_parser_context_free) (ubjs_parser_context *)

Callback when parser is about to be free-d.

Here you can cleanup your userdata.

Parameters
contextContext object you passed to ubjs_parser_new.

§ ubjs_parser_context_parsed

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.

Parameters
contextContext object you passed to ubjs_parser_new.
primitiveNewly parsed primitive.

Function Documentation

§ ubjs_parser_error_get_message_length()

UBJS_EXPORT ubjs_result ubjs_parser_error_get_message_length ( ubjs_parser_error this,
unsigned int *  plength 
)

Gets the error message's length.

Parameters
thisError.
plengthPointer to where set the value.
Returns
UR_ERROR if any of this/presult is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_parser_error_get_message_text()

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.

Parameters
thisError.
textTarget array.
Returns
UR_ERROR if any of this/text is 0, else UR_OK.

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_parser_free()

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.

Parameters
pthisPointer to the parser.
Returns
UR_ERROR if pthis is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_parser_get_context()

UBJS_EXPORT ubjs_result ubjs_parser_get_context ( ubjs_parser this,
ubjs_parser_context **  pcontext 
)

Gets user context from the parser.

Parameters
thisParser.
pcontextPointer to where put user context.
Returns
UR_ERROR if any of this/pcontext is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_parser_get_settings()

UBJS_EXPORT ubjs_result ubjs_parser_get_settings ( ubjs_parser this,
ubjs_parser_settings **  psettings 
)

Gets settings from the parser.

Parameters
thisParser.
psettingsPointer to where put settings.
Returns
UR_ERROR if any of this/psettings is 0, else UR_OK.

References UR_ERROR, and UR_OK.

§ ubjs_parser_new()

UBJS_EXPORT ubjs_result ubjs_parser_new ( ubjs_library lib,
ubjs_parser_settings settings,
ubjs_parser_context context,
ubjs_parser **  pthis 
)

Creates new parser.

Parameters
libLibrary handle.
settingsSettings. Can be 0.
contextUser context.
pthisPointer to where put newly created parser.
Returns
UR_ERROR if any of lib/pthis/context/context->parsed/context->error/context->free is 0, else UR_OK.
Since
0.4

References ubjs_parser_context::error, ubjs_parser_context::free, ubjs_parser_context::parsed, UR_ERROR, and UR_OK.

§ ubjs_parser_parse()

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.

Parameters
thisParser.
dataIncoming data.
lenLength of the data.
Returns
UR_ERROR if any of this/data is 0, else UR_OK.

References MARKER_ARRAY_END, MARKER_OBJECT_END, ubjs_prmtv_array(), ubjs_prmtv_array_add_last(), ubjs_prmtv_array_get_length(), ubjs_prmtv_char(), ubjs_prmtv_debug_string_copy(), ubjs_prmtv_debug_string_get_length(), ubjs_prmtv_false(), ubjs_prmtv_float32(), ubjs_prmtv_float64(), ubjs_prmtv_free(), ubjs_prmtv_hpn(), ubjs_prmtv_int16(), ubjs_prmtv_int16_get(), ubjs_prmtv_int32(), ubjs_prmtv_int32_get(), ubjs_prmtv_int64(), ubjs_prmtv_int8(), ubjs_prmtv_int8_get(), ubjs_prmtv_is_int16(), ubjs_prmtv_is_int32(), ubjs_prmtv_is_int8(), ubjs_prmtv_is_uint8(), ubjs_prmtv_noop(), ubjs_prmtv_null(), ubjs_prmtv_object(), ubjs_prmtv_object_get_length(), ubjs_prmtv_object_set(), ubjs_prmtv_str(), ubjs_prmtv_str_copy_text(), ubjs_prmtv_str_get_length(), ubjs_prmtv_true(), ubjs_prmtv_uint8(), ubjs_prmtv_uint8_get(), UFALSE, UR_ERROR, UR_OK, and UTRUE.

Here is the call graph for this function: