From 8dad985328e2183b224300aa992951131956fdb3 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 23 Jan 2024 13:12:11 +0100 Subject: core,codec-json,codec-minecraft,codec-netcdf,codec,io-tls,io,io_codec,window,window-opengl: Renamed file endings and changed includes --- modules/codec-minecraft/minecraft.h | 116 ------------------------------- modules/codec-minecraft/minecraft.hpp | 116 +++++++++++++++++++++++++++++++ modules/codec-minecraft/var_int_data.h | 31 --------- modules/codec-minecraft/var_int_data.hpp | 31 +++++++++ 4 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 modules/codec-minecraft/minecraft.h create mode 100644 modules/codec-minecraft/minecraft.hpp delete mode 100644 modules/codec-minecraft/var_int_data.h create mode 100644 modules/codec-minecraft/var_int_data.hpp (limited to 'modules/codec-minecraft') diff --git a/modules/codec-minecraft/minecraft.h b/modules/codec-minecraft/minecraft.h deleted file mode 100644 index c54549e..0000000 --- a/modules/codec-minecraft/minecraft.h +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace saw { -namespace encode { -struct Minecraft {}; -struct VarIntTransport {}; -} - -template -class data { -private: - ring_buffer buffer_; -public: - data() = default; - data(std::size_t size): - buffer_{size} - {} - - buffer& get_buffer(){ - return buffer_; - } -}; - -namespace mc { -namespace impl { -union minecraft_signed_four_conversion { - int32_t s; - uint32_t u; -}; - -union minecraft_signed_eight_conversion { - int64_t s; - uint64_t u; -}; - -template -class minecraft_encode { - static_assert(always_false, "This schema type is not being handled by the Minecraft encoding."); -}; - -template -class minecraft_encode{ - static error_or encode(const data& from, buffer& to){ - uint8_t encode_index = 0; - minecraft_signed_four_conversion value; - value.s = from.get(); - - /** - * VarInt max length is 5 bytes - */ - std::array encode_data; - - do { - uint8_t step = static_cast(value.u & 0x7F); - value.u = value.u >> 7; - if(value.u != 0){ - step |= 0x80; - } - encode_data[encode_index] = step; - ++encode_index; - }while(value.u != 0); - - auto err = buffer.push(encode_data[0], encode_index); - if (!err.template is_type()) { - return err; - } - - return no_error(); - } -}; - -template -class minecraft_decode { - static_assert(always_false, "This schema type is not being handled by the Minecraft encoding."); -}; - -template -class minecraft_decode{ - static error_or decode(buffer& from, data& to){ - uint8_t num_reads = 0; - - minecraft_signed_four_conversion value; - value.u = 0; - - uint8_t read{}; - do { - auto err = from.pop(read); - if( !err.template is_type() ){ - return err; - } - value.u |= ((read & 0x7F) << (7*num_reads)); - ++num_reads; - if(num_reads > 5){ - return make_error(); - } - } while( (read & 0x80) != 0); - - to.set(value.s); - - return no_error(); - } -}; - -} -} - - - -namespace mc { - -} -} diff --git a/modules/codec-minecraft/minecraft.hpp b/modules/codec-minecraft/minecraft.hpp new file mode 100644 index 0000000..c54549e --- /dev/null +++ b/modules/codec-minecraft/minecraft.hpp @@ -0,0 +1,116 @@ +#pragma once + +#include +#include +#include + +namespace saw { +namespace encode { +struct Minecraft {}; +struct VarIntTransport {}; +} + +template +class data { +private: + ring_buffer buffer_; +public: + data() = default; + data(std::size_t size): + buffer_{size} + {} + + buffer& get_buffer(){ + return buffer_; + } +}; + +namespace mc { +namespace impl { +union minecraft_signed_four_conversion { + int32_t s; + uint32_t u; +}; + +union minecraft_signed_eight_conversion { + int64_t s; + uint64_t u; +}; + +template +class minecraft_encode { + static_assert(always_false, "This schema type is not being handled by the Minecraft encoding."); +}; + +template +class minecraft_encode{ + static error_or encode(const data& from, buffer& to){ + uint8_t encode_index = 0; + minecraft_signed_four_conversion value; + value.s = from.get(); + + /** + * VarInt max length is 5 bytes + */ + std::array encode_data; + + do { + uint8_t step = static_cast(value.u & 0x7F); + value.u = value.u >> 7; + if(value.u != 0){ + step |= 0x80; + } + encode_data[encode_index] = step; + ++encode_index; + }while(value.u != 0); + + auto err = buffer.push(encode_data[0], encode_index); + if (!err.template is_type()) { + return err; + } + + return no_error(); + } +}; + +template +class minecraft_decode { + static_assert(always_false, "This schema type is not being handled by the Minecraft encoding."); +}; + +template +class minecraft_decode{ + static error_or decode(buffer& from, data& to){ + uint8_t num_reads = 0; + + minecraft_signed_four_conversion value; + value.u = 0; + + uint8_t read{}; + do { + auto err = from.pop(read); + if( !err.template is_type() ){ + return err; + } + value.u |= ((read & 0x7F) << (7*num_reads)); + ++num_reads; + if(num_reads > 5){ + return make_error(); + } + } while( (read & 0x80) != 0); + + to.set(value.s); + + return no_error(); + } +}; + +} +} + + + +namespace mc { + +} +} diff --git a/modules/codec-minecraft/var_int_data.h b/modules/codec-minecraft/var_int_data.h deleted file mode 100644 index 4fbdd57..0000000 --- a/modules/codec-minecraft/var_int_data.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -namespace saw { -template<> -class data { -private: - int32_t data_; -public: - data(); - data(int32_t data); - - int32_t get() const; - void set(int32_t); -}; - -template<> -class data { -private: - int64_t data_; -public: - data(); - data(int64_t data); - - int64_t get() const; - void set(int64_t); -}; - - -} diff --git a/modules/codec-minecraft/var_int_data.hpp b/modules/codec-minecraft/var_int_data.hpp new file mode 100644 index 0000000..4fbdd57 --- /dev/null +++ b/modules/codec-minecraft/var_int_data.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace saw { +template<> +class data { +private: + int32_t data_; +public: + data(); + data(int32_t data); + + int32_t get() const; + void set(int32_t); +}; + +template<> +class data { +private: + int64_t data_; +public: + data(); + data(int64_t data); + + int64_t get() const; + void set(int64_t); +}; + + +} -- cgit v1.2.3