diff --git a/src/lib/byteutils.cpp b/src/lib/byteutils.cpp index e31d8e4..610ae26 100644 --- a/src/lib/byteutils.cpp +++ b/src/lib/byteutils.cpp @@ -23,18 +23,6 @@ void byteutils::push_long(std::vector& stack, const int64_t& value) { stack.push_back(BYTE_7(value)); } -void byteutils::push_ushort(std::vector& stack, const uint16_t& value) { - stack.push_back(BYTE_0(value)); - stack.push_back(BYTE_1(value)); -} - -void byteutils::push_uint(std::vector& stack, const uint32_t& value) { - stack.push_back(BYTE_0(value)); - stack.push_back(BYTE_1(value)); - stack.push_back(BYTE_2(value)); - stack.push_back(BYTE_3(value)); -} - void byteutils::push_ulong(std::vector& stack, const uint64_t& value) { stack.push_back(BYTE_0(value)); stack.push_back(BYTE_1(value)); @@ -46,52 +34,38 @@ void byteutils::push_ulong(std::vector& stack, const uint64_t& value) { stack.push_back(BYTE_7(value)); } -namespace byteutils { -int16_t read_short(const uint8_t* stack, const uint64_t& index) { - return ((int16_t) stack[index + 1] << 8) | stack[index]; -} - -int32_t read_int(const uint8_t* stack, const uint64_t& index) { - return ((int32_t) read_short(stack, index + 2) << 16) | read_short(stack, index); -} - -int64_t read_long(const uint8_t* stack, const uint64_t& index) { - return ((int64_t) read_int(stack, index + 4) << 32) | read_int(stack, index); -} - -uint16_t read_ushort(const uint8_t* stack, const uint64_t& index) { - return ((uint16_t) stack[index + 1] << 8) | stack[index]; -} - -uint32_t read_uint(const uint8_t* stack, const uint64_t& index) { - return ((uint32_t) read_ushort(stack, index + 2) << 16) | read_ushort(stack, index); -} - -uint64_t read_ulong(const uint8_t* stack, const uint64_t& index) { - return ((uint64_t) read_uint(stack, index + 4) << 32) | read_uint(stack, index); -} -} - int16_t byteutils::read_short(const std::vector& stack, const uint64_t& index) { - return byteutils::read_short(stack.data(), index); + return ((int16_t) stack[index + 1] << 8) | stack[index + 0]; } int32_t byteutils::read_int(const std::vector& stack, const uint64_t& index) { - return byteutils::read_int(stack.data(), index); + return + ((int32_t) stack[index + 3] << 24) | + ((int32_t) stack[index + 2] << 16) | + ((int32_t) stack[index + 1] << 8) | + stack[index + 0]; } int64_t byteutils::read_long(const std::vector& stack, const uint64_t& index) { - return byteutils::read_long(stack.data(), index); -} - -uint16_t read_ushort(const std::vector& stack, const uint64_t& index) { - return byteutils::read_ushort(stack.data(), index); -} - -uint32_t read_uint(const std::vector& stack, const uint64_t& index) { - return byteutils::read_uint(stack.data(), index); + return + ((int64_t) stack[index + 7] << 56) | + ((int64_t) stack[index + 6] << 48) | + ((int64_t) stack[index + 5] << 40) | + ((int64_t) stack[index + 4] << 32) | + ((int64_t) stack[index + 3] << 24) | + ((int64_t) stack[index + 2] << 16) | + ((int64_t) stack[index + 1] << 8) | + stack[index + 0]; } uint64_t byteutils::read_ulong(const std::vector& stack, const uint64_t& index) { - return byteutils::read_ulong(stack.data(), index); + return + ((uint64_t) stack[index + 7] << 56) | + ((uint64_t) stack[index + 6] << 48) | + ((uint64_t) stack[index + 5] << 40) | + ((uint64_t) stack[index + 4] << 32) | + ((uint64_t) stack[index + 3] << 24) | + ((uint64_t) stack[index + 2] << 16) | + ((uint64_t) stack[index + 1] << 8) | + stack[index + 0]; } \ No newline at end of file diff --git a/src/lib/byteutils.h b/src/lib/byteutils.h index 8c7649e..dae9e24 100644 --- a/src/lib/byteutils.h +++ b/src/lib/byteutils.h @@ -22,17 +22,11 @@ namespace byteutils { void push_short(std::vector& stack, const int16_t& value); void push_int(std::vector& stack, const int32_t& value); void push_long(std::vector& stack, const int64_t& value); - -void push_ushort(std::vector& stack, const uint16_t& value); -void push_uint(std::vector& stack, const uint32_t& value); void push_ulong(std::vector& stack, const uint64_t& value); int16_t read_short(const std::vector& stack, const uint64_t& index); int32_t read_int(const std::vector& stack, const uint64_t& index); int64_t read_long(const std::vector& stack, const uint64_t& index); - -uint16_t read_ushort(const std::vector& stack, const uint64_t& index); -uint32_t read_uint(const std::vector& stack, const uint64_t& index); uint64_t read_ulong(const std::vector& stack, const uint64_t& index); }