mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Added documentation for anonymous fields
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# Anonymous fields
|
||||
|
||||
If you do not want to serialize field names, you do not have to use `rfl::Field`. You can just write your struct like this:
|
||||
|
||||
```cpp
|
||||
struct Person {
|
||||
std::string first_name;
|
||||
std::string last_name;
|
||||
std::vector<Person> children;
|
||||
};
|
||||
```
|
||||
|
||||
This is referred to as anonymous fields. It is particularly relevant if you are using a binary format.
|
||||
|
||||
This can be fully serialized and deserialized using `rfl::json::read` and `rfl::json::write`. No further annotations are needed.
|
||||
|
||||
However, there are a two things you have to keep in mind:
|
||||
|
||||
1) If you annotate *some* of the fields using either `rfl::Field` or `rfl::Flatten`, then you must annotate *all* of them using one of these two.
|
||||
2) If you are combining structs using `rfl::Flatten`, then all fields in all structs must be annotated using either using either `rfl::Field` or `rfl::Flatten`.
|
||||
Reference in New Issue
Block a user