generated from openacid/gotmpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint.go
197 lines (153 loc) · 4.1 KB
/
int.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Code generated 'by go generate ./...'; DO NOT EDIT.
package qcodec
import "encoding/binary"
// U16 converts uint16 to slice of 2 bytes and back.
type U16 struct{}
// Encode converts uint16 to slice of 2 bytes.
func (c U16) Encode(d interface{}) []byte {
b := make([]byte, 2)
v := d.(uint16)
binary.LittleEndian.PutUint16(b, v)
return b
}
// Decode converts slice of 2 bytes to uint16.
// It returns number bytes consumed and an uint16.
func (c U16) Decode(b []byte) (int, interface{}) {
size := int(2)
s := b[:size]
d := binary.LittleEndian.Uint16(s)
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c U16) Size(d interface{}) int {
return 2
}
// GetEncodedSize returns 2.
func (c U16) EncodedSize(b []byte) int {
return 2
}
// U32 converts uint32 to slice of 4 bytes and back.
type U32 struct{}
// Encode converts uint32 to slice of 4 bytes.
func (c U32) Encode(d interface{}) []byte {
b := make([]byte, 4)
v := d.(uint32)
binary.LittleEndian.PutUint32(b, v)
return b
}
// Decode converts slice of 4 bytes to uint32.
// It returns number bytes consumed and an uint32.
func (c U32) Decode(b []byte) (int, interface{}) {
size := int(4)
s := b[:size]
d := binary.LittleEndian.Uint32(s)
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c U32) Size(d interface{}) int {
return 4
}
// GetEncodedSize returns 4.
func (c U32) EncodedSize(b []byte) int {
return 4
}
// U64 converts uint64 to slice of 8 bytes and back.
type U64 struct{}
// Encode converts uint64 to slice of 8 bytes.
func (c U64) Encode(d interface{}) []byte {
b := make([]byte, 8)
v := d.(uint64)
binary.LittleEndian.PutUint64(b, v)
return b
}
// Decode converts slice of 8 bytes to uint64.
// It returns number bytes consumed and an uint64.
func (c U64) Decode(b []byte) (int, interface{}) {
size := int(8)
s := b[:size]
d := binary.LittleEndian.Uint64(s)
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c U64) Size(d interface{}) int {
return 8
}
// GetEncodedSize returns 8.
func (c U64) EncodedSize(b []byte) int {
return 8
}
// I16 converts int16 to slice of 2 bytes and back.
type I16 struct{}
// Encode converts int16 to slice of 2 bytes.
func (c I16) Encode(d interface{}) []byte {
b := make([]byte, 2)
v := uint16(d.(int16))
binary.LittleEndian.PutUint16(b, v)
return b
}
// Decode converts slice of 2 bytes to int16.
// It returns number bytes consumed and an int16.
func (c I16) Decode(b []byte) (int, interface{}) {
size := int(2)
s := b[:size]
d := int16(binary.LittleEndian.Uint16(s))
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c I16) Size(d interface{}) int {
return 2
}
// GetEncodedSize returns 2.
func (c I16) EncodedSize(b []byte) int {
return 2
}
// I32 converts int32 to slice of 4 bytes and back.
type I32 struct{}
// Encode converts int32 to slice of 4 bytes.
func (c I32) Encode(d interface{}) []byte {
b := make([]byte, 4)
v := uint32(d.(int32))
binary.LittleEndian.PutUint32(b, v)
return b
}
// Decode converts slice of 4 bytes to int32.
// It returns number bytes consumed and an int32.
func (c I32) Decode(b []byte) (int, interface{}) {
size := int(4)
s := b[:size]
d := int32(binary.LittleEndian.Uint32(s))
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c I32) Size(d interface{}) int {
return 4
}
// GetEncodedSize returns 4.
func (c I32) EncodedSize(b []byte) int {
return 4
}
// I64 converts int64 to slice of 8 bytes and back.
type I64 struct{}
// Encode converts int64 to slice of 8 bytes.
func (c I64) Encode(d interface{}) []byte {
b := make([]byte, 8)
v := uint64(d.(int64))
binary.LittleEndian.PutUint64(b, v)
return b
}
// Decode converts slice of 8 bytes to int64.
// It returns number bytes consumed and an int64.
func (c I64) Decode(b []byte) (int, interface{}) {
size := int(8)
s := b[:size]
d := int64(binary.LittleEndian.Uint64(s))
return size, d
}
// GetSize returns the size in byte after encoding v.
func (c I64) Size(d interface{}) int {
return 8
}
// GetEncodedSize returns 8.
func (c I64) EncodedSize(b []byte) int {
return 8
}