From c307c74cd6905937558d67829389718c64f75f1e Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Sun, 3 Mar 2024 08:42:11 +0100 Subject: [PATCH] Added a to_schema method to the CustomParser --- include/rfl/parsing/CustomParser.hpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/include/rfl/parsing/CustomParser.hpp b/include/rfl/parsing/CustomParser.hpp index 0192b206..fbebd9ab 100644 --- a/include/rfl/parsing/CustomParser.hpp +++ b/include/rfl/parsing/CustomParser.hpp @@ -7,15 +7,14 @@ #include "../internal/has_to_class_method_v.hpp" #include "../internal/to_ptr_field_tuple.hpp" #include "Parser.hpp" +#include "schema/Type.hpp" namespace rfl { namespace parsing { -template +template struct CustomParser { - static Result read(const ReaderType& _r, - const auto& _var) noexcept { + static Result read(const R& _r, const auto& _var) noexcept { const auto to_class = [](auto&& _h) -> Result { try { if constexpr (internal::has_to_class_method_v) { @@ -31,15 +30,20 @@ struct CustomParser { return Error(e.what()); } }; - return Parser::read(_r, _var) - .and_then(to_class); + return Parser::read(_r, _var).and_then(to_class); } template - static auto write(const WriterType& _w, const OriginalClass& _p, + static auto write(const W& _w, const OriginalClass& _p, const P& _parent) noexcept { - Parser::write( - _w, HelperStruct::from_class(_p), _parent); + Parser::write(_w, HelperStruct::from_class(_p), + _parent); + } + + static schema::Type to_schema( + std::map* _definitions) { + return Parser>::to_schema( + _definitions); } };