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_DOC
18#define FLECS_DOC
19#endif
20
21#ifndef FLECS_QUERY_DSL
22#define FLECS_QUERY_DSL /* For parsing component id expressions */
23#endif
24
25#ifndef FLECS_JSON_H
26#define FLECS_JSON_H
27
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
41 typedef struct ecs_from_json_desc_t {
42 const char *name;
43 const char *expr;
44
47 ecs_entity_t (*lookup_action)(
48 ecs_world_t*,
49 const char *value,
50 void *ctx);
51 void *lookup_ctx;
52
55 bool strict;
56} ecs_from_json_desc_t;
57
69FLECS_API
70 const char* ecs_ptr_from_json(
71 const ecs_world_t *world,
72 ecs_entity_t type,
73 void *ptr,
74 const char *json,
75 const ecs_from_json_desc_t *desc);
76
87FLECS_API
88 const char* ecs_entity_from_json(
89 ecs_world_t *world,
90 ecs_entity_t entity,
91 const char *json,
92 const ecs_from_json_desc_t *desc);
93
102FLECS_API
103 const char* ecs_world_from_json(
104 ecs_world_t *world,
105 const char *json,
106 const ecs_from_json_desc_t *desc);
107
115FLECS_API
116 const char* ecs_world_from_json_file(
117 ecs_world_t *world,
118 const char *filename,
119 const ecs_from_json_desc_t *desc);
120
135FLECS_API
136 char* ecs_array_to_json(
137 const ecs_world_t *world,
138 ecs_entity_t type,
139 const void *data,
140 int32_t count);
141
152FLECS_API
153 int ecs_array_to_json_buf(
154 const ecs_world_t *world,
155 ecs_entity_t type,
156 const void *data,
157 int32_t count,
158 ecs_strbuf_t *buf_out);
159
168FLECS_API
169 char* ecs_ptr_to_json(
170 const ecs_world_t *world,
171 ecs_entity_t type,
172 const void *data);
173
183FLECS_API
184 int ecs_ptr_to_json_buf(
185 const ecs_world_t *world,
186 ecs_entity_t type,
187 const void *data,
188 ecs_strbuf_t *buf_out);
189
200FLECS_API
201 char* ecs_type_info_to_json(
202 const ecs_world_t *world,
203 ecs_entity_t type);
204
213FLECS_API
214 int ecs_type_info_to_json_buf(
215 const ecs_world_t *world,
216 ecs_entity_t type,
217 ecs_strbuf_t *buf_out);
218
220 typedef struct ecs_entity_to_json_desc_t {
221 bool serialize_entity_id;
222 bool serialize_doc;
223 bool serialize_full_paths;
224 bool serialize_inherited;
225 bool serialize_values;
226 bool serialize_builtin;
227 bool serialize_type_info;
228 bool serialize_alerts;
229 ecs_entity_t serialize_refs;
230 bool serialize_matches;
232 bool (*component_filter)
233 (const ecs_world_t *, ecs_entity_t);
234} ecs_entity_to_json_desc_t;
235
237#ifndef __cplusplus
238#define ECS_ENTITY_TO_JSON_INIT (ecs_entity_to_json_desc_t){\
239 .serialize_entity_id = false, \
240 .serialize_doc = false, \
241 .serialize_full_paths = true, \
242 .serialize_inherited = false, \
243 .serialize_values = true, \
244 .serialize_builtin = false, \
245 .serialize_type_info = false, \
246 .serialize_alerts = false, \
247 .serialize_refs = 0, \
248 .serialize_matches = false, \
249 .component_filter = NULL, \
250}
251#else
252#define ECS_ENTITY_TO_JSON_INIT {\
253 false, \
254 false, \
255 true, \
256 false, \
257 true, \
258 false, \
259 false, \
260 false, \
261 0, \
262 false, \
263 nullptr, \
264}
265#endif
266
277FLECS_API
278 char* ecs_entity_to_json(
279 const ecs_world_t *world,
280 ecs_entity_t entity,
281 const ecs_entity_to_json_desc_t *desc);
282
291FLECS_API
292 int ecs_entity_to_json_buf(
293 const ecs_world_t *world,
294 ecs_entity_t entity,
295 ecs_strbuf_t *buf_out,
296 const ecs_entity_to_json_desc_t *desc);
297
299 typedef struct ecs_iter_to_json_desc_t {
300 bool serialize_entity_ids;
301 bool serialize_values;
302 bool serialize_builtin;
303 bool serialize_doc;
304 bool serialize_full_paths;
305 bool serialize_fields;
306 bool serialize_inherited;
307 bool serialize_table;
308 bool serialize_type_info;
309 bool serialize_field_info;
310 bool serialize_query_info;
311 bool serialize_query_plan;
312 bool serialize_query_profile;
313 bool dont_serialize_results;
314 bool serialize_alerts;
315 ecs_entity_t serialize_refs;
316 bool serialize_matches;
318 bool (*component_filter)
319 (const ecs_world_t *, ecs_entity_t);
320 ecs_poly_t *query;
321} ecs_iter_to_json_desc_t;
322
324#ifndef __cplusplus
325#define ECS_ITER_TO_JSON_INIT (ecs_iter_to_json_desc_t){\
326 .serialize_entity_ids = false, \
327 .serialize_values = true, \
328 .serialize_builtin = false, \
329 .serialize_doc = false, \
330 .serialize_full_paths = true, \
331 .serialize_fields = true, \
332 .serialize_inherited = false, \
333 .serialize_table = false, \
334 .serialize_type_info = false, \
335 .serialize_field_info = false, \
336 .serialize_query_info = false, \
337 .serialize_query_plan = false, \
338 .serialize_query_profile = false, \
339 .dont_serialize_results = false, \
340 .serialize_alerts = false, \
341 .serialize_refs = false, \
342 .serialize_matches = false, \
343 .component_filter = NULL, \
344 .query = NULL \
345}
346#else
347#define ECS_ITER_TO_JSON_INIT {\
348 false, \
349 true, \
350 false, \
351 false, \
352 true, \
353 true, \
354 false, \
355 false, \
356 false, \
357 false, \
358 false, \
359 false, \
360 false, \
361 false, \
362 false, \
363 false, \
364 false, \
365 nullptr, \
366 nullptr \
367}
368#endif
369
377FLECS_API
378 char* ecs_iter_to_json(
379 ecs_iter_t *iter,
380 const ecs_iter_to_json_desc_t *desc);
381
389FLECS_API
390 int ecs_iter_to_json_buf(
391 ecs_iter_t *iter,
392 ecs_strbuf_t *buf_out,
393 const ecs_iter_to_json_desc_t *desc);
394
396 typedef struct ecs_world_to_json_desc_t {
397 bool serialize_builtin;
398 bool serialize_modules;
399} ecs_world_to_json_desc_t;
400
418FLECS_API
419 char* ecs_world_to_json(
420 ecs_world_t *world,
421 const ecs_world_to_json_desc_t *desc);
422
430FLECS_API
431 int ecs_world_to_json_buf(
432 ecs_world_t *world,
433 ecs_strbuf_t *buf_out,
434 const ecs_world_to_json_desc_t *desc);
435
436#ifdef __cplusplus
437}
438#endif
439
440#endif
441
443
444#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:361
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:405
ecs_poly_t
void ecs_poly_t
A poly object.
Definition flecs.h:494
ecs_entity_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:220
ecs_entity_to_json_desc_t::serialize_values
bool serialize_values
Serialize component values.
Definition json.h:225
ecs_entity_to_json_desc_t::serialize_builtin
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:226
ecs_entity_to_json_desc_t::serialize_alerts
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:228
ecs_entity_to_json_desc_t::serialize_refs
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:229
ecs_entity_to_json_desc_t::serialize_matches
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:230
ecs_entity_to_json_desc_t::component_filter
bool(* component_filter)(const ecs_world_t *, ecs_entity_t)
Callback for if the component should be serialized.
Definition json.h:233
ecs_entity_to_json_desc_t::serialize_type_info
bool serialize_type_info
Serialize type info (requires serialize_values)
Definition json.h:227
ecs_entity_to_json_desc_t::serialize_inherited
bool serialize_inherited
Serialize base components.
Definition json.h:224
ecs_entity_to_json_desc_t::serialize_full_paths
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:223
ecs_entity_to_json_desc_t::serialize_entity_id
bool serialize_entity_id
Serialize entity id.
Definition json.h:221
ecs_entity_to_json_desc_t::serialize_doc
bool serialize_doc
Serialize doc attributes.
Definition json.h:222
ecs_from_json_desc_t
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:41
ecs_from_json_desc_t::name
const char * name
Name of expression (used for logging)
Definition json.h:42
ecs_from_json_desc_t::expr
const char * expr
Full expression (used for logging)
Definition json.h:43
ecs_from_json_desc_t::strict
bool strict
Require components to be registered with reflection data.
Definition json.h:55
ecs_from_json_desc_t::lookup_action
ecs_entity_t(* lookup_action)(ecs_world_t *, const char *value, void *ctx)
Callback that allows for specifying a custom lookup function.
Definition json.h:47
ecs_iter_t
Iterator.
Definition flecs.h:1142
ecs_iter_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:299
ecs_iter_to_json_desc_t::serialize_full_paths
bool serialize_full_paths
Serialize full paths for tags, components and pairs.
Definition json.h:304
ecs_iter_to_json_desc_t::serialize_query_plan
bool serialize_query_plan
Serialize query plan.
Definition json.h:311
ecs_iter_to_json_desc_t::serialize_fields
bool serialize_fields
Serialize field data.
Definition json.h:305
ecs_iter_to_json_desc_t::serialize_doc
bool serialize_doc
Serialize doc attributes.
Definition json.h:303
ecs_iter_to_json_desc_t::serialize_query_profile
bool serialize_query_profile
Profile query performance.
Definition json.h:312
ecs_iter_to_json_desc_t::serialize_query_info
bool serialize_query_info
Serialize query terms.
Definition json.h:310
ecs_iter_to_json_desc_t::dont_serialize_results
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:313
ecs_iter_to_json_desc_t::serialize_field_info
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:309
ecs_iter_to_json_desc_t::serialize_builtin
bool serialize_builtin
Serialize builtin data as components (e.g.
Definition json.h:302
ecs_iter_to_json_desc_t::serialize_table
bool serialize_table
Serialize entire table vs.
Definition json.h:307
ecs_iter_to_json_desc_t::serialize_refs
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:315
ecs_iter_to_json_desc_t::serialize_inherited
bool serialize_inherited
Serialize inherited components.
Definition json.h:306
ecs_iter_to_json_desc_t::query
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:320
ecs_iter_to_json_desc_t::serialize_alerts
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:314
ecs_iter_to_json_desc_t::component_filter
bool(* component_filter)(const ecs_world_t *, ecs_entity_t)
Callback for if the component should be serialized.
Definition json.h:319
ecs_iter_to_json_desc_t::serialize_values
bool serialize_values
Serialize component values.
Definition json.h:301
ecs_iter_to_json_desc_t::serialize_type_info
bool serialize_type_info
Serialize type information.
Definition json.h:308
ecs_iter_to_json_desc_t::serialize_entity_ids
bool serialize_entity_ids
Serialize entity ids.
Definition json.h:300
ecs_iter_to_json_desc_t::serialize_matches
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:316
ecs_world_to_json_desc_t
Used with ecs_iter_to_json().
Definition json.h:396
ecs_world_to_json_desc_t::serialize_builtin
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:397
ecs_world_to_json_desc_t::serialize_modules
bool serialize_modules
Exclude modules & contents.
Definition json.h:398