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
37typedef struct ecs_from_json_desc_t {
38 const char *name;
39 const char *expr;
44 const ecs_world_t*,
45 const char *value,
46 void *ctx);
47 void *lookup_ctx;
48
51 bool strict;
53
65FLECS_API
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
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
100 ecs_world_t *world,
101 const char *json,
102 const ecs_from_json_desc_t *desc);
103
111FLECS_API
113 ecs_world_t *world,
114 const char *filename,
115 const ecs_from_json_desc_t *desc);
116
131FLECS_API
133 const ecs_world_t *world,
134 ecs_entity_t type,
135 const void *data,
136 int32_t count);
137
148FLECS_API
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
166 const ecs_world_t *world,
167 ecs_entity_t type,
168 const void *data);
169
179FLECS_API
181 const ecs_world_t *world,
182 ecs_entity_t type,
183 const void *data,
184 ecs_strbuf_t *buf_out);
185
196FLECS_API
198 const ecs_world_t *world,
199 ecs_entity_t type);
200
209FLECS_API
211 const ecs_world_t *world,
212 ecs_entity_t type,
213 ecs_strbuf_t *buf_out);
214
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
254 const ecs_world_t *world,
255 ecs_entity_t entity,
256 const ecs_entity_to_json_desc_t *desc);
257
266FLECS_API
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
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
325 ecs_iter_t *iter,
326 const ecs_iter_to_json_desc_t *desc);
327
335FLECS_API
337 ecs_iter_t *iter,
338 ecs_strbuf_t *buf_out,
339 const ecs_iter_to_json_desc_t *desc);
340
346
364FLECS_API
366 ecs_world_t *world,
367 const ecs_world_to_json_desc_t *desc);
368
376FLECS_API
378 ecs_world_t *world,
379 ecs_strbuf_t *buf_out,
380 const ecs_world_to_json_desc_t *desc);
381
382
383
384/* Legacy deserializer functions. These can be used to load a v3 JSON string and
385 * save it to the new format. These functions will be removed in the next
386 * release. */
387
388FLECS_API
389const char* ecs_entity_from_json_legacy(
390 ecs_world_t *world,
391 ecs_entity_t entity,
392 const char *json,
393 const ecs_from_json_desc_t *desc);
394
395FLECS_API
396const char* ecs_world_from_json_legacy(
397 ecs_world_t *world,
398 const char *json,
399 const ecs_from_json_desc_t *desc);
400
401FLECS_API
402const char* ecs_world_from_json_file_legacy(
403 ecs_world_t *world,
404 const char *filename,
405 const ecs_from_json_desc_t *desc);
406
407#ifdef __cplusplus
408}
409#endif
410
411#endif
412
415#endif
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.
struct ecs_entity_to_json_desc_t ecs_entity_to_json_desc_t
Used with ecs_iter_to_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.
struct ecs_from_json_desc_t ecs_from_json_desc_t
Used with ecs_ptr_from_json(), ecs_entity_from_json().
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.
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.
struct ecs_world_to_json_desc_t ecs_world_to_json_desc_t
Used with ecs_iter_to_json().
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.
struct ecs_iter_to_json_desc_t ecs_iter_to_json_desc_t
Used with ecs_iter_to_json().
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.
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.
FLECS_API char * ecs_ptr_to_json(const ecs_world_t *world, ecs_entity_t type, const void *data)
Serialize value into JSON string.
FLECS_API char * ecs_type_info_to_json(const ecs_world_t *world, ecs_entity_t type)
Serialize type info to JSON.
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.
FLECS_API char * ecs_world_to_json(ecs_world_t *world, const ecs_world_to_json_desc_t *desc)
Serialize world into JSON string.
FLECS_API char * ecs_iter_to_json(ecs_iter_t *iter, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string.
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.
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.
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.
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_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:339
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:383
void ecs_poly_t
A poly object.
Definition flecs.h:475
Used with ecs_iter_to_json().
Definition json.h:216
bool serialize_values
Serialize component values.
Definition json.h:221
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:222
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:224
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:225
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:226
bool serialize_type_info
Serialize type info (requires serialize_values)
Definition json.h:223
bool serialize_inherited
Serialize base components.
Definition json.h:220
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:219
bool serialize_entity_id
Serialize entity id.
Definition json.h:217
bool serialize_doc
Serialize doc attributes.
Definition json.h:218
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:37
const char * name
Name of expression (used for logging)
Definition json.h:38
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
const char * expr
Full expression (used for logging)
Definition json.h:39
bool strict
Require components to be registered with reflection data.
Definition json.h:51
Iterator.
Definition flecs.h:1025
Used with ecs_iter_to_json().
Definition json.h:274
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:279
bool serialize_query_plan
Serialize query plan.
Definition json.h:286
bool serialize_fields
Serialize field data.
Definition json.h:280
bool serialize_doc
Serialize doc attributes.
Definition json.h:278
bool serialize_query_profile
Profile query performance.
Definition json.h:287
bool serialize_query_info
Serialize query terms.
Definition json.h:285
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:288
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:284
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:277
bool serialize_table
Serialize entire table vs.
Definition json.h:282
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:290
bool serialize_inherited
Serialize inherited components.
Definition json.h:281
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:292
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:289
bool serialize_values
Serialize component values.
Definition json.h:276
bool serialize_type_info
Serialize type information.
Definition json.h:283
bool serialize_entity_ids
Serialize entity ids.
Definition json.h:275
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:291
Used with ecs_iter_to_json().
Definition json.h:342
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:343
bool serialize_modules
Exclude modules & contents.
Definition json.h:344