diff options
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/.nix/derivation.nix | 31 | ||||
-rw-r--r-- | src/codec/SConscript | 38 | ||||
-rw-r--r-- | src/codec/SConstruct | 66 | ||||
-rw-r--r-- | src/codec/data.h | 89 | ||||
-rw-r--r-- | src/codec/proto_kel.h | 41 | ||||
-rw-r--r-- | src/codec/schema.h | 79 |
6 files changed, 344 insertions, 0 deletions
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 <forstio/core/common.h> +#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 <class T> struct native_data_type; + +template <> +struct native_data_type<schema::Primitive<schema::SignedInteger, 1>> { + using type = int8_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::SignedInteger, 2>> { + using type = int16_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::SignedInteger, 4>> { + using type = int32_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::SignedInteger, 8>> { + using type = int64_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::UnsignedInteger, 1>> { + using type = uint8_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::UnsignedInteger, 2>> { + using type = uint16_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::UnsignedInteger, 4>> { + using type = uint32_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::UnsignedInteger, 8>> { + using type = uint64_t; +}; + +template <> +struct native_data_type<schema::Primitive<schema::FloatingPoint, 4>> { + using type = float; +}; + +template<typename T, typename Encoding = encode::Native> +class data { +private: + static_assert(always_false<T>, "Type not supported"); +}; + +template<> +class data<schema::String, encode::Native> { +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<schema::String, encode::Native>& data){ + return value_ == data.value_; + } +}; + +template<typename T, size_t N> +class data<schema::Primitive<T,N>, 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 <forstio/core/error.h> + +namespace saw { +namespace encode { +struct ProtoKel {}; +} + +template<typename Schema> +class data<Schema, encode::ProtoKel> { +private: + own<buffer> buffer_; +public: + data(own<buffer>&& buffer__):buffer_{std::move(buffer__)}{} + + buffer& get_buffer(){ + return *buffer_; + } + + const buffer& get_buffer() const { + return *buffer_; + } +}; + +template<typename Schema> +class codec<Schema, encode::ProtoKel> { +private: +public: + error_or<data<Schema, encode::Native>> decode(const data<Schema, encode::ProtoKel>& encoded){ + return make_error<err::not_implemented>(); + } + + error_or<data<Schema, encode::ProtoKel>> encode(const data<Schema, encode::Native>& native){ + return make_error<err::not_implemented>(); + } +}; +} +} 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 <forstio/common.h> +#include <forstio/string_literal.h> + +namespace saw { +namespace schema { +// NOLINTBEGIN +template <typename T, string_literal Literal> struct NamedMember {}; + +template <typename... T> struct Struct { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <typename... V, string_literal... K> +struct Struct<NamedMember<V, K>...> {}; + +template <typename... T> struct Union { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <typename... V, string_literal... K> +struct Union<NamedMember<V, K>...> {}; + +template <typename T> struct Array {}; + +template<typename T, size_t S> FixedArray {}; + +template <typename... T> struct Tuple {}; + +struct String {}; + +struct SignedInteger {}; +struct UnsignedInteger {}; +struct FloatingPoint {}; + +template <class T, size_t N> struct Primitive { + static_assert(((std::is_same_v<T, SignedInteger> || + std::is_same_v<T, UnsignedInteger>)&&(N == 1 || N == 2 || + N == 4 || N == 8)) || + (std::is_same_v<T, FloatingPoint> && (N == 4 || N == 8)), + "Primitive Type is not supported"); +}; + +using Int8 = Primitive<SignedInteger, 1>; +using Int16 = Primitive<SignedInteger, 2>; +using Int32 = Primitive<SignedInteger, 4>; +using Int64 = Primitive<SignedInteger, 8>; + +using UInt8 = Primitive<UnsignedInteger, 1>; +using UInt16 = Primitive<UnsignedInteger, 2>; +using UInt32 = Primitive<UnsignedInteger, 4>; +using UInt64 = Primitive<UnsignedInteger, 8>; + +using Float32 = Primitive<FloatingPoint, 4>; +using Float64 = Primitive<FloatingPoint, 8>; + +/** + * Classes enabling Rpc calls + */ +template <class Request, class Response, string_literal Literal> +struct Function {}; + +template <class... T> struct Interface { + static_assert( + always_false<T...>, + "This schema template doesn't support this type of template argument"); +}; + +template <class... Request, class... Response, string_literal... Literal> +struct Interface<Function<Request, Response, Literal>...> {}; + +// NOLINTEND +} // namespace schema +} // namespace saw |