From 73fac05aa07a0dd16f7061baddd4b934c7855fed Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sat, 10 Jun 2023 23:45:17 +0200 Subject: c++: Setting up testing progress --- src/codec-json/json.h | 40 +++++++++++++++++++++------------------- src/codec-json/json.tmpl.h | 17 +++++++++-------- src/codec/data.h | 2 ++ src/codec/forst.h | 13 +++++++++++++ src/core/error.cpp | 4 ++-- src/core/error.h | 4 ++-- src/core/templates.h | 2 ++ 7 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 src/codec/forst.h (limited to 'src') diff --git a/src/codec-json/json.h b/src/codec-json/json.h index f23aff9..c8456b5 100644 --- a/src/codec-json/json.h +++ b/src/codec-json/json.h @@ -4,40 +4,43 @@ #include #include -#include "json.tmpl.h" - #include namespace saw { namespace encode { struct Json {}; } +} + +#include "json.tmpl.h" + +namespace saw { template class data { private: - own buffer_; + ring_buffer buffer_; public: - - data(): - buffer_{heap()} - {} + data():buffer_{}{} buffer& get_buffer(){ - assert(buffer_); - return *buffer_; + return buffer_; + } + + void push(uint8_t val){ + buffer_.push(val); } std::size_t get_size() const { - return buffer_.size(); + return buffer_.read_composite_length(); } uint8_t& at(std::size_t i){ - return buffer_.at(i); + return buffer_.read(i); } const uint8_t& at(std::size_t i) const { - return buffer_.at(i); + return buffer_.read(i); } }; @@ -57,7 +60,7 @@ public: /** * Default constructor */ - config(){} + codec(){} /** * Constructor @@ -68,16 +71,15 @@ public: SAW_DEFAULT_MOVE(codec); template - ErrorOr encode(const data& from_encode, data& to_encode){ + error_or encode(const data& from_encode, data& to_encode){ // To Be encoded - - - return Void {}; + return impl::json_encode::encode(from_encode, to_encode); } template - ErrorOr decode(const data& from_decode, data& to_decode){ - return Void {}; + error_or decode(const data& from_decode, data& to_decode){ + return void_t {}; } }; } + diff --git a/src/codec-json/json.tmpl.h b/src/codec-json/json.tmpl.h index 3699e10..a19e3dc 100644 --- a/src/codec-json/json.tmpl.h +++ b/src/codec-json/json.tmpl.h @@ -5,23 +5,23 @@ namespace saw { namespace impl { template -class json_encode_impl { +class json_encode { static_assert(always_false, "This schema type is not being handle by the json encoding."); }; template -class json_encode_impl, RootSchema, FromEncode> { - static ErrorOr encode(const data& from, data& to, size_t ptr) { +struct json_encode, RootSchema, FromEncode> { + static error_or encode(const data, FromEncode>& from, data, encode::Json>& to) { auto val = from.get(); std::array data; - auto tc_result = std::to_chars(reinterpret_cast(data.data()), reinrepret_cast(data.data())+data.size(), val); + auto tc_result = std::to_chars(reinterpret_cast(data.data()), reinterpret_cast(data.data())+data.size(), val); if(tc_result.ec != std::errc{}){ return make_error(); } size_t bytes_written = 0; - for(auto ptr = data.data(); ptr != tc_result.ptr; ++ptr){ + for(char* ptr = reinterpret_cast(data.data()); ptr != tc_result.ptr; ++ptr){ ++bytes_written; } @@ -31,11 +31,12 @@ class json_encode_impl, RootSchema, FromEncode> { return std::move(err); } - for(auto ptr = data.data(); ptr != tc_result.ptr; ++ptr){ - buff.push(ptr[0]); + for(char* ptr = reinterpret_cast(data.data()); ptr != tc_result.ptr; ++ptr){ + uint8_t* un_ptr = reinterpret_cast(ptr); + buff.push(un_ptr[0]); } - return Void{}; + return void_t{}; } }; } diff --git a/src/codec/data.h b/src/codec/data.h index 30b5239..895a2fb 100644 --- a/src/codec/data.h +++ b/src/codec/data.h @@ -11,6 +11,8 @@ namespace saw { namespace encode { struct Native {}; } +template +class codec; /* * Helper for the basic message container, so the class doesn't have to be * specialized 10 times. diff --git a/src/codec/forst.h b/src/codec/forst.h new file mode 100644 index 0000000..fee5fa6 --- /dev/null +++ b/src/codec/forst.h @@ -0,0 +1,13 @@ +#pragma once + +#include "data.h" + +namespace saw { +namespace encode { +struct Forst {}; +} + +class data { + +}; +} diff --git a/src/core/error.cpp b/src/core/error.cpp index 7258740..ef8dc57 100644 --- a/src/core/error.cpp +++ b/src/core/error.cpp @@ -32,7 +32,7 @@ const std::string_view error::get_message() const { } bool error::failed() const { - return this->is_error(); + return this->is_type(); } bool error::is_critical() const { @@ -104,7 +104,7 @@ error_or error_registry::search_or_register_id(const std::string_vi auto& err = err_or_id.get_error(); - if(err.is_error()){ + if(err.is_type()){ size_t new_index = infos.size(); if(new_index == std::numeric_limits::max()){ return make_error("Error registry ids are exhausted"); diff --git a/src/core/error.h b/src/core/error.h index 2ed7cd4..32eab1e 100644 --- a/src/core/error.h +++ b/src/core/error.h @@ -48,7 +48,7 @@ public: code get_id() const; template - bool is_error() const; + bool is_type() const; }; template @@ -225,7 +225,7 @@ private: }; template -bool error::is_error() const { +bool error::is_type() const { return error_code_ == impl::get_template_id(); } diff --git a/src/core/templates.h b/src/core/templates.h index 9b4bcac..6c0a74e 100644 --- a/src/core/templates.h +++ b/src/core/templates.h @@ -1,5 +1,7 @@ #pragma once +#include "string_literal.h" + namespace saw { template struct parameter_pack_index; -- cgit v1.2.3