diff options
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()); } |