-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathint_generator.py
More file actions
40 lines (31 loc) · 800 Bytes
/
int_generator.py
File metadata and controls
40 lines (31 loc) · 800 Bytes
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
template = """
func {FuncName}FromBytes(data []byte) ({DataType}, uint64) {
return binary.LittleEndian.{FuncName}(data), {Size}
}
"""
types = [
("uint16", 2),
("uint32", 4),
("uint64", 8),
]
code = """
// This piece of code was generated!!!
// DO NOT EDIT
func IntFromBytes(data []byte) (int, uint64) {
a, b := Int64FromBytes(data)
return a, b
}
func UintFromBytes(data []byte) (uint, uint64) {
a, b := Uint64FromBytes(data)
return a, b
}
func Int8FromBytes(data []byte) (int8, uint64) {
return int8(data[0]), 1
}
func Uint8FromBytes(data []byte) (uint8, uint64) {
return uint8(data[0]), 1
}
"""
for t in types:
code += template.replace("{FuncName}", t[0].capitalize()).replace("{DataType}", t[0]).replace("{Size}", str(t[1]))
print (code)