github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/utilities/common/hexutil/json_example_test.go (about) 1 package hexutil_test 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/neatlab/neatio/utilities/common/hexutil" 8 ) 9 10 type MyType [5]byte 11 12 func (v *MyType) UnmarshalText(input []byte) error { 13 return hexutil.UnmarshalFixedText("MyType", input, v[:]) 14 } 15 16 func (v MyType) String() string { 17 return hexutil.Bytes(v[:]).String() 18 } 19 20 func ExampleUnmarshalFixedText() { 21 var v1, v2 MyType 22 fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1)) 23 fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2)) 24 fmt.Println("v2:", v2) 25 26 }