17 #include <apr_buckets.h>
37 wa->callback(wa->context, &ch, 1, wa->p, wa->xctx);
44 wa->callback(wa->context, s, strlen(s), wa->p, wa->xctx);
51 wa->callback(wa->context, buffer, size, wa->p, wa->xctx);
67 static void convert_value_to_ubjson(
71 static void convert_list_to_ubjson(
75 static void convert_object_to_ubjson(
79 static void convert_string_to_ubjson(
84 static void convert_integer_to_ubjson(
88 static void convert_string_to_ubjson(
93 if (string->len == 1 && marker) {
95 impl_putc(wa, AFW_UBJSON_MARKER_CHAR);
96 impl_putc(wa, *(string->s));
101 impl_putc(wa, AFW_UBJSON_MARKER_STRING);
104 convert_integer_to_ubjson(wa, string->len);
107 if (string->len > 0) {
108 impl_write(wa, string->s, string->len);
114 static void convert_integer_to_ubjson(
135 if (i >= -128 && i <= 127) {
138 impl_putc(wa, AFW_UBJSON_MARKER_INT8);
139 impl_write(wa, (
const char*)&x,
sizeof(x));
142 else if (i >= 0 && i <= 255) {
145 impl_putc(wa, AFW_UBJSON_MARKER_UINT8);
146 impl_write(wa, (
const char*)&x,
sizeof(x));
149 else if (i >= -32768 && i <= 32767) {
151 AFW_ENDIAN_NATIVE_TO_BIG_16(&x);
153 impl_putc(wa, AFW_UBJSON_MARKER_INT16);
154 impl_write(wa, (
const char*)&x,
sizeof(x));
157 else if (i >= -2147483647 && i <= 2147483647) {
159 AFW_ENDIAN_NATIVE_TO_BIG_32(&x);
161 impl_putc(wa, AFW_UBJSON_MARKER_INT32);
162 impl_write(wa, (
const char*)&x,
sizeof(x));
168 "Unexpected error in UBJSON converting 64-bit integer.", wa->xctx);
173 static void convert_double_to_ubjson(
195 impl_putc(wa, AFW_UBJSON_MARKER_FLOAT64);
198 impl_write(wa, &d,
sizeof(d));
201 static void convert_object_to_ubjson(
210 impl_putc(wa, AFW_UBJSON_MARKER_OBJECT);
212 (wa->object_depth)++;
214 property_iterator = NULL;
223 wa->options, wa->p, wa->xctx);
225 convert_string_to_ubjson(wa, &afw_s__meta_,
AFW_FALSE);
226 convert_object_to_ubjson(wa, meta);
230 &property_name, wa->xctx);
234 convert_string_to_ubjson(wa, property_name,
AFW_FALSE);
237 convert_value_to_ubjson(wa, next);
240 &property_name, wa->xctx);
247 if (!wa->optimized) {
248 impl_putc(wa, AFW_UBJSON_MARKER_OBJECT_);
251 (wa->object_depth)--;
255 #ifdef __FIXME_REMOVE_OLD_BAG_CODE__
271 static void convert_bag_to_ubjson(
273 const afw_value_bag_t * bag)
281 impl_putc(wa, AFW_UBJSON_MARKER_ARRAY);
285 impl_putc(wa, AFW_UBJSON_MARKER_TYPE);
288 data_type = bag->data_type;
291 impl_putc(wa, AFW_UBJSON_MARKER_OBJECT);
293 impl_putc(wa, AFW_UBJSON_MARKER_ARRAY);
296 impl_putc(wa, AFW_UBJSON_MARKER_STRING);
300 "Not implemented. Cannot determine smallest type for UBJSON", wa->xctx);
307 impl_putc(wa, AFW_UBJSON_MARKER_COUNT);
308 convert_integer_to_ubjson(wa, count);
315 for (value = (
const char *)&(bag->internal),
318 value += bag->data_type->c_type_size,
321 memcpy(&entry->internal, value, bag->data_type->c_type_size);
325 convert_value_to_ubjson(wa, (
const afw_value_t *)entry);
331 if (!wa->optimized) {
332 impl_putc(wa, AFW_UBJSON_MARKER_ARRAY_);
339 static void convert_list_to_ubjson(
346 impl_putc(wa, AFW_UBJSON_MARKER_ARRAY);
353 list_iterator = NULL;
358 convert_value_to_ubjson(wa, next);
363 if (!wa->optimized) {
364 impl_putc(wa, AFW_UBJSON_MARKER_ARRAY_);
368 static void convert_value_to_ubjson(
385 "Unevaluated value encountered producing ubjson "
407 &AFW_JSON_S_PRIMITIVE_NULL))
409 impl_putc(wa, AFW_UBJSON_MARKER_NULL);
414 &AFW_JSON_S_PRIMITIVE_STRING))
420 convert_string_to_ubjson(wa,
string,
AFW_TRUE);
425 &AFW_JSON_S_PRIMITIVE_BOOLEAN))
428 impl_putc(wa, AFW_UBJSON_MARKER_TRUE);
430 impl_putc(wa, AFW_UBJSON_MARKER_FALSE);
447 "Cannot determine suitable encoding for this c type: %.*s",
448 value_data_type->cType.len, value_data_type->cType.s);
454 "Value type is invalid for this content-type", wa->xctx);
461 afw_ubjson_internal_write_value(
471 wa = create_from_value_wa(p, xctx);
472 wa->options = options;
473 wa->context = context;
474 wa->callback = callback;
477 convert_value_to_ubjson(wa, value);
493 afw_ubjson_internal_write_value(value, NULL,
494 writer->context, writer->callback, p, xctx);
Adaptive Framework Core API.
Adaptive Framework Endian Header.
Header file for Adaptive Framework UBJSON.
#define afw_data_type_is_double(A_DATA_TYPE)
Macro to determine if data type is double.
afw_value_as_double(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type double.
#define AFW_DATA_TYPE_CTYPE_Q_double
Quoted c type for data type id double.
#define AFW_DATA_TYPE_CTYPE_Q_integer
Quoted c type for data type id integer.
afw_value_as_integer(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type integer.
#define afw_value_is_list(A_VALUE)
Macro to determine if value is evaluated list.
afw_value_as_list(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type list.
#define afw_data_type_is_list(A_DATA_TYPE)
Macro to determine if data type is list.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
#define afw_data_type_is_object(A_DATA_TYPE)
Macro to determine if data type is object.
afw_value_as_object(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type object.
#define afw_data_type_is_string(A_DATA_TYPE)
Macro to determine if data type is string.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
apr_uint16_t afw_uint16_t
16-bit unsigned integer.
struct afw_iterator_s afw_iterator_t
#define AFW_UTF8_FMT_OPTIONAL_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify optional arg.
unsigned char afw_byte_t
A byte of memory (unsigned).
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
apr_uint32_t afw_uint32_t
32-bit unsigned integer.
apr_size_t afw_size_t
size_t.
afw_size_t(* afw_write_cb_t)(void *context, const void *buffer, afw_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for write callback function.
apr_int64_t afw_integer_t
typedef for big signed int.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 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_get_next_value(instance, iterator, p, xctx)
Call method get_next_value of interface afw_list.
afw_memory_writer_retrieve_and_release(const afw_memory_writer_t *writer, afw_xctx_t *xctx)
Retrieve memory as one chunk from memory writer and release writer.
afw_memory_create_writer(const afw_pool_t *p, afw_xctx_t *xctx)
Create a memory writer.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_memory_t * afw_ubjson_from_value(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
Convert an adaptive value to UBJSON.
afw_boolean_t afw_utf8_equal_utf8_z(const afw_utf8_t *s1, const afw_utf8_z_t *s2_z)
Check to see if a string equals a utf8_z string.
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.
#define afw_value_get_data_type(instance, xctx)
Call method get_data_type of interface afw_value.
#define afw_value_get_info(instance, info, p, xctx)
Call method get_info of interface afw_value.
afw_value_as_utf8(const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
afw_value_evaluated_t * afw_value_evaluated_allocate(const afw_data_type_t *data_type, const afw_pool_t *p, afw_xctx_t *xctx)
Allocate function for an evaluated data type value.
#define afw_value_is_defined_and_evaluated(A_VALUE)
Macro to determine if value is defined and evaluated.
afw_value_null
Adaptive value null.
Interface afw_data_type public struct.
Interface afw_list public struct.
Struct for memory pointer and size.
Return value from afw_memory_create_writer().
Struct for object processing options.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
struct for data type boolean values.
Struct to access internal of all evaluated values.
Filled in by afw_value get_info method.
Interface afw_value public struct.
Interface afw_xctx public struct.