Documentation ¶
Overview ¶
Package util provides common utility functions.
Index ¶
- Constants
- Variables
- func Base64Decode(dst, src []byte) error
- func Base64Encode(src []byte) []byte
- func Encode(b []byte) string
- func FromHex(s string) []byte
- func IsCi() bool
- func IsWindows() bool
- func Min[T constraints.Ordered](a, b T) T
- func Uint64ToBytesBigEndian(i uint64) []byte
- func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error
- func UnmarshalFixedText(typename string, input, out []byte) error
- type Bytes
- type MockGrpcServer
Constants ¶
const ( EnvCi = "CI" EnvOsWindows = "windows" )
Variables ¶
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 Base64Encode ¶ added in v1.0.0
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. Parameter s may be prefixed with "0x".
func Min ¶
func Min[T constraints.Ordered](a, b T) T
Min returns the smaller of the two inputs, both of type int.
func Uint64ToBytesBigEndian ¶
Uint64ToBytesBigEndian returns the byte representation of a uint64, using big endian encoding (which is not the default for spacemesh).
func UnmarshalFixedJSON ¶
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 ¶
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 ¶
MarshalText implements encoding.TextMarshaler.
func (*Bytes) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Bytes) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type MockGrpcServer ¶ added in v1.0.0
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