Documentation ¶
Overview ¶
Package hexutil implements hex encoding with Mx prefix. This encoding is used by the Ethereum RPC API to transport binary data in JSON payloads.
Encoding Rules ¶
All hex data must have prefix "Mx".
For byte slices, the hex data must be of even length. An empty byte slice encodes as "Mx".
Integers are encoded using the least amount of digits (no leading zero digits). Their encoding may be of uneven length. The number zero encodes as "Mx0".
Index ¶
- Variables
- func Decode(input string) ([]byte, error)
- func DecodeBig(input string) (*big.Int, error)
- func DecodeUint64(input string) (uint64, error)
- func Encode(b []byte) string
- func EncodeBig(bigint *big.Int) string
- func EncodeUint64(i uint64) string
- func MustDecode(input string) []byte
- func MustDecodeBig(input string) *big.Int
- func MustDecodeUint64(input string) uint64
- func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error
- func UnmarshalFixedText(typname string, input, out []byte) error
- func UnmarshalFixedUnprefixedText(typname string, input, out []byte) error
- type Big
- type Bytes
- type Uint
- type Uint64
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyString = &decError{"empty hex string"} ErrSyntax = &decError{"invalid hex string"} ErrMissingPrefix = &decError{"hex string without Mx prefix"} ErrOddLength = &decError{"hex string of odd length"} ErrEmptyNumber = &decError{"hex string \"Mx\""} ErrLeadingZero = &decError{"hex number with leading zero digits"} ErrUint64Range = &decError{"hex number > 64 bits"} ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)} ErrBig256Range = &decError{"hex number > 256 bits"} )
Error set
Functions ¶
func DecodeBig ¶
DecodeBig decodes a hex string with Mx prefix as a quantity. Numbers larger than 256 bits are not accepted.
func DecodeUint64 ¶
DecodeUint64 decodes a hex string with Mx prefix as a quantity.
func EncodeBig ¶
EncodeBig encodes bigint as a hex string with Mx prefix. The sign of the integer is ignored.
func EncodeUint64 ¶
EncodeUint64 encodes i as a hex string with Mx prefix.
func MustDecode ¶
MustDecode decodes a hex string with Mx prefix. It panics for invalid input.
func MustDecodeBig ¶
MustDecodeBig decodes a hex string with Mx prefix as a quantity. It panics for invalid input.
func MustDecodeUint64 ¶
MustDecodeUint64 decodes a hex string with Mx prefix as a quantity. It panics for invalid input.
func UnmarshalFixedJSON ¶
UnmarshalFixedJSON decodes the input as a string with Mx prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalJSON method for fixed-size types.
func UnmarshalFixedText ¶
UnmarshalFixedText decodes the input as a string with Mx prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.
func UnmarshalFixedUnprefixedText ¶
UnmarshalFixedUnprefixedText decodes the input as a string with optional Mx prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.
Types ¶
type Big ¶
Big marshals/unmarshals as a JSON string with Mx prefix. The zero value marshals as "Mx0".
Negative integers are not supported at this time. Attempting to marshal them will return an error. Values larger than 256bits are rejected by Unmarshal but will be marshaled without error.
func (Big) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Big) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Big) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type Bytes ¶
type Bytes []byte
Bytes marshals/unmarshals as a JSON string with Mx prefix. The empty slice marshals as "Mx".
func (Bytes) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Bytes) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Bytes) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Uint ¶
type Uint uint
Uint marshals/unmarshals as a JSON string with Mx prefix. The zero value marshals as "Mx0".
func (Uint) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Uint) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Uint64 ¶
type Uint64 uint64
Uint64 marshals/unmarshals as a JSON string with Mx prefix. The zero value marshals as "Mx0".
func (Uint64) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Uint64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler