Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_ubjson.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Implementation of afw_content_type interface for Universal Binary JSON
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw.h"
15 #include "afw_content_type_impl.h"
18 
19 
20 #include "afw_ubjson.h"
21 
22 /* Declares and rti/inf defines for interface afw_content_type */
23 #define AFW_IMPLEMENTATION_ID "afw_ubjson"
24 #define AFW_IMPLEMENTATION_VERSION AFW_UBJSON_VERSION_STRING
27 
28 /* Media types supported by this afw_content_type implementation. */
29 static const afw_utf8_t impl_media_types[] = {
30  AFW_UTF8_LITERAL(AFW_UBJSON_Q_CONTENT_TYPE)
31 };
32 
33 
36 /* Raw begin object list. */
37 static const afw_memory_t impl_raw_begin_object_list = {
38  (const afw_byte_t *)"[",
39  sizeof("[") - 1
40 };
41 
42 /* Raw end object list. */
43 static const afw_memory_t impl_raw_end_object_list = {
44  (const afw_byte_t *)"]",
45  sizeof("[") - 1
46 };
47 
48 /* This is referenced by generate/registers/content_type/ubjson.c. */
50 afw_ubjson_internal_content_type =
51 {
52  &impl_afw_content_type_inf,
53  AFW_UTF8_LITERAL("ubjson"),
54  sizeof(impl_media_types) / sizeof(afw_utf8_t),
55  &impl_media_types[0]
56 };
57 
58 
59 /* Convert a value to json and write it defined in afw_ubjson_from_value.c */
60 extern void afw_ubjson_internal_write_value(
61  const afw_value_t *value,
62  const afw_object_options_t *options,
63  void * context,
64  afw_write_cb_t callback,
65  const afw_pool_t *p, afw_xctx_t *xctx);
66 
67 
68 /* Define extension implementation. */
70 
71 
72 
73 /*
74  * Implementation of method initialize for interface afw_extension.
75  */
76 const afw_extension_t *
77 impl_afw_extension_initialize(
78  const afw_extension_t * instance,
79  const afw_object_t * properties,
80  const afw_pool_t * p,
81  afw_xctx_t *xctx)
82 {
83  /*
84  * IMPORTANT:
85  *
86  * Make sure associated _AdaptiveManifest_ is up to date,
87  * especially the "registers" property.
88  *
89  */
90 
91  /* See function in generated/afw_ubjson_generated.c. */
93 
94  /* Return extension info. */
95  return &impl_extension;
96 }
97 
98 
99 /*
100  * Implementation of method release of interface afw_extension.
101  */
102 void
103 impl_afw_extension_release(
104  const afw_extension_t * instance,
105  afw_xctx_t *xctx)
106 {
107  /* Extension release() is not currently called. */
108 }
109 
110 
111 /*
112  * Implementation of method to_value of interface afw_content_type.
113  */
114 const afw_value_t *
115 impl_afw_content_type_raw_to_value(
116  const afw_content_type_t * instance,
117  const afw_memory_t * raw,
118  const afw_utf8_t * source_location,
119  const afw_pool_t * p,
120  afw_xctx_t *xctx)
121 {
122  return afw_ubjson_to_value(raw, NULL, p, xctx);
123 }
124 
125 
126 
127 /*
128  * Implementation of method raw_to_object of interface afw_content_type.
129  */
130 const afw_object_t *
131 impl_afw_content_type_raw_to_object (
132  const afw_content_type_t * instance,
133  const afw_memory_t * raw,
134  const afw_utf8_t * source_location,
135  const afw_utf8_t * adaptor_id,
136  const afw_utf8_t * object_type_id,
137  const afw_utf8_t * object_id,
138  afw_boolean_t cede_p,
139  const afw_pool_t * p,
140  afw_xctx_t *xctx)
141 {
142  return afw_ubjson_to_object(raw, source_location,
143  adaptor_id, object_type_id, object_id, cede_p, p, xctx);
144 }
145 
146 
147 
148 /*
149  * Implementation of method write_value of interface afw_content_type.
150  */
151 void
152 impl_afw_content_type_write_value(
153  const afw_content_type_t * instance,
154  const afw_value_t * value,
155  const afw_object_options_t *options,
156  void * context,
157  afw_write_cb_t callback,
158  const afw_pool_t * p,
159  afw_xctx_t *xctx)
160 {
161  afw_ubjson_internal_write_value(value, options, context, callback,
162  p, xctx);
163 }
164 
165 
166 
167 /*
168  * Implementation of method create_object_list_writer of interface afw_content_type.
169  */
171 impl_afw_content_type_create_object_list_writer(
172  const afw_content_type_t * instance,
173  const afw_object_options_t *options,
174  void * context,
175  afw_write_cb_t callback,
176  const afw_pool_t *p, afw_xctx_t *xctx)
177 {
178  return afw_content_type_impl_create_object_list_writer(
179  instance, options, context, callback,
180  &impl_raw_begin_object_list,
181  NULL,
182  NULL,
183  &impl_raw_end_object_list,
184  p, xctx);
185 }
Adaptive Framework Core API.
Helpers for afw_content_type* implementation development.
Interface afw_interface implementation declares.
Interface afw_interface implementation declares.
Header file for Adaptive Framework UBJSON.
void afw_ubjson_generated_register(afw_xctx_t *xctx)
Generated register for afw_ubjson.
Adaptive Framework register generated (afw_ubjson) header.
Adaptive Framework Version (afw_ubjson_) header.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
Definition: afw_common.h:582
_Bool afw_boolean_t
Definition: afw_common.h:373
unsigned char afw_byte_t
A byte of memory (unsigned).
Definition: afw_common.h:208
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.
Definition: afw_common.h:1226
#define AFW_ENVIRONMENT_DEFINE_EXTENSION_IMPL()
Macro to put in each afw_extension implementation.
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 *pool, afw_xctx_t *xctx)
Convert UBJSON to an adaptive value.
Interface afw_content_type_object_list_writer public struct.
Interface afw_content_type public struct.
Interface afw_extension public struct.
Definition: afw_interface.h:55
Struct for memory pointer and size.
Definition: afw_common.h:505
Struct for object processing options.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.