#pragma once #include #include #include #include namespace saw { namespace encode { struct Json {}; } } #include "json.tmpl.h" namespace saw { template class data { private: ring_buffer buffer_; public: data():buffer_{}{} buffer& get_buffer(){ return buffer_; } void push(uint8_t val){ buffer_.push(val); } std::size_t get_size() const { return buffer_.read_composite_length(); } uint8_t& at(std::size_t i){ return buffer_.read(i); } const uint8_t& at(std::size_t i) const { return buffer_.read(i); } }; /** * Codec class for json */ template class codec { public: struct config { size_t depth = 16; size_t length = 1024; }; private: config cfg_; public: /** * Default constructor */ codec(){} /** * Constructor */ codec(config cfg__):cfg_{std::move(cfg__)}{} SAW_FORBID_COPY(codec); SAW_DEFAULT_MOVE(codec); template error_or encode(const data& from_encode, data& to_encode){ // To Be encoded return impl::json_encode::encode(from_encode, to_encode); } template error_or decode(const data& from_decode, data& to_decode){ return void_t {}; } }; }