-
Notifications
You must be signed in to change notification settings - Fork 1
/
shift.go
executable file
·73 lines (62 loc) · 1.34 KB
/
shift.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gbytes
import (
"encoding/binary"
)
/* encode 8 bits bool */
func EncodeBool(p []byte, c bool) []byte {
if c {
p[0] = 1
} else {
p[0] = 0
}
return p[1:]
}
/* decode 8 bits bool */
func DecodeBool(p []byte, c *bool) []byte {
if p[0] != 0 {
*c = true
} else {
*c = false
}
return p[1:]
}
/* encode 8 bits unsigned int */
func EncodeUint8(p []byte, c uint8) []byte {
p[0] = c
return p[1:]
}
/* decode 8 bits unsigned int */
func DecodeUint8(p []byte, c *byte) []byte {
*c = p[0]
return p[1:]
}
/* encode 16 bits unsigned int (lsb) */
func EncodeUint16(p []byte, w uint16) []byte {
binary.LittleEndian.PutUint16(p, w)
return p[2:]
}
/* decode 16 bits unsigned int (lsb) */
func DecodeUint16(p []byte, w *uint16) []byte {
*w = binary.LittleEndian.Uint16(p)
return p[2:]
}
/* encode 32 bits unsigned int (lsb) */
func EncodeUint32(p []byte, l uint32) []byte {
binary.LittleEndian.PutUint32(p, l)
return p[4:]
}
/* decode 32 bits unsigned int (lsb) */
func DecodeUint32(p []byte, l *uint32) []byte {
*l = binary.LittleEndian.Uint32(p)
return p[4:]
}
/* encode 64 bits unsigned int (lsb) */
func EncodeUint64(p []byte, l uint64) []byte {
binary.LittleEndian.PutUint64(p, l)
return p[8:]
}
/* decode 64 bits unsigned int (lsb) */
func DecodeUint64(p []byte, l *uint64) []byte {
*l = binary.LittleEndian.Uint64(p)
return p[8:]
}