Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeHex(input string) ([]byte, error)
- func EncodeHex(b []byte) string
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func MustDecodeHex(input string) []byte
- func UnmarshalFixedHexText(typname string, input, out []byte) error
- func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error
- func UnmarshalFixedText(typname string, input, out []byte) error
- type Hash
- type HexBytes
Constants ¶
const (
// HashLength is the expected length of the hash
HashLength = 32
)
Variables ¶
var ( ErrEmptyString = &decError{"empty hex string"} ErrSyntax = &decError{"invalid hex string"} ErrMissingPrefix = &decError{"hex string without 0x prefix"} ErrOddLength = &decError{"hex string of odd length"} ErrEmptyNumber = &decError{"hex string \"0x\""} 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"} )
Errors
Functions ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func MustDecodeHex ¶
MustDecodeHex decodes a hex string with 0x prefix. It panics for invalid input.
func UnmarshalFixedHexText ¶
UnmarshalFixedHexText decodes the input as a string with 0x 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 UnmarshalFixedJSON ¶ added in v0.4.4
UnmarshalFixedJSON decodes the input as a string with 0x 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 ¶ added in v0.4.4
UnmarshalFixedText decodes the input as a string with 0x 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 Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash) MarshalText ¶ added in v0.4.4
MarshalText returns the hex representation of h.
func (*Hash) SetBytes ¶
SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.
func (*Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (*Hash) UnmarshalJSON ¶ added in v0.4.4
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶ added in v0.4.4
UnmarshalText parses a hash in hex syntax.
type HexBytes ¶
type HexBytes []byte
HexBytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".
func (HexBytes) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*HexBytes) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*HexBytes) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.