From 4732bfaceccc5cd72195f5377aedfae050693337 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 27 Mar 2026 12:11:40 +0000 Subject: [PATCH 01/15] boost serialisation (reader/writer/parser complete) --- include/rfl/boost_serialization/Parser.hpp | 137 ++++++++++++ include/rfl/boost_serialization/Reader.hpp | 180 +++++++++++++++ include/rfl/boost_serialization/Writer.hpp | 249 +++++++++++++++++++++ 3 files changed, 566 insertions(+) create mode 100644 include/rfl/boost_serialization/Parser.hpp create mode 100644 include/rfl/boost_serialization/Reader.hpp create mode 100644 include/rfl/boost_serialization/Writer.hpp diff --git a/include/rfl/boost_serialization/Parser.hpp b/include/rfl/boost_serialization/Parser.hpp new file mode 100644 index 00000000..44d6a68f --- /dev/null +++ b/include/rfl/boost_serialization/Parser.hpp @@ -0,0 +1,137 @@ +#ifndef RFL_BOOST_SERIALIZATION_PARSER_HPP_ +#define RFL_BOOST_SERIALIZATION_PARSER_HPP_ + +#include "../Generic.hpp" +#include "../NamedTuple.hpp" +#include "../Tuple.hpp" +#include "../always_false.hpp" +#include "../parsing/Parser.hpp" +#include "Reader.hpp" +#include "Writer.hpp" + +namespace rfl { +namespace parsing { + +/// Boost.Serialization requires us to explicitly set all fields. Because +/// of that, we require all of the fields and then set them to nullptr, if +/// necessary. +template + requires AreReaderAndWriter, + boost_serialization::Writer, + NamedTuple> +struct Parser, + boost_serialization::Writer, + NamedTuple, ProcessorsType> + : public NamedTupleParser< + boost_serialization::Reader, + boost_serialization::Writer, + /*_ignore_empty_containers=*/false, + /*_all_required=*/true, + /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, + FieldTypes...> {}; + +template + requires AreReaderAndWriter, + boost_serialization::Writer, + rfl::Tuple> +struct Parser, + boost_serialization::Writer, rfl::Tuple, + ProcessorsType> + : public TupleParser, + boost_serialization::Writer, + /*_ignore_empty_containers=*/false, + /*_all_required=*/true, ProcessorsType, + rfl::Tuple> {}; + +template + requires AreReaderAndWriter, + boost_serialization::Writer, + std::tuple> +struct Parser, + boost_serialization::Writer, std::tuple, + ProcessorsType> + : public TupleParser, + boost_serialization::Writer, + /*_ignore_empty_containers=*/false, + /*_all_required=*/true, ProcessorsType, + std::tuple> {}; + +template + requires AreReaderAndWriter, + boost_serialization::Writer, Generic> +struct Parser, + boost_serialization::Writer, Generic, ProcessorsType> { + template + static Result read(const boost_serialization::Reader&, + const T&) noexcept { + static_assert(always_false_v, + "Generics are unsupported in Boost.Serialization."); + return error("Unsupported"); + } + + template + static void write(const boost_serialization::Writer&, + const Generic&, const P&) noexcept { + static_assert(always_false_v

, + "Generics are unsupported in Boost.Serialization."); + } + + template + static schema::Type to_schema(T*) { + static_assert(always_false_v, + "Generics are unsupported in Boost.Serialization."); + return schema::Type{}; + } +}; + +template + requires AreReaderAndWriter< + boost_serialization::Reader, + boost_serialization::Writer, + internal::Skip> +struct Parser, + boost_serialization::Writer, + internal::Skip, + ProcessorsType> { + using R = boost_serialization::Reader; + using W = boost_serialization::Writer; + + template + static Result> + read(const R&, const U&) noexcept { + static_assert(always_false_v, + "rfl::Skip is unsupported in Boost.Serialization."); + return error("Unsupported"); + } + + template + static void write(const W& /*_w*/, + const internal::Skip& /*_skip*/, + const P& /*_parent*/) noexcept { + static_assert(always_false_v

, + "rfl::Skip is unsupported in Boost.Serialization."); + } + + template + static schema::Type to_schema(U* /*_definitions*/) { + static_assert(always_false_v, + "rfl::Skip is unsupported in Boost.Serialization."); + return schema::Type{}; + } +}; + +} // namespace parsing +} // namespace rfl + +namespace rfl::boost_serialization { + +template +using Parser = + parsing::Parser, Writer, T, ProcessorsType>; + +} // namespace rfl::boost_serialization + +#endif diff --git a/include/rfl/boost_serialization/Reader.hpp b/include/rfl/boost_serialization/Reader.hpp new file mode 100644 index 00000000..f7b96a10 --- /dev/null +++ b/include/rfl/boost_serialization/Reader.hpp @@ -0,0 +1,180 @@ +#ifndef RFL_BOOST_SERIALIZATION_READER_HPP_ +#define RFL_BOOST_SERIALIZATION_READER_HPP_ + +#include +#include +#include +#include +#include + +#include "../Result.hpp" +#include "../always_false.hpp" + +namespace rfl::boost_serialization { + +template +struct Reader { + struct BoostInputArray { + IArchive* ar; + size_t size; + }; + + struct BoostInputMap { + IArchive* ar; + size_t size; + }; + + struct BoostInputObject { + IArchive* ar; + size_t size; + }; + + struct BoostInputUnion { + IArchive* ar; + }; + + struct BoostInputVar { + IArchive* ar; + }; + + using InputArrayType = BoostInputArray; + using InputMapType = BoostInputMap; + using InputObjectType = BoostInputObject; + using InputUnionType = BoostInputUnion; + using InputVarType = BoostInputVar; + + template + static constexpr bool has_custom_constructor = false; + + bool is_empty(const InputVarType& /*_var*/) const noexcept { return false; } + + template + rfl::Result to_basic_type(const InputVarType& _var) const noexcept { + try { + if constexpr (std::is_same, std::string>()) { + std::string val; + *_var.ar >> val; + return val; + } else if constexpr (std::is_same, bool>()) { + bool val = false; + *_var.ar >> val; + return val; + } else if constexpr (std::is_floating_point>()) { + double val = 0.0; + *_var.ar >> val; + return static_cast(val); + } else if constexpr (std::is_unsigned>()) { + std::uint64_t val = 0; + *_var.ar >> val; + return static_cast(val); + } else if constexpr (std::is_integral>()) { + std::int64_t val = 0; + *_var.ar >> val; + return static_cast(val); + } else { + static_assert(rfl::always_false_v, "Unsupported type."); + } + } catch (std::exception& e) { + return error(e.what()); + } + } + + rfl::Result to_array( + const InputVarType& _var) const noexcept { + try { + std::uint64_t size = 0; + *_var.ar >> size; + return InputArrayType{_var.ar, static_cast(size)}; + } catch (std::exception& e) { + return error(e.what()); + } + } + + rfl::Result to_object( + const InputVarType& _var) const noexcept { + try { + std::uint64_t size = 0; + *_var.ar >> size; + return InputObjectType{_var.ar, static_cast(size)}; + } catch (std::exception& e) { + return error(e.what()); + } + } + + rfl::Result to_map(const InputVarType& _var) const noexcept { + try { + std::uint64_t size = 0; + *_var.ar >> size; + return InputMapType{_var.ar, static_cast(size)}; + } catch (std::exception& e) { + return error(e.what()); + } + } + + rfl::Result to_union( + const InputVarType& _var) const noexcept { + return InputUnionType{_var.ar}; + } + + template + std::optional read_array(const ArrayReader& _array_reader, + const InputArrayType& _arr) const noexcept { + for (size_t i = 0; i < _arr.size; ++i) { + auto var = InputVarType{_arr.ar}; + const auto err = _array_reader.read(var); + if (err) { + return err; + } + } + return std::nullopt; + } + + template + std::optional read_map(const MapReader& _map_reader, + const InputMapType& _map) const noexcept { + try { + for (size_t i = 0; i < _map.size; ++i) { + std::string key; + *_map.ar >> key; + auto var = InputVarType{_map.ar}; + _map_reader.read(std::string_view(key), var); + } + return std::nullopt; + } catch (std::exception& e) { + return Error(e.what()); + } + } + + template + std::optional read_object(const ObjectReader& _object_reader, + const InputObjectType& _obj) const noexcept { + for (size_t i = 0; i < _obj.size; ++i) { + auto var = InputVarType{_obj.ar}; + _object_reader.read(static_cast(i), var); + } + return std::nullopt; + } + + template + rfl::Result read_union( + const InputUnionType& _union) const noexcept { + try { + std::uint64_t disc = 0; + *_union.ar >> disc; + auto var = InputVarType{_union.ar}; + return UnionReaderType::read(*this, static_cast(disc), var); + } catch (std::exception& e) { + return error(e.what()); + } + } + + template + rfl::Result use_custom_constructor( + const InputVarType& /*_var*/) const noexcept { + return rfl::error("Custom constructors are not supported."); + } +}; + +} // namespace rfl::boost_serialization + +#endif diff --git a/include/rfl/boost_serialization/Writer.hpp b/include/rfl/boost_serialization/Writer.hpp new file mode 100644 index 00000000..22fee16b --- /dev/null +++ b/include/rfl/boost_serialization/Writer.hpp @@ -0,0 +1,249 @@ +#ifndef RFL_BOOST_SERIALIZATION_WRITER_HPP_ +#define RFL_BOOST_SERIALIZATION_WRITER_HPP_ + +#include +#include +#include +#include + +#include "../always_false.hpp" + +namespace rfl::boost_serialization { + +template +class Writer { + public: + struct BoostOutputArray {}; + + struct BoostOutputMap {}; + + struct BoostOutputObject {}; + + struct BoostOutputUnion {}; + + struct BoostOutputVar {}; + + using OutputArrayType = BoostOutputArray; + using OutputMapType = BoostOutputMap; + using OutputObjectType = BoostOutputObject; + using OutputUnionType = BoostOutputUnion; + using OutputVarType = BoostOutputVar; + + Writer(OArchive* _ar) : ar_(_ar) {} + + ~Writer() = default; + + OutputArrayType array_as_root(const size_t _size) const { + *ar_ << static_cast(_size); + return OutputArrayType{}; + } + + OutputMapType map_as_root(const size_t _size) const { + *ar_ << static_cast(_size); + return OutputMapType{}; + } + + OutputObjectType object_as_root(const size_t _size) const { + *ar_ << static_cast(_size); + return OutputObjectType{}; + } + + OutputVarType null_as_root() const { + return OutputVarType{}; + } + + OutputUnionType union_as_root() const { + return OutputUnionType{}; + } + + template + OutputVarType value_as_root(const T& _var) const { + new_value(_var); + return OutputVarType{}; + } + + OutputArrayType add_array_to_array(const size_t _size, + OutputArrayType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputArrayType{}; + } + + OutputArrayType add_array_to_map(const std::string_view& /*_name*/, + const size_t _size, + OutputMapType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputArrayType{}; + } + + OutputArrayType add_array_to_object(const std::string_view& /*_name*/, + const size_t _size, + OutputObjectType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputArrayType{}; + } + + OutputArrayType add_array_to_union(const size_t _index, const size_t _size, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + *ar_ << static_cast(_size); + return OutputArrayType{}; + } + + OutputMapType add_map_to_array(const size_t _size, + OutputArrayType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputMapType{}; + } + + OutputMapType add_map_to_map(const std::string_view& /*_name*/, + const size_t _size, + OutputMapType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputMapType{}; + } + + OutputMapType add_map_to_object(const std::string_view& /*_name*/, + const size_t _size, + OutputObjectType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputMapType{}; + } + + OutputMapType add_map_to_union(const size_t _index, const size_t _size, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + *ar_ << static_cast(_size); + return OutputMapType{}; + } + + OutputObjectType add_object_to_array(const size_t _size, + OutputArrayType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputObjectType{}; + } + + OutputObjectType add_object_to_map(const std::string_view& /*_name*/, + const size_t _size, + OutputMapType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputObjectType{}; + } + + OutputObjectType add_object_to_object(const std::string_view& /*_name*/, + const size_t _size, + OutputObjectType* /*_parent*/) const { + *ar_ << static_cast(_size); + return OutputObjectType{}; + } + + OutputObjectType add_object_to_union(const size_t _index, const size_t _size, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + *ar_ << static_cast(_size); + return OutputObjectType{}; + } + + OutputUnionType add_union_to_array(OutputArrayType* /*_parent*/) const { + return OutputUnionType{}; + } + + OutputUnionType add_union_to_map(const std::string_view& /*_name*/, + OutputMapType* /*_parent*/) const { + return OutputUnionType{}; + } + + OutputUnionType add_union_to_object(const std::string_view& /*_name*/, + OutputObjectType* /*_parent*/) const { + return OutputUnionType{}; + } + + OutputUnionType add_union_to_union(const size_t _index, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + return OutputUnionType{}; + } + + template + OutputVarType add_value_to_array(const T& _var, + OutputArrayType* /*_parent*/) const { + new_value(_var); + return OutputVarType{}; + } + + template + OutputVarType add_value_to_map(const std::string_view& _name, const T& _var, + OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); + new_value(_var); + return OutputVarType{}; + } + + template + OutputVarType add_value_to_object(const std::string_view& /*_name*/, + const T& _var, + OutputObjectType* /*_parent*/) const { + new_value(_var); + return OutputVarType{}; + } + + template + OutputVarType add_value_to_union(const size_t _index, const T& _var, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + new_value(_var); + return OutputVarType{}; + } + + OutputVarType add_null_to_array(OutputArrayType* /*_parent*/) const { + return OutputVarType{}; + } + + OutputVarType add_null_to_map(const std::string_view& _name, + OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); + return OutputVarType{}; + } + + OutputVarType add_null_to_object(const std::string_view& /*_name*/, + OutputObjectType* /*_parent*/) const { + return OutputVarType{}; + } + + OutputVarType add_null_to_union(const size_t _index, + OutputUnionType* /*_parent*/) const { + *ar_ << static_cast(_index); + return OutputVarType{}; + } + + void end_array(OutputArrayType* /*_arr*/) const {} + + void end_map(OutputMapType* /*_obj*/) const {} + + void end_object(OutputObjectType* /*_obj*/) const {} + + private: + template + void new_value(const T& _var) const { + using Type = std::remove_cvref_t; + if constexpr (std::is_same()) { + *ar_ << _var; + } else if constexpr (std::is_same()) { + *ar_ << _var; + } else if constexpr (std::is_floating_point()) { + *ar_ << static_cast(_var); + } else if constexpr (std::is_unsigned()) { + *ar_ << static_cast(_var); + } else if constexpr (std::is_integral()) { + *ar_ << static_cast(_var); + } else { + static_assert(rfl::always_false_v, "Unsupported type."); + } + } + + private: + OArchive* ar_; +}; + +} // namespace rfl::boost_serialization + +#endif From 13db6f0a0498fa20003d0f6bece8f84d8cadab8d Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 27 Mar 2026 12:10:27 +0000 Subject: [PATCH 02/15] boost serialisation (read/write/load) --- include/rfl/boost_serialization.hpp | 13 +++++ include/rfl/boost_serialization/load.hpp | 22 ++++++++ include/rfl/boost_serialization/read.hpp | 69 +++++++++++++++++++++++ include/rfl/boost_serialization/save.hpp | 25 ++++++++ include/rfl/boost_serialization/write.hpp | 56 ++++++++++++++++++ 5 files changed, 185 insertions(+) create mode 100644 include/rfl/boost_serialization.hpp create mode 100644 include/rfl/boost_serialization/load.hpp create mode 100644 include/rfl/boost_serialization/read.hpp create mode 100644 include/rfl/boost_serialization/save.hpp create mode 100644 include/rfl/boost_serialization/write.hpp diff --git a/include/rfl/boost_serialization.hpp b/include/rfl/boost_serialization.hpp new file mode 100644 index 00000000..237da0e0 --- /dev/null +++ b/include/rfl/boost_serialization.hpp @@ -0,0 +1,13 @@ +#ifndef RFL_BOOST_SERIALIZATION_HPP_ +#define RFL_BOOST_SERIALIZATION_HPP_ + +#include "../rfl.hpp" +#include "boost_serialization/Parser.hpp" +#include "boost_serialization/Reader.hpp" +#include "boost_serialization/Writer.hpp" +#include "boost_serialization/load.hpp" +#include "boost_serialization/read.hpp" +#include "boost_serialization/save.hpp" +#include "boost_serialization/write.hpp" + +#endif diff --git a/include/rfl/boost_serialization/load.hpp b/include/rfl/boost_serialization/load.hpp new file mode 100644 index 00000000..e487e009 --- /dev/null +++ b/include/rfl/boost_serialization/load.hpp @@ -0,0 +1,22 @@ +#ifndef RFL_BOOST_SERIALIZATION_LOAD_HPP_ +#define RFL_BOOST_SERIALIZATION_LOAD_HPP_ + +#include "../Result.hpp" +#include "../io/load_bytes.hpp" +#include "read.hpp" + +namespace rfl { +namespace boost_serialization { + +template +Result load(const std::string& _fname) { + const auto read_bytes = [](const auto& _bytes) { + return read(_bytes); + }; + return rfl::io::load_bytes(_fname).and_then(read_bytes); +} + +} // namespace boost_serialization +} // namespace rfl + +#endif diff --git a/include/rfl/boost_serialization/read.hpp b/include/rfl/boost_serialization/read.hpp new file mode 100644 index 00000000..d93f7941 --- /dev/null +++ b/include/rfl/boost_serialization/read.hpp @@ -0,0 +1,69 @@ +#ifndef RFL_BOOST_SERIALIZATION_READ_HPP_ +#define RFL_BOOST_SERIALIZATION_READ_HPP_ + +#include +#include +#include + +#include +#include +#include + +#include "../Processors.hpp" +#include "../concepts.hpp" +#include "../internal/wrap_in_rfl_array_t.hpp" +#include "Parser.hpp" +#include "Reader.hpp" + +namespace rfl::boost_serialization { + +namespace detail { + +template +auto read_from_archive(IArchive& _ar) { + using R = Reader; + auto r = R(); + auto var = typename R::InputVarType{&_ar}; + return Parser>::read(r, var); +} + +} // namespace detail + +/// Parses an object from bytes using a binary archive. +template +Result> read( + const concepts::ByteLike auto* _bytes, const size_t _size) { + try { + std::string str(reinterpret_cast(_bytes), _size); + std::istringstream stream(str); + boost::archive::binary_iarchive ar(stream); + return detail::read_from_archive(ar); + } catch (std::exception& e) { + return error(e.what()); + } +} + +/// Parses an object from a byte container using a binary archive. +template +auto read(const concepts::ContiguousByteContainer auto& _bytes) { + return read(_bytes.data(), _bytes.size()); +} + +/// Parses an object from a stream using a binary archive. +template +auto read(std::istream& _stream) { + try { + boost::archive::binary_iarchive ar(_stream); + return detail::read_from_archive(ar); + } catch (std::exception& e) { + return Result>(error(e.what())); + } +} + +} // namespace rfl::boost_serialization + +#endif diff --git a/include/rfl/boost_serialization/save.hpp b/include/rfl/boost_serialization/save.hpp new file mode 100644 index 00000000..f919eec4 --- /dev/null +++ b/include/rfl/boost_serialization/save.hpp @@ -0,0 +1,25 @@ +#ifndef RFL_BOOST_SERIALIZATION_SAVE_HPP_ +#define RFL_BOOST_SERIALIZATION_SAVE_HPP_ + +#include +#include +#include + +#include "../Result.hpp" +#include "../io/save_bytes.hpp" +#include "write.hpp" + +namespace rfl::boost_serialization { + +template +Result save(const std::string& _fname, const auto& _obj) { + const auto write_func = [](const auto& _obj, + std::ostream& _stream) -> std::ostream& { + return write(_obj, _stream); + }; + return rfl::io::save_bytes(_fname, _obj, write_func); +} + +} // namespace rfl::boost_serialization + +#endif diff --git a/include/rfl/boost_serialization/write.hpp b/include/rfl/boost_serialization/write.hpp new file mode 100644 index 00000000..583aaa2b --- /dev/null +++ b/include/rfl/boost_serialization/write.hpp @@ -0,0 +1,56 @@ +#ifndef RFL_BOOST_SERIALIZATION_WRITE_HPP_ +#define RFL_BOOST_SERIALIZATION_WRITE_HPP_ + +#include +#include +#include + +#include +#include +#include +#include + +#include "../Processors.hpp" +#include "../parsing/Parent.hpp" +#include "Parser.hpp" +#include "Writer.hpp" + +namespace rfl::boost_serialization { + +/// Writes into an existing Boost output archive. +template +void write(OArchive& _ar, const auto& _obj) { + using T = std::remove_cvref_t; + using W = Writer; + using ParentType = parsing::Parent; + auto w = W(&_ar); + Parser>::write( + w, _obj, typename ParentType::Root{}); +} + +/// Returns serialized bytes using a binary archive. +template +std::vector write(const auto& _obj) { + std::ostringstream stream; + { + boost::archive::binary_oarchive ar(stream); + write(ar, _obj); + } + const auto str = stream.str(); + return std::vector(str.begin(), str.end()); +} + +/// Writes into an ostream using a binary archive. +template +std::ostream& write(const auto& _obj, std::ostream& _stream) { + boost::archive::binary_oarchive ar(_stream); + write(ar, _obj); + return _stream; +} + +} // namespace rfl::boost_serialization + +#endif From 7808a1ab7a8ecf928ed5467f062be012678f1616 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 27 Mar 2026 12:13:18 +0000 Subject: [PATCH 03/15] boost serialisation (cmake/vcpkg) --- CMakeLists.txt | 13 +++++++++++++ vcpkg.json | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b8b2408..5d2d63b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ option(REFLECTCPP_XML "Enable XML support" ${REFLECTCPP_ALL_FORMATS}) option(REFLECTCPP_TOML "Enable TOML support" ${REFLECTCPP_ALL_FORMATS}) option(REFLECTCPP_UBJSON "Enable UBJSON support" ${REFLECTCPP_ALL_FORMATS}) option(REFLECTCPP_YAML "Enable YAML support" ${REFLECTCPP_ALL_FORMATS}) +option(REFLECTCPP_BOOST_SERIALIZATION "Enable Boost.Serialization support" ${REFLECTCPP_ALL_FORMATS}) option(REFLECTCPP_BUILD_BENCHMARKS "Build benchmarks" OFF) option(REFLECTCPP_BUILD_TESTS "Build tests" OFF) @@ -65,6 +66,7 @@ if ( REFLECTCPP_CHECK_HEADERS OR (REFLECTCPP_JSON AND NOT REFLECTCPP_USE_BUNDLED_DEPENDENCIES) OR REFLECTCPP_AVRO OR + REFLECTCPP_BOOST_SERIALIZATION OR REFLECTCPP_BSON OR REFLECTCPP_CAPNPROTO OR REFLECTCPP_CBOR OR @@ -95,6 +97,10 @@ if (REFLECTCPP_USE_VCPKG) list(APPEND VCPKG_MANIFEST_FEATURES "avro") endif() + if (REFLECTCPP_BOOST_SERIALIZATION OR REFLECTCPP_CHECK_HEADERS) + list(APPEND VCPKG_MANIFEST_FEATURES "boost-serialization") + endif() + if (REFLECTCPP_BSON OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "bson") endif() @@ -424,6 +430,13 @@ if (REFLECTCPP_YAML OR REFLECTCPP_CHECK_HEADERS) target_link_libraries(reflectcpp PUBLIC yaml-cpp::yaml-cpp) endif () +if (REFLECTCPP_BOOST_SERIALIZATION OR REFLECTCPP_CHECK_HEADERS) + if (NOT TARGET Boost::serialization) + find_package(Boost REQUIRED COMPONENTS serialization) + endif () + target_link_libraries(reflectcpp PUBLIC Boost::serialization) +endif () + set_target_properties(reflectcpp PROPERTIES LINKER_LANGUAGE CXX) target_sources(reflectcpp PRIVATE ${REFLECT_CPP_SOURCES}) target_precompile_headers(reflectcpp PRIVATE [["rfl.hpp"]] ) diff --git a/vcpkg.json b/vcpkg.json index 64404444..02257f41 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -52,6 +52,14 @@ } ] }, + "boost-serialization": { + "description": "Enable Boost.Serialization support", + "dependencies": [ + { + "name": "boost-serialization" + } + ] + }, "capnproto": { "description": "Enable Cap'n Proto support", "dependencies": [ From f85d9c11d6a36b221f8929e1e9faf6a68991eaf4 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 27 Mar 2026 12:26:32 +0000 Subject: [PATCH 04/15] boost serialisation (tests) --- tests/CMakeLists.txt | 4 +++ tests/boost_serialization/CMakeLists.txt | 20 +++++++++++ tests/boost_serialization/test_array.cpp | 23 +++++++++++++ tests/boost_serialization/test_enum.cpp | 20 +++++++++++ tests/boost_serialization/test_map.cpp | 23 +++++++++++++ .../test_optional_fields.cpp | 28 +++++++++++++++ .../test_readme_example.cpp | 22 ++++++++++++ tests/boost_serialization/test_variant.cpp | 34 +++++++++++++++++++ tests/boost_serialization/write_and_read.hpp | 33 ++++++++++++++++++ 9 files changed, 207 insertions(+) create mode 100644 tests/boost_serialization/CMakeLists.txt create mode 100644 tests/boost_serialization/test_array.cpp create mode 100644 tests/boost_serialization/test_enum.cpp create mode 100644 tests/boost_serialization/test_map.cpp create mode 100644 tests/boost_serialization/test_optional_fields.cpp create mode 100644 tests/boost_serialization/test_readme_example.cpp create mode 100644 tests/boost_serialization/test_variant.cpp create mode 100644 tests/boost_serialization/write_and_read.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6401a739..bedcec41 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -65,3 +65,7 @@ endif() if (REFLECTCPP_YAML) add_subdirectory(yaml) endif() + +if (REFLECTCPP_BOOST_SERIALIZATION) + add_subdirectory(boost_serialization) +endif() diff --git a/tests/boost_serialization/CMakeLists.txt b/tests/boost_serialization/CMakeLists.txt new file mode 100644 index 00000000..84c9cab2 --- /dev/null +++ b/tests/boost_serialization/CMakeLists.txt @@ -0,0 +1,20 @@ +project(reflect-cpp-boost-serialization-tests) + +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") + +add_executable( + reflect-cpp-boost-serialization-tests + ${SOURCES} +) +target_precompile_headers(reflect-cpp-boost-serialization-tests PRIVATE [["rfl.hpp"]] ) + + +target_link_libraries(reflect-cpp-boost-serialization-tests PRIVATE reflectcpp_tests_crt) + +add_custom_command(TARGET reflect-cpp-boost-serialization-tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy -t $ $ + COMMAND_EXPAND_LISTS +) + +find_package(GTest) +gtest_discover_tests(reflect-cpp-boost-serialization-tests) diff --git a/tests/boost_serialization/test_array.cpp b/tests/boost_serialization/test_array.cpp new file mode 100644 index 00000000..42279091 --- /dev/null +++ b/tests/boost_serialization/test_array.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_array { + +struct Person { + std::string first_name; + int age; + std::vector hobbies; +}; + +TEST(boost_serialization, test_array) { + const auto homer = Person{ + .first_name = "Homer", + .age = 45, + .hobbies = std::vector({"bowling", "eating", "sleeping"})}; + + write_and_read_with_json(homer); +} +} // namespace test_array diff --git a/tests/boost_serialization/test_enum.cpp b/tests/boost_serialization/test_enum.cpp new file mode 100644 index 00000000..a04f41c5 --- /dev/null +++ b/tests/boost_serialization/test_enum.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_enum { + +enum class Color { red, green, blue }; + +struct Circle { + float radius; + Color color; +}; + +TEST(boost_serialization, test_enum) { + const auto circle = Circle{.radius = 2.0f, .color = Color::green}; + + write_and_read_with_json(circle); +} +} // namespace test_enum diff --git a/tests/boost_serialization/test_map.cpp b/tests/boost_serialization/test_map.cpp new file mode 100644 index 00000000..9c6fb2a3 --- /dev/null +++ b/tests/boost_serialization/test_map.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_map { + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + std::map attributes; +}; + +TEST(boost_serialization, test_map) { + const auto homer = + Person{.first_name = "Homer", + .attributes = {{"occupation", "Safety Inspector"}, + {"town", "Springfield"}}}; + + write_and_read(homer); +} +} // namespace test_map diff --git a/tests/boost_serialization/test_optional_fields.cpp b/tests/boost_serialization/test_optional_fields.cpp new file mode 100644 index 00000000..61a9235a --- /dev/null +++ b/tests/boost_serialization/test_optional_fields.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_optional_fields { + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + std::optional> children; +}; + +TEST(boost_serialization, test_optional_fields) { + const auto bart = Person{.first_name = "Bart"}; + + const auto lisa = Person{.first_name = "Lisa"}; + + const auto maggie = Person{.first_name = "Maggie"}; + + const auto homer = + Person{.first_name = "Homer", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read_with_json(homer); +} +} // namespace test_optional_fields diff --git a/tests/boost_serialization/test_readme_example.cpp b/tests/boost_serialization/test_readme_example.cpp new file mode 100644 index 00000000..4c2e84b5 --- /dev/null +++ b/tests/boost_serialization/test_readme_example.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_readme_example { + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + std::string town = "Springfield"; + int age; +}; + +TEST(boost_serialization, test_readme_example) { + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + write_and_read_with_json(homer); +} +} // namespace test_readme_example diff --git a/tests/boost_serialization/test_variant.cpp b/tests/boost_serialization/test_variant.cpp new file mode 100644 index 00000000..b87a3cc1 --- /dev/null +++ b/tests/boost_serialization/test_variant.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_variant { + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +struct Square { + double width; +}; + +using Shapes = std::variant; + +struct Drawing { + Shapes shape; +}; + +TEST(boost_serialization, test_variant) { + const auto drawing = Drawing{.shape = Circle{.radius = 5.0}}; + + write_and_read(drawing); +} +} // namespace test_variant diff --git a/tests/boost_serialization/write_and_read.hpp b/tests/boost_serialization/write_and_read.hpp new file mode 100644 index 00000000..1714dbc5 --- /dev/null +++ b/tests/boost_serialization/write_and_read.hpp @@ -0,0 +1,33 @@ +#ifndef WRITE_AND_READ_ +#define WRITE_AND_READ_ + +#include + +#include +#include +#include + +template +void write_and_read(const auto& _struct) { + using T = std::remove_cvref_t; + const auto serialized1 = rfl::boost_serialization::write(_struct); + const auto res = rfl::boost_serialization::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().what(); + const auto serialized2 = rfl::boost_serialization::write(res.value()); + EXPECT_EQ(serialized1, serialized2); +} + +template +void write_and_read_with_json(const auto& _struct) { + using T = std::remove_cvref_t; + const auto serialized1 = rfl::boost_serialization::write(_struct); + const auto res = rfl::boost_serialization::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().what(); + const auto serialized2 = rfl::boost_serialization::write(res.value()); + EXPECT_EQ(serialized1, serialized2); + EXPECT_EQ(rfl::json::write(_struct), + rfl::json::write(res.value())); +} +#endif From e230f9bc778b22951344eb984ceb7301e7378f26 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Sat, 28 Mar 2026 12:27:53 +0000 Subject: [PATCH 05/15] boost serialisatoin (better tests + literals) --- include/rfl/boost_serialization/Reader.hpp | 6 ++ include/rfl/boost_serialization/Writer.hpp | 3 + tests/boost_serialization/test_array.cpp | 23 ----- .../boost_serialization/test_basic_types.cpp | 83 +++++++++++++++++++ tests/boost_serialization/test_enum.cpp | 20 ----- tests/boost_serialization/test_map.cpp | 23 ----- .../test_optional_fields.cpp | 28 ------- .../test_readme_example.cpp | 22 ----- tests/boost_serialization/test_rfl_types.cpp | 65 +++++++++++++++ tests/boost_serialization/test_smart_ptrs.cpp | 66 +++++++++++++++ .../{test_variant.cpp => test_variants.cpp} | 12 ++- 11 files changed, 231 insertions(+), 120 deletions(-) delete mode 100644 tests/boost_serialization/test_array.cpp create mode 100644 tests/boost_serialization/test_basic_types.cpp delete mode 100644 tests/boost_serialization/test_enum.cpp delete mode 100644 tests/boost_serialization/test_map.cpp delete mode 100644 tests/boost_serialization/test_optional_fields.cpp delete mode 100644 tests/boost_serialization/test_readme_example.cpp create mode 100644 tests/boost_serialization/test_rfl_types.cpp create mode 100644 tests/boost_serialization/test_smart_ptrs.cpp rename tests/boost_serialization/{test_variant.cpp => test_variants.cpp} (60%) diff --git a/include/rfl/boost_serialization/Reader.hpp b/include/rfl/boost_serialization/Reader.hpp index f7b96a10..03bc0087 100644 --- a/include/rfl/boost_serialization/Reader.hpp +++ b/include/rfl/boost_serialization/Reader.hpp @@ -9,6 +9,7 @@ #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/is_literal.hpp" namespace rfl::boost_serialization { @@ -71,6 +72,11 @@ struct Reader { std::int64_t val = 0; *_var.ar >> val; return static_cast(val); + } else if constexpr (internal::is_literal_v) { + std::int64_t val = 0; + *_var.ar >> val; + return T::from_value( + static_cast::ValueType>(val)); } else { static_assert(rfl::always_false_v, "Unsupported type."); } diff --git a/include/rfl/boost_serialization/Writer.hpp b/include/rfl/boost_serialization/Writer.hpp index 22fee16b..0299be24 100644 --- a/include/rfl/boost_serialization/Writer.hpp +++ b/include/rfl/boost_serialization/Writer.hpp @@ -7,6 +7,7 @@ #include #include "../always_false.hpp" +#include "../internal/is_literal.hpp" namespace rfl::boost_serialization { @@ -235,6 +236,8 @@ class Writer { *ar_ << static_cast(_var); } else if constexpr (std::is_integral()) { *ar_ << static_cast(_var); + } else if constexpr (internal::is_literal_v) { + *ar_ << static_cast(_var.value()); } else { static_assert(rfl::always_false_v, "Unsupported type."); } diff --git a/tests/boost_serialization/test_array.cpp b/tests/boost_serialization/test_array.cpp deleted file mode 100644 index 42279091..00000000 --- a/tests/boost_serialization/test_array.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_array { - -struct Person { - std::string first_name; - int age; - std::vector hobbies; -}; - -TEST(boost_serialization, test_array) { - const auto homer = Person{ - .first_name = "Homer", - .age = 45, - .hobbies = std::vector({"bowling", "eating", "sleeping"})}; - - write_and_read_with_json(homer); -} -} // namespace test_array diff --git a/tests/boost_serialization/test_basic_types.cpp b/tests/boost_serialization/test_basic_types.cpp new file mode 100644 index 00000000..c3d8d7ce --- /dev/null +++ b/tests/boost_serialization/test_basic_types.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_basic_types { + +struct Person { + std::string first_name; + std::string last_name; + int age; +}; + +TEST(boost_serialization, test_simple_struct) { + const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + write_and_read_with_json(homer); +} + +struct Address { + std::string street; + std::string city; + int zip; +}; + +struct PersonWithAddress { + std::string first_name; + Address address; +}; + +TEST(boost_serialization, test_nested_struct) { + const auto homer = PersonWithAddress{ + .first_name = "Homer", + .address = Address{ + .street = "742 Evergreen Terrace", .city = "Springfield", .zip = 62704}}; + write_and_read_with_json(homer); +} + +enum class Color { red, green, blue }; + +struct Circle { + float radius; + Color color; +}; + +TEST(boost_serialization, test_enum) { + const auto circle = Circle{.radius = 2.0f, .color = Color::green}; + write_and_read_with_json(circle); +} + +struct WithContainers { + std::string name; + std::vector hobbies; + std::map attributes; + std::set lucky_numbers; +}; + +TEST(boost_serialization, test_containers) { + const auto homer = WithContainers{ + .name = "Homer", + .hobbies = {"bowling", "eating", "sleeping"}, + .attributes = {{"occupation", "Safety Inspector"}, {"town", "Springfield"}}, + .lucky_numbers = {7, 13, 42}}; + write_and_read_with_json(homer); +} + +struct WithOptional { + std::string first_name; + std::optional middle_name; + std::optional> children; +}; + +TEST(boost_serialization, test_optional_fields) { + const auto bart = WithOptional{.first_name = "Bart"}; + const auto homer = WithOptional{ + .first_name = "Homer", + .children = std::vector({bart})}; + write_and_read_with_json(homer); +} + +} // namespace test_basic_types diff --git a/tests/boost_serialization/test_enum.cpp b/tests/boost_serialization/test_enum.cpp deleted file mode 100644 index a04f41c5..00000000 --- a/tests/boost_serialization/test_enum.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -#include "write_and_read.hpp" - -namespace test_enum { - -enum class Color { red, green, blue }; - -struct Circle { - float radius; - Color color; -}; - -TEST(boost_serialization, test_enum) { - const auto circle = Circle{.radius = 2.0f, .color = Color::green}; - - write_and_read_with_json(circle); -} -} // namespace test_enum diff --git a/tests/boost_serialization/test_map.cpp b/tests/boost_serialization/test_map.cpp deleted file mode 100644 index 9c6fb2a3..00000000 --- a/tests/boost_serialization/test_map.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_map { - -struct Person { - std::string first_name; - std::string last_name = "Simpson"; - std::map attributes; -}; - -TEST(boost_serialization, test_map) { - const auto homer = - Person{.first_name = "Homer", - .attributes = {{"occupation", "Safety Inspector"}, - {"town", "Springfield"}}}; - - write_and_read(homer); -} -} // namespace test_map diff --git a/tests/boost_serialization/test_optional_fields.cpp b/tests/boost_serialization/test_optional_fields.cpp deleted file mode 100644 index 61a9235a..00000000 --- a/tests/boost_serialization/test_optional_fields.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_optional_fields { - -struct Person { - std::string first_name; - std::string last_name = "Simpson"; - std::optional> children; -}; - -TEST(boost_serialization, test_optional_fields) { - const auto bart = Person{.first_name = "Bart"}; - - const auto lisa = Person{.first_name = "Lisa"}; - - const auto maggie = Person{.first_name = "Maggie"}; - - const auto homer = - Person{.first_name = "Homer", - .children = std::vector({bart, lisa, maggie})}; - - write_and_read_with_json(homer); -} -} // namespace test_optional_fields diff --git a/tests/boost_serialization/test_readme_example.cpp b/tests/boost_serialization/test_readme_example.cpp deleted file mode 100644 index 4c2e84b5..00000000 --- a/tests/boost_serialization/test_readme_example.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_readme_example { - -struct Person { - std::string first_name; - std::string last_name = "Simpson"; - std::string town = "Springfield"; - int age; -}; - -TEST(boost_serialization, test_readme_example) { - const auto homer = - Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - - write_and_read_with_json(homer); -} -} // namespace test_readme_example diff --git a/tests/boost_serialization/test_rfl_types.cpp b/tests/boost_serialization/test_rfl_types.cpp new file mode 100644 index 00000000..1a3585ff --- /dev/null +++ b/tests/boost_serialization/test_rfl_types.cpp @@ -0,0 +1,65 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_rfl_types { + +struct PersonRenamed { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + int age; +}; + +TEST(boost_serialization, test_rename) { + const auto homer = PersonRenamed{.first_name = "Homer", .age = 45}; + write_and_read_with_json(homer); +} + +using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; + +struct PersonLiteral { + FirstName first_name; + std::vector children; +}; + +TEST(boost_serialization, test_literal) { + const auto bart = PersonLiteral{.first_name = FirstName::make<"Bart">()}; + write_and_read(bart); +} + +struct Inner { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"age", int> age; +}; + +struct Outer { + rfl::Flatten person; + rfl::Field<"employer", std::string> employer; +}; + +TEST(boost_serialization, test_flatten) { + const auto employee = + Outer{.person = Inner{.first_name = "Homer", .age = 45}, + .employer = "Mr. Burns"}; + write_and_read_with_json(employee); +} + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +using Shapes = rfl::TaggedUnion<"shape", Circle, Rectangle>; + +TEST(boost_serialization, test_tagged_union) { + const Shapes r = Rectangle{.height = 10, .width = 5}; + write_and_read_with_json(r); +} + +} // namespace test_rfl_types diff --git a/tests/boost_serialization/test_smart_ptrs.cpp b/tests/boost_serialization/test_smart_ptrs.cpp new file mode 100644 index 00000000..2e6aa4d4 --- /dev/null +++ b/tests/boost_serialization/test_smart_ptrs.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_smart_ptrs { + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_unique_ptr) { + auto children = std::make_unique>(); + children->emplace_back(Person{.first_name = "Bart"}); + children->emplace_back(Person{.first_name = "Lisa"}); + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + write_and_read(homer); +} + +struct PersonShared { + std::string first_name; + std::shared_ptr> children; +}; + +TEST(boost_serialization, test_shared_ptr) { + auto children = std::make_shared>(); + children->emplace_back(PersonShared{.first_name = "Bart"}); + const auto homer = + PersonShared{.first_name = "Homer", .children = std::move(children)}; + write_and_read_with_json(homer); +} + +struct DecisionTree { + struct Leaf { + using Tag = rfl::Literal<"Leaf">; + double value; + }; + + struct Node { + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + rfl::Box lesser; + rfl::Box greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +TEST(boost_serialization, test_box) { + auto node = DecisionTree::Node{ + .critical_value = 10.0, + .lesser = rfl::make_box( + DecisionTree{DecisionTree::Leaf{.value = 3.0}}), + .greater = rfl::make_box( + DecisionTree{DecisionTree::Leaf{.value = 5.0}})}; + const DecisionTree tree{.leaf_or_node = std::move(node)}; + write_and_read_with_json(tree); +} + +} // namespace test_smart_ptrs diff --git a/tests/boost_serialization/test_variant.cpp b/tests/boost_serialization/test_variants.cpp similarity index 60% rename from tests/boost_serialization/test_variant.cpp rename to tests/boost_serialization/test_variants.cpp index b87a3cc1..5597ff9a 100644 --- a/tests/boost_serialization/test_variant.cpp +++ b/tests/boost_serialization/test_variants.cpp @@ -1,11 +1,10 @@ #include -#include #include #include #include "write_and_read.hpp" -namespace test_variant { +namespace test_variants { struct Circle { double radius; @@ -26,9 +25,14 @@ struct Drawing { Shapes shape; }; -TEST(boost_serialization, test_variant) { +TEST(boost_serialization, test_std_variant) { const auto drawing = Drawing{.shape = Circle{.radius = 5.0}}; + write_and_read(drawing); +} +TEST(boost_serialization, test_std_variant_rectangle) { + const auto drawing = Drawing{.shape = Rectangle{.height = 10, .width = 5}}; write_and_read(drawing); } -} // namespace test_variant + +} // namespace test_variants From aea0234df9242688bda83d5f864fe2996aeab490 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Sat, 28 Mar 2026 12:32:10 +0000 Subject: [PATCH 06/15] boost serialisation (archive interop) --- include/rfl/boost_serialization/read.hpp | 6 ++ .../test_archive_interop.cpp | 66 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/boost_serialization/test_archive_interop.cpp diff --git a/include/rfl/boost_serialization/read.hpp b/include/rfl/boost_serialization/read.hpp index d93f7941..62cd26d4 100644 --- a/include/rfl/boost_serialization/read.hpp +++ b/include/rfl/boost_serialization/read.hpp @@ -29,6 +29,12 @@ auto read_from_archive(IArchive& _ar) { } // namespace detail +/// Reads from an existing Boost input archive. +template +auto read_from_archive(IArchive& _ar) { + return detail::read_from_archive(_ar); +} + /// Parses an object from bytes using a binary archive. template Result> read( diff --git a/tests/boost_serialization/test_archive_interop.cpp b/tests/boost_serialization/test_archive_interop.cpp new file mode 100644 index 00000000..0b432f7d --- /dev/null +++ b/tests/boost_serialization/test_archive_interop.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_archive_interop { + +struct Person { + std::string first_name; + std::string last_name; + int age; +}; + +TEST(boost_serialization, test_binary_archive_interop) { + const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + std::ostringstream os; + { + boost::archive::binary_oarchive oa(os); + rfl::boost_serialization::write(oa, homer); + } + + const auto str = os.str(); + std::istringstream is(str); + boost::archive::binary_iarchive ia(is); + const auto res = + rfl::boost_serialization::read_from_archive< + Person, boost::archive::binary_iarchive, + boost::archive::binary_oarchive>(ia); + EXPECT_TRUE(res && true) << "Error: " << res.error().what(); + EXPECT_EQ(res.value().first_name, "Homer"); + EXPECT_EQ(res.value().last_name, "Simpson"); + EXPECT_EQ(res.value().age, 45); +} + +TEST(boost_serialization, test_text_archive_round_trip) { + const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + std::ostringstream os; + { + boost::archive::text_oarchive oa(os); + rfl::boost_serialization::write(oa, homer); + } + + const auto str = os.str(); + std::istringstream is(str); + boost::archive::text_iarchive ia(is); + const auto res = + rfl::boost_serialization::read_from_archive< + Person, boost::archive::text_iarchive, + boost::archive::text_oarchive>(ia); + EXPECT_TRUE(res && true) << "Error: " << res.error().what(); + EXPECT_EQ(res.value().first_name, "Homer"); + EXPECT_EQ(res.value().last_name, "Simpson"); + EXPECT_EQ(res.value().age, 45); +} + +} // namespace test_archive_interop From 3001c71e6073d6c8ccafc050b27b6d29ba573ad7 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Sat, 28 Mar 2026 12:39:03 +0000 Subject: [PATCH 07/15] boost serialisation (more rfl types) --- tests/boost_serialization/test_rfl_types.cpp | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/boost_serialization/test_rfl_types.cpp b/tests/boost_serialization/test_rfl_types.cpp index 1a3585ff..522d4834 100644 --- a/tests/boost_serialization/test_rfl_types.cpp +++ b/tests/boost_serialization/test_rfl_types.cpp @@ -62,4 +62,31 @@ TEST(boost_serialization, test_tagged_union) { write_and_read_with_json(r); } +using Age = rfl::Validator, rfl::Maximum<130>>; + +struct PersonValidated { + std::string first_name; + Age age; + rfl::Email email; +}; + +TEST(boost_serialization, test_validator) { + const auto homer = PersonValidated{ + .first_name = "Homer", .age = 45, .email = "homer@simpson.com"}; + write_and_read_with_json(homer); +} + +using TS = rfl::Timestamp<"%Y-%m-%d">; + +struct PersonWithTimestamp { + std::string first_name; + TS birthday; +}; + +TEST(boost_serialization, test_timestamp) { + const auto bart = + PersonWithTimestamp{.first_name = "Bart", .birthday = "1987-04-19"}; + write_and_read_with_json(bart); +} + } // namespace test_rfl_types From 88e8f6ea37d0b379ea4c24a8ddfd64b30d4dc8af Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Sat, 28 Mar 2026 12:45:08 +0000 Subject: [PATCH 08/15] boost serialisation (tidy) --- include/rfl/boost_serialization/Parser.hpp | 4 +-- include/rfl/boost_serialization/Writer.hpp | 8 ++---- include/rfl/boost_serialization/read.hpp | 9 +++---- include/rfl/boost_serialization/save.hpp | 2 +- include/rfl/boost_serialization/write.hpp | 9 +++---- .../test_archive_interop.cpp | 20 +++++++------- .../boost_serialization/test_basic_types.cpp | 26 ++++++++++--------- tests/boost_serialization/test_rfl_types.cpp | 5 ++-- tests/boost_serialization/test_smart_ptrs.cpp | 12 ++++----- 9 files changed, 44 insertions(+), 51 deletions(-) diff --git a/include/rfl/boost_serialization/Parser.hpp b/include/rfl/boost_serialization/Parser.hpp index 44d6a68f..98b88450 100644 --- a/include/rfl/boost_serialization/Parser.hpp +++ b/include/rfl/boost_serialization/Parser.hpp @@ -21,8 +21,8 @@ template , NamedTuple> struct Parser, - boost_serialization::Writer, - NamedTuple, ProcessorsType> + boost_serialization::Writer, NamedTuple, + ProcessorsType> : public NamedTupleParser< boost_serialization::Reader, boost_serialization::Writer, diff --git a/include/rfl/boost_serialization/Writer.hpp b/include/rfl/boost_serialization/Writer.hpp index 0299be24..d27836a0 100644 --- a/include/rfl/boost_serialization/Writer.hpp +++ b/include/rfl/boost_serialization/Writer.hpp @@ -49,13 +49,9 @@ class Writer { return OutputObjectType{}; } - OutputVarType null_as_root() const { - return OutputVarType{}; - } + OutputVarType null_as_root() const { return OutputVarType{}; } - OutputUnionType union_as_root() const { - return OutputUnionType{}; - } + OutputUnionType union_as_root() const { return OutputUnionType{}; } template OutputVarType value_as_root(const T& _var) const { diff --git a/include/rfl/boost_serialization/read.hpp b/include/rfl/boost_serialization/read.hpp index 62cd26d4..81f86b8b 100644 --- a/include/rfl/boost_serialization/read.hpp +++ b/include/rfl/boost_serialization/read.hpp @@ -4,7 +4,6 @@ #include #include #include - #include #include #include @@ -44,8 +43,8 @@ Result> read( std::istringstream stream(str); boost::archive::binary_iarchive ar(stream); return detail::read_from_archive(ar); + boost::archive::binary_oarchive, Ps...>( + ar); } catch (std::exception& e) { return error(e.what()); } @@ -63,8 +62,8 @@ auto read(std::istream& _stream) { try { boost::archive::binary_iarchive ar(_stream); return detail::read_from_archive(ar); + boost::archive::binary_oarchive, Ps...>( + ar); } catch (std::exception& e) { return Result>(error(e.what())); } diff --git a/include/rfl/boost_serialization/save.hpp b/include/rfl/boost_serialization/save.hpp index f919eec4..fd5229e5 100644 --- a/include/rfl/boost_serialization/save.hpp +++ b/include/rfl/boost_serialization/save.hpp @@ -14,7 +14,7 @@ namespace rfl::boost_serialization { template Result save(const std::string& _fname, const auto& _obj) { const auto write_func = [](const auto& _obj, - std::ostream& _stream) -> std::ostream& { + std::ostream& _stream) -> std::ostream& { return write(_obj, _stream); }; return rfl::io::save_bytes(_fname, _obj, write_func); diff --git a/include/rfl/boost_serialization/write.hpp b/include/rfl/boost_serialization/write.hpp index 583aaa2b..dc9c7904 100644 --- a/include/rfl/boost_serialization/write.hpp +++ b/include/rfl/boost_serialization/write.hpp @@ -4,7 +4,6 @@ #include #include #include - #include #include #include @@ -35,8 +34,8 @@ std::vector write(const auto& _obj) { std::ostringstream stream; { boost::archive::binary_oarchive ar(stream); - write(ar, _obj); + write(ar, _obj); } const auto str = stream.str(); return std::vector(str.begin(), str.end()); @@ -46,8 +45,8 @@ std::vector write(const auto& _obj) { template std::ostream& write(const auto& _obj, std::ostream& _stream) { boost::archive::binary_oarchive ar(_stream); - write(ar, _obj); + write(ar, _obj); return _stream; } diff --git a/tests/boost_serialization/test_archive_interop.cpp b/tests/boost_serialization/test_archive_interop.cpp index 0b432f7d..ae9d569a 100644 --- a/tests/boost_serialization/test_archive_interop.cpp +++ b/tests/boost_serialization/test_archive_interop.cpp @@ -3,7 +3,6 @@ #include #include #include - #include #include #include @@ -20,7 +19,8 @@ struct Person { }; TEST(boost_serialization, test_binary_archive_interop) { - const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; std::ostringstream os; { @@ -31,10 +31,9 @@ TEST(boost_serialization, test_binary_archive_interop) { const auto str = os.str(); std::istringstream is(str); boost::archive::binary_iarchive ia(is); - const auto res = - rfl::boost_serialization::read_from_archive< - Person, boost::archive::binary_iarchive, - boost::archive::binary_oarchive>(ia); + const auto res = rfl::boost_serialization::read_from_archive< + Person, boost::archive::binary_iarchive, boost::archive::binary_oarchive>( + ia); EXPECT_TRUE(res && true) << "Error: " << res.error().what(); EXPECT_EQ(res.value().first_name, "Homer"); EXPECT_EQ(res.value().last_name, "Simpson"); @@ -42,7 +41,8 @@ TEST(boost_serialization, test_binary_archive_interop) { } TEST(boost_serialization, test_text_archive_round_trip) { - const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; std::ostringstream os; { @@ -53,10 +53,8 @@ TEST(boost_serialization, test_text_archive_round_trip) { const auto str = os.str(); std::istringstream is(str); boost::archive::text_iarchive ia(is); - const auto res = - rfl::boost_serialization::read_from_archive< - Person, boost::archive::text_iarchive, - boost::archive::text_oarchive>(ia); + const auto res = rfl::boost_serialization::read_from_archive< + Person, boost::archive::text_iarchive, boost::archive::text_oarchive>(ia); EXPECT_TRUE(res && true) << "Error: " << res.error().what(); EXPECT_EQ(res.value().first_name, "Homer"); EXPECT_EQ(res.value().last_name, "Simpson"); diff --git a/tests/boost_serialization/test_basic_types.cpp b/tests/boost_serialization/test_basic_types.cpp index c3d8d7ce..b26880eb 100644 --- a/tests/boost_serialization/test_basic_types.cpp +++ b/tests/boost_serialization/test_basic_types.cpp @@ -15,7 +15,8 @@ struct Person { }; TEST(boost_serialization, test_simple_struct) { - const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; write_and_read_with_json(homer); } @@ -31,10 +32,11 @@ struct PersonWithAddress { }; TEST(boost_serialization, test_nested_struct) { - const auto homer = PersonWithAddress{ - .first_name = "Homer", - .address = Address{ - .street = "742 Evergreen Terrace", .city = "Springfield", .zip = 62704}}; + const auto homer = + PersonWithAddress{.first_name = "Homer", + .address = Address{.street = "742 Evergreen Terrace", + .city = "Springfield", + .zip = 62704}}; write_and_read_with_json(homer); } @@ -58,11 +60,12 @@ struct WithContainers { }; TEST(boost_serialization, test_containers) { - const auto homer = WithContainers{ - .name = "Homer", - .hobbies = {"bowling", "eating", "sleeping"}, - .attributes = {{"occupation", "Safety Inspector"}, {"town", "Springfield"}}, - .lucky_numbers = {7, 13, 42}}; + const auto homer = + WithContainers{.name = "Homer", + .hobbies = {"bowling", "eating", "sleeping"}, + .attributes = {{"occupation", "Safety Inspector"}, + {"town", "Springfield"}}, + .lucky_numbers = {7, 13, 42}}; write_and_read_with_json(homer); } @@ -75,8 +78,7 @@ struct WithOptional { TEST(boost_serialization, test_optional_fields) { const auto bart = WithOptional{.first_name = "Bart"}; const auto homer = WithOptional{ - .first_name = "Homer", - .children = std::vector({bart})}; + .first_name = "Homer", .children = std::vector({bart})}; write_and_read_with_json(homer); } diff --git a/tests/boost_serialization/test_rfl_types.cpp b/tests/boost_serialization/test_rfl_types.cpp index 522d4834..ce43f8ea 100644 --- a/tests/boost_serialization/test_rfl_types.cpp +++ b/tests/boost_serialization/test_rfl_types.cpp @@ -40,9 +40,8 @@ struct Outer { }; TEST(boost_serialization, test_flatten) { - const auto employee = - Outer{.person = Inner{.first_name = "Homer", .age = 45}, - .employer = "Mr. Burns"}; + const auto employee = Outer{.person = Inner{.first_name = "Homer", .age = 45}, + .employer = "Mr. Burns"}; write_and_read_with_json(employee); } diff --git a/tests/boost_serialization/test_smart_ptrs.cpp b/tests/boost_serialization/test_smart_ptrs.cpp index 2e6aa4d4..96698c79 100644 --- a/tests/boost_serialization/test_smart_ptrs.cpp +++ b/tests/boost_serialization/test_smart_ptrs.cpp @@ -53,12 +53,12 @@ struct DecisionTree { }; TEST(boost_serialization, test_box) { - auto node = DecisionTree::Node{ - .critical_value = 10.0, - .lesser = rfl::make_box( - DecisionTree{DecisionTree::Leaf{.value = 3.0}}), - .greater = rfl::make_box( - DecisionTree{DecisionTree::Leaf{.value = 5.0}})}; + auto node = + DecisionTree::Node{.critical_value = 10.0, + .lesser = rfl::make_box( + DecisionTree{DecisionTree::Leaf{.value = 3.0}}), + .greater = rfl::make_box( + DecisionTree{DecisionTree::Leaf{.value = 5.0}})}; const DecisionTree tree{.leaf_or_node = std::move(node)}; write_and_read_with_json(tree); } From f9dc3e8008c1c8bd8e29074d3cc7c09d51f5b535 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Sat, 28 Mar 2026 16:27:28 +0000 Subject: [PATCH 09/15] boost serialisation (standard tests + workflows) --- .github/workflows/linux.yaml | 2 +- .github/workflows/windows.yaml | 4 +- .../test_add_struct_name.cpp | 45 +++++++++ .../test_archive_interop.cpp | 64 ------------- tests/boost_serialization/test_array.cpp | 34 +++++++ .../boost_serialization/test_basic_types.cpp | 85 ----------------- tests/boost_serialization/test_box.cpp | 40 ++++++++ .../test_combined_processors.cpp | 48 ++++++++++ .../test_custom_class1.cpp | 35 +++++++ .../test_custom_class3.cpp | 62 +++++++++++++ .../test_custom_class4.cpp | 63 +++++++++++++ .../test_default_values.cpp | 26 ++++++ tests/boost_serialization/test_deque.cpp | 25 +++++ tests/boost_serialization/test_enum.cpp | 21 +++++ .../test_field_variant.cpp | 31 +++++++ tests/boost_serialization/test_flag_enum.cpp | 32 +++++++ .../test_flag_enum_with_int.cpp | 31 +++++++ tests/boost_serialization/test_flatten.cpp | 31 +++++++ .../test_flatten_anonymous.cpp | 32 +++++++ .../boost_serialization/test_forward_list.cpp | 25 +++++ tests/boost_serialization/test_literal.cpp | 23 +++++ .../test_monster_example.cpp | 58 ++++++++++++ .../test_readme_example.cpp | 45 +++++++++ .../test_readme_example2.cpp | 20 ++++ tests/boost_serialization/test_ref.cpp | 40 ++++++++ tests/boost_serialization/test_rfl_types.cpp | 91 ------------------- tests/boost_serialization/test_save_load.cpp | 61 +++++++++++++ tests/boost_serialization/test_set.cpp | 23 +++++ tests/boost_serialization/test_size.cpp | 36 ++++++++ tests/boost_serialization/test_smart_ptrs.cpp | 66 -------------- .../test_snake_case_to_camel_case.cpp | 33 +++++++ .../test_snake_case_to_pascal_case.cpp | 33 +++++++ .../boost_serialization/test_tagged_union.cpp | 27 ++++++ tests/boost_serialization/test_timestamp.cpp | 29 ++++++ tests/boost_serialization/test_unique_ptr.cpp | 27 ++++++ .../boost_serialization/test_unique_ptr2.cpp | 40 ++++++++ tests/boost_serialization/test_variant.cpp | 28 ++++++ tests/boost_serialization/test_variants.cpp | 38 -------- 38 files changed, 1107 insertions(+), 347 deletions(-) create mode 100644 tests/boost_serialization/test_add_struct_name.cpp delete mode 100644 tests/boost_serialization/test_archive_interop.cpp create mode 100644 tests/boost_serialization/test_array.cpp delete mode 100644 tests/boost_serialization/test_basic_types.cpp create mode 100644 tests/boost_serialization/test_box.cpp create mode 100644 tests/boost_serialization/test_combined_processors.cpp create mode 100644 tests/boost_serialization/test_custom_class1.cpp create mode 100644 tests/boost_serialization/test_custom_class3.cpp create mode 100644 tests/boost_serialization/test_custom_class4.cpp create mode 100644 tests/boost_serialization/test_default_values.cpp create mode 100644 tests/boost_serialization/test_deque.cpp create mode 100644 tests/boost_serialization/test_enum.cpp create mode 100644 tests/boost_serialization/test_field_variant.cpp create mode 100644 tests/boost_serialization/test_flag_enum.cpp create mode 100644 tests/boost_serialization/test_flag_enum_with_int.cpp create mode 100644 tests/boost_serialization/test_flatten.cpp create mode 100644 tests/boost_serialization/test_flatten_anonymous.cpp create mode 100644 tests/boost_serialization/test_forward_list.cpp create mode 100644 tests/boost_serialization/test_literal.cpp create mode 100644 tests/boost_serialization/test_monster_example.cpp create mode 100644 tests/boost_serialization/test_readme_example.cpp create mode 100644 tests/boost_serialization/test_readme_example2.cpp create mode 100644 tests/boost_serialization/test_ref.cpp delete mode 100644 tests/boost_serialization/test_rfl_types.cpp create mode 100644 tests/boost_serialization/test_save_load.cpp create mode 100644 tests/boost_serialization/test_set.cpp create mode 100644 tests/boost_serialization/test_size.cpp delete mode 100644 tests/boost_serialization/test_smart_ptrs.cpp create mode 100644 tests/boost_serialization/test_snake_case_to_camel_case.cpp create mode 100644 tests/boost_serialization/test_snake_case_to_pascal_case.cpp create mode 100644 tests/boost_serialization/test_tagged_union.cpp create mode 100644 tests/boost_serialization/test_timestamp.cpp create mode 100644 tests/boost_serialization/test_unique_ptr.cpp create mode 100644 tests/boost_serialization/test_unique_ptr2.cpp create mode 100644 tests/boost_serialization/test_variant.cpp delete mode 100644 tests/boost_serialization/test_variants.cpp diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 9633ab35..5ee5d7da 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "CEREAL", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks", "headers"] + format: ["JSON", "AVRO", "BOOST_SERIALIZATION", "CAPNPROTO", "CBOR", "CEREAL", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks", "headers"] compiler: [llvm, gcc] compiler-version: [11, 12, 13, 14, 16, 17, 18] cxx: [20, 23] diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index 6aa4e3a0..59e76349 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "CEREAL", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks"] + format: ["JSON", "AVRO", "BOOST_SERIALIZATION", "CAPNPROTO", "CBOR", "CEREAL", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks"] name: "windows-msvc (${{ matrix.format }})" concurrency: group: "windows-${{ github.ref }}-${{ github.job }}-${{ matrix.format }}" @@ -77,7 +77,7 @@ jobs: strategy: fail-fast: false matrix: - format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML"] + format: ["JSON", "AVRO", "BOOST_SERIALIZATION", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML"] name: "windows-msvc-shared (${{ matrix.format }})" runs-on: windows-latest steps: diff --git a/tests/boost_serialization/test_add_struct_name.cpp b/tests/boost_serialization/test_add_struct_name.cpp new file mode 100644 index 00000000..55a4cb4e --- /dev/null +++ b/tests/boost_serialization/test_add_struct_name.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_add_struct_name { + +using Age = rfl::Validator, rfl::Maximum<130>>; + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::string town = "Springfield"; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector children; +}; + +TEST(boost_serialization, test_add_struct_name) { + const auto bart = Person{.first_name = "Bart", + .birthday = "1987-04-19", + .age = 10, + .email = "bart@simpson.com"}; + + const auto lisa = Person{.first_name = "Lisa", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; + + const auto maggie = Person{.first_name = "Maggie", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; + + const auto homer = + Person{.first_name = "Homer", + .birthday = "1987-04-19", + .age = 45, + .email = "homer@simpson.com", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read>(homer); +} +} // namespace test_add_struct_name diff --git a/tests/boost_serialization/test_archive_interop.cpp b/tests/boost_serialization/test_archive_interop.cpp deleted file mode 100644 index ae9d569a..00000000 --- a/tests/boost_serialization/test_archive_interop.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_archive_interop { - -struct Person { - std::string first_name; - std::string last_name; - int age; -}; - -TEST(boost_serialization, test_binary_archive_interop) { - const auto homer = - Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - - std::ostringstream os; - { - boost::archive::binary_oarchive oa(os); - rfl::boost_serialization::write(oa, homer); - } - - const auto str = os.str(); - std::istringstream is(str); - boost::archive::binary_iarchive ia(is); - const auto res = rfl::boost_serialization::read_from_archive< - Person, boost::archive::binary_iarchive, boost::archive::binary_oarchive>( - ia); - EXPECT_TRUE(res && true) << "Error: " << res.error().what(); - EXPECT_EQ(res.value().first_name, "Homer"); - EXPECT_EQ(res.value().last_name, "Simpson"); - EXPECT_EQ(res.value().age, 45); -} - -TEST(boost_serialization, test_text_archive_round_trip) { - const auto homer = - Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - - std::ostringstream os; - { - boost::archive::text_oarchive oa(os); - rfl::boost_serialization::write(oa, homer); - } - - const auto str = os.str(); - std::istringstream is(str); - boost::archive::text_iarchive ia(is); - const auto res = rfl::boost_serialization::read_from_archive< - Person, boost::archive::text_iarchive, boost::archive::text_oarchive>(ia); - EXPECT_TRUE(res && true) << "Error: " << res.error().what(); - EXPECT_EQ(res.value().first_name, "Homer"); - EXPECT_EQ(res.value().last_name, "Simpson"); - EXPECT_EQ(res.value().age, 45); -} - -} // namespace test_archive_interop diff --git a/tests/boost_serialization/test_array.cpp b/tests/boost_serialization/test_array.cpp new file mode 100644 index 00000000..67e286db --- /dev/null +++ b/tests/boost_serialization/test_array.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +// Make sure things still compile when +// rfl.hpp is included after rfl/cbor.hpp. +#include + +#include "write_and_read.hpp" + +namespace test_array { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children = nullptr; +}; + +TEST(boost_serialization, test_array) { + auto bart = Person{.first_name = "Bart"}; + + auto lisa = Person{.first_name = "Lisa"}; + + auto maggie = Person{.first_name = "Maggie"}; + + const auto homer = Person{ + .first_name = "Homer", + .children = std::make_unique>(std::array{ + std::move(bart), std::move(lisa), std::move(maggie)})}; + + write_and_read(homer); +} +} // namespace test_array diff --git a/tests/boost_serialization/test_basic_types.cpp b/tests/boost_serialization/test_basic_types.cpp deleted file mode 100644 index b26880eb..00000000 --- a/tests/boost_serialization/test_basic_types.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_basic_types { - -struct Person { - std::string first_name; - std::string last_name; - int age; -}; - -TEST(boost_serialization, test_simple_struct) { - const auto homer = - Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - write_and_read_with_json(homer); -} - -struct Address { - std::string street; - std::string city; - int zip; -}; - -struct PersonWithAddress { - std::string first_name; - Address address; -}; - -TEST(boost_serialization, test_nested_struct) { - const auto homer = - PersonWithAddress{.first_name = "Homer", - .address = Address{.street = "742 Evergreen Terrace", - .city = "Springfield", - .zip = 62704}}; - write_and_read_with_json(homer); -} - -enum class Color { red, green, blue }; - -struct Circle { - float radius; - Color color; -}; - -TEST(boost_serialization, test_enum) { - const auto circle = Circle{.radius = 2.0f, .color = Color::green}; - write_and_read_with_json(circle); -} - -struct WithContainers { - std::string name; - std::vector hobbies; - std::map attributes; - std::set lucky_numbers; -}; - -TEST(boost_serialization, test_containers) { - const auto homer = - WithContainers{.name = "Homer", - .hobbies = {"bowling", "eating", "sleeping"}, - .attributes = {{"occupation", "Safety Inspector"}, - {"town", "Springfield"}}, - .lucky_numbers = {7, 13, 42}}; - write_and_read_with_json(homer); -} - -struct WithOptional { - std::string first_name; - std::optional middle_name; - std::optional> children; -}; - -TEST(boost_serialization, test_optional_fields) { - const auto bart = WithOptional{.first_name = "Bart"}; - const auto homer = WithOptional{ - .first_name = "Homer", .children = std::vector({bart})}; - write_and_read_with_json(homer); -} - -} // namespace test_basic_types diff --git a/tests/boost_serialization/test_box.cpp b/tests/boost_serialization/test_box.cpp new file mode 100644 index 00000000..1afcdff5 --- /dev/null +++ b/tests/boost_serialization/test_box.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_box { + +struct DecisionTree { + struct Leaf { + using Tag = rfl::Literal<"Leaf">; + double value; + }; + + struct Node { + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + rfl::Box lesser; + rfl::Box greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +TEST(boost_serialization, test_box) { + auto leaf1 = DecisionTree::Leaf{.value = 3.0}; + + auto leaf2 = DecisionTree::Leaf{.value = 5.0}; + + auto node = DecisionTree::Node{ + .critical_value = 10.0, + .lesser = rfl::make_box(DecisionTree{leaf1}), + .greater = rfl::make_box(DecisionTree{leaf2})}; + + const DecisionTree tree{.leaf_or_node = std::move(node)}; + + write_and_read(tree); +} +} // namespace test_box diff --git a/tests/boost_serialization/test_combined_processors.cpp b/tests/boost_serialization/test_combined_processors.cpp new file mode 100644 index 00000000..7f5e041f --- /dev/null +++ b/tests/boost_serialization/test_combined_processors.cpp @@ -0,0 +1,48 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_combined_processors { + +using Age = rfl::Validator, rfl::Maximum<130>>; + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + std::string town = "Springfield"; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector children; +}; + +TEST(boost_serialization, test_combined_processors) { + const auto bart = Person{.first_name = "Bart", + .birthday = "1987-04-19", + .age = 10, + .email = "bart@simpson.com"}; + + const auto lisa = Person{.first_name = "Lisa", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; + + const auto maggie = Person{.first_name = "Maggie", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; + + const auto homer = + Person{.first_name = "Homer", + .birthday = "1987-04-19", + .age = 45, + .email = "homer@simpson.com", + .children = std::vector({bart, lisa, maggie})}; + + using Processors = + rfl::Processors>; + + write_and_read(homer); +} +} // namespace test_combined_processors diff --git a/tests/boost_serialization/test_custom_class1.cpp b/tests/boost_serialization/test_custom_class1.cpp new file mode 100644 index 00000000..b07d3746 --- /dev/null +++ b/tests/boost_serialization/test_custom_class1.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_custom_class1 { + +struct Person { + struct PersonImpl { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::vector children; + }; + + using ReflectionType = PersonImpl; + + Person(const PersonImpl& _impl) : impl(_impl) {} + + Person(const std::string& _first_name) + : impl(PersonImpl{.first_name = _first_name}) {} + + const ReflectionType& reflection() const { return impl; }; + + private: + PersonImpl impl; +}; + +TEST(boost_serialization, test_custom_class1) { + const auto bart = Person("Bart"); + + write_and_read(bart); +} +} // namespace test_custom_class1 diff --git a/tests/boost_serialization/test_custom_class3.cpp b/tests/boost_serialization/test_custom_class3.cpp new file mode 100644 index 00000000..79510b45 --- /dev/null +++ b/tests/boost_serialization/test_custom_class3.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_custom_class3 { + +struct Person { + Person(const std::string& _first_name, const std::string& _last_name, + const int _age) + : first_name_(_first_name), last_name_(_last_name), age_(_age) {} + + const auto& first_name() const { return first_name_; } + + const auto& last_name() const { return last_name_; } + + auto age() const { return age_; } + + private: + std::string first_name_; + std::string last_name_; + int age_; +}; + +struct PersonImpl { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + int age; + + static PersonImpl from_class(const Person& _p) noexcept { + return PersonImpl{.first_name = _p.first_name(), + .last_name = _p.last_name(), + .age = _p.age()}; + } + + Person to_class() const { return Person(first_name(), last_name(), age); } +}; +} // namespace test_custom_class3 + +namespace rfl { +namespace parsing { + +template +struct Parser + : public CustomParser {}; + +} // namespace parsing +} // namespace rfl + +namespace test_custom_class3 { + +TEST(boost_serialization, test_custom_class3) { + const auto bart = Person("Bart", "Simpson", 10); + + write_and_read(bart); +} + +} // namespace test_custom_class3 diff --git a/tests/boost_serialization/test_custom_class4.cpp b/tests/boost_serialization/test_custom_class4.cpp new file mode 100644 index 00000000..4cb88bc7 --- /dev/null +++ b/tests/boost_serialization/test_custom_class4.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_custom_class4 { + +struct Person { + Person(const std::string& _first_name, + const rfl::Box& _last_name, int _age) + : first_name_(_first_name), + last_name_(rfl::make_box(*_last_name)), + age_(_age) {} + + const auto& first_name() const { return first_name_; } + + const auto& last_name() const { return last_name_; } + + auto age() const { return age_; } + + private: + std::string first_name_; + rfl::Box last_name_; + int age_; +}; + +struct PersonImpl { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", rfl::Box> last_name; + rfl::Field<"age", int> age; + + static PersonImpl from_class(const Person& _p) noexcept { + return PersonImpl{.first_name = _p.first_name(), + .last_name = rfl::make_box(*_p.last_name()), + .age = _p.age()}; + } +}; + +} // namespace test_custom_class4 + +namespace rfl { +namespace parsing { + +template +struct Parser + : public CustomParser {}; + +} // namespace parsing +} // namespace rfl + +namespace test_custom_class4 { + +TEST(boost_serialization, test_custom_class4) { + const auto bart = test_custom_class4::Person( + "Bart", rfl::make_box("Simpson"), 10); + + write_and_read(bart); +} +} // namespace test_custom_class4 diff --git a/tests/boost_serialization/test_default_values.cpp b/tests/boost_serialization/test_default_values.cpp new file mode 100644 index 00000000..1a55dfd8 --- /dev/null +++ b/tests/boost_serialization/test_default_values.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_default_values { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::vector children; +}; + +TEST(boost_serialization, test_default_values) { + const auto bart = Person{.first_name = "Bart"}; + const auto lisa = Person{.first_name = "Lisa"}; + const auto maggie = Person{.first_name = "Maggie"}; + const auto homer = + Person{.first_name = "Homer", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_default_values diff --git a/tests/boost_serialization/test_deque.cpp b/tests/boost_serialization/test_deque.cpp new file mode 100644 index 00000000..55a3373a --- /dev/null +++ b/tests/boost_serialization/test_deque.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_deque { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_default_values) { + auto children = std::make_unique>(); + children->emplace_back(Person{.first_name = "Bart"}); + children->emplace_back(Person{.first_name = "Lisa"}); + children->emplace_back(Person{.first_name = "Maggie"}); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_deque diff --git a/tests/boost_serialization/test_enum.cpp b/tests/boost_serialization/test_enum.cpp new file mode 100644 index 00000000..a26019ab --- /dev/null +++ b/tests/boost_serialization/test_enum.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_enum { + +enum class Color { red, green, blue, yellow }; + +struct Circle { + float radius; + Color color; +}; + +TEST(boost_serialization, test_enum) { + const auto circle = Circle{.radius = 2.0, .color = Color::green}; + + write_and_read(circle); +} + +} // namespace test_enum diff --git a/tests/boost_serialization/test_field_variant.cpp b/tests/boost_serialization/test_field_variant.cpp new file mode 100644 index 00000000..eb94c59f --- /dev/null +++ b/tests/boost_serialization/test_field_variant.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_field_variant { + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +struct Square { + double width; +}; + +using Shapes = rfl::Variant, + rfl::Field<"rectangle", Rectangle>, + rfl::Field<"square", rfl::Box>>; + +TEST(boost_serialization, test_field_variant) { + const Shapes r = + rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); + + write_and_read(r); +} +} // namespace test_field_variant diff --git a/tests/boost_serialization/test_flag_enum.cpp b/tests/boost_serialization/test_flag_enum.cpp new file mode 100644 index 00000000..8d09cdd5 --- /dev/null +++ b/tests/boost_serialization/test_flag_enum.cpp @@ -0,0 +1,32 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_flag_enum { + +enum class Color { + red = 256, + green = 512, + blue = 1024, + yellow = 2048, + orange = (256 | 2048) // red + yellow = orange +}; + +inline Color operator|(Color c1, Color c2) { + return static_cast(static_cast(c1) | static_cast(c2)); +} + +struct Circle { + float radius; + Color color; +}; + +TEST(boost_serialization, test_flag_enum) { + const auto circle = + Circle{.radius = 2.0, .color = Color::blue | Color::orange}; + + write_and_read(circle); +} + +} // namespace test_flag_enum diff --git a/tests/boost_serialization/test_flag_enum_with_int.cpp b/tests/boost_serialization/test_flag_enum_with_int.cpp new file mode 100644 index 00000000..d4e887f0 --- /dev/null +++ b/tests/boost_serialization/test_flag_enum_with_int.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_flag_enum_with_int { + +enum class Color { + red = 256, + green = 512, + blue = 1024, + yellow = 2048, + orange = (256 | 2048) // red + yellow = orange +}; + +inline Color operator|(Color c1, Color c2) { + return static_cast(static_cast(c1) | static_cast(c2)); +} + +struct Circle { + float radius; + Color color; +}; + +TEST(boost_serialization, test_flag_enum_with_int) { + const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; + + write_and_read(circle); +} + +} // namespace test_flag_enum_with_int diff --git a/tests/boost_serialization/test_flatten.cpp b/tests/boost_serialization/test_flatten.cpp new file mode 100644 index 00000000..d8a5d6ca --- /dev/null +++ b/tests/boost_serialization/test_flatten.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_flatten { + +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", rfl::Box> last_name; + rfl::Field<"age", int> age; +}; + +struct Employee { + rfl::Flatten person; + rfl::Field<"employer", rfl::Box> employer; + rfl::Field<"salary", float> salary; +}; + +TEST(boost_serialization, test_flatten) { + const auto employee = Employee{ + .person = Person{.first_name = "Homer", + .last_name = rfl::make_box("Simpson"), + .age = 45}, + .employer = rfl::make_box("Mr. Burns"), + .salary = 60000.0}; + + write_and_read(employee); +} +} // namespace test_flatten diff --git a/tests/boost_serialization/test_flatten_anonymous.cpp b/tests/boost_serialization/test_flatten_anonymous.cpp new file mode 100644 index 00000000..bfad4b0d --- /dev/null +++ b/tests/boost_serialization/test_flatten_anonymous.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_flatten_anonymous { + +struct Person { + std::string first_name; + rfl::Box last_name; + int age; +}; + +struct Employee { + rfl::Flatten person; + rfl::Box employer; + float salary; +}; + +TEST(boost_serialization, test_flatten_anonymous) { + const auto employee = Employee{ + .person = Person{.first_name = "Homer", + .last_name = rfl::make_box("Simpson"), + .age = 45}, + .employer = rfl::make_box("Mr. Burns"), + .salary = 60000.0}; + + write_and_read(employee); +} + +} // namespace test_flatten_anonymous diff --git a/tests/boost_serialization/test_forward_list.cpp b/tests/boost_serialization/test_forward_list.cpp new file mode 100644 index 00000000..801c5295 --- /dev/null +++ b/tests/boost_serialization/test_forward_list.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_forward_list { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_forward_list) { + auto children = std::make_unique>(); + children->emplace_front(Person{.first_name = "Maggie"}); + children->emplace_front(Person{.first_name = "Lisa"}); + children->emplace_front(Person{.first_name = "Bart"}); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_forward_list diff --git a/tests/boost_serialization/test_literal.cpp b/tests/boost_serialization/test_literal.cpp new file mode 100644 index 00000000..519d85c4 --- /dev/null +++ b/tests/boost_serialization/test_literal.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_literal { + +using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; +using LastName = rfl::Literal<"Simpson">; + +struct Person { + rfl::Rename<"firstName", FirstName> first_name; + rfl::Rename<"lastName", LastName> last_name; + std::vector children; +}; + +TEST(boost_serialization, test_literal) { + const auto bart = Person{.first_name = FirstName::make<"Bart">()}; + + write_and_read(bart); +} +} // namespace test_literal diff --git a/tests/boost_serialization/test_monster_example.cpp b/tests/boost_serialization/test_monster_example.cpp new file mode 100644 index 00000000..b3c412ee --- /dev/null +++ b/tests/boost_serialization/test_monster_example.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_monster_example { + +using Color = rfl::Literal<"Red", "Green", "Blue">; + +struct Weapon { + std::string name; + short damage; +}; + +using Equipment = rfl::Variant>; + +struct Vec3 { + float x; + float y; + float z; +}; + +struct Monster { + Vec3 pos; + short mana = 150; + short hp = 100; + std::string name; + bool friendly = false; + std::vector inventory; + Color color = Color::make<"Blue">(); + std::vector weapons; + Equipment equipped; + std::vector path; +}; + +TEST(boost_serialization, test_monster_example) { + const auto sword = Weapon{.name = "Sword", .damage = 3}; + const auto axe = Weapon{.name = "Axe", .damage = 5}; + + const auto weapons = std::vector({sword, axe}); + + const auto position = Vec3{1.0f, 2.0f, 3.0f}; + + const auto inventory = std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + + const auto orc = Monster{.pos = position, + .mana = 150, + .hp = 80, + .name = "MyMonster", + .inventory = inventory, + .color = Color::make<"Red">(), + .weapons = weapons, + .equipped = rfl::make_field<"weapon">(axe)}; + + write_and_read(orc); +} +} // namespace test_monster_example diff --git a/tests/boost_serialization/test_readme_example.cpp b/tests/boost_serialization/test_readme_example.cpp new file mode 100644 index 00000000..17377053 --- /dev/null +++ b/tests/boost_serialization/test_readme_example.cpp @@ -0,0 +1,45 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_readme_example { + +using Age = rfl::Validator, rfl::Maximum<130>>; + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::string town = "Springfield"; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector child; +}; + +TEST(boost_serialization, test_readme_example) { + const auto bart = Person{.first_name = "Bart", + .birthday = "1987-04-19", + .age = 10, + .email = "bart@simpson.com"}; + + const auto lisa = Person{.first_name = "Lisa", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; + + const auto maggie = Person{.first_name = "Maggie", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; + + const auto homer = Person{.first_name = "Homer", + .birthday = "1987-04-19", + .age = 45, + .email = "homer@simpson.com", + .child = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_readme_example diff --git a/tests/boost_serialization/test_readme_example2.cpp b/tests/boost_serialization/test_readme_example2.cpp new file mode 100644 index 00000000..83529ab2 --- /dev/null +++ b/tests/boost_serialization/test_readme_example2.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_readme_example2 { + +struct Person { + std::string first_name; + std::string last_name; + int age; +}; + +TEST(boost_serialization, test_readme_example2) { + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + write_and_read(homer); +} +} // namespace test_readme_example2 diff --git a/tests/boost_serialization/test_ref.cpp b/tests/boost_serialization/test_ref.cpp new file mode 100644 index 00000000..c019a181 --- /dev/null +++ b/tests/boost_serialization/test_ref.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_ref { + +struct DecisionTree { + struct Leaf { + using Tag = rfl::Literal<"Leaf">; + double value; + }; + + struct Node { + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + rfl::Ref lesser; + rfl::Ref greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +TEST(boost_serialization, test_ref) { + const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; + + const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; + + auto node = DecisionTree::Node{ + .critical_value = 10.0, + .lesser = rfl::make_ref(DecisionTree{leaf1}), + .greater = rfl::make_ref(DecisionTree{leaf2})}; + + const DecisionTree tree{.leaf_or_node = std::move(node)}; + + write_and_read(tree); +} +} // namespace test_ref diff --git a/tests/boost_serialization/test_rfl_types.cpp b/tests/boost_serialization/test_rfl_types.cpp deleted file mode 100644 index ce43f8ea..00000000 --- a/tests/boost_serialization/test_rfl_types.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_rfl_types { - -struct PersonRenamed { - rfl::Rename<"firstName", std::string> first_name; - rfl::Rename<"lastName", std::string> last_name = "Simpson"; - int age; -}; - -TEST(boost_serialization, test_rename) { - const auto homer = PersonRenamed{.first_name = "Homer", .age = 45}; - write_and_read_with_json(homer); -} - -using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; - -struct PersonLiteral { - FirstName first_name; - std::vector children; -}; - -TEST(boost_serialization, test_literal) { - const auto bart = PersonLiteral{.first_name = FirstName::make<"Bart">()}; - write_and_read(bart); -} - -struct Inner { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"age", int> age; -}; - -struct Outer { - rfl::Flatten person; - rfl::Field<"employer", std::string> employer; -}; - -TEST(boost_serialization, test_flatten) { - const auto employee = Outer{.person = Inner{.first_name = "Homer", .age = 45}, - .employer = "Mr. Burns"}; - write_and_read_with_json(employee); -} - -struct Circle { - double radius; -}; - -struct Rectangle { - double height; - double width; -}; - -using Shapes = rfl::TaggedUnion<"shape", Circle, Rectangle>; - -TEST(boost_serialization, test_tagged_union) { - const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read_with_json(r); -} - -using Age = rfl::Validator, rfl::Maximum<130>>; - -struct PersonValidated { - std::string first_name; - Age age; - rfl::Email email; -}; - -TEST(boost_serialization, test_validator) { - const auto homer = PersonValidated{ - .first_name = "Homer", .age = 45, .email = "homer@simpson.com"}; - write_and_read_with_json(homer); -} - -using TS = rfl::Timestamp<"%Y-%m-%d">; - -struct PersonWithTimestamp { - std::string first_name; - TS birthday; -}; - -TEST(boost_serialization, test_timestamp) { - const auto bart = - PersonWithTimestamp{.first_name = "Bart", .birthday = "1987-04-19"}; - write_and_read_with_json(bart); -} - -} // namespace test_rfl_types diff --git a/tests/boost_serialization/test_save_load.cpp b/tests/boost_serialization/test_save_load.cpp new file mode 100644 index 00000000..e97c6e98 --- /dev/null +++ b/tests/boost_serialization/test_save_load.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include +#include +#include +#include + +namespace test_save_load { + +using Age = rfl::Validator, rfl::Maximum<130>>>; + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector children; +}; + +TEST(boost_serialization, test_save_load) { + const auto bart = Person{.first_name = "Bart", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 10, + .email = "bart@simpson.com", + .children = std::vector()}; + + const auto lisa = Person{.first_name = "Lisa", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; + + const auto maggie = Person{.first_name = "Maggie", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; + + const auto homer1 = + Person{.first_name = "Homer", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 45, + .email = "homer@simpson.com", + .children = std::vector({bart, lisa, maggie})}; + + rfl::boost_serialization::save("homer.boost_ser", homer1); + + const auto homer2 = + rfl::boost_serialization::load("homer.boost_ser").value(); + + const auto string1 = rfl::boost_serialization::write(homer1); + const auto string2 = rfl::boost_serialization::write(homer2); + + EXPECT_EQ(string1, string2); +} +} // namespace test_save_load diff --git a/tests/boost_serialization/test_set.cpp b/tests/boost_serialization/test_set.cpp new file mode 100644 index 00000000..f783bb2c --- /dev/null +++ b/tests/boost_serialization/test_set.cpp @@ -0,0 +1,23 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_set { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_set) { + auto children = std::make_unique>( + std::set({"Bart", "Lisa", "Maggie"})); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_set diff --git a/tests/boost_serialization/test_size.cpp b/tests/boost_serialization/test_size.cpp new file mode 100644 index 00000000..3c91004c --- /dev/null +++ b/tests/boost_serialization/test_size.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_size { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + rfl::Validator, + rfl::Size, rfl::EqualTo<3>>>> + children; +}; + +TEST(boost_serialization, test_size) { + const auto bart = Person{ + .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto lisa = Person{ + .first_name = "Lisa", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto maggie = Person{ + .first_name = "Maggie", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto homer = + Person{.first_name = "Homer", + .last_name = "Simpson", + .birthday = "1987-04-19", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_size diff --git a/tests/boost_serialization/test_smart_ptrs.cpp b/tests/boost_serialization/test_smart_ptrs.cpp deleted file mode 100644 index 96698c79..00000000 --- a/tests/boost_serialization/test_smart_ptrs.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_smart_ptrs { - -struct Person { - std::string first_name; - std::string last_name = "Simpson"; - std::unique_ptr> children; -}; - -TEST(boost_serialization, test_unique_ptr) { - auto children = std::make_unique>(); - children->emplace_back(Person{.first_name = "Bart"}); - children->emplace_back(Person{.first_name = "Lisa"}); - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - write_and_read(homer); -} - -struct PersonShared { - std::string first_name; - std::shared_ptr> children; -}; - -TEST(boost_serialization, test_shared_ptr) { - auto children = std::make_shared>(); - children->emplace_back(PersonShared{.first_name = "Bart"}); - const auto homer = - PersonShared{.first_name = "Homer", .children = std::move(children)}; - write_and_read_with_json(homer); -} - -struct DecisionTree { - struct Leaf { - using Tag = rfl::Literal<"Leaf">; - double value; - }; - - struct Node { - using Tag = rfl::Literal<"Node">; - rfl::Rename<"criticalValue", double> critical_value; - rfl::Box lesser; - rfl::Box greater; - }; - - using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; - rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; -}; - -TEST(boost_serialization, test_box) { - auto node = - DecisionTree::Node{.critical_value = 10.0, - .lesser = rfl::make_box( - DecisionTree{DecisionTree::Leaf{.value = 3.0}}), - .greater = rfl::make_box( - DecisionTree{DecisionTree::Leaf{.value = 5.0}})}; - const DecisionTree tree{.leaf_or_node = std::move(node)}; - write_and_read_with_json(tree); -} - -} // namespace test_smart_ptrs diff --git a/tests/boost_serialization/test_snake_case_to_camel_case.cpp b/tests/boost_serialization/test_snake_case_to_camel_case.cpp new file mode 100644 index 00000000..20f108a7 --- /dev/null +++ b/tests/boost_serialization/test_snake_case_to_camel_case.cpp @@ -0,0 +1,33 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_snake_case_to_camel_case { + +struct Person { + std::string first_name; + std::string last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + std::vector children; +}; + +TEST(boost_serialization, test_snake_case_to_camel_case) { + const auto bart = Person{ + .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto lisa = Person{ + .first_name = "Lisa", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto maggie = Person{ + .first_name = "Maggie", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto homer = + Person{.first_name = "Homer", + .last_name = "Simpson", + .birthday = "1987-04-19", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_snake_case_to_camel_case diff --git a/tests/boost_serialization/test_snake_case_to_pascal_case.cpp b/tests/boost_serialization/test_snake_case_to_pascal_case.cpp new file mode 100644 index 00000000..df0a8123 --- /dev/null +++ b/tests/boost_serialization/test_snake_case_to_pascal_case.cpp @@ -0,0 +1,33 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_snake_case_to_pascal_case { + +struct Person { + std::string first_name; + std::string last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + std::vector children; +}; + +TEST(boost_serialization, test_snake_case_to_pascal_case) { + const auto bart = Person{ + .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto lisa = Person{ + .first_name = "Lisa", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto maggie = Person{ + .first_name = "Maggie", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto homer = + Person{.first_name = "Homer", + .last_name = "Simpson", + .birthday = "1987-04-19", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_snake_case_to_pascal_case diff --git a/tests/boost_serialization/test_tagged_union.cpp b/tests/boost_serialization/test_tagged_union.cpp new file mode 100644 index 00000000..956292bf --- /dev/null +++ b/tests/boost_serialization/test_tagged_union.cpp @@ -0,0 +1,27 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_tagged_union { + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +struct Square { + double width; +}; + +using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; + +TEST(boost_serialization, test_tagged_union) { + const Shapes r = Rectangle{.height = 10, .width = 5}; + write_and_read(r); +} +} // namespace test_tagged_union diff --git a/tests/boost_serialization/test_timestamp.cpp b/tests/boost_serialization/test_timestamp.cpp new file mode 100644 index 00000000..dbeb95bf --- /dev/null +++ b/tests/boost_serialization/test_timestamp.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_timestamp { + +using TS = rfl::Timestamp<"%Y-%m-%d">; + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + TS birthday; +}; + +TEST(boost_serialization, test_timestamp) { + const auto result = TS::from_string("nonsense"); + + if (result) { + std::cout << "Failed: Expected an error, but got none." << std::endl; + return; + } + + const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19"}; + + write_and_read(bart); +} +} // namespace test_timestamp diff --git a/tests/boost_serialization/test_unique_ptr.cpp b/tests/boost_serialization/test_unique_ptr.cpp new file mode 100644 index 00000000..186be261 --- /dev/null +++ b/tests/boost_serialization/test_unique_ptr.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_unique_ptr { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_unique_ptr) { + auto children = std::make_unique>(); + children->emplace_back(Person{.first_name = "Bart"}); + children->emplace_back(Person{.first_name = "Lisa"}); + children->emplace_back(Person{.first_name = "Maggie"}); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_unique_ptr diff --git a/tests/boost_serialization/test_unique_ptr2.cpp b/tests/boost_serialization/test_unique_ptr2.cpp new file mode 100644 index 00000000..f4610757 --- /dev/null +++ b/tests/boost_serialization/test_unique_ptr2.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_unique_ptr2 { + +struct DecisionTree { + struct Leaf { + using Tag = rfl::Literal<"Leaf">; + double value; + }; + + struct Node { + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + std::unique_ptr lesser; + std::unique_ptr greater; + }; + + using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; + + rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; +}; + +TEST(boost_serialization, test_unique_ptr2) { + auto leaf1 = DecisionTree::Leaf{.value = 3.0}; + + auto leaf2 = DecisionTree::Leaf{.value = 5.0}; + + auto node = DecisionTree::Node{ + .critical_value = 10.0, + .lesser = std::make_unique(DecisionTree{leaf1}), + .greater = std::make_unique(DecisionTree{leaf2})}; + + const DecisionTree tree{.leaf_or_node = std::move(node)}; + + write_and_read(tree); +} +} // namespace test_unique_ptr2 diff --git a/tests/boost_serialization/test_variant.cpp b/tests/boost_serialization/test_variant.cpp new file mode 100644 index 00000000..4b87ecb7 --- /dev/null +++ b/tests/boost_serialization/test_variant.cpp @@ -0,0 +1,28 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_variant { + +struct Circle { + double radius; +}; + +struct Rectangle { + double height; + double width; +}; + +struct Square { + double width; +}; + +using Shapes = std::variant>; + +TEST(boost_serialization, test_variant) { + const Shapes r = Rectangle{.height = 10, .width = 5}; + + write_and_read(r); +} +} // namespace test_variant diff --git a/tests/boost_serialization/test_variants.cpp b/tests/boost_serialization/test_variants.cpp deleted file mode 100644 index 5597ff9a..00000000 --- a/tests/boost_serialization/test_variants.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_variants { - -struct Circle { - double radius; -}; - -struct Rectangle { - double height; - double width; -}; - -struct Square { - double width; -}; - -using Shapes = std::variant; - -struct Drawing { - Shapes shape; -}; - -TEST(boost_serialization, test_std_variant) { - const auto drawing = Drawing{.shape = Circle{.radius = 5.0}}; - write_and_read(drawing); -} - -TEST(boost_serialization, test_std_variant_rectangle) { - const auto drawing = Drawing{.shape = Rectangle{.height = 10, .width = 5}}; - write_and_read(drawing); -} - -} // namespace test_variants From b9054379d0b75cee57e5bfd24c715478d5b5621c Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Thu, 2 Apr 2026 21:36:28 +0100 Subject: [PATCH 10/15] benchmarking --- CMakeLists.txt | 1 + benchmarks/all/canada_read.cpp | 43 ++++++++++++++++++----------- benchmarks/all/canada_write.cpp | 42 ++++++++++++++++++----------- benchmarks/all/licenses_read.cpp | 45 ++++++++++++++++++++----------- benchmarks/all/licenses_write.cpp | 45 ++++++++++++++++++++----------- benchmarks/all/person_read.cpp | 45 ++++++++++++++++++++----------- benchmarks/all/person_write.cpp | 45 ++++++++++++++++++++----------- 7 files changed, 172 insertions(+), 94 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d2d63b0..a3d684a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,7 @@ if(REFLECTCPP_BUILD_BENCHMARKS) set(REFLECTCPP_TOML ON CACHE BOOL "" FORCE) set(REFLECTCPP_UBJSON ON CACHE BOOL "" FORCE) set(REFLECTCPP_YAML ON CACHE BOOL "" FORCE) + set(REFLECTCPP_BOOST_SERIALIZATION ON CACHE BOOL "" FORCE) endif() if ( diff --git a/benchmarks/all/canada_read.cpp b/benchmarks/all/canada_read.cpp index e848ffea..9f0313fc 100644 --- a/benchmarks/all/canada_read.cpp +++ b/benchmarks/all/canada_read.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ static FeatureCollection load_data() { // ---------------------------------------------------------------------------- -static void BM_canada_read_reflect_cpp_avro(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -58,7 +59,7 @@ static void BM_canada_read_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_canada_read_reflect_cpp_avro); -static void BM_canada_read_reflect_cpp_bson(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_bson(benchmark::State& state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -69,7 +70,19 @@ static void BM_canada_read_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_canada_read_reflect_cpp_bson); -static void BM_canada_read_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = rfl::boost_serialization::write(load_data()); + for (auto _ : state) { + const auto res = rfl::boost_serialization::read(data); + if (!res) { + std::cout << res.error().what() << std::endl; + } + } +} +BENCHMARK(BM_canada_read_reflect_cpp_boost_serialization); + +static void BM_canada_read_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -81,7 +94,7 @@ static void BM_canada_read_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_canada_read_reflect_cpp_capnproto); -static void BM_canada_read_reflect_cpp_cbor(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_cbor(benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -93,7 +106,7 @@ static void BM_canada_read_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_cbor); static void BM_canada_read_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = @@ -117,6 +130,7 @@ static void BM_canada_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_cereal); static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -128,7 +142,7 @@ static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_flexbuf); static void BM_canada_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = @@ -140,7 +154,7 @@ static void BM_canada_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_flexbuf_without_field_names); -static void BM_canada_read_reflect_cpp_json(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_json(benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -152,7 +166,7 @@ static void BM_canada_read_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_json); static void BM_canada_read_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = @@ -164,7 +178,7 @@ static void BM_canada_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_json_without_field_names); -static void BM_canada_read_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_msgpack(benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -176,7 +190,7 @@ static void BM_canada_read_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_msgpack); static void BM_canada_read_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = @@ -188,7 +202,7 @@ static void BM_canada_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_msgpack_without_field_names); -static void BM_canada_read_reflect_cpp_toml(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_toml(benchmark::State& state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -199,7 +213,7 @@ static void BM_canada_read_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_canada_read_reflect_cpp_toml); -static void BM_canada_read_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_ubjson(benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -211,7 +225,7 @@ static void BM_canada_read_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_ubjson); static void BM_canada_read_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = @@ -223,7 +237,7 @@ static void BM_canada_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_ubjson_without_field_names); -static void BM_canada_read_reflect_cpp_yaml(benchmark::State &state) { +static void BM_canada_read_reflect_cpp_yaml(benchmark::State& state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); @@ -237,4 +251,3 @@ BENCHMARK(BM_canada_read_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace canada_read - diff --git a/benchmarks/all/canada_write.cpp b/benchmarks/all/canada_write.cpp index 3b7005c0..5e751688 100644 --- a/benchmarks/all/canada_write.cpp +++ b/benchmarks/all/canada_write.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ static FeatureCollection load_data() { // ---------------------------------------------------------------------------- -static void BM_canada_write_reflect_cpp_avro(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -58,7 +59,7 @@ static void BM_canada_write_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_canada_write_reflect_cpp_avro); -static void BM_canada_write_reflect_cpp_bson(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_bson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -69,7 +70,19 @@ static void BM_canada_write_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_canada_write_reflect_cpp_bson); -static void BM_canada_write_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::boost_serialization::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_canada_write_reflect_cpp_boost_serialization); + +static void BM_canada_write_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -81,7 +94,7 @@ static void BM_canada_write_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_canada_write_reflect_cpp_capnproto); -static void BM_canada_write_reflect_cpp_cbor(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_cbor(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -93,7 +106,7 @@ static void BM_canada_write_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_cbor); static void BM_canada_write_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -116,7 +129,7 @@ static void BM_canada_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_cereal); static void BM_canada_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -127,7 +140,7 @@ static void BM_canada_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_flexbuf_without_field_names); -static void BM_canada_write_reflect_cpp_json(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_json(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -139,7 +152,7 @@ static void BM_canada_write_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_json); static void BM_canada_write_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -150,7 +163,7 @@ static void BM_canada_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_json_without_field_names); -static void BM_canada_write_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_msgpack(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -162,7 +175,7 @@ static void BM_canada_write_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_msgpack); static void BM_canada_write_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -173,7 +186,7 @@ static void BM_canada_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_msgpack_without_field_names); -static void BM_canada_write_reflect_cpp_toml(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_toml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -184,7 +197,7 @@ static void BM_canada_write_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_canada_write_reflect_cpp_toml); -static void BM_canada_write_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_ubjson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -196,7 +209,7 @@ static void BM_canada_write_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_ubjson); static void BM_canada_write_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -207,7 +220,7 @@ static void BM_canada_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_ubjson_without_field_names); -static void BM_canada_write_reflect_cpp_yaml(benchmark::State &state) { +static void BM_canada_write_reflect_cpp_yaml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); @@ -221,4 +234,3 @@ BENCHMARK(BM_canada_write_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace canada_write - diff --git a/benchmarks/all/licenses_read.cpp b/benchmarks/all/licenses_read.cpp index 28958252..46f1b173 100644 --- a/benchmarks/all/licenses_read.cpp +++ b/benchmarks/all/licenses_read.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,7 @@ static Licenses load_data() { // ---------------------------------------------------------------------------- -static void BM_licenses_read_reflect_cpp_avro(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -75,7 +76,7 @@ static void BM_licenses_read_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_licenses_read_reflect_cpp_avro); -static void BM_licenses_read_reflect_cpp_bson(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_bson(benchmark::State& state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -86,7 +87,19 @@ static void BM_licenses_read_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_licenses_read_reflect_cpp_bson); -static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = rfl::boost_serialization::write(load_data()); + for (auto _ : state) { + const auto res = rfl::boost_serialization::read(data); + if (!res) { + std::cout << res.error().what() << std::endl; + } + } +} +BENCHMARK(BM_licenses_read_reflect_cpp_boost_serialization); + +static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -98,7 +111,7 @@ static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_licenses_read_reflect_cpp_capnproto); -static void BM_licenses_read_reflect_cpp_cbor(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_cbor(benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -110,7 +123,7 @@ static void BM_licenses_read_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_cbor); static void BM_licenses_read_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -133,6 +146,7 @@ static void BM_licenses_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_cereal); static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -144,7 +158,7 @@ static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_flexbuf); static void BM_licenses_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -155,7 +169,7 @@ static void BM_licenses_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_flexbuf_without_field_names); -static void BM_licenses_read_reflect_cpp_json(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_json(benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -167,7 +181,7 @@ static void BM_licenses_read_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_json); static void BM_licenses_read_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -178,7 +192,7 @@ static void BM_licenses_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_json_without_field_names); -static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -190,7 +204,7 @@ static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_msgpack); static void BM_licenses_read_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -201,7 +215,7 @@ static void BM_licenses_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_msgpack_without_field_names); -static void BM_licenses_read_reflect_cpp_xml(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_xml(benchmark::State& state) { const auto data = rfl::xml::write<"license">(load_data()); for (auto _ : state) { const auto res = rfl::xml::read(data); @@ -212,7 +226,7 @@ static void BM_licenses_read_reflect_cpp_xml(benchmark::State &state) { } BENCHMARK(BM_licenses_read_reflect_cpp_xml); -static void BM_licenses_read_reflect_cpp_toml(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_toml(benchmark::State& state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -223,7 +237,7 @@ static void BM_licenses_read_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_licenses_read_reflect_cpp_toml); -static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -235,7 +249,7 @@ static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_ubjson); static void BM_licenses_read_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -246,7 +260,7 @@ static void BM_licenses_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_ubjson_without_field_names); -static void BM_licenses_read_reflect_cpp_yaml(benchmark::State &state) { +static void BM_licenses_read_reflect_cpp_yaml(benchmark::State& state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); @@ -260,4 +274,3 @@ BENCHMARK(BM_licenses_read_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace licenses_read - diff --git a/benchmarks/all/licenses_write.cpp b/benchmarks/all/licenses_write.cpp index 74e74746..eb570f58 100644 --- a/benchmarks/all/licenses_write.cpp +++ b/benchmarks/all/licenses_write.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -63,7 +64,7 @@ static Licenses load_data() { // ---------------------------------------------------------------------------- -static void BM_licenses_write_reflect_cpp_avro(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -75,7 +76,7 @@ static void BM_licenses_write_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_licenses_write_reflect_cpp_avro); -static void BM_licenses_write_reflect_cpp_bson(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_bson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -86,7 +87,19 @@ static void BM_licenses_write_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_licenses_write_reflect_cpp_bson); -static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::boost_serialization::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_licenses_write_reflect_cpp_boost_serialization); + +static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -98,7 +111,7 @@ static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_licenses_write_reflect_cpp_capnproto); -static void BM_licenses_write_reflect_cpp_cbor(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_cbor(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -110,7 +123,7 @@ static void BM_licenses_write_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_cbor); static void BM_licenses_write_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -133,6 +146,7 @@ static void BM_licenses_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_cereal); static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -144,7 +158,7 @@ static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_flexbuf); static void BM_licenses_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -155,7 +169,7 @@ static void BM_licenses_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_flexbuf_without_field_names); -static void BM_licenses_write_reflect_cpp_json(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_json(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -167,7 +181,7 @@ static void BM_licenses_write_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_json); static void BM_licenses_write_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -178,7 +192,7 @@ static void BM_licenses_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_json_without_field_names); -static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -190,7 +204,7 @@ static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_msgpack); static void BM_licenses_write_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -201,7 +215,7 @@ static void BM_licenses_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_msgpack_without_field_names); -static void BM_licenses_write_reflect_cpp_toml(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_toml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -212,7 +226,7 @@ static void BM_licenses_write_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_licenses_write_reflect_cpp_toml); -static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -224,7 +238,7 @@ static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_ubjson); static void BM_licenses_write_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -235,7 +249,7 @@ static void BM_licenses_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_ubjson_without_field_names); -static void BM_licenses_write_reflect_cpp_xml(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_xml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::xml::write(data); @@ -246,7 +260,7 @@ static void BM_licenses_write_reflect_cpp_xml(benchmark::State &state) { } BENCHMARK(BM_licenses_write_reflect_cpp_xml); -static void BM_licenses_write_reflect_cpp_yaml(benchmark::State &state) { +static void BM_licenses_write_reflect_cpp_yaml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); @@ -260,4 +274,3 @@ BENCHMARK(BM_licenses_write_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace licenses_write - diff --git a/benchmarks/all/person_read.cpp b/benchmarks/all/person_read.cpp index 80e79d26..9d18f0a6 100644 --- a/benchmarks/all/person_read.cpp +++ b/benchmarks/all/person_read.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,7 @@ static Person load_data() { // ---------------------------------------------------------------------------- -static void BM_person_read_reflect_cpp_avro(benchmark::State &state) { +static void BM_person_read_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -53,7 +54,7 @@ static void BM_person_read_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_person_read_reflect_cpp_avro); -static void BM_person_read_reflect_cpp_bson(benchmark::State &state) { +static void BM_person_read_reflect_cpp_bson(benchmark::State& state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -64,7 +65,19 @@ static void BM_person_read_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_person_read_reflect_cpp_bson); -static void BM_person_read_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_person_read_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = rfl::boost_serialization::write(load_data()); + for (auto _ : state) { + const auto res = rfl::boost_serialization::read(data); + if (!res) { + std::cout << res.error().what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_boost_serialization); + +static void BM_person_read_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -76,7 +89,7 @@ static void BM_person_read_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_person_read_reflect_cpp_capnproto); -static void BM_person_read_reflect_cpp_cbor(benchmark::State &state) { +static void BM_person_read_reflect_cpp_cbor(benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -88,7 +101,7 @@ static void BM_person_read_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_cbor); static void BM_person_read_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -111,6 +124,7 @@ static void BM_person_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_cereal); static void BM_person_read_reflect_cpp_flexbuf(benchmark::State &state) { +static void BM_person_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -122,7 +136,7 @@ static void BM_person_read_reflect_cpp_flexbuf(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_flexbuf); static void BM_person_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -133,7 +147,7 @@ static void BM_person_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_flexbuf_without_field_names); -static void BM_person_read_reflect_cpp_json(benchmark::State &state) { +static void BM_person_read_reflect_cpp_json(benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -145,7 +159,7 @@ static void BM_person_read_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_json); static void BM_person_read_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -156,7 +170,7 @@ static void BM_person_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_json_without_field_names); -static void BM_person_read_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_person_read_reflect_cpp_msgpack(benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -168,7 +182,7 @@ static void BM_person_read_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_msgpack); static void BM_person_read_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -179,7 +193,7 @@ static void BM_person_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_msgpack_without_field_names); -static void BM_person_read_reflect_cpp_toml(benchmark::State &state) { +static void BM_person_read_reflect_cpp_toml(benchmark::State& state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -190,7 +204,7 @@ static void BM_person_read_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_person_read_reflect_cpp_toml); -static void BM_person_read_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_person_read_reflect_cpp_ubjson(benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -202,7 +216,7 @@ static void BM_person_read_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_ubjson); static void BM_person_read_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -213,7 +227,7 @@ static void BM_person_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_ubjson_without_field_names); -static void BM_person_read_reflect_cpp_xml(benchmark::State &state) { +static void BM_person_read_reflect_cpp_xml(benchmark::State& state) { const auto data = rfl::xml::write(load_data()); for (auto _ : state) { const auto res = rfl::xml::read(data); @@ -224,7 +238,7 @@ static void BM_person_read_reflect_cpp_xml(benchmark::State &state) { } BENCHMARK(BM_person_read_reflect_cpp_xml); -static void BM_person_read_reflect_cpp_yaml(benchmark::State &state) { +static void BM_person_read_reflect_cpp_yaml(benchmark::State& state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); @@ -238,4 +252,3 @@ BENCHMARK(BM_person_read_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace person_read - diff --git a/benchmarks/all/person_write.cpp b/benchmarks/all/person_write.cpp index 3e2f5131..910e3eb6 100644 --- a/benchmarks/all/person_write.cpp +++ b/benchmarks/all/person_write.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,7 @@ static Person load_data() { // ---------------------------------------------------------------------------- -static void BM_person_write_reflect_cpp_avro(benchmark::State &state) { +static void BM_person_write_reflect_cpp_avro(benchmark::State& state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -54,7 +55,7 @@ static void BM_person_write_reflect_cpp_avro(benchmark::State &state) { } BENCHMARK(BM_person_write_reflect_cpp_avro); -static void BM_person_write_reflect_cpp_bson(benchmark::State &state) { +static void BM_person_write_reflect_cpp_bson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -65,7 +66,19 @@ static void BM_person_write_reflect_cpp_bson(benchmark::State &state) { } BENCHMARK(BM_person_write_reflect_cpp_bson); -static void BM_person_write_reflect_cpp_capnproto(benchmark::State &state) { +static void BM_person_write_reflect_cpp_boost_serialization( + benchmark::State& state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::boost_serialization::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_boost_serialization); + +static void BM_person_write_reflect_cpp_capnproto(benchmark::State& state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -77,7 +90,7 @@ static void BM_person_write_reflect_cpp_capnproto(benchmark::State &state) { } BENCHMARK(BM_person_write_reflect_cpp_capnproto); -static void BM_person_write_reflect_cpp_cbor(benchmark::State &state) { +static void BM_person_write_reflect_cpp_cbor(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -89,7 +102,7 @@ static void BM_person_write_reflect_cpp_cbor(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_cbor); static void BM_person_write_reflect_cpp_cbor_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -112,6 +125,7 @@ static void BM_person_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_cereal); static void BM_person_write_reflect_cpp_flexbuf(benchmark::State &state) { +static void BM_person_write_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -123,7 +137,7 @@ static void BM_person_write_reflect_cpp_flexbuf(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_flexbuf); static void BM_person_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -134,7 +148,7 @@ static void BM_person_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_flexbuf_without_field_names); -static void BM_person_write_reflect_cpp_json(benchmark::State &state) { +static void BM_person_write_reflect_cpp_json(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -146,7 +160,7 @@ static void BM_person_write_reflect_cpp_json(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_json); static void BM_person_write_reflect_cpp_json_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -157,7 +171,7 @@ static void BM_person_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_json_without_field_names); -static void BM_person_write_reflect_cpp_msgpack(benchmark::State &state) { +static void BM_person_write_reflect_cpp_msgpack(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -169,7 +183,7 @@ static void BM_person_write_reflect_cpp_msgpack(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_msgpack); static void BM_person_write_reflect_cpp_msgpack_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -180,7 +194,7 @@ static void BM_person_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_msgpack_without_field_names); -static void BM_person_write_reflect_cpp_toml(benchmark::State &state) { +static void BM_person_write_reflect_cpp_toml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -191,7 +205,7 @@ static void BM_person_write_reflect_cpp_toml(benchmark::State &state) { } BENCHMARK(BM_person_write_reflect_cpp_toml); -static void BM_person_write_reflect_cpp_ubjson(benchmark::State &state) { +static void BM_person_write_reflect_cpp_ubjson(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -203,7 +217,7 @@ static void BM_person_write_reflect_cpp_ubjson(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_ubjson); static void BM_person_write_reflect_cpp_ubjson_without_field_names( - benchmark::State &state) { + benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -214,7 +228,7 @@ static void BM_person_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_ubjson_without_field_names); -static void BM_person_write_reflect_cpp_xml(benchmark::State &state) { +static void BM_person_write_reflect_cpp_xml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::xml::write(data); @@ -225,7 +239,7 @@ static void BM_person_write_reflect_cpp_xml(benchmark::State &state) { } BENCHMARK(BM_person_write_reflect_cpp_xml); -static void BM_person_write_reflect_cpp_yaml(benchmark::State &state) { +static void BM_person_write_reflect_cpp_yaml(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); @@ -239,4 +253,3 @@ BENCHMARK(BM_person_write_reflect_cpp_yaml); // ---------------------------------------------------------------------------- } // namespace person_write - From 13c4867765a1fcbc5eb92cc027a17c2d5bfdcd68 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 3 Apr 2026 11:20:18 +0100 Subject: [PATCH 11/15] boost serialisation (docs) --- README.md | 1 + docs/supported_formats/boost_serialization.md | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 docs/supported_formats/boost_serialization.md diff --git a/README.md b/README.md index 1232851a..6ada9d1b 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ The following table lists the serialization formats currently supported by refle |--------------|------------------------------------------------------|--------------|------------| -----------------------------------------------------| | JSON | [yyjson](https://github.com/ibireme/yyjson) | >= 0.8.0 | MIT | out-of-the-box support, included in this repository | | Avro | [avro-c](https://avro.apache.org/docs/1.11.1/api/c/) | >= 1.11.3 | Apache 2.0 | Schemaful binary format | +| Boost.Serialization | [Boost.Serialization](https://www.boost.org/doc/libs/release/libs/serialization/) | >= 1.74.0 | BSL 1.0 | Streaming binary format with archive interop | | BSON | [libbson](https://github.com/mongodb/mongo-c-driver) | >= 1.25.1 | Apache 2.0 | JSON-like binary format | | Cap'n Proto | [capnproto](https://capnproto.org) | >= 1.0.2 | MIT | Schemaful binary format | | CBOR | [jsoncons](https://github.com/danielaparker/jsoncons)| >= 0.176.0 | BSL 1.0 | JSON-like binary format | diff --git a/docs/supported_formats/boost_serialization.md b/docs/supported_formats/boost_serialization.md new file mode 100644 index 00000000..191ca61d --- /dev/null +++ b/docs/supported_formats/boost_serialization.md @@ -0,0 +1,90 @@ +# Boost.Serialization + +For Boost.Serialization support, you must also include the header `` and link to the [Boost.Serialization](https://www.boost.org/doc/libs/release/libs/serialization/) library. +Furthermore, when compiling reflect-cpp, you need to pass `-DREFLECTCPP_BOOST_SERIALIZATION=ON` to cmake. If you are using vcpkg, there +should be an appropriate feature that will abstract this away for you. + +Unlike most other formats supported by reflect-cpp, which use document-tree based libraries, Boost.Serialization streams data sequentially through archive objects. reflect-cpp implements this as a schemaful binary format, similar to Avro and Cap'n Proto. + +## Reading and writing + +Suppose you have a struct like this: + +```cpp +struct Person { + std::string first_name; + std::string last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + std::vector children; +}; +``` + +A `Person` can be serialized like this: + +```cpp +const auto person = Person{...}; +const std::vector bytes = rfl::boost_serialization::write(person); +``` + +You can parse bytes like this: + +```cpp +const rfl::Result result = rfl::boost_serialization::read(bytes); +``` + +## Loading and saving + +You can also load and save to disc using a very similar syntax: + +```cpp +const rfl::Result result = rfl::boost_serialization::load("/path/to/file.bin"); + +const auto person = Person{...}; +rfl::boost_serialization::save("/path/to/file.bin", person); +``` + +## Reading from and writing into streams + +You can also read from and write into any `std::istream` and `std::ostream` respectively. + +```cpp +const rfl::Result result = rfl::boost_serialization::read(my_istream); + +const auto person = Person{...}; +rfl::boost_serialization::write(person, my_ostream); +``` + +## Archive interop + +One of the key features of the Boost.Serialization backend is that you can use it with existing Boost archives directly. This allows reflect-cpp types to participate in larger Boost serialization workflows. + +```cpp +#include +#include +#include + +// Writing into an existing Boost archive +boost::archive::binary_oarchive oa(my_ostream); +rfl::boost_serialization::write(oa, person); + +// Reading from an existing Boost archive +boost::archive::binary_iarchive ia(my_istream); +const auto result = rfl::boost_serialization::read_from_archive< + Person, boost::archive::binary_iarchive, + boost::archive::binary_oarchive>(ia); +``` + +This also works with text archives: + +```cpp +#include +#include + +boost::archive::text_oarchive oa(my_ostream); +rfl::boost_serialization::write(oa, person); + +boost::archive::text_iarchive ia(my_istream); +const auto result = rfl::boost_serialization::read_from_archive< + Person, boost::archive::text_iarchive, + boost::archive::text_oarchive>(ia); +``` From ca4461024fff64428072805cb3e9ac10852c3926 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 3 Apr 2026 11:59:04 +0100 Subject: [PATCH 12/15] boost serialisation (clean) --- benchmarks/all/canada_read.cpp | 31 ++++++++++++++--------------- benchmarks/all/canada_write.cpp | 30 ++++++++++++++-------------- benchmarks/all/licenses_read.cpp | 33 +++++++++++++++---------------- benchmarks/all/licenses_write.cpp | 33 +++++++++++++++---------------- benchmarks/all/person_read.cpp | 33 +++++++++++++++---------------- benchmarks/all/person_write.cpp | 33 +++++++++++++++---------------- 6 files changed, 94 insertions(+), 99 deletions(-) diff --git a/benchmarks/all/canada_read.cpp b/benchmarks/all/canada_read.cpp index 9f0313fc..853b98c6 100644 --- a/benchmarks/all/canada_read.cpp +++ b/benchmarks/all/canada_read.cpp @@ -47,7 +47,7 @@ static FeatureCollection load_data() { // ---------------------------------------------------------------------------- -static void BM_canada_read_reflect_cpp_avro(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -59,7 +59,7 @@ static void BM_canada_read_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_canada_read_reflect_cpp_avro); -static void BM_canada_read_reflect_cpp_bson(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_bson(benchmark::State &state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -71,7 +71,7 @@ static void BM_canada_read_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_bson); static void BM_canada_read_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::boost_serialization::write(load_data()); for (auto _ : state) { const auto res = rfl::boost_serialization::read(data); @@ -82,7 +82,7 @@ static void BM_canada_read_reflect_cpp_boost_serialization( } BENCHMARK(BM_canada_read_reflect_cpp_boost_serialization); -static void BM_canada_read_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -94,7 +94,7 @@ static void BM_canada_read_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_canada_read_reflect_cpp_capnproto); -static void BM_canada_read_reflect_cpp_cbor(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_cbor(benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -106,7 +106,7 @@ static void BM_canada_read_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_cbor); static void BM_canada_read_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = @@ -130,7 +130,6 @@ static void BM_canada_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_canada_read_reflect_cpp_cereal); static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State &state) { -static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -142,7 +141,7 @@ static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_flexbuf); static void BM_canada_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = @@ -154,7 +153,7 @@ static void BM_canada_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_flexbuf_without_field_names); -static void BM_canada_read_reflect_cpp_json(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_json(benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -166,7 +165,7 @@ static void BM_canada_read_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_json); static void BM_canada_read_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = @@ -178,7 +177,7 @@ static void BM_canada_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_json_without_field_names); -static void BM_canada_read_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_msgpack(benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -190,7 +189,7 @@ static void BM_canada_read_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_msgpack); static void BM_canada_read_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = @@ -202,7 +201,7 @@ static void BM_canada_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_msgpack_without_field_names); -static void BM_canada_read_reflect_cpp_toml(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_toml(benchmark::State &state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -213,7 +212,7 @@ static void BM_canada_read_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_canada_read_reflect_cpp_toml); -static void BM_canada_read_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_ubjson(benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -225,7 +224,7 @@ static void BM_canada_read_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_canada_read_reflect_cpp_ubjson); static void BM_canada_read_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = @@ -237,7 +236,7 @@ static void BM_canada_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_canada_read_reflect_cpp_ubjson_without_field_names); -static void BM_canada_read_reflect_cpp_yaml(benchmark::State& state) { +static void BM_canada_read_reflect_cpp_yaml(benchmark::State &state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); diff --git a/benchmarks/all/canada_write.cpp b/benchmarks/all/canada_write.cpp index 5e751688..87254f14 100644 --- a/benchmarks/all/canada_write.cpp +++ b/benchmarks/all/canada_write.cpp @@ -47,7 +47,7 @@ static FeatureCollection load_data() { // ---------------------------------------------------------------------------- -static void BM_canada_write_reflect_cpp_avro(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -59,7 +59,7 @@ static void BM_canada_write_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_canada_write_reflect_cpp_avro); -static void BM_canada_write_reflect_cpp_bson(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_bson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -71,7 +71,7 @@ static void BM_canada_write_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_canada_write_reflect_cpp_bson); static void BM_canada_write_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::boost_serialization::write(data); @@ -82,7 +82,7 @@ static void BM_canada_write_reflect_cpp_boost_serialization( } BENCHMARK(BM_canada_write_reflect_cpp_boost_serialization); -static void BM_canada_write_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -94,7 +94,7 @@ static void BM_canada_write_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_canada_write_reflect_cpp_capnproto); -static void BM_canada_write_reflect_cpp_cbor(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_cbor(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -106,7 +106,7 @@ static void BM_canada_write_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_canada_write_reflect_cpp_cbor); static void BM_canada_write_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -129,7 +129,7 @@ static void BM_canada_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_canada_write_reflect_cpp_cereal); static void BM_canada_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -140,7 +140,7 @@ static void BM_canada_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_flexbuf_without_field_names); -static void BM_canada_write_reflect_cpp_json(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_json(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -152,7 +152,7 @@ static void BM_canada_write_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_canada_write_reflect_cpp_json); static void BM_canada_write_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -163,7 +163,7 @@ static void BM_canada_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_json_without_field_names); -static void BM_canada_write_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_msgpack(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -175,7 +175,7 @@ static void BM_canada_write_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_canada_write_reflect_cpp_msgpack); static void BM_canada_write_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -186,7 +186,7 @@ static void BM_canada_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_msgpack_without_field_names); -static void BM_canada_write_reflect_cpp_toml(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_toml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -197,7 +197,7 @@ static void BM_canada_write_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_canada_write_reflect_cpp_toml); -static void BM_canada_write_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_ubjson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -209,7 +209,7 @@ static void BM_canada_write_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_canada_write_reflect_cpp_ubjson); static void BM_canada_write_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -220,7 +220,7 @@ static void BM_canada_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_canada_write_reflect_cpp_ubjson_without_field_names); -static void BM_canada_write_reflect_cpp_yaml(benchmark::State& state) { +static void BM_canada_write_reflect_cpp_yaml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); diff --git a/benchmarks/all/licenses_read.cpp b/benchmarks/all/licenses_read.cpp index 46f1b173..b12bd5d1 100644 --- a/benchmarks/all/licenses_read.cpp +++ b/benchmarks/all/licenses_read.cpp @@ -64,7 +64,7 @@ static Licenses load_data() { // ---------------------------------------------------------------------------- -static void BM_licenses_read_reflect_cpp_avro(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -76,7 +76,7 @@ static void BM_licenses_read_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_licenses_read_reflect_cpp_avro); -static void BM_licenses_read_reflect_cpp_bson(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_bson(benchmark::State &state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -88,7 +88,7 @@ static void BM_licenses_read_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_bson); static void BM_licenses_read_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::boost_serialization::write(load_data()); for (auto _ : state) { const auto res = rfl::boost_serialization::read(data); @@ -99,7 +99,7 @@ static void BM_licenses_read_reflect_cpp_boost_serialization( } BENCHMARK(BM_licenses_read_reflect_cpp_boost_serialization); -static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -111,7 +111,7 @@ static void BM_licenses_read_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_licenses_read_reflect_cpp_capnproto); -static void BM_licenses_read_reflect_cpp_cbor(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_cbor(benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -123,7 +123,7 @@ static void BM_licenses_read_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_cbor); static void BM_licenses_read_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -146,7 +146,6 @@ static void BM_licenses_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_licenses_read_reflect_cpp_cereal); static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State &state) { -static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -158,7 +157,7 @@ static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_flexbuf); static void BM_licenses_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -169,7 +168,7 @@ static void BM_licenses_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_flexbuf_without_field_names); -static void BM_licenses_read_reflect_cpp_json(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_json(benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -181,7 +180,7 @@ static void BM_licenses_read_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_json); static void BM_licenses_read_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -192,7 +191,7 @@ static void BM_licenses_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_json_without_field_names); -static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -204,7 +203,7 @@ static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_msgpack); static void BM_licenses_read_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -215,7 +214,7 @@ static void BM_licenses_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_msgpack_without_field_names); -static void BM_licenses_read_reflect_cpp_xml(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_xml(benchmark::State &state) { const auto data = rfl::xml::write<"license">(load_data()); for (auto _ : state) { const auto res = rfl::xml::read(data); @@ -226,7 +225,7 @@ static void BM_licenses_read_reflect_cpp_xml(benchmark::State& state) { } BENCHMARK(BM_licenses_read_reflect_cpp_xml); -static void BM_licenses_read_reflect_cpp_toml(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_toml(benchmark::State &state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -237,7 +236,7 @@ static void BM_licenses_read_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_licenses_read_reflect_cpp_toml); -static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -249,7 +248,7 @@ static void BM_licenses_read_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_licenses_read_reflect_cpp_ubjson); static void BM_licenses_read_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -260,7 +259,7 @@ static void BM_licenses_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_licenses_read_reflect_cpp_ubjson_without_field_names); -static void BM_licenses_read_reflect_cpp_yaml(benchmark::State& state) { +static void BM_licenses_read_reflect_cpp_yaml(benchmark::State &state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); diff --git a/benchmarks/all/licenses_write.cpp b/benchmarks/all/licenses_write.cpp index eb570f58..fbfca915 100644 --- a/benchmarks/all/licenses_write.cpp +++ b/benchmarks/all/licenses_write.cpp @@ -64,7 +64,7 @@ static Licenses load_data() { // ---------------------------------------------------------------------------- -static void BM_licenses_write_reflect_cpp_avro(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -76,7 +76,7 @@ static void BM_licenses_write_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_licenses_write_reflect_cpp_avro); -static void BM_licenses_write_reflect_cpp_bson(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_bson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -88,7 +88,7 @@ static void BM_licenses_write_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_bson); static void BM_licenses_write_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::boost_serialization::write(data); @@ -99,7 +99,7 @@ static void BM_licenses_write_reflect_cpp_boost_serialization( } BENCHMARK(BM_licenses_write_reflect_cpp_boost_serialization); -static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -111,7 +111,7 @@ static void BM_licenses_write_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_licenses_write_reflect_cpp_capnproto); -static void BM_licenses_write_reflect_cpp_cbor(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_cbor(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -123,7 +123,7 @@ static void BM_licenses_write_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_cbor); static void BM_licenses_write_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -146,7 +146,6 @@ static void BM_licenses_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_licenses_write_reflect_cpp_cereal); static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State &state) { -static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -158,7 +157,7 @@ static void BM_licenses_write_reflect_cpp_flexbuf(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_flexbuf); static void BM_licenses_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -169,7 +168,7 @@ static void BM_licenses_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_flexbuf_without_field_names); -static void BM_licenses_write_reflect_cpp_json(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_json(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -181,7 +180,7 @@ static void BM_licenses_write_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_json); static void BM_licenses_write_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -192,7 +191,7 @@ static void BM_licenses_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_json_without_field_names); -static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -204,7 +203,7 @@ static void BM_licenses_write_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_msgpack); static void BM_licenses_write_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -215,7 +214,7 @@ static void BM_licenses_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_msgpack_without_field_names); -static void BM_licenses_write_reflect_cpp_toml(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_toml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -226,7 +225,7 @@ static void BM_licenses_write_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_licenses_write_reflect_cpp_toml); -static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -238,7 +237,7 @@ static void BM_licenses_write_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_licenses_write_reflect_cpp_ubjson); static void BM_licenses_write_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -249,7 +248,7 @@ static void BM_licenses_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_licenses_write_reflect_cpp_ubjson_without_field_names); -static void BM_licenses_write_reflect_cpp_xml(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_xml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::xml::write(data); @@ -260,7 +259,7 @@ static void BM_licenses_write_reflect_cpp_xml(benchmark::State& state) { } BENCHMARK(BM_licenses_write_reflect_cpp_xml); -static void BM_licenses_write_reflect_cpp_yaml(benchmark::State& state) { +static void BM_licenses_write_reflect_cpp_yaml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); diff --git a/benchmarks/all/person_read.cpp b/benchmarks/all/person_read.cpp index 9d18f0a6..24a995be 100644 --- a/benchmarks/all/person_read.cpp +++ b/benchmarks/all/person_read.cpp @@ -42,7 +42,7 @@ static Person load_data() { // ---------------------------------------------------------------------------- -static void BM_person_read_reflect_cpp_avro(benchmark::State& state) { +static void BM_person_read_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = rfl::avro::write(load_data(), schema); for (auto _ : state) { @@ -54,7 +54,7 @@ static void BM_person_read_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_person_read_reflect_cpp_avro); -static void BM_person_read_reflect_cpp_bson(benchmark::State& state) { +static void BM_person_read_reflect_cpp_bson(benchmark::State &state) { const auto data = rfl::bson::write(load_data()); for (auto _ : state) { const auto res = rfl::bson::read(data); @@ -66,7 +66,7 @@ static void BM_person_read_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_bson); static void BM_person_read_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::boost_serialization::write(load_data()); for (auto _ : state) { const auto res = rfl::boost_serialization::read(data); @@ -77,7 +77,7 @@ static void BM_person_read_reflect_cpp_boost_serialization( } BENCHMARK(BM_person_read_reflect_cpp_boost_serialization); -static void BM_person_read_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_person_read_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = rfl::capnproto::write(load_data(), schema); for (auto _ : state) { @@ -89,7 +89,7 @@ static void BM_person_read_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_person_read_reflect_cpp_capnproto); -static void BM_person_read_reflect_cpp_cbor(benchmark::State& state) { +static void BM_person_read_reflect_cpp_cbor(benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -101,7 +101,7 @@ static void BM_person_read_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_cbor); static void BM_person_read_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::cbor::write(load_data()); for (auto _ : state) { const auto res = rfl::cbor::read(data); @@ -124,7 +124,6 @@ static void BM_person_read_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_person_read_reflect_cpp_cereal); static void BM_person_read_reflect_cpp_flexbuf(benchmark::State &state) { -static void BM_person_read_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -136,7 +135,7 @@ static void BM_person_read_reflect_cpp_flexbuf(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_flexbuf); static void BM_person_read_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::flexbuf::write(load_data()); for (auto _ : state) { const auto res = rfl::flexbuf::read(data); @@ -147,7 +146,7 @@ static void BM_person_read_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_flexbuf_without_field_names); -static void BM_person_read_reflect_cpp_json(benchmark::State& state) { +static void BM_person_read_reflect_cpp_json(benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -159,7 +158,7 @@ static void BM_person_read_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_json); static void BM_person_read_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::json::write(load_data()); for (auto _ : state) { const auto res = rfl::json::read(data); @@ -170,7 +169,7 @@ static void BM_person_read_reflect_cpp_json_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_json_without_field_names); -static void BM_person_read_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_person_read_reflect_cpp_msgpack(benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -182,7 +181,7 @@ static void BM_person_read_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_msgpack); static void BM_person_read_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::msgpack::write(load_data()); for (auto _ : state) { const auto res = rfl::msgpack::read(data); @@ -193,7 +192,7 @@ static void BM_person_read_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_msgpack_without_field_names); -static void BM_person_read_reflect_cpp_toml(benchmark::State& state) { +static void BM_person_read_reflect_cpp_toml(benchmark::State &state) { const auto data = rfl::toml::write(load_data()); for (auto _ : state) { const auto res = rfl::toml::read(data); @@ -204,7 +203,7 @@ static void BM_person_read_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_person_read_reflect_cpp_toml); -static void BM_person_read_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_person_read_reflect_cpp_ubjson(benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -216,7 +215,7 @@ static void BM_person_read_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_person_read_reflect_cpp_ubjson); static void BM_person_read_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = rfl::ubjson::write(load_data()); for (auto _ : state) { const auto res = rfl::ubjson::read(data); @@ -227,7 +226,7 @@ static void BM_person_read_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_person_read_reflect_cpp_ubjson_without_field_names); -static void BM_person_read_reflect_cpp_xml(benchmark::State& state) { +static void BM_person_read_reflect_cpp_xml(benchmark::State &state) { const auto data = rfl::xml::write(load_data()); for (auto _ : state) { const auto res = rfl::xml::read(data); @@ -238,7 +237,7 @@ static void BM_person_read_reflect_cpp_xml(benchmark::State& state) { } BENCHMARK(BM_person_read_reflect_cpp_xml); -static void BM_person_read_reflect_cpp_yaml(benchmark::State& state) { +static void BM_person_read_reflect_cpp_yaml(benchmark::State &state) { const auto data = rfl::yaml::write(load_data()); for (auto _ : state) { const auto res = rfl::yaml::read(data); diff --git a/benchmarks/all/person_write.cpp b/benchmarks/all/person_write.cpp index 910e3eb6..eb946c4e 100644 --- a/benchmarks/all/person_write.cpp +++ b/benchmarks/all/person_write.cpp @@ -43,7 +43,7 @@ static Person load_data() { // ---------------------------------------------------------------------------- -static void BM_person_write_reflect_cpp_avro(benchmark::State& state) { +static void BM_person_write_reflect_cpp_avro(benchmark::State &state) { const auto schema = rfl::avro::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -55,7 +55,7 @@ static void BM_person_write_reflect_cpp_avro(benchmark::State& state) { } BENCHMARK(BM_person_write_reflect_cpp_avro); -static void BM_person_write_reflect_cpp_bson(benchmark::State& state) { +static void BM_person_write_reflect_cpp_bson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::bson::write(data); @@ -67,7 +67,7 @@ static void BM_person_write_reflect_cpp_bson(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_bson); static void BM_person_write_reflect_cpp_boost_serialization( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::boost_serialization::write(data); @@ -78,7 +78,7 @@ static void BM_person_write_reflect_cpp_boost_serialization( } BENCHMARK(BM_person_write_reflect_cpp_boost_serialization); -static void BM_person_write_reflect_cpp_capnproto(benchmark::State& state) { +static void BM_person_write_reflect_cpp_capnproto(benchmark::State &state) { const auto schema = rfl::capnproto::to_schema(); const auto data = load_data(); for (auto _ : state) { @@ -90,7 +90,7 @@ static void BM_person_write_reflect_cpp_capnproto(benchmark::State& state) { } BENCHMARK(BM_person_write_reflect_cpp_capnproto); -static void BM_person_write_reflect_cpp_cbor(benchmark::State& state) { +static void BM_person_write_reflect_cpp_cbor(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -102,7 +102,7 @@ static void BM_person_write_reflect_cpp_cbor(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_cbor); static void BM_person_write_reflect_cpp_cbor_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::cbor::write(data); @@ -125,7 +125,6 @@ static void BM_person_write_reflect_cpp_cereal(benchmark::State &state) { BENCHMARK(BM_person_write_reflect_cpp_cereal); static void BM_person_write_reflect_cpp_flexbuf(benchmark::State &state) { -static void BM_person_write_reflect_cpp_flexbuf(benchmark::State& state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -137,7 +136,7 @@ static void BM_person_write_reflect_cpp_flexbuf(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_flexbuf); static void BM_person_write_reflect_cpp_flexbuf_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::flexbuf::write(data); @@ -148,7 +147,7 @@ static void BM_person_write_reflect_cpp_flexbuf_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_flexbuf_without_field_names); -static void BM_person_write_reflect_cpp_json(benchmark::State& state) { +static void BM_person_write_reflect_cpp_json(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -160,7 +159,7 @@ static void BM_person_write_reflect_cpp_json(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_json); static void BM_person_write_reflect_cpp_json_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::json::write(data); @@ -171,7 +170,7 @@ static void BM_person_write_reflect_cpp_json_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_json_without_field_names); -static void BM_person_write_reflect_cpp_msgpack(benchmark::State& state) { +static void BM_person_write_reflect_cpp_msgpack(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -183,7 +182,7 @@ static void BM_person_write_reflect_cpp_msgpack(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_msgpack); static void BM_person_write_reflect_cpp_msgpack_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::msgpack::write(data); @@ -194,7 +193,7 @@ static void BM_person_write_reflect_cpp_msgpack_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_msgpack_without_field_names); -static void BM_person_write_reflect_cpp_toml(benchmark::State& state) { +static void BM_person_write_reflect_cpp_toml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::toml::write(data); @@ -205,7 +204,7 @@ static void BM_person_write_reflect_cpp_toml(benchmark::State& state) { } BENCHMARK(BM_person_write_reflect_cpp_toml); -static void BM_person_write_reflect_cpp_ubjson(benchmark::State& state) { +static void BM_person_write_reflect_cpp_ubjson(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -217,7 +216,7 @@ static void BM_person_write_reflect_cpp_ubjson(benchmark::State& state) { BENCHMARK(BM_person_write_reflect_cpp_ubjson); static void BM_person_write_reflect_cpp_ubjson_without_field_names( - benchmark::State& state) { + benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::ubjson::write(data); @@ -228,7 +227,7 @@ static void BM_person_write_reflect_cpp_ubjson_without_field_names( } BENCHMARK(BM_person_write_reflect_cpp_ubjson_without_field_names); -static void BM_person_write_reflect_cpp_xml(benchmark::State& state) { +static void BM_person_write_reflect_cpp_xml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::xml::write(data); @@ -239,7 +238,7 @@ static void BM_person_write_reflect_cpp_xml(benchmark::State& state) { } BENCHMARK(BM_person_write_reflect_cpp_xml); -static void BM_person_write_reflect_cpp_yaml(benchmark::State& state) { +static void BM_person_write_reflect_cpp_yaml(benchmark::State &state) { const auto data = load_data(); for (auto _ : state) { const auto output = rfl::yaml::write(data); From ce6c8e3630b60d7b3f425a0562e9d695f9fc3a96 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 3 Apr 2026 12:27:38 +0100 Subject: [PATCH 13/15] boost serialisation (map keys) --- include/rfl/boost_serialization/Writer.hpp | 12 ++++++--- .../boost_serialization/test_literal_map.cpp | 21 +++++++++++++++ tests/boost_serialization/test_map.cpp | 26 ++++++++++++++++++ .../test_map_with_key_validation.cpp | 27 +++++++++++++++++++ tests/boost_serialization/test_string_map.cpp | 18 +++++++++++++ 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 tests/boost_serialization/test_literal_map.cpp create mode 100644 tests/boost_serialization/test_map.cpp create mode 100644 tests/boost_serialization/test_map_with_key_validation.cpp create mode 100644 tests/boost_serialization/test_string_map.cpp diff --git a/include/rfl/boost_serialization/Writer.hpp b/include/rfl/boost_serialization/Writer.hpp index d27836a0..df8bf4e5 100644 --- a/include/rfl/boost_serialization/Writer.hpp +++ b/include/rfl/boost_serialization/Writer.hpp @@ -65,9 +65,10 @@ class Writer { return OutputArrayType{}; } - OutputArrayType add_array_to_map(const std::string_view& /*_name*/, + OutputArrayType add_array_to_map(const std::string_view& _name, const size_t _size, OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); *ar_ << static_cast(_size); return OutputArrayType{}; } @@ -92,9 +93,10 @@ class Writer { return OutputMapType{}; } - OutputMapType add_map_to_map(const std::string_view& /*_name*/, + OutputMapType add_map_to_map(const std::string_view& _name, const size_t _size, OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); *ar_ << static_cast(_size); return OutputMapType{}; } @@ -119,9 +121,10 @@ class Writer { return OutputObjectType{}; } - OutputObjectType add_object_to_map(const std::string_view& /*_name*/, + OutputObjectType add_object_to_map(const std::string_view& _name, const size_t _size, OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); *ar_ << static_cast(_size); return OutputObjectType{}; } @@ -144,8 +147,9 @@ class Writer { return OutputUnionType{}; } - OutputUnionType add_union_to_map(const std::string_view& /*_name*/, + OutputUnionType add_union_to_map(const std::string_view& _name, OutputMapType* /*_parent*/) const { + *ar_ << std::string(_name); return OutputUnionType{}; } diff --git a/tests/boost_serialization/test_literal_map.cpp b/tests/boost_serialization/test_literal_map.cpp new file mode 100644 index 00000000..c3335248 --- /dev/null +++ b/tests/boost_serialization/test_literal_map.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_literal_map { + +using FieldName = rfl::Literal<"firstName", "lastName">; + +TEST(boost_serialization, test_literal_map) { + std::map> homer; + homer.insert(std::make_pair(FieldName::make<"firstName">(), + std::make_unique("Homer"))); + homer.insert(std::make_pair(FieldName::make<"lastName">(), + std::make_unique("Simpson"))); + + write_and_read(homer); +} +} // namespace test_literal_map diff --git a/tests/boost_serialization/test_map.cpp b/tests/boost_serialization/test_map.cpp new file mode 100644 index 00000000..d8d463f4 --- /dev/null +++ b/tests/boost_serialization/test_map.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_map { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::map children; +}; + +TEST(boost_serialization, test_map) { + auto children = std::map(); + children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); + children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); + children.insert(std::make_pair("child3", Person{.first_name = "Maggie"})); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_map diff --git a/tests/boost_serialization/test_map_with_key_validation.cpp b/tests/boost_serialization/test_map_with_key_validation.cpp new file mode 100644 index 00000000..4a422b1c --- /dev/null +++ b/tests/boost_serialization/test_map_with_key_validation.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_map_with_key_validation { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(boost_serialization, test_map_with_key_validation) { + auto children = std::make_unique>(); + + children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); + children->insert(std::make_pair("Lisa", Person{.first_name = "Lisa"})); + children->insert(std::make_pair("Maggie", Person{.first_name = "Maggie"})); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_map_with_key_validation diff --git a/tests/boost_serialization/test_string_map.cpp b/tests/boost_serialization/test_string_map.cpp new file mode 100644 index 00000000..14887045 --- /dev/null +++ b/tests/boost_serialization/test_string_map.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_string_map { +TEST(boost_serialization, test_string_map) { + std::map> homer; + homer.insert( + std::make_pair("firstName", std::make_unique("Homer"))); + homer.insert( + std::make_pair("lastName", std::make_unique("Simpson"))); + + write_and_read(homer); +} +} // namespace test_string_map From 1015d2e7b99c10b1c1699c72b2601f7c362f32aa Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 3 Apr 2026 12:45:02 +0100 Subject: [PATCH 14/15] boost serialisation (no tracking) --- include/rfl/boost_serialization/read.hpp | 6 ++++-- include/rfl/boost_serialization/write.hpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/rfl/boost_serialization/read.hpp b/include/rfl/boost_serialization/read.hpp index 81f86b8b..d778a5b7 100644 --- a/include/rfl/boost_serialization/read.hpp +++ b/include/rfl/boost_serialization/read.hpp @@ -41,7 +41,8 @@ Result> read( try { std::string str(reinterpret_cast(_bytes), _size); std::istringstream stream(str); - boost::archive::binary_iarchive ar(stream); + boost::archive::binary_iarchive ar( + stream, boost::archive::no_header | boost::archive::no_tracking); return detail::read_from_archive( ar); @@ -60,7 +61,8 @@ auto read(const concepts::ContiguousByteContainer auto& _bytes) { template auto read(std::istream& _stream) { try { - boost::archive::binary_iarchive ar(_stream); + boost::archive::binary_iarchive ar( + _stream, boost::archive::no_header | boost::archive::no_tracking); return detail::read_from_archive( ar); diff --git a/include/rfl/boost_serialization/write.hpp b/include/rfl/boost_serialization/write.hpp index dc9c7904..88e8595c 100644 --- a/include/rfl/boost_serialization/write.hpp +++ b/include/rfl/boost_serialization/write.hpp @@ -33,7 +33,8 @@ template std::vector write(const auto& _obj) { std::ostringstream stream; { - boost::archive::binary_oarchive ar(stream); + boost::archive::binary_oarchive ar( + stream, boost::archive::no_header | boost::archive::no_tracking); write(ar, _obj); } @@ -44,7 +45,8 @@ std::vector write(const auto& _obj) { /// Writes into an ostream using a binary archive. template std::ostream& write(const auto& _obj, std::ostream& _stream) { - boost::archive::binary_oarchive ar(_stream); + boost::archive::binary_oarchive ar( + _stream, boost::archive::no_header | boost::archive::no_tracking); write(ar, _obj); return _stream; From 89c1fc95abe6bdb8089447e0900a3d65965064b0 Mon Sep 17 00:00:00 2001 From: Ron0Studios Date: Fri, 3 Apr 2026 13:05:58 +0100 Subject: [PATCH 15/15] boost serialisation (read path zerocopy) --- include/rfl/boost_serialization/read.hpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/rfl/boost_serialization/read.hpp b/include/rfl/boost_serialization/read.hpp index d778a5b7..1773f82e 100644 --- a/include/rfl/boost_serialization/read.hpp +++ b/include/rfl/boost_serialization/read.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include "../Processors.hpp" @@ -26,6 +26,15 @@ auto read_from_archive(IArchive& _ar) { return Parser>::read(r, var); } +/// A read-only streambuf that wraps an existing memory buffer without copying. +class MemBuf : public std::streambuf { + public: + MemBuf(const char* _data, size_t _size) { + auto* p = const_cast(_data); + setg(p, p, p + _size); + } +}; + } // namespace detail /// Reads from an existing Boost input archive. @@ -39,8 +48,8 @@ template Result> read( const concepts::ByteLike auto* _bytes, const size_t _size) { try { - std::string str(reinterpret_cast(_bytes), _size); - std::istringstream stream(str); + detail::MemBuf buf(reinterpret_cast(_bytes), _size); + std::istream stream(&buf); boost::archive::binary_iarchive ar( stream, boost::archive::no_header | boost::archive::no_tracking); return detail::read_from_archive