From ae8bdbc2726da2190e3fdaca1f4e5c8c3f5b84d8 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 17 Jan 2024 09:42:41 -0500 Subject: [PATCH] fix: need to use original endian functions from s5 --- utils/endian.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/utils/endian.go b/utils/endian.go index 8f1c76f..1ebc368 100644 --- a/utils/endian.go +++ b/utils/endian.go @@ -1,16 +1,21 @@ package utils -import "encoding/binary" - func EncodeEndian(value uint64, length int) []byte { - byteSlice := make([]byte, length) - binary.LittleEndian.PutUint64(byteSlice, value) - return byteSlice + res := make([]byte, length) + + for i := 0; i < length; i++ { + res[i] = byte(value & 0xff) + value = value >> 8 + } + return res } -func DecodeEndian(byteSlice []byte) uint64 { - buffer := make([]byte, 8) - copy(buffer, byteSlice) +func DecodeEndian(bytes []byte) uint64 { + var total uint64 - return binary.LittleEndian.Uint64(buffer) + for i := 0; i < len(bytes); i++ { + total += uint64(bytes[i]) << (8 * uint(i)) + } + + return total }