Deserialize a component from a custom format #1894
-
|
I want to do something like this: However, I was thinking, what if I could add a function to the component instead, that does this push, set_float, pop stuff. Or something even more dynamic, since we are declaring the component with Edit, found something, however I feel it is a little roundabout way to do this: It would be nice to have something iterable to retrieve all the members. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The key thing about deserializing though is that the input string (or blob, ...) tells you what you're deserializing, not the type. For example, if you see a If you were to iterate all members of a type in order, you'd require that members always appear in the same order in the input data, which would be brittle. That said, if you are serializing, it makes a lot of sense to iterate members. See this example for how you can do that: |
Beta Was this translation helpful? Give feedback.
The key thing about deserializing though is that the input string (or blob, ...) tells you what you're deserializing, not the type. For example, if you see a
{in the input string, you callecs_meta_push. If you see a comma, you callecs_meta_nextetc.If you were to iterate all members of a type in order, you'd require that members always appear in the same order in the input data, which would be brittle.
That said, if you are serializing, it makes a lot of sense to iterate members. See this example for how you can do that:
https://github.com/SanderMertens/flecs/blob/master/examples/cpp/reflection/custom_serializer/src/main.cpp