1#include <ser_opaque_type.h>
2#include <stdio.h>
3
4
5typedef struct {
6 int32_t a;
7 int32_t b;
8} Sum;
9
10
12 const Sum *data = ptr;
17
18 int32_t result = data->a + data->b;
19 ser->
member(ser,
"result");
21 return 0;
22}
23
24
25void* Sum_ensure_member(void *ptr, const char *member) {
26 Sum *data = ptr;
27 if (!strcmp(member, "a")) {
28 return &data->a;
29 } else if (!strcmp(member, "b")) {
30 return &data->b;
31 } else {
32 return NULL;
33 }
34}
35
36int main(int argc, char *argv[]) {
38
39
41
42
44 .members = {
48 }
49 });
50
51
52
54
56
57 .type.as_type = sum_type_descriptor,
58
59 .type.serialize = Sum_serialize,
60
61 .type.ensure_member = Sum_ensure_member
62 });
63
64 Sum v = { .a = 10, .b = 20 };
65
66
68 printf("%s\n", json);
69 ecs_os_free(json);
70
71
73
74
76 printf("%s\n", json);
77 ecs_os_free(json);
78
79
80
81
82
84}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
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 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_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
#define ECS_COMPONENT(world, id)
Declare and define a component.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
int(*) member(const struct ecs_serializer_t *ser, const char *member)
Serialize member.
int(*) value(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.