Webcom C SDK
Webcom datasync protocol parsing functions
enum  wc_parser_result_t { WC_PARSER_OK = 0, WC_PARSER_CONTINUE, WC_PARSER_ERROR }
 
wc_parser_twc_datasync_parser_new ()
 
wc_parser_result_t wc_datasync_parse_msg_ex (wc_parser_t *parser, char *buf, size_t len, wc_msg_t *res)
 
const char * wc_datasync_parser_get_error (wc_parser_t *parser)
 
int wc_datasync_parse_msg (char *str, wc_msg_t *res)
 
void wc_datasync_parser_free (wc_parser_t *parser)
 
int wc_datasync_key_cmp (const char *sa, const char *sb)
 

Detailed Description

Enumeration Type Documentation

◆ wc_parser_result_t

Enumerator
WC_PARSER_OK 
WC_PARSER_CONTINUE 
WC_PARSER_ERROR 

Function Documentation

◆ wc_datasync_key_cmp()

int wc_datasync_key_cmp ( const char *  sa,
const char *  sb 
)

Compares two strings using the Webcom key order:

  • Keys that are parsable as integers are ordered before others.
  • Integer keys are ordered following natural order on integers.
  • Other keys are considered as strings and ordered in lexicographical order.

Example: "0" < "1" < "9" < "72" < "521" < "1000" < "aa" < "bb"

Parameters
safirst string
sbsecond string
Returns
a negative number if sa < sb, positive number if sa > sb, 0 if equal

◆ wc_datasync_parse_msg()

int wc_datasync_parse_msg ( char *  str,
wc_msg_t res 
)

Parses a null-terminated webcom message string.

This function parses a null-terminated string containing a webcom message (JSON document) and populates the wc_msg_t object given as parameter.

Parameters
strthe message string to parse
[out]resthe wc_msg_t object to populate
Returns
1 on success, 0 on error

◆ wc_datasync_parse_msg_ex()

wc_parser_result_t wc_datasync_parse_msg_ex ( wc_parser_t parser,
char *  buf,
size_t  len,
wc_msg_t res 
)

Parses a JSON text buffer to populate a wc_msg_t object.

If you have only partial buffers, you can call this function several times with the following buffers and the same parser object. It will return WC_PARSER_CONTINUE until the end of the JSON document has been parsed.

Parameters
parserthe parser created by wc_parser_new()
bufthe JSON text buffer to parse
lenthe buffer length
[out]resthe wc_msg_t object to populate
Returns
WC_PARSER_OK on success, WC_PARSER_CONTINUE if the JSON document is not complete, WC_ERROR if a parsing error occurred (see wc_parser_get_error() to get the error description)

◆ wc_datasync_parser_free()

void wc_datasync_parser_free ( wc_parser_t parser)

Frees a wc_parser_t object previously allocated by wc_parser_new()

Parameters
parserthe wc_parser_t object to free

◆ wc_datasync_parser_get_error()

const char* wc_datasync_parser_get_error ( wc_parser_t parser)

Returns a string describing a parsing error.

Returns
the description if an error occurred, NULL otherwise

◆ wc_datasync_parser_new()

wc_parser_t* wc_datasync_parser_new ( )

Creates a new wc_parser_t object.

Returns
a pointer to the new object or NULL in case of failure