Skip to content

Commit ee3b623

Browse files
Adding example code (which may change)
1 parent 7a974bc commit ee3b623

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ The serialization functionality in this repository is useful when explicit contr
2121
This library uses `std::format` style formatting. For example:
2222

2323
```
24-
(insert example code)
24+
struct Hike {
25+
unsigned int distance;
26+
int elevation;
27+
std::optional<std::string>> name;
28+
std::vector<int> waypoints;
29+
};
30+
// ...
31+
chops::mutable_shared_buffer buf;
32+
33+
chops::binary_serialize(buf, "{32ui}{16i}{8ui}{16ui}{16ui}{64i}",
34+
hike_obj.distance, hike_obj.elevation, hike_obj.name, hike_obj.waypoints);
35+
36+
// ...
37+
net_obj.send(buf);
38+
39+
```
40+
41+
The buffer will contain the following:
42+
43+
```
44+
32 bit unsigned integer containing distance value
45+
16 bit signed integer containing elevation value
46+
8 bit unsigned integer corresponding to true or false for the optional
47+
16 bit unsigned integer for the size of the name string
48+
0 - N 8 bit characters for the name string
49+
16 bit unsigned integer for the size of the waypoints vector
50+
0 - N 64 bit signed integers for each waypoint value
2551
```
2652

2753
The documentation overview provides a comparison with other serialization libraries as well as a rationale for the design decisions.

0 commit comments

Comments
 (0)