From d6380ea2911800882e1470e4ce1172bbeabf5dd2 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 14 Feb 2024 11:06:11 +0100 Subject: codec-json: Prettified tuple encoding --- modules/codec-json/c++/json.hpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'modules/codec-json/c++/json.hpp') diff --git a/modules/codec-json/c++/json.hpp b/modules/codec-json/c++/json.hpp index ad29acb..20342e3 100644 --- a/modules/codec-json/c++/json.hpp +++ b/modules/codec-json/c++/json.hpp @@ -59,6 +59,20 @@ public: return buffer_.read(i); } }; + +template +struct codec_config; + +template<> +struct codec_config { + uint64_t depth = 16u; + uint64_t length = 4096u; + bool pretty = false; + + bool is_within(uint64_t bytes, uint64_t d){ + return bytes <= length && d <= depth; + } +}; } #include "json.tmpl.hpp" @@ -70,14 +84,8 @@ namespace saw { */ template class codec { -public: - struct config { - size_t depth = 16; - size_t length = 4096; - bool pretty = false; - }; private: - config cfg_; + codec_config cfg_; public: /** * Default constructor @@ -87,7 +95,7 @@ public: /** * Constructor */ - codec(config cfg__):cfg_{std::move(cfg__)}{} + codec(const codec_config& cfg__):cfg_{cfg_}{} SAW_FORBID_COPY(codec); SAW_DEFAULT_MOVE(codec); @@ -96,7 +104,7 @@ public: error_or encode(const data& from_encode, data& to_encode){ // To Be encoded buffer_view buff_v{to_encode.get_buffer()}; - auto eov = impl::json_encode::encode(from_encode, buff_v); + auto eov = impl::json_encode::encode(from_encode, buff_v, 0, cfg_.pretty); if(eov.is_error()){ return std::move(eov.get_error()); } -- cgit v1.2.3