diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-02-14 11:06:11 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-02-14 11:06:11 +0100 |
commit | d6380ea2911800882e1470e4ce1172bbeabf5dd2 (patch) | |
tree | a45e451d9f8c2e676a4f44e7f6e822e50893fb55 /modules/codec-json/c++/json.hpp | |
parent | d1d40903a582099762db04feeec451d7f0a617a8 (diff) |
codec-json: Prettified tuple encoding
Diffstat (limited to 'modules/codec-json/c++/json.hpp')
-rw-r--r-- | modules/codec-json/c++/json.hpp | 26 |
1 files changed, 17 insertions, 9 deletions
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<typename Encoding> +struct codec_config; + +template<> +struct codec_config<encode::Json> { + 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<typename Schema> class codec<Schema, encode::Json> { -public: - struct config { - size_t depth = 16; - size_t length = 4096; - bool pretty = false; - }; private: - config cfg_; + codec_config<encode::Json> cfg_; public: /** * Default constructor @@ -87,7 +95,7 @@ public: /** * Constructor */ - codec(config cfg__):cfg_{std::move(cfg__)}{} + codec(const codec_config<encode::Json>& cfg__):cfg_{cfg_}{} SAW_FORBID_COPY(codec); SAW_DEFAULT_MOVE(codec); @@ -96,7 +104,7 @@ public: error_or<void> encode(const data<Schema, FromEncoding>& from_encode, data<Schema, encode::Json>& to_encode){ // To Be encoded buffer_view buff_v{to_encode.get_buffer()}; - auto eov = impl::json_encode<Schema, FromEncoding>::encode(from_encode, buff_v); + auto eov = impl::json_encode<Schema, FromEncoding>::encode(from_encode, buff_v, 0, cfg_.pretty); if(eov.is_error()){ return std::move(eov.get_error()); } |