Skip to content

Commit bda6306

Browse files
Merge branch 'main' into f/avro
2 parents 99e1270 + bfa6004 commit bda6306

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2279
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
*.flexbuf
4949
*.msgpack
5050
*.toml
51+
*.ubjson
5152
*.xml
5253
*.yml
5354
*.yaml

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option(REFLECTCPP_FLEXBUFFERS "Enable flexbuffers support" OFF)
1010
option(REFLECTCPP_MSGPACK "Enable msgpack support" OFF)
1111
option(REFLECTCPP_XML "Enable XML support" OFF)
1212
option(REFLECTCPP_TOML "Enable TOML support" OFF)
13+
option(REFLECTCPP_UBJSON "Enable UBJSON support" OFF)
1314
option(REFLECTCPP_YAML "Enable YAML support" OFF)
1415

1516
option(REFLECTCPP_BUILD_BENCHMARKS "Build benchmarks" OFF)
@@ -27,11 +28,12 @@ if(REFLECTCPP_BUILD_BENCHMARKS)
2728
set(REFLECTCPP_MSGPACK ON CACHE BOOL "" FORCE)
2829
set(REFLECTCPP_XML ON CACHE BOOL "" FORCE)
2930
set(REFLECTCPP_TOML ON CACHE BOOL "" FORCE)
31+
set(REFLECTCPP_UBJSON ON CACHE BOOL "" FORCE)
3032
set(REFLECTCPP_YAML ON CACHE BOOL "" FORCE)
3133
endif()
3234
if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BUILD_BENCHMARKS OR
3335
(REFLECTCPP_JSON AND NOT REFLECTCPP_USE_BUNDLED_DEPENDENCIES) OR REFLECTCPP_AVRO OR
34-
REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_YAML)
36+
REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_UBJSON OR REFLECTCPP_YAML)
3537
# enable vcpkg per default if require features other than JSON
3638
set(REFLECTCPP_USE_VCPKG_DEFAULT ON)
3739
endif()
@@ -161,6 +163,14 @@ if (REFLECTCPP_TOML)
161163
endif ()
162164
endif()
163165

166+
if (REFLECTCPP_UBJSON)
167+
list(APPEND REFLECT_CPP_SOURCES
168+
src/reflectcpp_ubjson.cpp
169+
)
170+
target_include_directories(reflectcpp SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
171+
find_package(jsoncons CONFIG REQUIRED)
172+
endif ()
173+
164174
if (REFLECTCPP_XML)
165175
list(APPEND REFLECT_CPP_SOURCES
166176
src/reflectcpp_xml.cpp

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The following table lists the serialization formats currently supported by refle
3636
| flexbuffers | [flatbuffers](https://github.com/google/flatbuffers) | >= 23.5.26 | Apache 2.0 | Schema-less version of flatbuffers, binary format |
3737
| msgpack | [msgpack-c](https://github.com/msgpack/msgpack-c) | >= 6.0.0 | BSL 1.0 | JSON-like binary format |
3838
| TOML | [toml++](https://github.com/marzer/tomlplusplus) | >= 3.4.0 | MIT | Textual format with an emphasis on readability |
39+
| UBJSON | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format |
3940
| XML | [pugixml](https://github.com/zeux/pugixml) | >= 1.14 | MIT | Textual format used in many legacy projects |
4041
| YAML | [yaml-cpp](https://github.com/jbeder/yaml-cpp) | >= 0.8.0 | MIT | Textual format with an emphasis on readability |
4142

@@ -114,13 +115,15 @@ rfl::cbor::write(homer);
114115
rfl::flexbuf::write(homer);
115116
rfl::msgpack::write(homer);
116117
rfl::toml::write(homer);
118+
rfl::ubjson::write(homer);
117119
rfl::xml::write(homer);
118120

119121
rfl::bson::read<Person>(bson_bytes);
120122
rfl::cbor::read<Person>(cbor_bytes);
121123
rfl::flexbuf::read<Person>(flexbuf_bytes);
122124
rfl::msgpack::read<Person>(msgpack_bytes);
123125
rfl::toml::read<Person>(toml_string);
126+
rfl::ubjson::read<Person>(ubjson_bytes);
124127
rfl::xml::read<Person>(xml_string);
125128
```
126129

@@ -471,7 +474,7 @@ In addition, it supports the following custom containers:
471474
472475
- `rfl::Binary`: Used to express numbers in binary format.
473476
- `rfl::Box`: Similar to `std::unique_ptr`, but (almost) guaranteed to never be null.
474-
- `rfl::Bytestring`: An alias for `std::basic_string<std::byte>`. Supported by BSON, CBOR, flexbuffers and msgpack.
477+
- `rfl::Bytestring`: An alias for `std::basic_string<std::byte>`. Supported by BSON, CBOR, flexbuffers, msgpack and UBJSON.
475478
- `rfl::Generic`: A catch-all type that can represent (almost) anything.
476479
- `rfl::Hex`: Used to express numbers in hex format.
477480
- `rfl::Literal`: An explicitly enumerated string.
@@ -569,6 +572,7 @@ set(REFLECTCPP_CBOR ON) # Optional
569572
set(REFLECTCPP_FLEXBUFFERS ON) # Optional
570573
set(REFLECTCPP_MSGPACK ON) # Optional
571574
set(REFLECTCPP_TOML ON) # Optional
575+
set(REFLECTCPP_UBJSON ON) # Optional
572576
set(REFLECTCPP_XML ON) # Optional
573577
set(REFLECTCPP_YAML ON) # Optional
574578
@@ -619,7 +623,7 @@ To run the tests, do the following:
619623
To compile the tests with serialization formats other than JSON, do the following:
620624

621625
```bash
622-
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
626+
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_UBJSON=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
623627
cmake --build build -j 4 # gcc, clang
624628
cmake --build build --config Release -j 4 # MSVC
625629
```
@@ -633,6 +637,7 @@ To run the tests, do the following:
633637
./build/tests/msgpack/reflect-cpp-msgpack-tests
634638
./build/tests/json/reflect-cpp-json-tests
635639
./build/tests/toml/reflect-cpp-toml-tests
640+
./build/tests/ubjson/reflect-cpp-ubjson-tests
636641
./build/tests/xml/reflect-cpp-xml-tests
637642
./build/tests/yaml/reflect-cpp-yaml-tests
638643
```

benchmarks/all/canada_read.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/yaml.hpp>
1314
#include <type_traits>
1415
#include <vector>
@@ -164,6 +165,30 @@ static void BM_canada_read_reflect_cpp_toml(benchmark::State &state) {
164165
}
165166
BENCHMARK(BM_canada_read_reflect_cpp_toml);
166167

168+
static void BM_canada_read_reflect_cpp_ubjson(benchmark::State &state) {
169+
const auto data = rfl::ubjson::write(load_data());
170+
for (auto _ : state) {
171+
const auto res = rfl::ubjson::read<FeatureCollection>(data);
172+
if (!res) {
173+
std::cout << res.error()->what() << std::endl;
174+
}
175+
}
176+
}
177+
BENCHMARK(BM_canada_read_reflect_cpp_ubjson);
178+
179+
static void BM_canada_read_reflect_cpp_ubjson_without_field_names(
180+
benchmark::State &state) {
181+
const auto data = rfl::ubjson::write<rfl::NoFieldNames>(load_data());
182+
for (auto _ : state) {
183+
const auto res =
184+
rfl::ubjson::read<FeatureCollection, rfl::NoFieldNames>(data);
185+
if (!res) {
186+
std::cout << res.error()->what() << std::endl;
187+
}
188+
}
189+
}
190+
BENCHMARK(BM_canada_read_reflect_cpp_ubjson_without_field_names);
191+
167192
static void BM_canada_read_reflect_cpp_yaml(benchmark::State &state) {
168193
const auto data = rfl::yaml::write(load_data());
169194
for (auto _ : state) {

benchmarks/all/canada_write.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/yaml.hpp>
1314
#include <type_traits>
1415
#include <vector>
@@ -149,6 +150,29 @@ static void BM_canada_write_reflect_cpp_toml(benchmark::State &state) {
149150
}
150151
BENCHMARK(BM_canada_write_reflect_cpp_toml);
151152

153+
static void BM_canada_write_reflect_cpp_ubjson(benchmark::State &state) {
154+
const auto data = load_data();
155+
for (auto _ : state) {
156+
const auto output = rfl::ubjson::write(data);
157+
if (output.size() == 0) {
158+
std::cout << "No output" << std::endl;
159+
}
160+
}
161+
}
162+
BENCHMARK(BM_canada_write_reflect_cpp_ubjson);
163+
164+
static void BM_canada_write_reflect_cpp_ubjson_without_field_names(
165+
benchmark::State &state) {
166+
const auto data = load_data();
167+
for (auto _ : state) {
168+
const auto output = rfl::ubjson::write<rfl::NoFieldNames>(data);
169+
if (output.size() == 0) {
170+
std::cout << "No output" << std::endl;
171+
}
172+
}
173+
}
174+
BENCHMARK(BM_canada_write_reflect_cpp_ubjson_without_field_names);
175+
152176
static void BM_canada_write_reflect_cpp_yaml(benchmark::State &state) {
153177
const auto data = load_data();
154178
for (auto _ : state) {

benchmarks/all/licenses_read.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/xml.hpp>
1314
#include <rfl/yaml.hpp>
1415
#include <type_traits>
@@ -187,6 +188,29 @@ static void BM_licenses_read_reflect_cpp_toml(benchmark::State &state) {
187188
}
188189
BENCHMARK(BM_licenses_read_reflect_cpp_toml);
189190

191+
static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State &state) {
192+
const auto data = rfl::ubjson::write(load_data());
193+
for (auto _ : state) {
194+
const auto res = rfl::ubjson::read<Licenses>(data);
195+
if (!res) {
196+
std::cout << res.error()->what() << std::endl;
197+
}
198+
}
199+
}
200+
BENCHMARK(BM_licenses_read_reflect_cpp_ubjson);
201+
202+
static void BM_licenses_read_reflect_cpp_ubjson_without_field_names(
203+
benchmark::State &state) {
204+
const auto data = rfl::ubjson::write<rfl::NoFieldNames>(load_data());
205+
for (auto _ : state) {
206+
const auto res = rfl::ubjson::read<Licenses, rfl::NoFieldNames>(data);
207+
if (!res) {
208+
std::cout << res.error()->what() << std::endl;
209+
}
210+
}
211+
}
212+
BENCHMARK(BM_licenses_read_reflect_cpp_ubjson_without_field_names);
213+
190214
static void BM_licenses_read_reflect_cpp_yaml(benchmark::State &state) {
191215
const auto data = rfl::yaml::write(load_data());
192216
for (auto _ : state) {

benchmarks/all/licenses_write.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/xml.hpp>
1314
#include <rfl/yaml.hpp>
1415
#include <type_traits>
@@ -176,6 +177,29 @@ static void BM_licenses_write_reflect_cpp_toml(benchmark::State &state) {
176177
}
177178
BENCHMARK(BM_licenses_write_reflect_cpp_toml);
178179

180+
static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State &state) {
181+
const auto data = load_data();
182+
for (auto _ : state) {
183+
const auto output = rfl::ubjson::write(data);
184+
if (output.size() == 0) {
185+
std::cout << "No output" << std::endl;
186+
}
187+
}
188+
}
189+
BENCHMARK(BM_licenses_write_reflect_cpp_ubjson);
190+
191+
static void BM_licenses_write_reflect_cpp_ubjson_without_field_names(
192+
benchmark::State &state) {
193+
const auto data = load_data();
194+
for (auto _ : state) {
195+
const auto output = rfl::ubjson::write<rfl::NoFieldNames>(data);
196+
if (output.size() == 0) {
197+
std::cout << "No output" << std::endl;
198+
}
199+
}
200+
}
201+
BENCHMARK(BM_licenses_write_reflect_cpp_ubjson_without_field_names);
202+
179203
static void BM_licenses_write_reflect_cpp_xml(benchmark::State &state) {
180204
const auto data = load_data();
181205
for (auto _ : state) {

benchmarks/all/person_read.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/xml.hpp>
1314
#include <rfl/yaml.hpp>
1415
#include <type_traits>
1516
#include <vector>
16-
1717
namespace person_read {
1818

1919
// ----------------------------------------------------------------------------
@@ -156,6 +156,29 @@ static void BM_person_read_reflect_cpp_toml(benchmark::State &state) {
156156
}
157157
BENCHMARK(BM_person_read_reflect_cpp_toml);
158158

159+
static void BM_person_read_reflect_cpp_ubjson(benchmark::State &state) {
160+
const auto data = rfl::ubjson::write(load_data());
161+
for (auto _ : state) {
162+
const auto res = rfl::ubjson::read<Person>(data);
163+
if (!res) {
164+
std::cout << res.error()->what() << std::endl;
165+
}
166+
}
167+
}
168+
BENCHMARK(BM_person_read_reflect_cpp_ubjson);
169+
170+
static void BM_person_read_reflect_cpp_ubjson_without_field_names(
171+
benchmark::State &state) {
172+
const auto data = rfl::ubjson::write<rfl::NoFieldNames>(load_data());
173+
for (auto _ : state) {
174+
const auto res = rfl::ubjson::read<Person, rfl::NoFieldNames>(data);
175+
if (!res) {
176+
std::cout << res.error()->what() << std::endl;
177+
}
178+
}
179+
}
180+
BENCHMARK(BM_person_read_reflect_cpp_ubjson_without_field_names);
181+
159182
static void BM_person_read_reflect_cpp_xml(benchmark::State &state) {
160183
const auto data = rfl::xml::write(load_data());
161184
for (auto _ : state) {

benchmarks/all/person_write.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <rfl/json.hpp>
1010
#include <rfl/msgpack.hpp>
1111
#include <rfl/toml.hpp>
12+
#include <rfl/ubjson.hpp>
1213
#include <rfl/xml.hpp>
1314
#include <rfl/yaml.hpp>
1415
#include <type_traits>
@@ -156,6 +157,29 @@ static void BM_person_write_reflect_cpp_toml(benchmark::State &state) {
156157
}
157158
BENCHMARK(BM_person_write_reflect_cpp_toml);
158159

160+
static void BM_person_write_reflect_cpp_ubjson(benchmark::State &state) {
161+
const auto data = load_data();
162+
for (auto _ : state) {
163+
const auto output = rfl::ubjson::write(data);
164+
if (output.size() == 0) {
165+
std::cout << "No output" << std::endl;
166+
}
167+
}
168+
}
169+
BENCHMARK(BM_person_write_reflect_cpp_ubjson);
170+
171+
static void BM_person_write_reflect_cpp_ubjson_without_field_names(
172+
benchmark::State &state) {
173+
const auto data = load_data();
174+
for (auto _ : state) {
175+
const auto output = rfl::ubjson::write<rfl::NoFieldNames>(data);
176+
if (output.size() == 0) {
177+
std::cout << "No output" << std::endl;
178+
}
179+
}
180+
}
181+
BENCHMARK(BM_person_write_reflect_cpp_ubjson_without_field_names);
182+
159183
static void BM_person_write_reflect_cpp_xml(benchmark::State &state) {
160184
const auto data = load_data();
161185
for (auto _ : state) {

docs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@
8888

8989
6.6) [TOML](https://github.com/getml/reflect-cpp/blob/main/docs/toml.md)
9090

91-
6.7) [XML](https://github.com/getml/reflect-cpp/blob/main/docs/xml.md)
91+
6.7) [UBJSON](https://github.com/getml/reflect-cpp/blob/main/docs/ubjson.md)
9292

93-
6.8) [YAML](https://github.com/getml/reflect-cpp/blob/main/docs/yaml.md)
93+
6.8) [XML](https://github.com/getml/reflect-cpp/blob/main/docs/xml.md)
94+
95+
6.9) [YAML](https://github.com/getml/reflect-cpp/blob/main/docs/yaml.md)
9496

9597
## 7) Advanced topics
9698

0 commit comments

Comments
 (0)