-
Notifications
You must be signed in to change notification settings - Fork 4
/
binary.go
71 lines (58 loc) · 1.69 KB
/
binary.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
package bin
import (
"encoding/binary"
"math/big"
"github.com/meverselabs/meverse/common"
"github.com/meverselabs/meverse/common/amount"
)
// Uint16Bytes returns a byte array of the uint16 number
func Uint16Bytes(v uint16) []byte {
BNum := make([]byte, 2)
binary.LittleEndian.PutUint16(BNum, v)
return BNum
}
// Uint32Bytes returns a byte array of the uint32 number
func Uint32Bytes(v uint32) []byte {
BNum := make([]byte, 4)
binary.LittleEndian.PutUint32(BNum, v)
return BNum
}
// Uint64Bytes returns a byte array of the uint64 number
func Uint64Bytes(v uint64) []byte {
BNum := make([]byte, 8)
binary.LittleEndian.PutUint64(BNum, v)
return BNum
}
// PutUint16 returns a byte array of the uint16 number
func PutUint16(bs []byte, v uint16) {
binary.LittleEndian.PutUint16(bs, v)
}
// Uint32 returns a byte array of the uint32 number
func PutUint32(bs []byte, v uint32) {
binary.LittleEndian.PutUint32(bs, v)
}
// Uint64 returns a byte array of the uint64 number
func PutUint64(bs []byte, v uint64) {
binary.LittleEndian.PutUint64(bs, v)
}
// Uint16 returns a uint16 number of the byte array
func Uint16(v []byte) uint16 {
return binary.LittleEndian.Uint16(v)
}
// Uint32 returns a uint32 number of the byte array
func Uint32(v []byte) uint32 {
return binary.LittleEndian.Uint32(v)
}
// Uint64 returns a uint64 number of the byte array
func Uint64(v []byte) uint64 {
return binary.LittleEndian.Uint64(v)
}
// Amount returns a Amount of the byte array
func Amount(v []byte) *amount.Amount {
return &amount.Amount{Int: big.NewInt(0).SetBytes(v)}
}
// Amount returns a Amount of the byte array
func Address(v []byte) common.Address {
bi := big.NewInt(0).SetBytes(v)
return common.BigToAddress(bi)
}