File: rfl_skip.md

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (59 lines) | stat: -rw-r--r-- 1,500 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# `rfl::Skip`  

It is possible to skip the serialization and deserialization of fields using `rfl::Skip`.

Note that `rfl::Skip` is unsupported by all schemaful formats, like Avro.

```cpp
struct Person {
  rfl::Rename<"firstName", std::string> first_name;
  rfl::Rename<"lastName", std::string> last_name;
  rfl::Skip<std::string> town;
  Age age;
};
```

This means that the field `town` will be ignored:

```json
{"firstName":"Homer","lastName":"Simpson","age":45}
```

If you only want to skip the deserialization, but not the serialization, you can use `rfl::SkipDeserialization`:


```cpp
struct Person {
  rfl::Rename<"firstName", std::string> first_name;
  rfl::Rename<"lastName", std::string> last_name;
  rfl::SkipDeserialization<std::string> town;
  Age age;
};
```

If you only want to skip the serialization, but not the deserialization, you can use `rfl::SkipSerialization`. 
Note that this implies that the serializied data cannot be deserialized, because the field `town`
is expected during deserialization, but not serialized.

```cpp
struct Person {
  rfl::Rename<"firstName", std::string> first_name;
  rfl::Rename<"lastName", std::string> last_name;
  rfl::SkipSerialization<std::string> town;
  Age age;
};
```

You can access the underlying value in the field `town` using any of the following operators:

```cpp
person.town();
person.town.get();
person.town.value();
```

You can assign the underlying field just like any other field:

```cpp
person.town = "Springfield";
```