Flecs: include/flecs/addons/json.h Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1
11#ifdef FLECS_JSON
12
13#ifndef FLECS_META
14#define FLECS_META
15#endif
16
17#ifndef FLECS_SCRIPT
18#define FLECS_SCRIPT
19#endif
20
21#ifndef FLECS_JSON_H
22#define FLECS_JSON_H
23
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37 typedef struct ecs_from_json_desc_t {
38 const char *name;
39 const char *expr;
43 ecs_entity_t (*lookup_action)(
44 const ecs_world_t*,
45 const char *value,
46 void *ctx);
47 void *lookup_ctx;
48
51 bool strict;
52} ecs_from_json_desc_t;
53
65FLECS_API
66 const char* ecs_ptr_from_json(
67 const ecs_world_t *world,
68 ecs_entity_t type,
69 void *ptr,
70 const char *json,
71 const ecs_from_json_desc_t *desc);
72
83FLECS_API
84 const char* ecs_entity_from_json(
85 ecs_world_t *world,
86 ecs_entity_t entity,
87 const char *json,
88 const ecs_from_json_desc_t *desc);
89
98FLECS_API
99 const char* ecs_world_from_json(
100 ecs_world_t *world,
101 const char *json,
102 const ecs_from_json_desc_t *desc);
103
111FLECS_API
112 const char* ecs_world_from_json_file(
113 ecs_world_t *world,
114 const char *filename,
115 const ecs_from_json_desc_t *desc);
116
131FLECS_API
132 char* ecs_array_to_json(
133 const ecs_world_t *world,
134 ecs_entity_t type,
135 const void *data,
136 int32_t count);
137
148FLECS_API
149 int ecs_array_to_json_buf(
150 const ecs_world_t *world,
151 ecs_entity_t type,
152 const void *data,
153 int32_t count,
154 ecs_strbuf_t *buf_out);
155
164FLECS_API
165 char* ecs_ptr_to_json(
166 const ecs_world_t *world,
167 ecs_entity_t type,
168 const void *data);
169
179FLECS_API
180 int ecs_ptr_to_json_buf(
181 const ecs_world_t *world,
182 ecs_entity_t type,
183 const void *data,
184 ecs_strbuf_t *buf_out);
185
196FLECS_API
197 char* ecs_type_info_to_json(
198 const ecs_world_t *world,
199 ecs_entity_t type);
200
209FLECS_API
210 int ecs_type_info_to_json_buf(
211 const ecs_world_t *world,
212 ecs_entity_t type,
213 ecs_strbuf_t *buf_out);
214
216 typedef struct ecs_entity_to_json_desc_t {
217 bool serialize_entity_id;
218 bool serialize_doc;
219 bool serialize_full_paths;
220 bool serialize_inherited;
221 bool serialize_values;
222 bool serialize_builtin;
223 bool serialize_type_info;
224 bool serialize_alerts;
225 ecs_entity_t serialize_refs;
226 bool serialize_matches;
227} ecs_entity_to_json_desc_t;
228
230#define ECS_ENTITY_TO_JSON_INIT (ecs_entity_to_json_desc_t){\
231 .serialize_doc = false, \
232 .serialize_full_paths = true, \
233 .serialize_inherited = false, \
234 .serialize_values = true, \
235 .serialize_builtin = false, \
236 .serialize_type_info = false, \
237 .serialize_alerts = false, \
238 .serialize_refs = 0, \
239 .serialize_matches = false, \
240}
241
252FLECS_API
253 char* ecs_entity_to_json(
254 const ecs_world_t *world,
255 ecs_entity_t entity,
256 const ecs_entity_to_json_desc_t *desc);
257
266FLECS_API
267 int ecs_entity_to_json_buf(
268 const ecs_world_t *world,
269 ecs_entity_t entity,
270 ecs_strbuf_t *buf_out,
271 const ecs_entity_to_json_desc_t *desc);
272
274 typedef struct ecs_iter_to_json_desc_t {
275 bool serialize_entity_ids;
276 bool serialize_values;
277 bool serialize_builtin;
278 bool serialize_doc;
279 bool serialize_full_paths;
280 bool serialize_fields;
281 bool serialize_inherited;
282 bool serialize_table;
283 bool serialize_type_info;
284 bool serialize_field_info;
285 bool serialize_query_info;
286 bool serialize_query_plan;
287 bool serialize_query_profile;
288 bool dont_serialize_results;
289 bool serialize_alerts;
290 ecs_entity_t serialize_refs;
291 bool serialize_matches;
292 ecs_poly_t *query;
293} ecs_iter_to_json_desc_t;
294
296#define ECS_ITER_TO_JSON_INIT (ecs_iter_to_json_desc_t){\
297 .serialize_entity_ids = false, \
298 .serialize_values = true, \
299 .serialize_builtin = false, \
300 .serialize_doc = false, \
301 .serialize_full_paths = true, \
302 .serialize_fields = true, \
303 .serialize_inherited = false, \
304 .serialize_table = false, \
305 .serialize_type_info = false, \
306 .serialize_field_info = false, \
307 .serialize_query_info = false, \
308 .serialize_query_plan = false, \
309 .serialize_query_profile = false, \
310 .dont_serialize_results = false, \
311 .serialize_alerts = false, \
312 .serialize_refs = false, \
313 .serialize_matches = false, \
314}
315
323FLECS_API
324 char* ecs_iter_to_json(
325 ecs_iter_t *iter,
326 const ecs_iter_to_json_desc_t *desc);
327
335FLECS_API
336 int ecs_iter_to_json_buf(
337 ecs_iter_t *iter,
338 ecs_strbuf_t *buf_out,
339 const ecs_iter_to_json_desc_t *desc);
340
342 typedef struct ecs_world_to_json_desc_t {
343 bool serialize_builtin;
344 bool serialize_modules;
345} ecs_world_to_json_desc_t;
346
364FLECS_API
365 char* ecs_world_to_json(
366 ecs_world_t *world,
367 const ecs_world_to_json_desc_t *desc);
368
376FLECS_API
377 int ecs_world_to_json_buf(
378 ecs_world_t *world,
379 ecs_strbuf_t *buf_out,
380 const ecs_world_to_json_desc_t *desc);
381
382#ifdef __cplusplus
383}
384#endif
385
386#endif
387
390#endif
ecs_entity_from_json
FLECS_API const char * ecs_entity_from_json(ecs_world_t *world, ecs_entity_t entity, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON object with multiple component values into entity.
ecs_entity_to_json_desc_t
struct ecs_entity_to_json_desc_t ecs_entity_to_json_desc_t
Used with ecs_iter_to_json().
ecs_world_from_json
FLECS_API const char * ecs_world_from_json(ecs_world_t *world, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON object with multiple entities into the world.
ecs_from_json_desc_t
struct ecs_from_json_desc_t ecs_from_json_desc_t
Used with ecs_ptr_from_json(), ecs_entity_from_json().
ecs_type_info_to_json_buf
FLECS_API int ecs_type_info_to_json_buf(const ecs_world_t *world, ecs_entity_t type, ecs_strbuf_t *buf_out)
Serialize type info into JSON string buffer.
ecs_iter_to_json_buf
FLECS_API int ecs_iter_to_json_buf(ecs_iter_t *iter, ecs_strbuf_t *buf_out, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string buffer.
ecs_world_to_json_desc_t
struct ecs_world_to_json_desc_t ecs_world_to_json_desc_t
Used with ecs_iter_to_json().
ecs_ptr_to_json_buf
FLECS_API int ecs_ptr_to_json_buf(const ecs_world_t *world, ecs_entity_t type, const void *data, ecs_strbuf_t *buf_out)
Serialize value into JSON string buffer.
ecs_iter_to_json_desc_t
struct ecs_iter_to_json_desc_t ecs_iter_to_json_desc_t
Used with ecs_iter_to_json().
ecs_world_from_json_file
FLECS_API const char * ecs_world_from_json_file(ecs_world_t *world, const char *filename, const ecs_from_json_desc_t *desc)
Same as ecs_world_from_json(), but loads JSON from file.
ecs_entity_to_json
FLECS_API char * ecs_entity_to_json(const ecs_world_t *world, ecs_entity_t entity, const ecs_entity_to_json_desc_t *desc)
Serialize entity into JSON string.
ecs_ptr_to_json
FLECS_API char * ecs_ptr_to_json(const ecs_world_t *world, ecs_entity_t type, const void *data)
Serialize value into JSON string.
ecs_type_info_to_json
FLECS_API char * ecs_type_info_to_json(const ecs_world_t *world, ecs_entity_t type)
Serialize type info to JSON.
ecs_world_to_json_buf
FLECS_API int ecs_world_to_json_buf(ecs_world_t *world, ecs_strbuf_t *buf_out, const ecs_world_to_json_desc_t *desc)
Serialize world into JSON string buffer.
ecs_world_to_json
FLECS_API char * ecs_world_to_json(ecs_world_t *world, const ecs_world_to_json_desc_t *desc)
Serialize world into JSON string.
ecs_iter_to_json
FLECS_API char * ecs_iter_to_json(ecs_iter_t *iter, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string.
ecs_ptr_from_json
FLECS_API const char * ecs_ptr_from_json(const ecs_world_t *world, ecs_entity_t type, void *ptr, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON string into value.
ecs_array_to_json_buf
FLECS_API int ecs_array_to_json_buf(const ecs_world_t *world, ecs_entity_t type, const void *data, int32_t count, ecs_strbuf_t *buf_out)
Serialize array into JSON string buffer.
ecs_array_to_json
FLECS_API char * ecs_array_to_json(const ecs_world_t *world, ecs_entity_t type, const void *data, int32_t count)
Serialize array into JSON string.
ecs_entity_to_json_buf
FLECS_API int ecs_entity_to_json_buf(const ecs_world_t *world, ecs_entity_t entity, ecs_strbuf_t *buf_out, const ecs_entity_to_json_desc_t *desc)
Serialize entity into JSON string buffer.
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:347
ecs_world_t
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:391
ecs_poly_t
void ecs_poly_t
A poly object.
Definition flecs.h:480
ecs_entity_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:216
ecs_entity_to_json_desc_t::serialize_values
bool serialize_values
Serialize component values.
Definition json.h:221
ecs_entity_to_json_desc_t::serialize_builtin
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:222
ecs_entity_to_json_desc_t::serialize_alerts
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:224
ecs_entity_to_json_desc_t::serialize_refs
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:225
ecs_entity_to_json_desc_t::serialize_matches
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:226
ecs_entity_to_json_desc_t::serialize_type_info
bool serialize_type_info
Serialize type info (requires serialize_values)
Definition json.h:223
ecs_entity_to_json_desc_t::serialize_inherited
bool serialize_inherited
Serialize base components.
Definition json.h:220
ecs_entity_to_json_desc_t::serialize_full_paths
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:219
ecs_entity_to_json_desc_t::serialize_entity_id
bool serialize_entity_id
Serialize entity id.
Definition json.h:217
ecs_entity_to_json_desc_t::serialize_doc
bool serialize_doc
Serialize doc attributes.
Definition json.h:218
ecs_from_json_desc_t
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:37
ecs_from_json_desc_t::name
const char * name
Name of expression (used for logging)
Definition json.h:38
ecs_from_json_desc_t::lookup_action
ecs_entity_t(* lookup_action)(const ecs_world_t *, const char *value, void *ctx)
Callback that allows for specifying a custom lookup function.
Definition json.h:43
ecs_from_json_desc_t::expr
const char * expr
Full expression (used for logging)
Definition json.h:39
ecs_from_json_desc_t::strict
bool strict
Require components to be registered with reflection data.
Definition json.h:51
ecs_iter_t
Iterator.
Definition flecs.h:1062
ecs_iter_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:274
ecs_iter_to_json_desc_t::serialize_full_paths
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:279
ecs_iter_to_json_desc_t::serialize_query_plan
bool serialize_query_plan
Serialize query plan.
Definition json.h:286
ecs_iter_to_json_desc_t::serialize_fields
bool serialize_fields
Serialize field data.
Definition json.h:280
ecs_iter_to_json_desc_t::serialize_doc
bool serialize_doc
Serialize doc attributes.
Definition json.h:278
ecs_iter_to_json_desc_t::serialize_query_profile
bool serialize_query_profile
Profile query performance.
Definition json.h:287
ecs_iter_to_json_desc_t::serialize_query_info
bool serialize_query_info
Serialize query terms.
Definition json.h:285
ecs_iter_to_json_desc_t::dont_serialize_results
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:288
ecs_iter_to_json_desc_t::serialize_field_info
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:284
ecs_iter_to_json_desc_t::serialize_builtin
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:277
ecs_iter_to_json_desc_t::serialize_table
bool serialize_table
Serialize entire table vs.
Definition json.h:282
ecs_iter_to_json_desc_t::serialize_refs
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:290
ecs_iter_to_json_desc_t::serialize_inherited
bool serialize_inherited
Serialize inherited components.
Definition json.h:281
ecs_iter_to_json_desc_t::query
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:292
ecs_iter_to_json_desc_t::serialize_alerts
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:289
ecs_iter_to_json_desc_t::serialize_values
bool serialize_values
Serialize component values.
Definition json.h:276
ecs_iter_to_json_desc_t::serialize_type_info
bool serialize_type_info
Serialize type information.
Definition json.h:283
ecs_iter_to_json_desc_t::serialize_entity_ids
bool serialize_entity_ids
Serialize entity ids.
Definition json.h:275
ecs_iter_to_json_desc_t::serialize_matches
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:291
ecs_world_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:342
ecs_world_to_json_desc_t::serialize_builtin
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:343
ecs_world_to_json_desc_t::serialize_modules
bool serialize_modules
Exclude modules & contents.
Definition json.h:344