diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-06-05 08:41:27 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-06-05 08:41:27 +0200 |
commit | 07fd10c0584c7f0827dfd3ff8319e4cb174e5973 (patch) | |
tree | cfb095c15076fdc7df2a4bf208e3170f96c4dbcb /src | |
parent | 766120ab30d9dfc1f74e57ea7062f62796e244f3 (diff) |
codec-json, c++: Initial ideas for json codec.
Technically We do have to transcode and the language we are transcoding
from requires to have some restriction rules as an argument.
Diffstat (limited to 'src')
-rw-r--r-- | src/codec-json/json.h | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/src/codec-json/json.h b/src/codec-json/json.h index 2c5b83e..0ba7a2d 100644 --- a/src/codec-json/json.h +++ b/src/codec-json/json.h @@ -1,12 +1,81 @@ #pragma once +#include <forstio/core/buffer.h> +#include <forstio/core/common.h> +#include <forstio/codec/data.h> + +#include <algorithm> + namespace saw { -namespace encoded { +namespace encode { struct Json {}; } template<typename Schema> -class codec<Schema, Json> { +class data<Schema, encode::Json> { +private: + own<buffer> buffer_; +public: + data() = default; + + void reserve(std::size_t i){ + buffer_.reserve(i); + } + + void concat(int8_t c){ + buffer_.emplace_back(c); + } + + std::size_t get_size() const { + return buffer_.size(); + } + + int8_t& at(std::size_t i){ + return buffer_.at(i); + } + + const int8_t& at(std::size_t i) const { + return buffer_.at(i); + } +}; + +/** + * Codec class for json + */ +template<typename Schema> +class codec<Schema, encode::Json> { +public: + struct config { + size_t depth = 16; + size_t length = 1024; + }; +private: + config cfg_; +public: + /** + * Default constructor + */ + config(){} + + /** + * Constructor + */ + codec(config cfg__):cfg_{std::move(cfg__)}{} + + SAW_FORBID_COPY(codec); + SAW_DEFAULT_MOVE(codec); + + template <typename FromEncoding> + ErrorOr<void> encode(const data<Schema, FromEncoding>& from_encode, data<Schema, encode::Json>& to_encode){ + // To Be encoded + + + return Void {}; + } + template <typename ToEncoding> + ErrorOr<void> decode(const data<Schema, encode::Json>& from_decode, data<Schema, ToEncoding>& to_decode){ + return Void {}; + } }; } |