#pragma once #include #include class ByteUtils { public: using Word = int16_t; using DWord = int32_t; using QWord = int64_t; static bool MostSignificantBitIsOne(char c) { return c & (1 << 7); } static Word GetWordFirstBit(const Word word) { return word & ByteUtils::WORD_FIRST_BIT; }; static Word GetWordLastByte(const Word word) { return word & ByteUtils::WORD_LAST_BYTE; } static void ReverseBuffer(char* buffer, char* reverse, unsigned size, unsigned targetSize) { for(unsigned idx=0; idx static T ToType(char* buffer, bool reverse = true) { T result {0}; if(reverse) { char reversed[sizeof(T)]; ReverseBuffer(buffer, reversed, sizeof(T), sizeof(T)); std::memcpy(&result, reversed, sizeof(T)); } else { std::memcpy(&result, buffer, sizeof(T)); } return result; } static Word ToWord(char* buffer, bool reverse = true) { return ToType(buffer, reverse); } static DWord ToDWord(char* buffer, bool reverse = true) { return ToType(buffer, reverse); } static QWord ToQWord(char* buffer, bool reverse = true) { return ToType(buffer, reverse); } static bool Compare(char* buffer, const char* tag, unsigned size) { for(unsigned idx=0; idx