hexutil

package
v0.0.0-...-ff78b6e Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

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"}
)

These errors are from go-ethereum in order to keep compatibility with geth error codes.

Functions

func CompressNibbles

func CompressNibbles(nibbles []byte, out *[]byte)

CompressNibbles - supports only even number of nibbles

HI_NIBBLE(b) = (b >> 4) & 0x0F LO_NIBBLE(b) = b & 0x0F

func Decode

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

Decode decodes a hex string with 0x prefix.

func DecodeBig

func DecodeBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

DecodeUint64 decodes a hex string with 0x prefix as a quantity.

func DecompressNibbles

func DecompressNibbles(in []byte, out *[]byte)

DecompressNibbles - supports only even number of nibbles

HI_NIBBLE(b) = (b >> 4) & 0x0F LO_NIBBLE(b) = b & 0x0F

func EncodeBig

func EncodeBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.

func EncodeUint64

func EncodeUint64(i uint64) string

EncodeUint64 encodes i as a hex string with 0x prefix.

func MustDecode

func MustDecode(input string) []byte

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

func MustDecodeBig

func MustDecodeBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func UnmarshalFixedUnprefixedText

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

UnmarshalFixedUnprefixedText decodes the input as a string with optional 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 Big

type Big big.Int

Big marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

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

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

MarshalText implements encoding.TextMarshaler

func (*Big) String

func (b *Big) String() string

String returns the hex encoding of b.

func (*Big) ToInt

func (b *Big) ToInt() *big.Int

ToInt converts b to a big.Int.

func (*Big) Uint64

func (b *Big) Uint64() uint64

func (*Big) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Big) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler

type Uint

type Uint uint

Uint marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Uint) String

func (b Uint) String() string

String returns the hex encoding of b.

func (*Uint) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Uint) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type Uint64

type Uint64 uint64

Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".

func (Uint64) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Uint64) String

func (b Uint64) String() string

String returns the hex encoding of b.

func (Uint64) Uint64

func (b Uint64) Uint64() uint64

func (*Uint64) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Uint64) UnmarshalText

func (b *Uint64) 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