From 25c58c44ffab01d3b0eeefbd095d7df9e14db4a9 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Tue, 7 Nov 2023 19:17:49 +0100 Subject: [PATCH] Added documentation for anonymous fields --- docs/anonymous_fields.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/anonymous_fields.md diff --git a/docs/anonymous_fields.md b/docs/anonymous_fields.md new file mode 100644 index 00000000..706caf6d --- /dev/null +++ b/docs/anonymous_fields.md @@ -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 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`.