1#include <ser_opaque_string.h>
2#include <stdio.h>
3
4
5typedef struct {
6 char *value;
7} String;
8
9
11 const String *data = ptr;
13}
14
15static void String_assign_string(void *ptr, const char *value) {
16 String *data = ptr;
17
18 if (data->value) {
19 ecs_os_free(data->value);
20 }
21
22 data->value = ecs_os_strdup(value);
23}
24
25int main(int argc, char *argv[]) {
27
28
30
31
32
34
36
38
39 .type.serialize = String_serialize,
40 .type.assign_string = String_assign_string
41 });
42
43 String v = {0};
44
45
47
48
49 printf("%s\n", v.value);
50
51
53 printf("%s\n", json);
54 ecs_os_free(json);
55
56
57
58 ecs_os_free(v.value);
59
61
62
63
64
65}
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.
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(*) value(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.