This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
bytes.go
255 lines (218 loc) · 5.21 KB
/
bytes.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package solsha3
import (
"github.com/ethereum/go-ethereum/common"
)
// Byte byte
func Byte(input interface{}) []byte {
return Bytes1(input)
}
// Bytes1 bytes1
func Bytes1(input interface{}) []byte {
return parseBytes(input, 1)
}
// Bytes2 bytes2
func Bytes2(input interface{}) []byte {
return parseBytes(input, 2)
}
// Bytes3 bytes3
func Bytes3(input interface{}) []byte {
return parseBytes(input, 3)
}
// Bytes4 bytes4
func Bytes4(input interface{}) []byte {
return parseBytes(input, 4)
}
// Bytes5 bytes5
func Bytes5(input interface{}) []byte {
return parseBytes(input, 5)
}
// Bytes6 bytes6
func Bytes6(input interface{}) []byte {
return parseBytes(input, 6)
}
// Bytes7 bytes7
func Bytes7(input interface{}) []byte {
return parseBytes(input, 7)
}
// Bytes8 bytes8
func Bytes8(input interface{}) []byte {
return parseBytes(input, 8)
}
// Bytes9 bytes9
func Bytes9(input interface{}) []byte {
return parseBytes(input, 9)
}
// Bytes10 bytes10
func Bytes10(input interface{}) []byte {
return parseBytes(input, 10)
}
// Bytes11 bytes11
func Bytes11(input interface{}) []byte {
return parseBytes(input, 11)
}
// Bytes12 bytes12
func Bytes12(input interface{}) []byte {
return parseBytes(input, 12)
}
// Bytes13 bytes13
func Bytes13(input interface{}) []byte {
return parseBytes(input, 13)
}
// Bytes14 bytes14
func Bytes14(input interface{}) []byte {
return parseBytes(input, 14)
}
// Bytes15 bytes15
func Bytes15(input interface{}) []byte {
return parseBytes(input, 15)
}
// Bytes16 bytes16
func Bytes16(input interface{}) []byte {
return parseBytes(input, 16)
}
// Bytes17 bytes17
func Bytes17(input interface{}) []byte {
return parseBytes(input, 17)
}
// Bytes18 bytes18
func Bytes18(input interface{}) []byte {
return parseBytes(input, 18)
}
// Bytes19 bytes19
func Bytes19(input interface{}) []byte {
return parseBytes(input, 19)
}
// Bytes20 bytes20
func Bytes20(input interface{}) []byte {
return parseBytes(input, 20)
}
// Bytes21 bytes21
func Bytes21(input interface{}) []byte {
return parseBytes(input, 21)
}
// Bytes22 bytes22
func Bytes22(input interface{}) []byte {
return parseBytes(input, 22)
}
// Bytes23 bytes23
func Bytes23(input interface{}) []byte {
return parseBytes(input, 23)
}
// Bytes24 bytes24
func Bytes24(input interface{}) []byte {
return parseBytes(input, 24)
}
// Bytes25 bytes25
func Bytes25(input interface{}) []byte {
return parseBytes(input, 25)
}
// Bytes26 bytes26
func Bytes26(input interface{}) []byte {
return parseBytes(input, 26)
}
// Bytes27 bytes27
func Bytes27(input interface{}) []byte {
return parseBytes(input, 27)
}
// Bytes28 bytes28
func Bytes28(input interface{}) []byte {
return parseBytes(input, 28)
}
// Bytes29 bytes29
func Bytes29(input interface{}) []byte {
return parseBytes(input, 29)
}
// Bytes30 bytes30
func Bytes30(input interface{}) []byte {
return parseBytes(input, 30)
}
// Bytes31 bytes31
func Bytes31(input interface{}) []byte {
return parseBytes(input, 31)
}
// Bytes32 bytes32
func Bytes32(input interface{}) []byte {
return parseBytes(input, 32)
}
func rightPadBytes(v []byte, byteLen int) []byte {
if byteLen == -1 {
return v
}
return common.RightPadBytes(v[:], byteLen)
}
func parseBytes(input interface{}, byteLen int) []byte {
switch v := input.(type) {
case [1]byte:
return rightPadBytes(v[:], byteLen)
case [2]byte:
return rightPadBytes(v[:], byteLen)
case [3]byte:
return rightPadBytes(v[:], byteLen)
case [4]byte:
return rightPadBytes(v[:], byteLen)
case [5]byte:
return rightPadBytes(v[:], byteLen)
case [6]byte:
return rightPadBytes(v[:], byteLen)
case [7]byte:
return rightPadBytes(v[:], byteLen)
case [8]byte:
return rightPadBytes(v[:], byteLen)
case [9]byte:
return rightPadBytes(v[:], byteLen)
case [10]byte:
return rightPadBytes(v[:], byteLen)
case [11]byte:
return rightPadBytes(v[:], byteLen)
case [12]byte:
return rightPadBytes(v[:], byteLen)
case [13]byte:
return rightPadBytes(v[:], byteLen)
case [14]byte:
return rightPadBytes(v[:], byteLen)
case [15]byte:
return rightPadBytes(v[:], byteLen)
case [16]byte:
return rightPadBytes(v[:], byteLen)
case [17]byte:
return rightPadBytes(v[:], byteLen)
case [18]byte:
return rightPadBytes(v[:], byteLen)
case [19]byte:
return rightPadBytes(v[:], byteLen)
case [20]byte:
return rightPadBytes(v[:], byteLen)
case [21]byte:
return rightPadBytes(v[:], byteLen)
case [22]byte:
return rightPadBytes(v[:], byteLen)
case [23]byte:
return rightPadBytes(v[:], byteLen)
case [24]byte:
return rightPadBytes(v[:], byteLen)
case [25]byte:
return rightPadBytes(v[:], byteLen)
case [26]byte:
return rightPadBytes(v[:], byteLen)
case [27]byte:
return rightPadBytes(v[:], byteLen)
case [28]byte:
return rightPadBytes(v[:], byteLen)
case [29]byte:
return rightPadBytes(v[:], byteLen)
case [30]byte:
return rightPadBytes(v[:], byteLen)
case [31]byte:
return rightPadBytes(v[:], byteLen)
case [32]byte:
return rightPadBytes(v[:], byteLen)
case []byte:
return rightPadBytes(v, byteLen)
case string:
hexb := stringToBytes(v)
h := common.RightPadBytes(hexb, byteLen)
return h
default:
return rightPadBytes([]byte(""), byteLen)
}
}