File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ func NewHexOrDecimal256(x int64) *HexOrDecimal256 {
49
49
return & h
50
50
}
51
51
52
+ // UnmarshalJSON implements json.Unmarshaler.
53
+ //
54
+ // It is similar to UnmarshalText, but allows parsing real decimals too, not just
55
+ // quoted decimal strings.
56
+ func (i * HexOrDecimal256 ) UnmarshalJSON (input []byte ) error {
57
+ if len (input ) > 0 && input [0 ] == '"' {
58
+ input = input [1 : len (input )- 1 ]
59
+ }
60
+ return i .UnmarshalText (input )
61
+ }
62
+
52
63
// UnmarshalText implements encoding.TextUnmarshaler.
53
64
func (i * HexOrDecimal256 ) UnmarshalText (input []byte ) error {
54
65
bigint , ok := ParseBig256 (string (input ))
Original file line number Diff line number Diff line change @@ -41,6 +41,17 @@ const (
41
41
// HexOrDecimal64 marshals uint64 as hex or decimal.
42
42
type HexOrDecimal64 uint64
43
43
44
+ // UnmarshalJSON implements json.Unmarshaler.
45
+ //
46
+ // It is similar to UnmarshalText, but allows parsing real decimals too, not just
47
+ // quoted decimal strings.
48
+ func (i * HexOrDecimal64 ) UnmarshalJSON (input []byte ) error {
49
+ if len (input ) > 0 && input [0 ] == '"' {
50
+ input = input [1 : len (input )- 1 ]
51
+ }
52
+ return i .UnmarshalText (input )
53
+ }
54
+
44
55
// UnmarshalText implements encoding.TextUnmarshaler.
45
56
func (i * HexOrDecimal64 ) UnmarshalText (input []byte ) error {
46
57
int , ok := ParseUint64 (string (input ))
You can’t perform that action at this time.
0 commit comments