Flecs v3.2
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_EXPR
14#define FLECS_EXPR
15#endif
16
17#ifndef FLECS_JSON_H
18#define FLECS_JSON_H
19
28#ifdef __cplusplus
29extern "C" {
30#endif
31
33typedef struct ecs_from_json_desc_t {
34 const char *name;
35 const char *expr;
40 const ecs_world_t*,
41 const char *value,
42 void *ctx);
43 void *lookup_ctx;
44
47 bool strict;
49
61FLECS_API
63 const ecs_world_t *world,
64 ecs_entity_t type,
65 void *ptr,
66 const char *json,
67 const ecs_from_json_desc_t *desc);
68
79FLECS_API
81 ecs_world_t *world,
82 ecs_entity_t entity,
83 const char *json,
84 const ecs_from_json_desc_t *desc);
85
94FLECS_API
96 ecs_world_t *world,
97 const char *json,
98 const ecs_from_json_desc_t *desc);
99
107FLECS_API
109 ecs_world_t *world,
110 const char *filename,
111 const ecs_from_json_desc_t *desc);
112
127FLECS_API
129 const ecs_world_t *world,
130 ecs_entity_t type,
131 const void *data,
132 int32_t count);
133
144FLECS_API
146 const ecs_world_t *world,
147 ecs_entity_t type,
148 const void *data,
149 int32_t count,
150 ecs_strbuf_t *buf_out);
151
160FLECS_API
162 const ecs_world_t *world,
163 ecs_entity_t type,
164 const void *data);
165
175FLECS_API
177 const ecs_world_t *world,
178 ecs_entity_t type,
179 const void *data,
180 ecs_strbuf_t *buf_out);
181
192FLECS_API
194 const ecs_world_t *world,
195 ecs_entity_t type);
196
205FLECS_API
207 const ecs_world_t *world,
208 ecs_entity_t type,
209 ecs_strbuf_t *buf_out);
210
229
230#define ECS_ENTITY_TO_JSON_INIT (ecs_entity_to_json_desc_t){true, false,\
231 false, false, false, true, false, true, false, false, false, false, false,\
232 false, false }
233
244FLECS_API
246 const ecs_world_t *world,
247 ecs_entity_t entity,
248 const ecs_entity_to_json_desc_t *desc);
249
258FLECS_API
260 const ecs_world_t *world,
261 ecs_entity_t entity,
262 ecs_strbuf_t *buf_out,
263 const ecs_entity_to_json_desc_t *desc);
264
294
295#define ECS_ITER_TO_JSON_INIT (ecs_iter_to_json_desc_t){\
296 .serialize_term_ids = true, \
297 .serialize_term_labels = false, \
298 .serialize_ids = true, \
299 .serialize_id_labels = false, \
300 .serialize_sources = true, \
301 .serialize_variables = true, \
302 .serialize_is_set = true, \
303 .serialize_values = true, \
304 .serialize_entities = true, \
305 .serialize_entity_labels = false, \
306 .serialize_entity_ids = false, \
307 .serialize_entity_names = false, \
308 .serialize_variable_labels = false, \
309 .serialize_variable_ids = false, \
310 .serialize_colors = false, \
311 .measure_eval_duration = false, \
312 .serialize_type_info = false, \
313 .serialize_table = false, \
314 .serialize_rows = false, \
315 .serialize_field_info = false, \
316 .serialize_query_info = false, \
317 .serialize_query_plan = false, \
318 .serialize_query_profile = false, \
319 .dont_serialize_results = false, \
320}
321
330FLECS_API
332 const ecs_world_t *world,
333 ecs_iter_t *iter,
334 const ecs_iter_to_json_desc_t *desc);
335
344FLECS_API
346 const ecs_world_t *world,
347 ecs_iter_t *iter,
348 ecs_strbuf_t *buf_out,
349 const ecs_iter_to_json_desc_t *desc);
350
356
374FLECS_API
376 ecs_world_t *world,
377 const ecs_world_to_json_desc_t *desc);
378
386FLECS_API
388 ecs_world_t *world,
389 ecs_strbuf_t *buf_out,
390 const ecs_world_to_json_desc_t *desc);
391
392#ifdef __cplusplus
393}
394#endif
395
396#endif
397
400#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.
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_iter_to_json(const ecs_world_t *world, ecs_iter_t *iter, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string.
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 int ecs_iter_to_json_buf(const ecs_world_t *world, ecs_iter_t *iter, ecs_strbuf_t *buf_out, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string buffer.
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:318
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:362
void ecs_poly_t
A poly object.
Definition flecs.h:501
Used with ecs_iter_to_json().
Definition json.h:212
bool serialize_values
Serialize component values.
Definition json.h:223
bool serialize_label
Serialize doc name.
Definition json.h:214
bool serialize_alerts
Serialize active alerts for entity.
Definition json.h:225
bool serialize_brief
Serialize brief doc description.
Definition json.h:215
bool serialize_hidden
Serialize ids hidden by override.
Definition json.h:222
bool serialize_path
Serialize full pathname.
Definition json.h:213
bool serialize_private
Serialize private components.
Definition json.h:221
ecs_entity_t serialize_refs
Serialize references (incoming edges) for relationship.
Definition json.h:226
bool serialize_id_labels
Serialize labels of (component) ids.
Definition json.h:219
bool serialize_matches
Serialize which queries entity matches with.
Definition json.h:227
bool serialize_link
Serialize doc link (URL)
Definition json.h:216
bool serialize_ids
Serialize (component) ids.
Definition json.h:218
bool serialize_type_info
Serialize type info (requires serialize_values)
Definition json.h:224
bool serialize_color
Serialize doc color.
Definition json.h:217
bool serialize_base
Serialize base components.
Definition json.h:220
Used with ecs_ptr_from_json(), ecs_entity_from_json().
Definition json.h:33
const char * name
Name of expression (used for logging)
Definition json.h:34
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:39
const char * expr
Full expression (used for logging)
Definition json.h:35
bool strict
Require components to be registered with reflection data.
Definition json.h:47
Used with ecs_iter_to_json().
Definition json.h:266
bool serialize_ids
Serialize actual (matched) component ids.
Definition json.h:269
bool serialize_query_plan
Serialize query plan.
Definition json.h:289
bool serialize_rows
Use row-based serialization, with entities in separate elements.
Definition json.h:286
bool serialize_id_labels
Serialize actual (matched) component id labels.
Definition json.h:270
bool measure_eval_duration
Serialize evaluation duration.
Definition json.h:283
bool serialize_variable_ids
Serialize numerical ids for variables.
Definition json.h:281
bool serialize_query_profile
Profile query performance.
Definition json.h:290
bool serialize_query_info
Serialize query terms.
Definition json.h:288
bool serialize_sources
Serialize sources.
Definition json.h:271
bool dont_serialize_results
If true, query won't be evaluated.
Definition json.h:291
bool serialize_colors
Serialize doc color for entities.
Definition json.h:282
bool serialize_entities
Serialize entities (for This terms)
Definition json.h:276
bool serialize_field_info
Serialize metadata for fields returned by query.
Definition json.h:287
bool serialize_variables
Serialize variables.
Definition json.h:272
bool serialize_entity_names
Serialize names (not paths) for entities.
Definition json.h:279
bool serialize_variable_labels
Serialize doc name for variables.
Definition json.h:280
bool serialize_table
Serialize entire table vs.
Definition json.h:285
bool serialize_term_ids
Serialize query term component ids.
Definition json.h:267
bool serialize_term_labels
Serialize query term component id labels.
Definition json.h:268
bool serialize_private
Serialize component values.
Definition json.h:275
ecs_poly_t * query
Query object (required for serialize_query_[plan|profile]).
Definition json.h:292
bool serialize_entity_labels
Serialize doc name for entities.
Definition json.h:277
bool serialize_values
Serialize component values.
Definition json.h:274
bool serialize_type_info
Serialize type information.
Definition json.h:284
bool serialize_entity_ids
Serialize numerical ids for entities.
Definition json.h:278
bool serialize_is_set
Serialize is_set (for optional terms)
Definition json.h:273
Used with ecs_iter_to_json().
Definition json.h:352
bool serialize_builtin
Exclude flecs modules & contents.
Definition json.h:353
bool serialize_modules
Exclude modules & contents.
Definition json.h:354