24 const unsigned char *ptr;
43 static const afw_list_t * afw_ubjson_parse_array(
47 static const afw_utf8_t * afw_ubjson_parse_string(
56 size_t afw_ubjson_parse_length(
63 static unsigned char afw_ubjson_peek_byte(
66 if (parser->cursor > parser->input->size) {
70 return *(parser->ptr);
73 static unsigned char afw_ubjson_next_byte(
78 if (parser->cursor > parser->input->size) {
90 static void afw_ubjson_next_bytes(
94 if (parser->cursor + len > parser->input->size) {
98 memcpy(buf, parser->ptr, len);
100 parser->cursor += len;
103 size_t afw_ubjson_parse_length(
110 c = afw_ubjson_next_byte(parser, xctx);
113 case AFW_UBJSON_MARKER_INT8:
114 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 1, xctx);
118 case AFW_UBJSON_MARKER_UINT8:
119 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 1, xctx);
123 case AFW_UBJSON_MARKER_INT16:
124 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 2, xctx);
125 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 16);
129 case AFW_UBJSON_MARKER_INT32:
130 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 4, xctx);
131 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 32);
137 "Error: invalid numeric type for string length", xctx);
153 case AFW_UBJSON_MARKER_CHAR:
154 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 1, xctx);
158 case AFW_UBJSON_MARKER_INT8:
159 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 1, xctx);
163 case AFW_UBJSON_MARKER_UINT8:
164 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 1, xctx);
168 case AFW_UBJSON_MARKER_INT16:
169 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 2, xctx);
170 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 16);
174 case AFW_UBJSON_MARKER_INT32:
175 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 4, xctx);
176 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 32);
180 case AFW_UBJSON_MARKER_INT64:
181 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 8, xctx);
182 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 64);
186 case AFW_UBJSON_MARKER_FLOAT32:
187 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 4, xctx);
188 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 32);
192 case AFW_UBJSON_MARKER_FLOAT64:
193 afw_ubjson_next_bytes(parser, (
unsigned char*) &c_type, 8, xctx);
194 AFW_ENDIAN_BIG_TO_NATIVE(&c_type, 64);
200 "Error: invalid numeric type.", xctx);
214 len = afw_ubjson_parse_length(parser, xctx);
216 if (parser->cursor + len > parser->input->size) {
218 "Error: string length exceeds input.", xctx);
224 parser->cursor += len;
241 c = afw_ubjson_peek_byte(parser, xctx);
244 if (c == AFW_UBJSON_MARKER_TYPE) {
246 type = afw_ubjson_next_byte(parser, xctx);
248 c = afw_ubjson_peek_byte(parser, xctx);
249 if (c == AFW_UBJSON_MARKER_COUNT) {
251 count = afw_ubjson_parse_length(parser, xctx);
253 }
else if (c == AFW_UBJSON_MARKER_COUNT) {
255 count = afw_ubjson_parse_length(parser, xctx);
258 while (c != AFW_UBJSON_MARKER_ARRAY_) {
259 value = afw_ubjson_parse_value(parser, type, xctx);
263 c = afw_ubjson_peek_byte(parser, xctx);
266 c = afw_ubjson_next_byte(parser, xctx);
289 parser->embedding_object,
290 parser->property_name,
291 false, parser->cede_p, parser->p, xctx);
301 saved_embedding_object = parser->embedding_object;
302 parser->embedding_object = obj;
303 saved_property_name = parser->property_name;
304 parser->property_name = NULL;
305 default_path = (!saved_embedding_object) ? parser->path : NULL;
307 c = afw_ubjson_peek_byte(parser, xctx);
310 if (c == AFW_UBJSON_MARKER_TYPE) {
312 type = afw_ubjson_next_byte(parser, xctx);
314 c = afw_ubjson_peek_byte(parser, xctx);
315 if (c == AFW_UBJSON_MARKER_COUNT) {
317 count = afw_ubjson_parse_length(parser, xctx);
319 }
else if (c == AFW_UBJSON_MARKER_COUNT) {
321 count = afw_ubjson_parse_length(parser, xctx);
324 c = afw_ubjson_peek_byte(parser, xctx);
325 while (c != AFW_UBJSON_MARKER_OBJECT_) {
326 property_name = afw_ubjson_parse_string(parser, xctx);
327 parser->property_name = property_name;
328 property_value = afw_ubjson_parse_value(parser, type, xctx);
345 property_value, xctx);
348 c = afw_ubjson_peek_byte(parser, xctx);
351 c = afw_ubjson_next_byte(parser, xctx);
357 parser->embedding_object = saved_embedding_object;
358 parser->property_name = saved_property_name;
378 c = afw_ubjson_next_byte(parser, xctx);
382 case AFW_UBJSON_MARKER_NULL:
387 case AFW_UBJSON_MARKER_NOOP:
392 case AFW_UBJSON_MARKER_TRUE:
397 case AFW_UBJSON_MARKER_FALSE:
402 case AFW_UBJSON_MARKER_INT8:
403 case AFW_UBJSON_MARKER_UINT8:
404 case AFW_UBJSON_MARKER_INT16:
405 case AFW_UBJSON_MARKER_INT32:
406 case AFW_UBJSON_MARKER_INT64:
407 case AFW_UBJSON_MARKER_FLOAT32:
408 case AFW_UBJSON_MARKER_FLOAT64:
409 value = afw_ubjson_parse_number(parser, c, xctx);
413 case AFW_UBJSON_MARKER_HIGH_PRECISION:
416 "Error: high-precision numbers not implemented.", xctx);
420 case AFW_UBJSON_MARKER_CHAR:
421 c = afw_ubjson_next_byte(parser, xctx);
426 case AFW_UBJSON_MARKER_STRING:
427 string = afw_ubjson_parse_string(parser, xctx);
432 case AFW_UBJSON_MARKER_ARRAY:
433 list = afw_ubjson_parse_array(parser, xctx);
438 case AFW_UBJSON_MARKER_OBJECT:
439 obj = afw_ubjson_parse_object(parser, xctx);
445 "Error: unknown value type marker.", xctx);
464 parser.input = ubjson;
465 parser.ptr = parser.input->ptr;
467 parser.embedding_object = NULL;
468 parser.property_name = NULL;
471 parser.cede_p =
false;
473 value = afw_ubjson_parse_value(&parser, 0, xctx);
495 parser.input = ubjson;
496 parser.ptr = parser.input->ptr;
498 parser.embedding_object = NULL;
499 parser.property_name = NULL;
501 parser.cede_p =
true;
503 adaptor_id, object_type_id, object_id, parser.p, xctx);
506 afw_ubjson_next_byte(&parser, xctx);
509 return afw_ubjson_parse_object(&parser, xctx);
Adaptive Framework Core API.
Header file for Adaptive Framework UBJSON.
afw_value_create_boolean(afw_boolean_t internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type boolean value.
afw_value_create_double(double internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type double value.
afw_value_create_integer(afw_integer_t internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type integer value.
afw_value_create_list(const afw_list_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type list value.
afw_value_create_null(void *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type null value.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
#define AFW_POSSIBLY_UNUSED_VARIABLE
Macro to avoid unused variable warning.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define afw_list_create_generic(p, xctx)
Create an value list in memory.
afw_list_add_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method add_value of interface afw_list_setter.
afw_object_path_make(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_pool_t *p, afw_xctx_t *xctx)
Construct an object path in a specified pool.
#define AFW_OBJECT_CREATE_ENTITY_OR_EMBEDDED(result, embedding_object, property_name, always_create_unmanaged, cede_p, entity_p, xctx)
Helper macro to create a new entity or embedded object.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
const afw_object_t * afw_ubjson_to_object(const afw_memory_t *ubjson, const afw_utf8_t *source_location, const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_boolean_t cede_p, const afw_pool_t *p, afw_xctx_t *xctx)
Convert from UBJSON to adaptive object.
const afw_value_t * afw_ubjson_to_value(const afw_memory_t *ubjson, const afw_utf8_t *path, const afw_pool_t *p, afw_xctx_t *xctx)
Convert UBJSON to an adaptive value.
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
Interface afw_list public struct.
Struct for memory pointer and size.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for data type object values.
Interface afw_value public struct.
Interface afw_xctx public struct.
Typedef for union of all cType.