Skip to content

Commit 8aa2b48

Browse files
Merge pull request #3 from connectivecpp/develop
Merging develop to main
2 parents 1df9a85 + 794e6e1 commit 8aa2b48

File tree

8 files changed

+535
-602
lines changed

8 files changed

+535
-602
lines changed

.github/workflows/build_run_unit_test_cmake.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
build_matrix:
1313
strategy:
1414
matrix:
15-
# os: [ubuntu-latest, windows-latest, macos-14]
16-
os: [ubuntu-latest]
15+
os: [ubuntu-latest, windows-latest, macos-14]
16+
# os: [ubuntu-latest]
1717
runs-on: ${{ matrix.os }}
1818
defaults:
1919
run:

README.md

+45-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Binary Serialize, Header-Only C++ 20 Binary Serialization Classes and Functions
1+
# Binary Serialize, Header-Only C++ 20 Binary Serialization Classes and Functions Using a `std::format` Like Syntax
22

33
#### Unit Test and Documentation Generation Workflow Status
44

@@ -10,11 +10,52 @@
1010

1111
![GH Tag](https://img.shields.io/github/v/tag/connectivecpp/binary-serialize?label=GH%20tag)
1212

13+
![License](https://img.shields.io/badge/License-Boost%201.0-blue)
14+
1315
## Overview
1416

15-
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).
17+
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.
18+
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).
22+
23+
This library uses `std::format` style formatting. For example:
24+
25+
```
26+
struct Hike {
27+
unsigned int distance;
28+
int elevation;
29+
std::optional<std::string>> name;
30+
std::vector<int> waypoints;
31+
};
32+
// ...
33+
chops::expandable_buffer<std::endian::big, chops::mutable_shared_buffer> buf;
34+
35+
chops::binary_serialize(buf, "{32u}{16}{8u}{16u}{16u}{64}",
36+
hike_obj.distance, hike_obj.elevation, hike_obj.name, hike_obj.waypoints);
37+
38+
// ...
39+
net_obj.send(buf.get_buf());
40+
41+
```
42+
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):
45+
46+
```
47+
32 bit unsigned integer containing distance value
48+
16 bit signed integer containing elevation value
49+
8 bit unsigned integer corresponding to true or false for the optional
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)
52+
16 bit unsigned integer for the size of the waypoints vector
53+
0 - N 64 bit signed integers for each waypoint value
54+
```
55+
56+
The documentation overview provides a comparison with other serialization libraries as well as a rationale for the design decisions.
1657

17-
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.
58+
Inspiration and thanks go to [Louis Langholtz](https://github.com/louis-langholtz), who steered me towards considering the `std::format` API.
1859

1960
## Generated Documentation
2061

@@ -38,7 +79,7 @@ The unit test code uses [Catch2](https://github.com/catchorg/Catch2). If the `BI
3879

3980
The unit test uses utilities from Connective C++'s [utility-rack](https://github.com/connectivecpp/utility-rack).
4081

41-
Specific version (or branch) specs for the dependenies are in `test/CMakeLists.txt`.
82+
Specific version (or branch) specs for the dependencies are in the [test/CMakeLists.txt](test/CMakeLists.txt) file, look for the `CPMAddPackage` commands.
4283

4384
## Build and Run Unit Tests
4485

0 commit comments

Comments
 (0)