From 7779119ea724987128ebd4bb4c0433dee8b5f877 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Wed, 14 Jun 2023 12:51:20 +0200 Subject: c++: Let test run in test-case derivation and ammend changed schema dimension changes --- src/codec-json/json.tmpl.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/codec-json/json.tmpl.h') diff --git a/src/codec-json/json.tmpl.h b/src/codec-json/json.tmpl.h index 38959b2..0d1c7f0 100644 --- a/src/codec-json/json.tmpl.h +++ b/src/codec-json/json.tmpl.h @@ -227,5 +227,81 @@ struct json_encode...>, RootSchema, FromEnc return void_t{}; } }; + +template +struct json_encode...>, RootSchema, FromEncode> { + + template + static error_or encode_element(const data...>, FromEncode>& from, buffer& to){ + if(from.template holds_alternative::literal>()){ + // Encode the name + { + std::string_view view = parameter_key_pack_type::literal.view(); + error err = to.push('"'); + if(!err.template is_type()){ + return err; + } + err = to.push(*reinterpret_cast(view.data()), view.size()); + if(!err.template is_type()){ + return err; + } + err = to.push('"'); + if(!err.template is_type()){ + return err; + } + } + // Add the separator + { + auto eov_ele = to.push(':'); + if(!eov_ele.template is_type()){ + return eov_ele; + } + } + + // Encode the value + auto eov = json_encode::type, RootSchema, FromEncode>::encode(from.template get::literal>(), to); + } + // Go to the next element + if constexpr ( (i+1) < sizeof...(T)){ + { + auto eov_ele = encode_element(from, to); + if(eov_ele.is_error()){ + return eov_ele; + } + } + + + } + + return void_t{}; + } + static error_or encode(const data...>, FromEncode>& from, buffer& to) { + { + auto err = to.push('{'); + if(!err.template is_type()){ + return err; + } + } + if constexpr ( sizeof...(T) > 0 ){ + auto eov = encode_element<0>(from, to); + if(eov.is_error()){ + return eov; + } + } + { + auto err = to.push('}'); + if(!err.template is_type()){ + return err; + } + } + + return void_t{}; + } +}; + +template +struct json_decode; + + } } -- cgit v1.2.3