Skip to content

Commit b7d2947

Browse files
tweaking README comments
1 parent 9ec6329 commit b7d2947

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
The `binary_serialize` functions and classes provide serializing and unserializing of binary data. Serialization provides a way to transform application objects into and out of byte streams that can be sent over a network (or used for file IO). Many serialization libraries transform objects to and from text representations, but this library keeps data in binary formats.
1818

19-
The serialization functionality in this repository is useful when explicit control is needed for every bit and byte. This allows a developer to match an existing wire protocol or encoding scheme or to define his or her own wire protocol. Support is provided for fundamental arithmetic types as well as certain C++ vocabulary types such as `std::optional`. Both big and little endian support is provided.
19+
The serialization functionality in this repository is useful when explicit control is needed for every bit and byte. This allows a developer to match an existing wire protocol or encoding scheme or to define his or her own wire protocol. Support is provided for fundamental arithmetic types as well as many C++ vocabulary types such as `std::optional`. Both big and little endian support is provided.
20+
21+
Full flexibility is provided for sequences such as `std::string` or `std::vector`. The number of elements can be specified to take 8 or 16 or 32 (etc) bits, followed by the sequence of chars or array elements. Similar flexibility is provided for vocabulary types such as `std::optional`, where the boolean flag can be specified as 8 or 16 or 32 (etc) bits, followed by the object (or none, if there is no value in the optional).
2022

2123
This library uses `std::format` style formatting. For example:
2224

@@ -28,24 +30,25 @@ This library uses `std::format` style formatting. For example:
2830
std::vector<int> waypoints;
2931
};
3032
// ...
31-
chops::mutable_shared_buffer buf;
33+
chops::expandable_buffer<std::endian::big, chops::mutable_shared_buffer> buf;
3234
33-
chops::binary_serialize(buf, "{32ui}{16i}{8ui}{16ui}{16ui}{64i}",
35+
chops::binary_serialize(buf, "{32u}{16}{8u}{16u}{16u}{64}",
3436
hike_obj.distance, hike_obj.elevation, hike_obj.name, hike_obj.waypoints);
3537
3638
// ...
37-
net_obj.send(buf);
39+
net_obj.send(buf.get_buf());
3840
3941
```
4042

41-
The buffer will contain the following:
43+
The buffer will contain the following (note that truncation or casting will happen between the application
44+
object types and the serialized types as needed):
4245

4346
```
4447
32 bit unsigned integer containing distance value
4548
16 bit signed integer containing elevation value
4649
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
50+
16 bit unsigned integer for the size of the name string (if optional is true)
51+
0 - N 8 bit characters for the name string (if optional is true)
4952
16 bit unsigned integer for the size of the waypoints vector
5053
0 - N 64 bit signed integers for each waypoint value
5154
```

0 commit comments

Comments
 (0)