hexutil

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: GPL-3.0 Imports: 6 Imported by: 16

Documentation

Index

Examples

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

Functions

func Decode

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

func DecodeBig

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

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

func Encode

func Encode(b []byte) string

func EncodeBig

func EncodeBig(bigint *big.Int) string

func EncodeUint64

func EncodeUint64(i uint64) string

func MustDecode

func MustDecode(input string) []byte

func MustDecodeBig

func MustDecodeBig(input string) *big.Int

func MustDecodeUint64

func MustDecodeUint64(input string) uint64

func UnmarshalAddrFixedJSON

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

func UnmarshalAddrFixedText

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

func UnmarshalFixedJSON

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

func UnmarshalFixedText

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

import (
	"encoding/json"
	"fmt"

	"github.com/neatlab/neatio/utilities/common/hexutil"
)

type MyType [5]byte

func (v *MyType) UnmarshalText(input []byte) error {
	return hexutil.UnmarshalFixedText("MyType", input, v[:])
}

func (v MyType) String() string {
	return hexutil.Bytes(v[:]).String()
}

func main() {
	var v1, v2 MyType
	fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1))
	fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2))
	fmt.Println("v2:", v2)

}
Output:

func UnmarshalFixedUnprefixedText

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

Types

type Big

type Big big.Int

func (Big) MarshalText

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

func (*Big) String

func (b *Big) String() string

func (*Big) ToInt

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

func (*Big) UnmarshalJSON

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

func (*Big) UnmarshalText

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

type Bytes

type Bytes []byte

func (Bytes) MarshalText

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

func (Bytes) String

func (b Bytes) String() string

func (*Bytes) UnmarshalJSON

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

func (*Bytes) UnmarshalText

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

type Uint

type Uint uint

func (Uint) MarshalText

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

func (Uint) String

func (b Uint) String() string

func (*Uint) UnmarshalJSON

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

func (*Uint) UnmarshalText

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

type Uint64

type Uint64 uint64

func (Uint64) MarshalText

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

func (Uint64) String

func (b Uint64) String() string

func (*Uint64) UnmarshalJSON

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

func (*Uint64) UnmarshalText

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

Jump to

Keyboard shortcuts

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