From 2aa2af0007b7e969845642027c635cd3fd9c8aea Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Wed, 3 May 2023 20:34:02 +0200 Subject: Moved dirs and added codec-json dir --- src/codec/.nix/derivation.nix | 31 +++++++++++++++ src/codec/SConscript | 38 ++++++++++++++++++ src/codec/SConstruct | 66 ++++++++++++++++++++++++++++++++ src/codec/data.h | 89 +++++++++++++++++++++++++++++++++++++++++++ src/codec/proto_kel.h | 41 ++++++++++++++++++++ src/codec/schema.h | 79 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 344 insertions(+) create mode 100644 src/codec/.nix/derivation.nix create mode 100644 src/codec/SConscript create mode 100644 src/codec/SConstruct create mode 100644 src/codec/data.h create mode 100644 src/codec/proto_kel.h create mode 100644 src/codec/schema.h (limited to 'src/codec') diff --git a/src/codec/.nix/derivation.nix b/src/codec/.nix/derivation.nix new file mode 100644 index 0000000..c9fac2e --- /dev/null +++ b/src/codec/.nix/derivation.nix @@ -0,0 +1,31 @@ +{ lib +, stdenvNoCC +, scons +, clang +, clang-tools +, version +, forstio +}: + +let + +in stdenvNoCC.mkDerivation { + pname = "forstio-codec"; + inherit version; + + src = ./..; + + enableParallelBuilding = true; + + buildInputs = [ + forstio.core + ]; + + nativeBuildInputs = [ + scons + clang + clang-tools + ]; + + outputs = ["out" "dev"]; +} diff --git a/src/codec/SConscript b/src/codec/SConscript new file mode 100644 index 0000000..c038d42 --- /dev/null +++ b/src/codec/SConscript @@ -0,0 +1,38 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +codec_env = env.Clone(); + +codec_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +codec_env.headers = sorted(glob.glob(dir_path + "/*.h")) + +env.sources += codec_env.sources; +env.headers += codec_env.headers; + +## Shared lib +objects_shared = [] +codec_env.add_source_files(objects_shared, codec_env.sources, shared=True); +codec_env.library_shared = codec_env.SharedLibrary('#build/forstio-codec', [objects_shared]); + +## Static lib +objects_static = [] +codec_env.add_source_files(objects_static, codec_env.sources, shared=False); +codec_env.library_static = codec_env.StaticLibrary('#build/forstio-codec', [objects_static]); + +# Set Alias +env.Alias('library_codec', [codec_env.library_shared, codec_env.library_static]); + +env.targets += ['library_codec']; + +# Install +env.Install('$prefix/lib/', [codec_env.library_shared, codec_env.library_static]); +env.Install('$prefix/include/forstio/codec/', [codec_env.headers]); diff --git a/src/codec/SConstruct b/src/codec/SConstruct new file mode 100644 index 0000000..0d7b7c6 --- /dev/null +++ b/src/codec/SConstruct @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=['forstio-core']) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/src/codec/data.h b/src/codec/data.h new file mode 100644 index 0000000..1682ae7 --- /dev/null +++ b/src/codec/data.h @@ -0,0 +1,89 @@ +#pragma once + +#include +#include "schema.h" + +namespace saw { +namespace encode { +struct Native {}; +} +/* + * Helper for the basic message container, so the class doesn't have to be + * specialized 10 times. + */ +template struct native_data_type; + +template <> +struct native_data_type> { + using type = int8_t; +}; + +template <> +struct native_data_type> { + using type = int16_t; +}; + +template <> +struct native_data_type> { + using type = int32_t; +}; + +template <> +struct native_data_type> { + using type = int64_t; +}; + +template <> +struct native_data_type> { + using type = uint8_t; +}; + +template <> +struct native_data_type> { + using type = uint16_t; +}; + +template <> +struct native_data_type> { + using type = uint32_t; +}; + +template <> +struct native_data_type> { + using type = uint64_t; +}; + +template <> +struct native_data_type> { + using type = float; +}; + +template +class data { +private: + static_assert(always_false, "Type not supported"); +}; + +template<> +class data { +private: + std::string value_; +public: + SAW_FORBID_COPY(data); + + data(std::string&& value__):value_{std::move(value__)}{} + + std::size_t size() const { + return value_.size(); + } + + bool operator==(const data& data){ + return value_ == data.value_; + } +}; + +template +class data, encode::Native> { +private: +}; +} diff --git a/src/codec/proto_kel.h b/src/codec/proto_kel.h new file mode 100644 index 0000000..3b4ebac --- /dev/null +++ b/src/codec/proto_kel.h @@ -0,0 +1,41 @@ +#pragma once + +#include "data.h" + +#include + +namespace saw { +namespace encode { +struct ProtoKel {}; +} + +template +class data { +private: + own buffer_; +public: + data(own&& buffer__):buffer_{std::move(buffer__)}{} + + buffer& get_buffer(){ + return *buffer_; + } + + const buffer& get_buffer() const { + return *buffer_; + } +}; + +template +class codec { +private: +public: + error_or> decode(const data& encoded){ + return make_error(); + } + + error_or> encode(const data& native){ + return make_error(); + } +}; +} +} diff --git a/src/codec/schema.h b/src/codec/schema.h new file mode 100644 index 0000000..b23aaa1 --- /dev/null +++ b/src/codec/schema.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include + +namespace saw { +namespace schema { +// NOLINTBEGIN +template struct NamedMember {}; + +template struct Struct { + static_assert( + always_false, + "This schema template doesn't support this type of template argument"); +}; + +template +struct Struct...> {}; + +template struct Union { + static_assert( + always_false, + "This schema template doesn't support this type of template argument"); +}; + +template +struct Union...> {}; + +template struct Array {}; + +template FixedArray {}; + +template struct Tuple {}; + +struct String {}; + +struct SignedInteger {}; +struct UnsignedInteger {}; +struct FloatingPoint {}; + +template struct Primitive { + static_assert(((std::is_same_v || + std::is_same_v)&&(N == 1 || N == 2 || + N == 4 || N == 8)) || + (std::is_same_v && (N == 4 || N == 8)), + "Primitive Type is not supported"); +}; + +using Int8 = Primitive; +using Int16 = Primitive; +using Int32 = Primitive; +using Int64 = Primitive; + +using UInt8 = Primitive; +using UInt16 = Primitive; +using UInt32 = Primitive; +using UInt64 = Primitive; + +using Float32 = Primitive; +using Float64 = Primitive; + +/** + * Classes enabling Rpc calls + */ +template +struct Function {}; + +template struct Interface { + static_assert( + always_false, + "This schema template doesn't support this type of template argument"); +}; + +template +struct Interface...> {}; + +// NOLINTEND +} // namespace schema +} // namespace saw -- cgit v1.2.3