util

package
v0.0.0-tn Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

Package util provides common utility functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSyntax        = errors.New("invalid hex string")
	ErrMissingPrefix = errors.New("hex string without 0x prefix")
	ErrOddLength     = errors.New("hex string of odd length")
	ErrUint64Range   = errors.New("hex number > 64 bits")
)

Errors.

Functions

func Base64Decode added in v1.0.0

func Base64Decode(dst, src []byte) error

func Base64Encode added in v1.0.0

func Base64Encode(src []byte) []byte

func Encode

func Encode(b []byte) string

Encode 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. Parameter s may be prefixed with "0x".

func Uint64ToBytesBigEndian

func Uint64ToBytesBigEndian(i uint64) []byte

Uint64ToBytesBigEndian returns the byte representation of a uint64, using big endian encoding (which is not the default for spacemesh).

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(typename 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 Bytes

type Bytes []byte

Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (Bytes) MarshalText

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

MarshalText implements encoding.TextMarshaler.

func (Bytes) String

func (b Bytes) String() string

String returns the hex encoding of b.

func (*Bytes) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

type MockGrpcServer added in v1.0.0

type MockGrpcServer struct {
	*grpc.Server
	Port uint16
	// contains filtered or unexported fields
}

MockGrpcServer allows for simulating a GRPC server in tests. Typical usage: ``` gtw := NewMockGrpcServer(t) <register required GRPC services> var eg errgroup.Group eg.Go(gtw.Serve) t.Cleanup(func() { require.NoError(t, eg.Wait()) }) t.Cleanup(gtw.Stop) ``` .

func NewMockGrpcServer added in v1.0.0

func NewMockGrpcServer(t testing.TB) *MockGrpcServer

func (*MockGrpcServer) Serve added in v1.0.0

func (s *MockGrpcServer) Serve() error

func (*MockGrpcServer) Target added in v1.0.0

func (s *MockGrpcServer) Target() string

Jump to

Keyboard shortcuts

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