diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-02-14 11:17:23 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-02-14 11:17:23 +0100 |
commit | 2b072c7ec0578ce96b20e076fc6601d90e8b9dcc (patch) | |
tree | 019c0441d83c07df8d16301963ffcea6a1dc2beb /modules/codec-json | |
parent | d6380ea2911800882e1470e4ce1172bbeabf5dd2 (diff) |
codec-json: Trying to add more prettyfied json encoding
Diffstat (limited to 'modules/codec-json')
-rw-r--r-- | modules/codec-json/c++/json.hpp | 2 | ||||
-rw-r--r-- | modules/codec-json/c++/json.tmpl.hpp | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/modules/codec-json/c++/json.hpp b/modules/codec-json/c++/json.hpp index 20342e3..b77f328 100644 --- a/modules/codec-json/c++/json.hpp +++ b/modules/codec-json/c++/json.hpp @@ -95,7 +95,7 @@ public: /** * Constructor */ - codec(const codec_config<encode::Json>& cfg__):cfg_{cfg_}{} + codec(const codec_config<encode::Json>& cfg__):cfg_{cfg__}{} SAW_FORBID_COPY(codec); SAW_DEFAULT_MOVE(codec); diff --git a/modules/codec-json/c++/json.tmpl.hpp b/modules/codec-json/c++/json.tmpl.hpp index 748f2c2..e8226f9 100644 --- a/modules/codec-json/c++/json.tmpl.hpp +++ b/modules/codec-json/c++/json.tmpl.hpp @@ -176,11 +176,23 @@ struct json_encode<schema::Array<T,D>, FromEncode> { template<size_t Level> static error_or<void> encode_level(const data<Schema, FromEncode>& from, buffer& to, std::array<std::size_t, D>& index, uint64_t depth, bool pretty){ if constexpr (Level == D){ + if(pretty){ + auto eov = json_helper::print_pretty_indent(to, depth); + if(eov.is_error()){ + return eov; + } + } auto eov = json_encode<T, FromEncode>::encode(from.at(index), to, depth, pretty); if(eov.is_error()){ return eov; } } else { + if(pretty){ + auto eov = json_helper::print_pretty_indent(to, depth); + if(eov.is_error()){ + return eov; + } + } { auto err = to.push('['); if(!err.template is_type<err::no_error>()){ @@ -284,6 +296,12 @@ struct json_encode<schema::Struct<schema::Member<T,Key>...>, FromEncode> { template<size_t i> static error_or<void> encode_element(const data<Schema, FromEncode>& from, buffer& to, uint64_t depth, bool pretty){ + if(pretty){ + auto eov = json_helper::print_pretty_indent(to, depth); + if(eov.is_error()){ + return eov; + } + } // Encode the name { std::string_view view = parameter_key_pack_type<i, Key...>::literal.view(); @@ -339,7 +357,13 @@ struct json_encode<schema::Struct<schema::Member<T,Key>...>, FromEncode> { } } if constexpr ( sizeof...(T) > 0 ){ - auto eov = encode_element<0>(from, to, depth, pretty); + auto eov = encode_element<0>(from, to, depth+1u, pretty); + if(eov.is_error()){ + return eov; + } + } + if(pretty){ + auto eov = json_helper::print_pretty_indent(to, depth); if(eov.is_error()){ return eov; } |