diff --git a/include/rfl/avro/Parser.hpp b/include/rfl/avro/Parser.hpp index 369bb797..31e93cc0 100644 --- a/include/rfl/avro/Parser.hpp +++ b/include/rfl/avro/Parser.hpp @@ -48,13 +48,13 @@ template requires AreReaderAndWriter struct Parser { template - static Result read(const avro::Reader&, const T&) noexcept { + static Result read(const avro::Reader&, const T&) { static_assert(always_false_v, "Generics are unsupported in Avro."); return error("Unsupported"); } template - static void write(const avro::Writer&, const Generic&, const P&) noexcept { + static void write(const avro::Writer&, const Generic&, const P&) { static_assert(always_false_v

, "Generics are unsupported in Avro."); } @@ -78,7 +78,7 @@ struct Parser static Result> - read(const R&, const U&) noexcept { + read(const R&, const U&) { static_assert(always_false_v, "rfl::Skip is unsupported in Avro."); return Error("Unsupported"); } @@ -87,7 +87,7 @@ struct Parser& /*_skip*/, - const P& /*_parent*/) noexcept { + const P& /*_parent*/) { static_assert(always_false_v

, "rfl::Skip is unsupported in Avro."); } diff --git a/include/rfl/avro/Reader.hpp b/include/rfl/avro/Reader.hpp index db02f67e..71cff92b 100644 --- a/include/rfl/avro/Reader.hpp +++ b/include/rfl/avro/Reader.hpp @@ -9,10 +9,9 @@ #include #include -#include "../Bytestring.hpp" #include "../Result.hpp" -#include "../Vectorstring.hpp" #include "../always_false.hpp" +#include "../concepts.hpp" #include "../internal/is_literal.hpp" #include "../parsing/schemaful/IsSchemafulReader.hpp" @@ -67,22 +66,15 @@ struct Reader { return std::string(""); } return std::string(c_str, size - 1); - } else if constexpr (std::is_same, - rfl::Bytestring>() || - std::is_same, - rfl::Vectorstring>()) { + } else if constexpr (concepts::MutableContiguousByteContainer< + std::remove_cvref_t>) { using VectorType = std::remove_cvref_t; using ValueType = typename VectorType::value_type; const void* ptr = nullptr; size_t size = 0; const auto err = avro_value_get_bytes(_var.val_, &ptr, &size); if (err) { - if constexpr (std::is_same, - rfl::Bytestring>()) { - return error("Could not cast to bytestring."); - } else { - return error("Could not cast to vectorstring."); - } + return error("Could not cast to bytestring."); } const auto data = internal::ptr_cast(ptr); return VectorType(data, data + size); @@ -93,7 +85,8 @@ struct Reader { int result_value = 0; int result = avro_value_get_boolean(_var.val_, &result_value); if (result != 0) { - return error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + return error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return (result_value != 0); @@ -191,16 +184,16 @@ struct Reader { const InputArrayType& _arr) const noexcept { size_t size = 0; int res = avro_value_get_size(_arr.val_, &size); - if(res) - { - return Error(std::string(__FUNCTION__) + " error(" + std::to_string(res) + "): " + avro_strerror()); + if (res) { + return Error(std::string(__FUNCTION__) + " error(" + std::to_string(res) + + "): " + avro_strerror()); } for (size_t ix = 0; ix < size; ++ix) { avro_value_t element; res = avro_value_get_by_index(_arr.val_, ix, &element, nullptr); - if(res) - { - return Error(std::string(__FUNCTION__) + " error(" + std::to_string(res) + "): " + avro_strerror()); + if (res) { + return Error(std::string(__FUNCTION__) + " error(" + + std::to_string(res) + "): " + avro_strerror()); } const auto err = _array_reader.read(InputVarType{&element}); if (err) { @@ -215,17 +208,17 @@ struct Reader { const InputMapType& _map) const noexcept { size_t size = 0; int res = avro_value_get_size(_map.val_, &size); - if(res!=0) - { - return Error(std::string(__FUNCTION__) + " error("+ std::to_string(res)+"): " + avro_strerror()); + if (res != 0) { + return Error(std::string(__FUNCTION__) + " error(" + std::to_string(res) + + "): " + avro_strerror()); } for (size_t ix = 0; ix < size; ++ix) { avro_value_t element; const char* key = nullptr; res = avro_value_get_by_index(_map.val_, ix, &element, &key); - if(res!=0) - { - return Error(std::string(__FUNCTION__) + " error("+ std::to_string(res)+"): " + avro_strerror()); + if (res != 0) { + return Error(std::string(__FUNCTION__) + " error(" + + std::to_string(res) + "): " + avro_strerror()); } _map_reader.read(std::string_view(key), InputVarType{&element}); } @@ -237,16 +230,16 @@ struct Reader { const InputObjectType& _obj) const noexcept { size_t size = 0; int res = avro_value_get_size(_obj.val_, &size); - if(res!=0) - { - return Error(std::string(__FUNCTION__) + " error("+ std::to_string(res)+"): " + avro_strerror()); + if (res != 0) { + return Error(std::string(__FUNCTION__) + " error(" + std::to_string(res) + + "): " + avro_strerror()); } for (size_t ix = 0; ix < size; ++ix) { avro_value_t element; res = avro_value_get_by_index(_obj.val_, ix, &element, nullptr); - if(res!=0) - { - return Error(std::string(__FUNCTION__) + " error("+ std::to_string(res)+"): " + avro_strerror()); + if (res != 0) { + return Error(std::string(__FUNCTION__) + " error(" + + std::to_string(res) + "): " + avro_strerror()); } _object_reader.read(static_cast(ix), InputVarType{&element}); } diff --git a/include/rfl/avro/Writer.hpp b/include/rfl/avro/Writer.hpp index 5f780256..4cdf2832 100644 --- a/include/rfl/avro/Writer.hpp +++ b/include/rfl/avro/Writer.hpp @@ -5,18 +5,15 @@ #include #include +#include #include #include #include -#include "../Bytestring.hpp" -#include "../Timestamp.hpp" -#include "../Vectorstring.hpp" #include "../always_false.hpp" #include "../common.hpp" +#include "../concepts.hpp" #include "../internal/is_literal.hpp" -#include "../internal/is_validator.hpp" -#include "../patterns.hpp" namespace rfl::avro { @@ -52,15 +49,15 @@ class RFL_API Writer { ~Writer(); - OutputArrayType array_as_root(const size_t _size) const noexcept; + OutputArrayType array_as_root(const size_t _size) const; - OutputMapType map_as_root(const size_t _size) const noexcept; + OutputMapType map_as_root(const size_t _size) const; - OutputObjectType object_as_root(const size_t _size) const noexcept; + OutputObjectType object_as_root(const size_t _size) const; OutputVarType null_as_root() const; - OutputUnionType union_as_root() const noexcept; + OutputUnionType union_as_root() const; template OutputVarType value_as_root(const T& _var) const { @@ -138,7 +135,7 @@ class RFL_API Writer { avro_value_t new_value; int result = avro_value_append(&_parent->val_, &new_value, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + throw std::runtime_error("Error adding value to array: error(" + std::to_string(result) + "): " + avro_strerror()); } @@ -153,7 +150,7 @@ class RFL_API Writer { int result = avro_value_add(&_parent->val_, _name.data(), &new_value, nullptr, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + throw std::runtime_error("Error adding value to map: error(" + std::to_string(result) + "): " + avro_strerror()); } @@ -169,7 +166,7 @@ class RFL_API Writer { int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_value, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + throw std::runtime_error("Error adding value to object: error(" + std::to_string(result) + "): " + avro_strerror()); } @@ -181,13 +178,13 @@ class RFL_API Writer { OutputVarType add_value_to_union(const size_t _index, const T& _var, OutputUnionType* _parent) const { if (_index > static_cast(INT_MAX)) { - throw std::runtime_error(std::string(__FUNCTION__) + " index error"); + throw std::runtime_error("Error adding value to unions: Index error"); } avro_value_t new_value; int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_value); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + throw std::runtime_error("Error adding value to union: error(" + std::to_string(result) + "): " + avro_strerror()); } @@ -204,67 +201,79 @@ class RFL_API Writer { private: template void set_value(const T& _var, avro_value_t* _val) const { - if constexpr (std::is_same, std::string>()) { + using Type = std::remove_cvref_t; + + if constexpr (std::is_same_v) { int result = avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + - std::to_string(result) + - "): " + avro_strerror()); + throw std::runtime_error( + "Error setting string value: " + std::to_string(result) + ": " + + avro_strerror()); } - } else if constexpr (std::is_same, - rfl::Bytestring>() || - std::is_same, - rfl::Vectorstring>()) { + + } else if constexpr (concepts::MutableContiguousByteContainer) { auto var = _var; if (!var.data()) { return; } int result = avro_value_set_bytes(_val, var.data(), var.size()); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + - std::to_string(result) + - "): " + avro_strerror()); + throw std::runtime_error( + "Error setting bytestring value: " + std::to_string(result) + ": " + + avro_strerror()); } - } else if constexpr (std::is_same, bool>()) { + + } else if constexpr (std::is_same_v) { int result = avro_value_set_boolean(_val, _var); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + - std::to_string(result) + - "): " + avro_strerror()); + throw std::runtime_error( + "Error setting boolean value: " + std::to_string(result) + ": " + + avro_strerror()); } - } else if constexpr (std::is_floating_point>()) { - /*int result = avro_value_set_double(_val, static_cast(_var)); + + } else if constexpr (std::is_same_v) { + int result = avro_value_set_float(_val, static_cast(_var)); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ - std::to_string(result)+"): " + avro_strerror()); - }*/ - avro_value_set_double(_val, static_cast(_var)); - } else if constexpr (std::is_integral>()) { - /*int result = avro_value_set_long(_val, static_cast(_var)); + throw std::runtime_error( + "Error setting float value: " + std::to_string(result) + ": " + + avro_strerror()); + } + + } else if constexpr (std::is_floating_point_v) { + int result = avro_value_set_double(_val, static_cast(_var)); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ - std::to_string(result)+"): " + avro_strerror()); - }*/ - avro_value_set_long(_val, static_cast(_var)); + throw std::runtime_error( + "Error setting double value: " + std::to_string(result) + ": " + + avro_strerror()); + } + + } else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) { + int result = avro_value_set_long(_val, static_cast(_var)); + if (result != 0) { + throw std::runtime_error( + "Error setting long value: " + std::to_string(result) + ": " + + avro_strerror()); + } + + } else if constexpr (std::is_integral_v) { + int result = avro_value_set_int(_val, static_cast(_var)); + if (result != 0) { + throw std::runtime_error( + "Error setting int value: " + std::to_string(result) + ": " + + avro_strerror()); + } + } else if constexpr (internal::is_literal_v) { int result = avro_value_set_enum(_val, static_cast(_var.value())); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error(" + - std::to_string(result) + - "): " + avro_strerror()); + throw std::runtime_error( + "Error setting literal value: " + std::to_string(result) + ": " + + avro_strerror()); } - } else if constexpr (internal::is_validator_v) { - using ValueType = std::remove_cvref_t; - const auto val = _var.value(); - set_value(val, _val); - } else if constexpr (std::is_same, - rfl::Timestamp<"%Y-%m-%d">>()) { - const auto str = _var.to_string(); - set_value(str, _val); - } else if constexpr (std::is_same, rfl::Email>()) { - const auto& str = static_cast(_var); - set_value(str, _val); + } else { static_assert(rfl::always_false_v, "Unsupported type."); } diff --git a/include/rfl/avro/schema/Type.hpp b/include/rfl/avro/schema/Type.hpp index ee76bea3..3c3b621c 100644 --- a/include/rfl/avro/schema/Type.hpp +++ b/include/rfl/avro/schema/Type.hpp @@ -6,7 +6,6 @@ #include #include "../../Literal.hpp" -//#include "../../Object.hpp" #include "../../Ref.hpp" #include "../../Rename.hpp" #include "../../Variant.hpp" @@ -36,7 +35,7 @@ struct RFL_API Type { }; struct Double { - Literal<"float"> type{}; + Literal<"double"> type{}; }; struct Bytes { diff --git a/include/rfl/avro/to_schema.hpp b/include/rfl/avro/to_schema.hpp index ec3e56d0..3e9adc40 100644 --- a/include/rfl/avro/to_schema.hpp +++ b/include/rfl/avro/to_schema.hpp @@ -3,18 +3,12 @@ #include -//#include "../Literal.hpp" #include "../Processors.hpp" -//#include "../Variant.hpp" -//#include "../json.hpp" -//#include "../parsing/schema/Type.hpp" -//#include "../parsing/schema/ValidationType.hpp" +#include "../common.hpp" #include "../parsing/schema/make.hpp" #include "Reader.hpp" #include "Schema.hpp" #include "Writer.hpp" -//#include "schema/Type.hpp" -#include "../common.hpp" namespace rfl::avro { diff --git a/include/rfl/parsing/CustomParser.hpp b/include/rfl/parsing/CustomParser.hpp index dc436031..2369c113 100644 --- a/include/rfl/parsing/CustomParser.hpp +++ b/include/rfl/parsing/CustomParser.hpp @@ -39,8 +39,7 @@ struct CustomParser { } template - static auto write(const W& _w, const OriginalClass& _p, - const P& _parent) noexcept { + static auto write(const W& _w, const OriginalClass& _p, const P& _parent) { Parser::write( _w, HelperStruct::from_class(_p), _parent); } diff --git a/include/rfl/parsing/FieldVariantParser.hpp b/include/rfl/parsing/FieldVariantParser.hpp index cb0db047..ffd6a4dd 100644 --- a/include/rfl/parsing/FieldVariantParser.hpp +++ b/include/rfl/parsing/FieldVariantParser.hpp @@ -57,7 +57,7 @@ struct FieldVariantParser { template static void write(const W& _w, const rfl::Variant& _v, - const P& _parent) noexcept { + const P& _parent) { static_assert( internal::no_duplicate_field_names>(), "Externally tagged variants cannot have duplicate field " diff --git a/include/rfl/parsing/MapParser.hpp b/include/rfl/parsing/MapParser.hpp index 25cf69bb..03432c9a 100644 --- a/include/rfl/parsing/MapParser.hpp +++ b/include/rfl/parsing/MapParser.hpp @@ -44,7 +44,7 @@ struct MapParser { } template - static void write(const W& _w, const MapType& _m, const P& _parent) noexcept { + static void write(const W& _w, const MapType& _m, const P& _parent) { if constexpr (schemaful::IsSchemafulWriter) { write_map(_w, _m, _parent); } else { @@ -82,8 +82,7 @@ struct MapParser { } template - static void write_map(const W& _w, const MapType& _m, - const P& _parent) noexcept { + static void write_map(const W& _w, const MapType& _m, const P& _parent) { auto m = ParentType::add_map(_w, _m.size(), _parent); using ParentMapType = @@ -122,8 +121,7 @@ struct MapParser { } template - static void write_object(const W& _w, const MapType& _m, - const P& _parent) noexcept { + static void write_object(const W& _w, const MapType& _m, const P& _parent) { auto obj = ParentType::add_object(_w, _m.size(), _parent); for (const auto& [k, v] : _m) { if constexpr (internal::has_reflection_type_v) { diff --git a/include/rfl/parsing/NamedTupleParser.hpp b/include/rfl/parsing/NamedTupleParser.hpp index 34ac15a4..b081d88b 100644 --- a/include/rfl/parsing/NamedTupleParser.hpp +++ b/include/rfl/parsing/NamedTupleParser.hpp @@ -145,7 +145,7 @@ struct NamedTupleParser { template static void write(const W& _w, const NamedTuple& _tup, - const P& _parent) noexcept { + const P& _parent) { if constexpr (_no_field_names) { auto arr = ParentType::add_array(_w, _tup.num_fields(), _parent); build_object(_w, _tup, &arr, std::make_integer_sequence()); @@ -169,7 +169,7 @@ struct NamedTupleParser { template static void add_field_to_object(const W& _w, const NamedTuple& _tup, - OutputObjectOrArrayType* _ptr) noexcept { + OutputObjectOrArrayType* _ptr) { using FieldType = internal::nth_element_t<_i, FieldTypes...>; using ValueType = std::remove_cvref_t; const auto value = rfl::get<_i>(_tup); @@ -222,7 +222,7 @@ struct NamedTupleParser { template static void build_object(const W& _w, const NamedTuple& _tup, OutputObjectOrArrayType* _ptr, - std::integer_sequence) noexcept { + std::integer_sequence) { (add_field_to_object<_is>(_w, _tup, _ptr), ...); } diff --git a/include/rfl/parsing/Parser_array.hpp b/include/rfl/parsing/Parser_array.hpp index f907440a..8b5bb4fa 100644 --- a/include/rfl/parsing/Parser_array.hpp +++ b/include/rfl/parsing/Parser_array.hpp @@ -55,7 +55,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const std::array& _arr, - const P& _parent) noexcept { + const P& _parent) { auto arr = ParentType::add_array(_w, _size, _parent); const auto new_parent = typename ParentType::Array{&arr}; for (const auto& e : _arr) { diff --git a/include/rfl/parsing/Parser_box.hpp b/include/rfl/parsing/Parser_box.hpp index 33e17880..56bf25ac 100644 --- a/include/rfl/parsing/Parser_box.hpp +++ b/include/rfl/parsing/Parser_box.hpp @@ -13,19 +13,21 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> { using InputVarType = typename R::InputVarType; - static Result> read(const R& _r, const InputVarType& _var) noexcept { - const auto to_box = [](auto&& _t) { return Box::make(std::move(_t)); }; + static Result> read(const R& _r, + const InputVarType& _var) noexcept { + const auto to_box = [](auto&& _t) { + return Box::make(std::move(_t)); + }; return Parser, ProcessorsType>::read(_r, _var) .transform(to_box); } template - static void write(const W& _w, const Box& _box, - const P& _parent) noexcept { + static void write(const W& _w, const Box& _box, const P& _parent) { Parser, ProcessorsType>::write(_w, *_box, _parent); } diff --git a/include/rfl/parsing/Parser_bytestring.hpp b/include/rfl/parsing/Parser_bytestring.hpp index 18980d09..75e9b9fb 100644 --- a/include/rfl/parsing/Parser_bytestring.hpp +++ b/include/rfl/parsing/Parser_bytestring.hpp @@ -23,8 +23,7 @@ struct Parser { } template - static void write(const W& _w, const Bytestring& _b, - const P& _parent) noexcept { + static void write(const W& _w, const Bytestring& _b, const P& _parent) { ParentType::add_value(_w, _b, _parent); } diff --git a/include/rfl/parsing/Parser_c_array.hpp b/include/rfl/parsing/Parser_c_array.hpp index be117145..58447a00 100644 --- a/include/rfl/parsing/Parser_c_array.hpp +++ b/include/rfl/parsing/Parser_c_array.hpp @@ -17,7 +17,7 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter + requires AreReaderAndWriter struct Parser { public: using InputArrayType = typename R::InputArrayType; @@ -33,8 +33,7 @@ struct Parser { } template - static void write(const W& _w, const CArray& _arr, - const P& _parent) noexcept { + static void write(const W& _w, const CArray& _arr, const P& _parent) { auto arr = ParentType::add_array(_w, _size, _parent); const auto new_parent = typename ParentType::Array{&arr}; for (const auto& e : _arr) { diff --git a/include/rfl/parsing/Parser_default.hpp b/include/rfl/parsing/Parser_default.hpp index b2cc5551..eed67f9a 100644 --- a/include/rfl/parsing/Parser_default.hpp +++ b/include/rfl/parsing/Parser_default.hpp @@ -105,7 +105,7 @@ struct Parser { } template - static void write(const W& _w, const T& _var, const P& _parent) noexcept { + static void write(const W& _w, const T& _var, const P& _parent) { if constexpr (internal::has_write_reflector) { Parser::ReflType, ProcessorsType>::write( _w, Reflector::from(_var), _parent); diff --git a/include/rfl/parsing/Parser_duration.hpp b/include/rfl/parsing/Parser_duration.hpp index 8f6e995f..f82ee752 100644 --- a/include/rfl/parsing/Parser_duration.hpp +++ b/include/rfl/parsing/Parser_duration.hpp @@ -50,8 +50,7 @@ struct Parser, ProcessorsType> { } template - static void write(const W& _w, const DurationType& _d, - const P& _parent) noexcept { + static void write(const W& _w, const DurationType& _d, const P& _parent) { const auto r = RType{.count = static_cast(_d.count()), .unit = make_unit()}; return Parser::write(_w, r, _parent); diff --git a/include/rfl/parsing/Parser_filepath.hpp b/include/rfl/parsing/Parser_filepath.hpp index 0c067cd8..a9414417 100644 --- a/include/rfl/parsing/Parser_filepath.hpp +++ b/include/rfl/parsing/Parser_filepath.hpp @@ -33,7 +33,7 @@ struct Parser { template static void write(const W& _w, const std::filesystem::path& _p, - const P& _parent) noexcept { + const P& _parent) { return Parser::write(_w, _p.string(), _parent); } diff --git a/include/rfl/parsing/Parser_optional.hpp b/include/rfl/parsing/Parser_optional.hpp index d4b7af17..d7f07f7a 100644 --- a/include/rfl/parsing/Parser_optional.hpp +++ b/include/rfl/parsing/Parser_optional.hpp @@ -38,7 +38,9 @@ struct Parser, ProcessorsType> { if (_r.is_empty(_var)) { return std::optional(); } - const auto to_opt = [](auto&& _t) { return std::make_optional(std::forward(_t)); }; + const auto to_opt = [](auto&& _t) { + return std::make_optional(std::forward(_t)); + }; return Parser, ProcessorsType>::read(_r, _var) .transform(to_opt); @@ -46,8 +48,7 @@ struct Parser, ProcessorsType> { } template - static void write(const W& _w, const std::optional& _o, - const P& _parent) noexcept { + static void write(const W& _w, const std::optional& _o, const P& _parent) { if constexpr (schemaful::IsSchemafulWriter) { auto u = ParentType::add_union(_w, _parent); using UnionType = typename ParentType::template Union; diff --git a/include/rfl/parsing/Parser_pair.hpp b/include/rfl/parsing/Parser_pair.hpp index adf463f1..0cf2336f 100644 --- a/include/rfl/parsing/Parser_pair.hpp +++ b/include/rfl/parsing/Parser_pair.hpp @@ -15,7 +15,7 @@ namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> { using InputVarType = typename R::InputVarType; @@ -33,7 +33,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const std::pair& _p, - const P& _parent) noexcept { + const P& _parent) { const auto tup = std::make_tuple(&_p.first, &_p.second); Parser, ProcessorsType>::write(_w, tup, _parent); diff --git a/include/rfl/parsing/Parser_ptr.hpp b/include/rfl/parsing/Parser_ptr.hpp index 33ec7383..c709e1a8 100644 --- a/include/rfl/parsing/Parser_ptr.hpp +++ b/include/rfl/parsing/Parser_ptr.hpp @@ -47,7 +47,7 @@ struct Parser { } template - static void write(const W& _w, const T* _ptr, const P& _parent) noexcept { + static void write(const W& _w, const T* _ptr, const P& _parent) { if (!_ptr) { ParentType::add_null(_w, _parent); return; diff --git a/include/rfl/parsing/Parser_ref.hpp b/include/rfl/parsing/Parser_ref.hpp index 1c1348e7..452fef55 100644 --- a/include/rfl/parsing/Parser_ref.hpp +++ b/include/rfl/parsing/Parser_ref.hpp @@ -14,7 +14,7 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> { using InputVarType = typename R::InputVarType; @@ -25,8 +25,7 @@ struct Parser, ProcessorsType> { } template - static void write(const W& _w, const Ref& _ref, - const P& _parent) noexcept { + static void write(const W& _w, const Ref& _ref, const P& _parent) { Parser, ProcessorsType>::write(_w, *_ref, _parent); } diff --git a/include/rfl/parsing/Parser_reference_wrapper.hpp b/include/rfl/parsing/Parser_reference_wrapper.hpp index 5642e8ab..840de089 100644 --- a/include/rfl/parsing/Parser_reference_wrapper.hpp +++ b/include/rfl/parsing/Parser_reference_wrapper.hpp @@ -31,7 +31,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const std::reference_wrapper _ref, - const P& _p) noexcept { + const P& _p) { Parser, ProcessorsType>::write(_w, _ref.get(), _p); } diff --git a/include/rfl/parsing/Parser_rename.hpp b/include/rfl/parsing/Parser_rename.hpp index 161a8e57..a79846d1 100644 --- a/include/rfl/parsing/Parser_rename.hpp +++ b/include/rfl/parsing/Parser_rename.hpp @@ -16,7 +16,7 @@ namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> { using InputVarType = typename R::InputVarType; @@ -31,7 +31,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const Rename<_name, T>& _rename, - const P& _parent) noexcept { + const P& _parent) { Parser, ProcessorsType>::write( _w, _rename.value(), _parent); } diff --git a/include/rfl/parsing/Parser_result.hpp b/include/rfl/parsing/Parser_result.hpp index 1aa96d0a..0b5085fe 100644 --- a/include/rfl/parsing/Parser_result.hpp +++ b/include/rfl/parsing/Parser_result.hpp @@ -45,8 +45,7 @@ struct Parser, ProcessorsType> { } template - static void write(const W& _w, const Result& _r, - const P& _parent) noexcept { + static void write(const W& _w, const Result& _r, const P& _parent) { if (_r) { Parser, ProcessorsType>::write( _w, _r.value(), _parent); diff --git a/include/rfl/parsing/Parser_rfl_array.hpp b/include/rfl/parsing/Parser_rfl_array.hpp index f0660a88..9e5c470b 100644 --- a/include/rfl/parsing/Parser_rfl_array.hpp +++ b/include/rfl/parsing/Parser_rfl_array.hpp @@ -15,7 +15,7 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> { public: using InputArrayType = typename R::InputArrayType; @@ -30,7 +30,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const internal::Array& _arr, - const P& _parent) noexcept { + const P& _parent) { Parser::write(_w, _arr.arr_, _parent); } diff --git a/include/rfl/parsing/Parser_rfl_variant.hpp b/include/rfl/parsing/Parser_rfl_variant.hpp index 5de448fc..8c5dd2f5 100644 --- a/include/rfl/parsing/Parser_rfl_variant.hpp +++ b/include/rfl/parsing/Parser_rfl_variant.hpp @@ -92,7 +92,7 @@ class Parser, ProcessorsType> { template static void write(const W& _w, const rfl::Variant& _variant, - const P& _parent) noexcept { + const P& _parent) { if constexpr (internal::all_fields>()) { if constexpr (schemaful::IsSchemafulWriter) { using WrappedType = rfl::Variant< diff --git a/include/rfl/parsing/Parser_skip.hpp b/include/rfl/parsing/Parser_skip.hpp index dab03012..b5346c7f 100644 --- a/include/rfl/parsing/Parser_skip.hpp +++ b/include/rfl/parsing/Parser_skip.hpp @@ -44,7 +44,7 @@ struct Parser& _skip, - const P& _parent) noexcept { + const P& _parent) { if constexpr (_skip_serialization) { ParentType::add_null(_w, _parent); } else { diff --git a/include/rfl/parsing/Parser_span.hpp b/include/rfl/parsing/Parser_span.hpp index e8e2f7a1..2593821c 100644 --- a/include/rfl/parsing/Parser_span.hpp +++ b/include/rfl/parsing/Parser_span.hpp @@ -55,8 +55,7 @@ struct Parser, ProcessorsType> { } template - static void write(const W& _w, const std::span& _span, - const P& _parent) noexcept { + static void write(const W& _w, const std::span& _span, const P& _parent) { auto arr = ParentType::add_array(_w, _span.size(), _parent); const auto new_parent = typename ParentType::Array{&arr}; for (const auto& v : _span) { diff --git a/include/rfl/parsing/Parser_string_view.hpp b/include/rfl/parsing/Parser_string_view.hpp index 62e5db43..d09273d3 100644 --- a/include/rfl/parsing/Parser_string_view.hpp +++ b/include/rfl/parsing/Parser_string_view.hpp @@ -46,8 +46,7 @@ struct Parser { } template - static void write(const W& _w, const std::string_view& _str, - const P& _p) noexcept { + static void write(const W& _w, const std::string_view& _str, const P& _p) { Parser::write(_w, std::string(_str), _p); } diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index ce4622d3..f752762a 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -73,7 +73,7 @@ struct Parser, static void write( const W& _w, const TaggedUnion<_discriminator, AlternativeTypes...>& _tagged_union, - const P& _parent) noexcept { + const P& _parent) { if constexpr (schemaful::IsSchemafulWriter) { Parser, ProcessorsType>::write( _w, _tagged_union.variant(), _parent); diff --git a/include/rfl/parsing/Parser_unique_ptr.hpp b/include/rfl/parsing/Parser_unique_ptr.hpp index b9d60587..344fdb3d 100644 --- a/include/rfl/parsing/Parser_unique_ptr.hpp +++ b/include/rfl/parsing/Parser_unique_ptr.hpp @@ -46,7 +46,7 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const std::unique_ptr& _s, - const P& _parent) noexcept { + const P& _parent) { if constexpr (schemaful::IsSchemafulWriter) { auto u = ParentType::add_union(_w, _parent); using UnionType = typename ParentType::template Union; diff --git a/include/rfl/parsing/Parser_variant.hpp b/include/rfl/parsing/Parser_variant.hpp index 159e65aa..2bfa3e87 100644 --- a/include/rfl/parsing/Parser_variant.hpp +++ b/include/rfl/parsing/Parser_variant.hpp @@ -11,6 +11,7 @@ #include "../Result.hpp" #include "../Variant.hpp" #include "../always_false.hpp" +#include "../internal/all_fields.hpp" #include "../internal/to_ptr_field.hpp" #include "FieldVariantParser.hpp" #include "Parent.hpp" @@ -21,8 +22,6 @@ #include "schemaful/IsSchemafulWriter.hpp" #include "schemaful/VariantReader.hpp" #include "to_single_error_message.hpp" -#include "../internal/all_fields.hpp" - namespace rfl::parsing { @@ -72,11 +71,11 @@ class Parser, ProcessorsType> { return _r.template read_union, V>(_u); }); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; - using FieldVariantType = - rfl::Variant...>; + using FieldVariantType = rfl::Variant< + VariantAlternativeWrapper...>; const auto from_field_variant = [](auto&& _field) -> std::variant { return std::move(_field.value()); @@ -109,7 +108,7 @@ class Parser, ProcessorsType> { template static void write(const W& _w, const std::variant& _variant, - const P& _parent) noexcept { + const P& _parent) { if constexpr (internal::all_fields>()) { if constexpr (schemaful::IsSchemafulWriter) { using WrappedType = rfl::Variant< @@ -152,11 +151,12 @@ class Parser, ProcessorsType> { }, _variant); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; using FieldVariantType = - rfl::Variant...>; + rfl::Variant...>; const auto to_field_variant = [](const T& _t) -> FieldVariantType { return VariantAlternativeWrapper(&_t); @@ -179,11 +179,11 @@ class Parser, ProcessorsType> { return FieldVariantParser::to_schema(_definitions); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; - using FieldVariantType = - rfl::Variant...>; + using FieldVariantType = rfl::Variant< + VariantAlternativeWrapper...>; return Parser::to_schema( _definitions); diff --git a/include/rfl/parsing/Parser_vectorstring.hpp b/include/rfl/parsing/Parser_vectorstring.hpp index 474473da..c64a8199 100644 --- a/include/rfl/parsing/Parser_vectorstring.hpp +++ b/include/rfl/parsing/Parser_vectorstring.hpp @@ -23,8 +23,7 @@ struct Parser { } template - static void write(const W& _w, const Vectorstring& _b, - const P& _parent) noexcept { + static void write(const W& _w, const Vectorstring& _b, const P& _parent) { ParentType::add_value(_w, _b, _parent); } diff --git a/include/rfl/parsing/Parser_wstring.hpp b/include/rfl/parsing/Parser_wstring.hpp index e8441b18..73ee2c43 100644 --- a/include/rfl/parsing/Parser_wstring.hpp +++ b/include/rfl/parsing/Parser_wstring.hpp @@ -52,8 +52,7 @@ struct Parser { } template - static void write(const W& _w, const std::wstring& _str, - const P& _parent) noexcept { + static void write(const W& _w, const std::wstring& _str, const P& _parent) { if (_str.empty()) { ParentType::add_value(_w, std::string(), _parent); return; diff --git a/include/rfl/parsing/TupleParser.hpp b/include/rfl/parsing/TupleParser.hpp index 0c16b425..bda80536 100644 --- a/include/rfl/parsing/TupleParser.hpp +++ b/include/rfl/parsing/TupleParser.hpp @@ -73,8 +73,7 @@ struct TupleParser { } template - static void write(const W& _w, const TupleType& _tup, - const P& _parent) noexcept { + static void write(const W& _w, const TupleType& _tup, const P& _parent) { if constexpr (schemaful::IsSchemafulWriter) { const auto named_tuple = schemaful::tuple_to_named_tuple(_tup); Parser, @@ -115,7 +114,7 @@ struct TupleParser { template static void add_to_array(const W& _w, const TupleType& _tup, - const P& _parent) noexcept { + const P& _parent) { using NewFieldType = std::remove_cvref_t>; Parser::write(_w, rfl::get<_i>(_tup), @@ -124,7 +123,7 @@ struct TupleParser { template static void to_array(const W& _w, const TupleType& _tup, const P& _parent, - std::integer_sequence) noexcept { + std::integer_sequence) { (add_to_array<_is>(_w, _tup, _parent), ...); } }; diff --git a/include/rfl/parsing/VectorParser.hpp b/include/rfl/parsing/VectorParser.hpp index 7f83c61e..afbe6733 100644 --- a/include/rfl/parsing/VectorParser.hpp +++ b/include/rfl/parsing/VectorParser.hpp @@ -72,8 +72,7 @@ struct VectorParser { } template - static void write(const W& _w, const VecType& _vec, - const P& _parent) noexcept { + static void write(const W& _w, const VecType& _vec, const P& _parent) { if constexpr (treat_as_map()) { MapParser::write(_w, _vec, _parent); } else { diff --git a/src/rfl/avro/Writer.cpp b/src/rfl/avro/Writer.cpp index 4cf98d35..2c0ce3bc 100644 --- a/src/rfl/avro/Writer.cpp +++ b/src/rfl/avro/Writer.cpp @@ -1,4 +1,5 @@ #include "rfl/avro/Writer.hpp" + #include #include "rfl/parsing/schemaful/IsSchemafulWriter.hpp" @@ -12,29 +13,28 @@ Writer::Writer(avro_value_t* _root) : root_(_root){}; Writer::~Writer() = default; -Writer::OutputArrayType Writer::array_as_root( - const size_t /*_size*/) const noexcept { +Writer::OutputArrayType Writer::array_as_root(const size_t /*_size*/) const { return OutputArrayType{*root_}; } -Writer::OutputMapType Writer::map_as_root(const size_t /*_size*/) const noexcept { +Writer::OutputMapType Writer::map_as_root(const size_t /*_size*/) const { return OutputMapType{*root_}; } -Writer::OutputObjectType Writer::object_as_root( - const size_t /*_size*/) const noexcept { +Writer::OutputObjectType Writer::object_as_root(const size_t /*_size*/) const { return OutputObjectType{*root_}; } Writer::OutputVarType Writer::null_as_root() const { int result = avro_value_set_null(root_); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputVarType{*root_}; } -Writer::OutputUnionType Writer::union_as_root() const noexcept { +Writer::OutputUnionType Writer::union_as_root() const { return OutputUnionType{*root_}; } @@ -43,18 +43,21 @@ Writer::OutputArrayType Writer::add_array_to_array( avro_value_t new_array; int result = avro_value_append(&_parent->val_, &new_array, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputArrayType{new_array}; } -Writer::OutputArrayType Writer::add_array_to_map( - const std::string_view& _name, const size_t /*_size*/, - OutputMapType* _parent) const { +Writer::OutputArrayType Writer::add_array_to_map(const std::string_view& _name, + const size_t /*_size*/, + OutputMapType* _parent) const { avro_value_t new_array; - int result = avro_value_add(&_parent->val_, _name.data(), &new_array, nullptr, nullptr); + int result = avro_value_add(&_parent->val_, _name.data(), &new_array, nullptr, + nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputArrayType{new_array}; } @@ -63,9 +66,11 @@ Writer::OutputArrayType Writer::add_array_to_object( const std::string_view& _name, const size_t /*_size*/, OutputObjectType* _parent) const { avro_value_t new_array; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_array, nullptr); + int result = + avro_value_get_by_name(&_parent->val_, _name.data(), &new_array, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputArrayType{new_array}; } @@ -77,30 +82,35 @@ Writer::OutputArrayType Writer::add_array_to_union( throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_array; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_array); + int result = avro_value_set_branch(&_parent->val_, static_cast(_index), + &new_array); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputArrayType{new_array}; } -Writer::OutputMapType Writer::add_map_to_array( - const size_t /*_size*/, OutputArrayType* _parent) const { +Writer::OutputMapType Writer::add_map_to_array(const size_t /*_size*/, + OutputArrayType* _parent) const { avro_value_t new_map; int result = avro_value_append(&_parent->val_, &new_map, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputMapType{new_map}; } -Writer::OutputMapType Writer::add_map_to_map( - const std::string_view& _name, const size_t /*_size*/, - OutputMapType* _parent) const { +Writer::OutputMapType Writer::add_map_to_map(const std::string_view& _name, + const size_t /*_size*/, + OutputMapType* _parent) const { avro_value_t new_map; - int result = avro_value_add(&_parent->val_, _name.data(), &new_map, nullptr, nullptr); + int result = + avro_value_add(&_parent->val_, _name.data(), &new_map, nullptr, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputMapType{new_map}; } @@ -109,23 +119,27 @@ Writer::OutputMapType Writer::add_map_to_object( const std::string_view& _name, const size_t /*_size*/, OutputObjectType* _parent) const { avro_value_t new_map; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_map, nullptr); + int result = + avro_value_get_by_name(&_parent->val_, _name.data(), &new_map, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputMapType{new_map}; } -Writer::OutputMapType Writer::add_map_to_union( - const size_t _index, const size_t /*_size*/, - OutputUnionType* _parent) const { +Writer::OutputMapType Writer::add_map_to_union(const size_t _index, + const size_t /*_size*/, + OutputUnionType* _parent) const { if (_index > static_cast(INT_MAX)) { throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_map; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_map); + int result = + avro_value_set_branch(&_parent->val_, static_cast(_index), &new_map); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputMapType{new_map}; } @@ -134,8 +148,9 @@ Writer::OutputObjectType Writer::add_object_to_array( const size_t /*_size*/, OutputArrayType* _parent) const { avro_value_t new_object; int result = avro_value_append(&_parent->val_, &new_object, nullptr); - if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + if (result != 0) { + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputObjectType{new_object}; } @@ -144,9 +159,11 @@ Writer::OutputObjectType Writer::add_object_to_map( const std::string_view& _name, const size_t /*_size*/, OutputMapType* _parent) const { avro_value_t new_object; - int result = avro_value_add(&_parent->val_, _name.data(), &new_object, nullptr, nullptr); + int result = avro_value_add(&_parent->val_, _name.data(), &new_object, + nullptr, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputObjectType{new_object}; } @@ -155,9 +172,11 @@ Writer::OutputObjectType Writer::add_object_to_object( const std::string_view& _name, const size_t /*_size*/, OutputObjectType* _parent) const { avro_value_t new_object; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_object, nullptr); + int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_object, + nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputObjectType{new_object}; } @@ -169,9 +188,11 @@ Writer::OutputObjectType Writer::add_object_to_union( throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_object; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_object); + int result = avro_value_set_branch(&_parent->val_, static_cast(_index), + &new_object); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputObjectType{new_object}; } @@ -181,17 +202,20 @@ Writer::OutputUnionType Writer::add_union_to_array( avro_value_t new_union; int result = avro_value_append(&_parent->val_, &new_union, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputUnionType{new_union}; } -Writer::OutputUnionType Writer::add_union_to_map( - const std::string_view& _name, OutputMapType* _parent) const { +Writer::OutputUnionType Writer::add_union_to_map(const std::string_view& _name, + OutputMapType* _parent) const { avro_value_t new_union; - int result = avro_value_add(&_parent->val_, _name.data(), &new_union, nullptr, nullptr); + int result = avro_value_add(&_parent->val_, _name.data(), &new_union, nullptr, + nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputUnionType{new_union}; } @@ -199,9 +223,11 @@ Writer::OutputUnionType Writer::add_union_to_map( Writer::OutputUnionType Writer::add_union_to_object( const std::string_view& _name, OutputObjectType* _parent) const { avro_value_t new_union; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_union, nullptr); + int result = + avro_value_get_by_name(&_parent->val_, _name.data(), &new_union, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputUnionType{new_union}; } @@ -212,9 +238,11 @@ Writer::OutputUnionType Writer::add_union_to_union( throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_union; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_union); + int result = avro_value_set_branch(&_parent->val_, static_cast(_index), + &new_union); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputUnionType{new_union}; } @@ -224,25 +252,30 @@ Writer::OutputVarType Writer::add_null_to_array( avro_value_t new_null; int result = avro_value_append(&_parent->val_, &new_null, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } result = avro_value_set_null(&new_null); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputVarType{new_null}; } -Writer::OutputVarType Writer::add_null_to_map( - const std::string_view& _name, OutputMapType* _parent) const { +Writer::OutputVarType Writer::add_null_to_map(const std::string_view& _name, + OutputMapType* _parent) const { avro_value_t new_null; - int result = avro_value_add(&_parent->val_, _name.data(), &new_null, nullptr, nullptr); + int result = + avro_value_add(&_parent->val_, _name.data(), &new_null, nullptr, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } result = avro_value_set_null(&new_null); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputVarType{new_null}; } @@ -250,13 +283,16 @@ Writer::OutputVarType Writer::add_null_to_map( Writer::OutputVarType Writer::add_null_to_object( const std::string_view& _name, OutputObjectType* _parent) const { avro_value_t new_null; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_null, nullptr); + int result = + avro_value_get_by_name(&_parent->val_, _name.data(), &new_null, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } result = avro_value_set_null(&new_null); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputVarType{new_null}; } @@ -267,13 +303,16 @@ Writer::OutputVarType Writer::add_null_to_union( throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_null; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_null); + int result = avro_value_set_branch(&_parent->val_, static_cast(_index), + &new_null); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } result = avro_value_set_null(&new_null); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + "): " + avro_strerror()); } return OutputVarType{new_null}; } diff --git a/src/rfl/avro/to_schema.cpp b/src/rfl/avro/to_schema.cpp index 1e40d938..c9d2cbef 100644 --- a/src/rfl/avro/to_schema.cpp +++ b/src/rfl/avro/to_schema.cpp @@ -55,9 +55,6 @@ schema::Type type_to_avro_schema_type( return schema::Type{.value = schema::Type::Bytes{}}; } else if constexpr (std::is_same() || - std::is_same() || - std::is_same() || - std::is_same() || std::is_same()) { return schema::Type{.value = schema::Type::Int{}}; diff --git a/tests/avro/test_add_struct_name.cpp b/tests/avro/test_add_struct_name.cpp index 9059e189..87324e61 100644 --- a/tests/avro/test_add_struct_name.cpp +++ b/tests/avro/test_add_struct_name.cpp @@ -40,6 +40,6 @@ TEST(avro, test_add_struct_name) { .email = "homer@simpson.com", .children = std::vector({bart, lisa, maggie})}; - write_and_read>(homer); + write_and_read_with_json>(homer); } } // namespace test_add_struct_name diff --git a/tests/avro/test_array.cpp b/tests/avro/test_array.cpp index 1c23263a..9c8e5e48 100644 --- a/tests/avro/test_array.cpp +++ b/tests/avro/test_array.cpp @@ -29,6 +29,6 @@ TEST(avro, test_array) { .children = std::make_unique>(std::array{ std::move(bart), std::move(lisa), std::move(maggie)})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_array diff --git a/tests/avro/test_box.cpp b/tests/avro/test_box.cpp index 0fa7aa9f..151f8583 100644 --- a/tests/avro/test_box.cpp +++ b/tests/avro/test_box.cpp @@ -35,7 +35,6 @@ TEST(avro, test_box) { const DecisionTree tree{.leaf_or_node = std::move(node)}; - write_and_read(tree); - + write_and_read_with_json(tree); } } // namespace test_box diff --git a/tests/avro/test_combined_processors.cpp b/tests/avro/test_combined_processors.cpp index f794b94a..354815b4 100644 --- a/tests/avro/test_combined_processors.cpp +++ b/tests/avro/test_combined_processors.cpp @@ -43,6 +43,6 @@ TEST(avro, test_combined_processors) { using Processors = rfl::Processors>; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_combined_processors diff --git a/tests/avro/test_custom_class1.cpp b/tests/avro/test_custom_class1.cpp index 9e9b5fae..bca796ee 100644 --- a/tests/avro/test_custom_class1.cpp +++ b/tests/avro/test_custom_class1.cpp @@ -30,6 +30,6 @@ struct Person { TEST(avro, test_custom_class1) { const auto bart = Person("Bart"); - write_and_read(bart); + write_and_read_with_json(bart); } } // namespace test_custom_class1 diff --git a/tests/avro/test_custom_class3.cpp b/tests/avro/test_custom_class3.cpp index ee68f209..715771c6 100644 --- a/tests/avro/test_custom_class3.cpp +++ b/tests/avro/test_custom_class3.cpp @@ -56,7 +56,7 @@ namespace test_custom_class3 { TEST(avro, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); - write_and_read(bart); + write_and_read_with_json(bart); } } // namespace test_custom_class3 diff --git a/tests/avro/test_custom_class4.cpp b/tests/avro/test_custom_class4.cpp index 831b86c0..0db5f0ca 100644 --- a/tests/avro/test_custom_class4.cpp +++ b/tests/avro/test_custom_class4.cpp @@ -58,6 +58,6 @@ TEST(avro, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); - write_and_read(bart); + write_and_read_with_json(bart); } } // namespace test_custom_class4 diff --git a/tests/avro/test_default_values.cpp b/tests/avro/test_default_values.cpp index a2407b0e..59a2b8cc 100644 --- a/tests/avro/test_default_values.cpp +++ b/tests/avro/test_default_values.cpp @@ -21,6 +21,6 @@ TEST(avro, test_default_values) { Person{.first_name = "Homer", .children = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_default_values diff --git a/tests/avro/test_deque.cpp b/tests/avro/test_deque.cpp index 8e65a47e..a8832f22 100644 --- a/tests/avro/test_deque.cpp +++ b/tests/avro/test_deque.cpp @@ -20,7 +20,6 @@ TEST(avro, test_default_values) { const auto homer = Person{.first_name = "Homer", .children = std::move(children)}; - write_and_read(homer); - + write_and_read_with_json(homer); } } // namespace test_deque diff --git a/tests/avro/test_enum.cpp b/tests/avro/test_enum.cpp index 18ad25a3..bafe9fad 100644 --- a/tests/avro/test_enum.cpp +++ b/tests/avro/test_enum.cpp @@ -16,7 +16,7 @@ struct Circle { TEST(avro, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; - write_and_read(circle); + write_and_read_with_json(circle); } } // namespace test_enum diff --git a/tests/avro/test_field_variant.cpp b/tests/avro/test_field_variant.cpp index d9760516..759280f5 100644 --- a/tests/avro/test_field_variant.cpp +++ b/tests/avro/test_field_variant.cpp @@ -26,6 +26,6 @@ TEST(avro, test_field_variant_std) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); - write_and_read(r); + write_and_read_with_json(r); } } // namespace test_field_variant diff --git a/tests/avro/test_field_variant_std.cpp b/tests/avro/test_field_variant_std.cpp index f61dca50..473e3ab7 100644 --- a/tests/avro/test_field_variant_std.cpp +++ b/tests/avro/test_field_variant_std.cpp @@ -26,6 +26,6 @@ TEST(avro, test_field_variant_std) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); - write_and_read(r); + write_and_read_with_json(r); } } // namespace test_field_variant_std diff --git a/tests/avro/test_flag_enum.cpp b/tests/avro/test_flag_enum.cpp index 38a14d3e..39e62e2b 100644 --- a/tests/avro/test_flag_enum.cpp +++ b/tests/avro/test_flag_enum.cpp @@ -26,7 +26,7 @@ TEST(avro, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; - write_and_read(circle); + write_and_read_with_json(circle); } } // namespace test_flag_enum diff --git a/tests/avro/test_flag_enum_with_int.cpp b/tests/avro/test_flag_enum_with_int.cpp index 3428f66d..45544b6a 100644 --- a/tests/avro/test_flag_enum_with_int.cpp +++ b/tests/avro/test_flag_enum_with_int.cpp @@ -25,7 +25,7 @@ struct Circle { TEST(avro, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; - write_and_read(circle); + write_and_read_with_json(circle); } } // namespace test_flag_enum_with_int diff --git a/tests/avro/test_flatten.cpp b/tests/avro/test_flatten.cpp index 46bc17af..4325afad 100644 --- a/tests/avro/test_flatten.cpp +++ b/tests/avro/test_flatten.cpp @@ -26,6 +26,6 @@ TEST(avro, test_flatten) { .employer = rfl::make_box("Mr. Burns"), .salary = 60000.0}; - write_and_read(employee); + write_and_read_with_json(employee); } } // namespace test_flatten diff --git a/tests/avro/test_flatten_anonymous.cpp b/tests/avro/test_flatten_anonymous.cpp index 6cebe8e5..8212f3e8 100644 --- a/tests/avro/test_flatten_anonymous.cpp +++ b/tests/avro/test_flatten_anonymous.cpp @@ -26,7 +26,7 @@ TEST(avro, test_flatten_anonymous) { .employer = rfl::make_box("Mr. Burns"), .salary = 60000.0}; - write_and_read(employee); + write_and_read_with_json(employee); } } // namespace test_flatten_anonymous diff --git a/tests/avro/test_float_and_int.cpp b/tests/avro/test_float_and_int.cpp new file mode 100644 index 00000000..091dcb3d --- /dev/null +++ b/tests/avro/test_float_and_int.cpp @@ -0,0 +1,38 @@ +#include +#include + +#include "write_and_read.hpp" + +namespace test_float_and_int { + +struct float_struct { + float i; +}; + +struct double_struct { + double i; +}; + +struct int_struct { + int i; +}; + +struct long_struct { + long i; +}; + +TEST(avro, test_float_and_int) { + float_struct test_float_struct{.i = 0.1}; + + double_struct test_double_struct{.i = 0.1}; + + int_struct test_int_struct{.i = 1}; + + long_struct test_long_struct{.i = 1}; + + write_and_read_with_json(test_float_struct); + write_and_read_with_json(test_double_struct); + write_and_read_with_json(test_int_struct); + write_and_read_with_json(test_long_struct); +} +} // namespace test_float_and_int diff --git a/tests/avro/test_map2.cpp b/tests/avro/test_map2.cpp index bd50cfa3..852fd58e 100644 --- a/tests/avro/test_map2.cpp +++ b/tests/avro/test_map2.cpp @@ -22,6 +22,6 @@ TEST(avro, test_map2) { const auto homer = Person{.first_name = "Homer", .children = std::move(children)}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_map2 diff --git a/tests/avro/test_monster_example.cpp b/tests/avro/test_monster_example.cpp index 3a0f7507..ef8ba215 100644 --- a/tests/avro/test_monster_example.cpp +++ b/tests/avro/test_monster_example.cpp @@ -53,6 +53,6 @@ TEST(avro, test_monster_example) { .weapons = weapons, .equipped = rfl::make_field<"weapon">(axe)}; - write_and_read(orc); + write_and_read_with_json(orc); } } // namespace test_monster_example diff --git a/tests/avro/test_optional_fields.cpp b/tests/avro/test_optional_fields.cpp index 9b5b0a24..0df4d7e1 100644 --- a/tests/avro/test_optional_fields.cpp +++ b/tests/avro/test_optional_fields.cpp @@ -24,6 +24,6 @@ TEST(avro, test_optional_fields) { Person{.first_name = "Homer", .children = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_optional_fields diff --git a/tests/avro/test_readme_example.cpp b/tests/avro/test_readme_example.cpp index c33614d7..38dc1880 100644 --- a/tests/avro/test_readme_example.cpp +++ b/tests/avro/test_readme_example.cpp @@ -40,6 +40,6 @@ TEST(avro, test_readme_example) { .email = "homer@simpson.com", .child = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_readme_example diff --git a/tests/avro/test_readme_example2.cpp b/tests/avro/test_readme_example2.cpp index 135ca15b..1fd0cf5a 100644 --- a/tests/avro/test_readme_example2.cpp +++ b/tests/avro/test_readme_example2.cpp @@ -15,6 +15,6 @@ TEST(avro, test_readme_example2) { const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_readme_example2 diff --git a/tests/avro/test_readme_example3.cpp b/tests/avro/test_readme_example3.cpp index 37903bfd..fbeb3d7b 100644 --- a/tests/avro/test_readme_example3.cpp +++ b/tests/avro/test_readme_example3.cpp @@ -25,6 +25,6 @@ TEST(avro, test_readme_example3) { .birthday = "1987-04-19", .children = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_readme_example3 diff --git a/tests/avro/test_ref.cpp b/tests/avro/test_ref.cpp index 6d812cf0..892dd908 100644 --- a/tests/avro/test_ref.cpp +++ b/tests/avro/test_ref.cpp @@ -23,7 +23,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -TEST(avro, test_ref) { +TEST(avro, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -35,7 +35,6 @@ TEST(avro, test_ref) { const DecisionTree tree{.leaf_or_node = std::move(node)}; - write_and_read(tree); - + write_and_read_with_json(tree); } } // namespace test_ref diff --git a/tests/avro/test_rfl_variant.cpp b/tests/avro/test_rfl_variant.cpp index d7b2090f..f3439b37 100644 --- a/tests/avro/test_rfl_variant.cpp +++ b/tests/avro/test_rfl_variant.cpp @@ -23,6 +23,6 @@ using Shapes = rfl::Variant>; TEST(avro, test_rfl_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); + write_and_read_with_json(r); } } // namespace test_variant diff --git a/tests/avro/test_set.cpp b/tests/avro/test_set.cpp index 83a04493..a80b0e44 100644 --- a/tests/avro/test_set.cpp +++ b/tests/avro/test_set.cpp @@ -11,13 +11,13 @@ struct Person { std::unique_ptr> children; }; -TEST(avro, test_set) { +TEST(avro, 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); + write_and_read_with_json(homer); } } // namespace test_set diff --git a/tests/avro/test_shared_ptr.cpp b/tests/avro/test_shared_ptr.cpp index 9026e213..31c91b29 100644 --- a/tests/avro/test_shared_ptr.cpp +++ b/tests/avro/test_shared_ptr.cpp @@ -23,6 +23,6 @@ TEST(avro, test_shared_ptr) { const auto homer = Person{.first_name = "Homer", .children = std::move(children)}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_shared_ptr diff --git a/tests/avro/test_snake_case_to_camel_case.cpp b/tests/avro/test_snake_case_to_camel_case.cpp index eea79fa3..3a2b1064 100644 --- a/tests/avro/test_snake_case_to_camel_case.cpp +++ b/tests/avro/test_snake_case_to_camel_case.cpp @@ -28,6 +28,6 @@ TEST(avro, test_snake_case_to_camel_case) { .birthday = "1987-04-19", .children = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_snake_case_to_camel_case diff --git a/tests/avro/test_snake_case_to_pascal_case.cpp b/tests/avro/test_snake_case_to_pascal_case.cpp index ea4b2270..7c623d0b 100644 --- a/tests/avro/test_snake_case_to_pascal_case.cpp +++ b/tests/avro/test_snake_case_to_pascal_case.cpp @@ -28,6 +28,6 @@ TEST(avro, test_snake_case_to_pascal_case) { .birthday = "1987-04-19", .children = std::vector({bart, lisa, maggie})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_snake_case_to_pascal_case diff --git a/tests/avro/test_string_map.cpp b/tests/avro/test_string_map.cpp index 4c4ed0c4..ad6869d1 100644 --- a/tests/avro/test_string_map.cpp +++ b/tests/avro/test_string_map.cpp @@ -14,6 +14,6 @@ TEST(avro, test_string_map) { homer.insert( std::make_pair("lastName", std::make_unique("Simpson"))); - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_string_map diff --git a/tests/avro/test_tagged_union.cpp b/tests/avro/test_tagged_union.cpp index 7e6f40e9..f00617dc 100644 --- a/tests/avro/test_tagged_union.cpp +++ b/tests/avro/test_tagged_union.cpp @@ -22,6 +22,6 @@ using Shapes = rfl::TaggedUnion<"shape", Rectangle, Circle, Square>; TEST(avro, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); + write_and_read_with_json(r); } } // namespace test_tagged_union diff --git a/tests/avro/test_timestamp.cpp b/tests/avro/test_timestamp.cpp index aa4d050b..cc13d0bf 100644 --- a/tests/avro/test_timestamp.cpp +++ b/tests/avro/test_timestamp.cpp @@ -14,7 +14,7 @@ struct Person { TS birthday; }; -TEST(avro, test_timestamp) { +TEST(avro, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { @@ -24,6 +24,6 @@ TEST(avro, test_timestamp) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19"}; - write_and_read(bart); + write_and_read_with_json(bart); } } // namespace test_timestamp diff --git a/tests/avro/test_tuple.cpp b/tests/avro/test_tuple.cpp index e9cd1233..98dde5d4 100644 --- a/tests/avro/test_tuple.cpp +++ b/tests/avro/test_tuple.cpp @@ -28,6 +28,6 @@ TEST(avro, test_tuple) { std::tuple{ std::move(bart), std::move(lisa), std::move(maggie)})}; - write_and_read(homer); + write_and_read_with_json(homer); } } // namespace test_tuple diff --git a/tests/avro/test_tutorial_example.cpp b/tests/avro/test_tutorial_example.cpp index 3d430b25..04f36fd4 100644 --- a/tests/avro/test_tutorial_example.cpp +++ b/tests/avro/test_tutorial_example.cpp @@ -4,21 +4,9 @@ #include #include -//#include "write_and_read.hpp" - /// The basic example from the Avro C tutorial. namespace test_tutorial_example { -const char PERSON_SCHEMA[] = - "{\"type\":\"record\",\ - \"name\":\"Person\",\ - \"fields\":[\ - {\"name\": \"ID\", \"type\": \"long\"},\ - {\"name\": \"First\", \"type\": \"string\"},\ - {\"name\": \"Last\", \"type\": \"string\"},\ - {\"name\": \"Phone\", \"type\": \"string\"},\ - {\"name\": \"Age\", \"type\": \"int\"}]}"; - struct Person { size_t ID; std::string First; @@ -33,12 +21,11 @@ TEST(avro, test_tutorial_example) { .Last = "Graves", .Phone = "(555) 123-5678", .Age = 30}; - const auto schema = rfl::avro::Schema::from_json(PERSON_SCHEMA); - const auto serialized1 = rfl::avro::write(person, schema.value()); - const auto res = rfl::avro::read(serialized1, schema.value()); + const auto serialized1 = rfl::avro::write(person); + const auto res = rfl::avro::read(serialized1); EXPECT_TRUE(res && true) << "Test failed on read. Error: " << res.error().what(); - const auto serialized2 = rfl::avro::write(res.value(), schema.value()); + const auto serialized2 = rfl::avro::write(res.value()); EXPECT_EQ(serialized1, serialized2); } } // namespace test_tutorial_example diff --git a/tests/avro/write_and_read.hpp b/tests/avro/write_and_read.hpp index 7a8f801b..f60168b7 100644 --- a/tests/avro/write_and_read.hpp +++ b/tests/avro/write_and_read.hpp @@ -4,6 +4,8 @@ #include #include +#include +#include template void write_and_read(const auto& _struct) { @@ -15,4 +17,17 @@ void write_and_read(const auto& _struct) { const auto serialized2 = rfl::avro::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::avro::write(_struct); + const auto res = rfl::avro::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().what(); + const auto serialized2 = rfl::avro::write(res.value()); + EXPECT_EQ(serialized1, serialized2); + EXPECT_EQ(rfl::json::write(_struct), + rfl::json::write(res.value())); +} #endif