fix: revert again to using s5's original endian implementations

This commit is contained in:
Derrick Hammer 2024-01-24 10:58:05 -05:00
parent ba00e15518
commit 7ca0a67ba5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 11 deletions

View File

@ -1,16 +1,20 @@
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
}
func DecodeEndian(byteSlice []byte) uint64 { for i := length - 1; i >= 0; i-- {
buffer := make([]byte, 8) res[i] = byte(value & 0xff)
copy(buffer, byteSlice) value = value >> 8
}
return binary.LittleEndian.Uint64(buffer) return res
}
func DecodeEndian(bytes []byte) uint64 {
var total uint64
for _, b := range bytes {
total = total*256 + uint64(b)
}
return total
} }