1#include <ser_std_string.h>
2#include <iostream>
3#include <string>
4
5
6
7struct StringComponent {
8 std::string a;
9 std::string b;
10};
11
12int main(int, char *[]) {
14
15
19 const char *str = data->c_str();
20 return s->
value(flecs::String, &str);
21 })
22 .assign_string([](std::string* data, const char *value) {
23 *data = value;
24 });
25
26
28 .member<std::string>("a")
29 .member<std::string>("b");
30
31
32 StringComponent v = {"foo", "bar"};
33 std::cout << ecs.
to_json(&v) << std::endl;
34
35
36 ecs.
from_json(&v,
"{\"a\": \"hello\", \"b\": \"world\"}");
37 std::cout << "{a: " << v.a << ", b: " << v.b << "}" << std::endl;
38
39
40
41
42}
component & opaque(const Func &type_support)
Register an opaque type interface.
const char * from_json(flecs::entity_t tid, void *value, const char *json, flecs::from_json_desc_t *desc=nullptr)
Deserialize a value from JSON.
flecs::string to_json(flecs::entity_t tid, const void *value) const
Serialize an untyped value to JSON.
flecs::component< T > component(Args &&... args) const
Find or register a component.
int(*) value(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.