fix: need to use original endian functions from s5

This commit is contained in:
Derrick Hammer 2024-01-17 09:42:41 -05:00
parent fe11954e1d
commit ae8bdbc272
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 9 deletions

View File

@ -1,16 +1,21 @@
package utils package utils
import "encoding/binary"
func EncodeEndian(value uint64, length int) []byte { func EncodeEndian(value uint64, length int) []byte {
byteSlice := make([]byte, length) res := make([]byte, length)
binary.LittleEndian.PutUint64(byteSlice, value)
return byteSlice for i := 0; i < length; i++ {
res[i] = byte(value & 0xff)
value = value >> 8
}
return res
} }
func DecodeEndian(byteSlice []byte) uint64 { func DecodeEndian(bytes []byte) uint64 {
buffer := make([]byte, 8) var total uint64
copy(buffer, byteSlice)
return binary.LittleEndian.Uint64(buffer) for i := 0; i < len(bytes); i++ {
total += uint64(bytes[i]) << (8 * uint(i))
}
return total
} }