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#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
270 const ecs_world_t *world,
271 ecs_entity_t entity,
272 const ecs_entity_to_json_desc_t *desc);
273
282FLECS_API
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
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
365 ecs_iter_t *iter,
366 const ecs_iter_to_json_desc_t *desc);
367
375FLECS_API
377 ecs_iter_t *iter,
378 ecs_strbuf_t *buf_out,
379 const ecs_iter_to_json_desc_t *desc);
380
386
404FLECS_API
406 ecs_world_t *world,
407 const ecs_world_to_json_desc_t *desc);
408
416FLECS_API
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
430#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:346
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:390
void ecs_poly_t
A poly object.
Definition flecs.h:479
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:1100
Used with ecs_iter_to_json().
Definition json.h:290
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:295
bool serialize_query_plan
Serialize query plan.
Definition json.h:302
bool serialize_fields
Serialize field data.
Definition json.h:296
bool serialize_doc
Serialize doc attributes.
Definition json.h:294
bool serialize_query_profile
Profile query performance.
Definition json.h:303
bool serialize_query_info
Serialize query terms.
Definition json.h:301
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:304
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:300
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:293
bool serialize_table
Serialize entire table vs.
Definition json.h:298
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:306
bool serialize_inherited
Serialize inherited components.
Definition json.h:297
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:308
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:305
bool serialize_values
Serialize component values.
Definition json.h:292
bool serialize_type_info
Serialize type information.
Definition json.h:299
bool serialize_entity_ids
Serialize entity ids.
Definition json.h:291
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:307
Used with ecs_iter_to_json().
Definition json.h:382
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:383
bool serialize_modules
Exclude modules & contents.
Definition json.h:384