1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 04:25:11 +00:00
Files
go-fmp/fmp/fmp_util.go

42 lines
727 B
Go
Raw Normal View History

2025-06-12 11:44:57 +02:00
package fmp
2025-06-22 19:14:22 +02:00
func addIf(cond bool, val uint64) uint64 {
if cond {
return val
2025-06-14 16:28:41 +02:00
}
2025-06-22 19:14:22 +02:00
return 0
2025-06-14 16:28:41 +02:00
}
2025-06-22 19:14:22 +02:00
func decodeVarUint64(payload []byte) uint64 {
var length uint64
2025-06-12 21:21:55 +02:00
n := min(len(payload), 8) // clamp to uint64
2025-06-12 11:44:57 +02:00
for i := range n {
length <<= 8
length |= uint64(payload[i])
2025-06-12 11:44:57 +02:00
}
return length
}
2025-06-22 19:14:22 +02:00
func decodeString(payload []byte) string {
2025-06-12 11:44:57 +02:00
result := ""
for i := range payload {
result += string(payload[i] ^ 0x5A)
}
return result
}
2025-06-22 20:08:53 +02:00
func encodeUint(size uint, value int) []byte {
result := make([]byte, size)
for i := range size {
result[i] = byte(value & 0xFF)
value >>= 8
}
return result
}
func writeToSlice(slice []byte, start int, payload ...byte) {
for i := range payload {
slice[start+i] = payload[i]
}
}