1 // Package common contains various helper functions.
9 // FromHex convert hex byte string to []byte
10 func FromHex(s string) []byte {
23 // Bytes2Hex convert byte array to string
24 func Bytes2Hex(d []byte) string {
25 return hex.EncodeToString(d)
28 // Hex2Bytes convert hex string to byte array
29 func Hex2Bytes(str string) []byte {
30 h, _ := hex.DecodeString(str)
34 // Unit64ToBytes convert uint64 to bytes
35 func Unit64ToBytes(n uint64) []byte {
36 buf := make([]byte, 8)
37 binary.LittleEndian.PutUint64(buf, n)
41 // BytesToUnit64 convert bytes to uint64
42 func BytesToUnit64(b []byte) uint64 {
43 return binary.LittleEndian.Uint64(b)