2024-01-03 09:56:10 +00:00
|
|
|
package utils
|
|
|
|
|
2024-01-10 16:00:01 +00:00
|
|
|
func EncodeEndian(value uint64, length int) []byte {
|
2024-01-17 14:42:41 +00:00
|
|
|
res := make([]byte, length)
|
|
|
|
|
|
|
|
for i := 0; i < length; i++ {
|
|
|
|
res[i] = byte(value & 0xff)
|
|
|
|
value = value >> 8
|
|
|
|
}
|
|
|
|
return res
|
2024-01-03 09:56:10 +00:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:42:41 +00:00
|
|
|
func DecodeEndian(bytes []byte) uint64 {
|
|
|
|
var total uint64
|
|
|
|
|
|
|
|
for i := 0; i < len(bytes); i++ {
|
|
|
|
total += uint64(bytes[i]) << (8 * uint(i))
|
|
|
|
}
|
2024-01-03 12:17:37 +00:00
|
|
|
|
2024-01-17 14:42:41 +00:00
|
|
|
return total
|
2024-01-03 09:56:10 +00:00
|
|
|
}
|