-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex.go
67 lines (51 loc) · 1.6 KB
/
hex.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
package ctrsigcheck
import (
"encoding/hex"
"fmt"
"strings"
)
// Hex wraps a []byte so that it encodes to hexadecimal.
type Hex []byte
func (h Hex) String() string {
return strings.ToUpper(hex.EncodeToString(h))
}
// MarshalText implements encoding.TextMarshaler, also used for JSON encoding.
func (h Hex) MarshalText() ([]byte, error) {
return []byte(h.String()), nil
}
// Hex8 wraps an uint8 so that it encodes to hexadecimal.
type Hex8 uint8
func (h Hex8) String() string {
return fmt.Sprintf("%02X", uint8(h))
}
// MarshalText implements encoding.TextMarshaler, also used for JSON encoding.
func (h Hex8) MarshalText() ([]byte, error) {
return []byte(h.String()), nil
}
// Hex16 wraps an uint16 so that it encodes to hexadecimal.
type Hex16 uint16
func (h Hex16) String() string {
return fmt.Sprintf("%04X", uint16(h))
}
// MarshalText implements encoding.TextMarshaler, also used for JSON encoding.
func (h Hex16) MarshalText() ([]byte, error) {
return []byte(h.String()), nil
}
// Hex32 wraps an uint32 so that it encodes to hexadecimal.
type Hex32 uint32
func (h Hex32) String() string {
return fmt.Sprintf("%08X", uint32(h))
}
// MarshalText implements encoding.TextMarshaler, also used for JSON encoding.
func (h Hex32) MarshalText() ([]byte, error) {
return []byte(h.String()), nil
}
// Hex64 wraps an uint64 so that it encodes to hexadecimal.
type Hex64 uint64
func (h Hex64) String() string {
return fmt.Sprintf("%016X", uint64(h))
}
// MarshalText implements encoding.TextMarshaler, also used for JSON encoding.
func (h Hex64) MarshalText() ([]byte, error) {
return []byte(h.String()), nil
}