protocol

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2019 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
)

Variables

View Source
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 DecodeHex

func DecodeHex(input string) ([]byte, error)

DecodeHex decodes a hex string with 0x prefix.

func EncodeHex

func EncodeHex(b []byte) string

EncodeHex encodes b as a hex string with 0x prefix.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func MustDecodeHex

func MustDecodeHex(input string) []byte

MustDecodeHex decodes a hex string with 0x prefix. It panics for invalid input.

func UnmarshalFixedHexText

func UnmarshalFixedHexText(typname string, input, out []byte) error

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

func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error

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

func UnmarshalFixedText(typname string, input, out []byte) error

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

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*Hash) Hex

func (h *Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

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

func (h *Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

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

func (b HexBytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (HexBytes) String

func (b HexBytes) String() string

String returns the hex encoding of b.

func (*HexBytes) UnmarshalJSON

func (b *HexBytes) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*HexBytes) UnmarshalText

func (b *HexBytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL