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
10
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
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37 typedef struct ecs_from_json_desc_t {
38 const char *name;
39 const char *expr;
40
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#ifndef __cplusplus
231#define ECS_ENTITY_TO_JSON_INIT (ecs_entity_to_json_desc_t){\
232 .serialize_entity_id = false, \
233 .serialize_doc = false, \
234 .serialize_full_paths = true, \
235 .serialize_inherited = false, \
236 .serialize_values = true, \
237 .serialize_builtin = false, \
238 .serialize_type_info = false, \
239 .serialize_alerts = false, \
240 .serialize_refs = 0, \
241 .serialize_matches = false, \
242}
243#else
244#define ECS_ENTITY_TO_JSON_INIT {\
245 false, \
246 false, \
247 true, \
248 false, \
249 true, \
250 false, \
251 false, \
252 false, \
253 0, \
254 false, \
255}
256#endif
257
268FLECS_API
269 char* ecs_entity_to_json(
270 const ecs_world_t *world,
271 ecs_entity_t entity,
272 const ecs_entity_to_json_desc_t *desc);
273
282FLECS_API
283 int ecs_entity_to_json_buf(
284 const ecs_world_t *world,
285 ecs_entity_t entity,
286 ecs_strbuf_t *buf_out,
287 const ecs_entity_to_json_desc_t *desc);
288
290 typedef struct ecs_iter_to_json_desc_t {
291 bool serialize_entity_ids;
292 bool serialize_values;
293 bool serialize_builtin;
294 bool serialize_doc;
295 bool serialize_full_paths;
296 bool serialize_fields;
297 bool serialize_inherited;
298 bool serialize_table;
299 bool serialize_type_info;
300 bool serialize_field_info;
301 bool serialize_query_info;
302 bool serialize_query_plan;
303 bool serialize_query_profile;
304 bool dont_serialize_results;
305 bool serialize_alerts;
306 ecs_entity_t serialize_refs;
307 bool serialize_matches;
308 ecs_poly_t *query;
309} ecs_iter_to_json_desc_t;
310
312#ifndef __cplusplus
313#define ECS_ITER_TO_JSON_INIT (ecs_iter_to_json_desc_t){\
314 .serialize_entity_ids = false, \
315 .serialize_values = true, \
316 .serialize_builtin = false, \
317 .serialize_doc = false, \
318 .serialize_full_paths = true, \
319 .serialize_fields = true, \
320 .serialize_inherited = false, \
321 .serialize_table = false, \
322 .serialize_type_info = false, \
323 .serialize_field_info = false, \
324 .serialize_query_info = false, \
325 .serialize_query_plan = false, \
326 .serialize_query_profile = false, \
327 .dont_serialize_results = false, \
328 .serialize_alerts = false, \
329 .serialize_refs = false, \
330 .serialize_matches = false, \
331 .query = NULL \
332}
333#else
334#define ECS_ITER_TO_JSON_INIT {\
335 false, \
336 true, \
337 false, \
338 false, \
339 true, \
340 true, \
341 false, \
342 false, \
343 false, \
344 false, \
345 false, \
346 false, \
347 false, \
348 false, \
349 false, \
350 false, \
351 false, \
352 nullptr \
353}
354#endif
355
363FLECS_API
364 char* ecs_iter_to_json(
365 ecs_iter_t *iter,
366 const ecs_iter_to_json_desc_t *desc);
367
375FLECS_API
376 int ecs_iter_to_json_buf(
377 ecs_iter_t *iter,
378 ecs_strbuf_t *buf_out,
379 const ecs_iter_to_json_desc_t *desc);
380
382 typedef struct ecs_world_to_json_desc_t {
383 bool serialize_builtin;
384 bool serialize_modules;
385} ecs_world_to_json_desc_t;
386
404FLECS_API
405 char* ecs_world_to_json(
406 ecs_world_t *world,
407 const ecs_world_to_json_desc_t *desc);
408
416FLECS_API
417 int ecs_world_to_json_buf(
418 ecs_world_t *world,
419 ecs_strbuf_t *buf_out,
420 const ecs_world_to_json_desc_t *desc);
421
422#ifdef __cplusplus
423}
424#endif
425
426#endif
427
429
430#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_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_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_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_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:346
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:390
ecs_poly_t
void ecs_poly_t
A poly object.
Definition flecs.h:479
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:1099
ecs_iter_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:290
ecs_iter_to_json_desc_t::serialize_full_paths
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:295
ecs_iter_to_json_desc_t::serialize_query_plan
bool serialize_query_plan
Serialize query plan.
Definition json.h:302
ecs_iter_to_json_desc_t::serialize_fields
bool serialize_fields
Serialize field data.
Definition json.h:296
ecs_iter_to_json_desc_t::serialize_doc
bool serialize_doc
Serialize doc attributes.
Definition json.h:294
ecs_iter_to_json_desc_t::serialize_query_profile
bool serialize_query_profile
Profile query performance.
Definition json.h:303
ecs_iter_to_json_desc_t::serialize_query_info
bool serialize_query_info
Serialize query terms.
Definition json.h:301
ecs_iter_to_json_desc_t::dont_serialize_results
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:304
ecs_iter_to_json_desc_t::serialize_field_info
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:300
ecs_iter_to_json_desc_t::serialize_builtin
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:293
ecs_iter_to_json_desc_t::serialize_table
bool serialize_table
Serialize entire table vs.
Definition json.h:298
ecs_iter_to_json_desc_t::serialize_refs
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:306
ecs_iter_to_json_desc_t::serialize_inherited
bool serialize_inherited
Serialize inherited components.
Definition json.h:297
ecs_iter_to_json_desc_t::query
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:308
ecs_iter_to_json_desc_t::serialize_alerts
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:305
ecs_iter_to_json_desc_t::serialize_values
bool serialize_values
Serialize component values.
Definition json.h:292
ecs_iter_to_json_desc_t::serialize_type_info
bool serialize_type_info
Serialize type information.
Definition json.h:299
ecs_iter_to_json_desc_t::serialize_entity_ids
bool serialize_entity_ids
Serialize entity ids.
Definition json.h:291
ecs_iter_to_json_desc_t::serialize_matches
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:307
ecs_world_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:382
ecs_world_to_json_desc_t::serialize_builtin
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:383
ecs_world_to_json_desc_t::serialize_modules
bool serialize_modules
Exclude modules & contents.
Definition json.h:384