22 lines
438 B
Go
22 lines
438 B
Go
|
package binary
|
||
|
|
||
|
func BinaryGetInt(bytes []byte, s, length int) (res int64) {
|
||
|
res = 0
|
||
|
|
||
|
for i := 0; i < length; i++ {
|
||
|
res += (int64) (bytes[s + i]) << (8*uint(length - i - 1))
|
||
|
}
|
||
|
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
func BinaryGetBool(bytes []byte, s int) bool {
|
||
|
return bytes[s] == 1
|
||
|
}
|
||
|
|
||
|
func BinaryGetString(bytes []byte, s int) (string, int) {
|
||
|
strStart := s+1
|
||
|
strEnd := strStart + int(bytes[s])
|
||
|
return string(bytes[strStart:strEnd]), 1+int(bytes[s])
|
||
|
}
|