types

package
v0.0.0-...-215cb89 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: GPL-3.0 Imports: 9 Imported by: 6

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const MaxTimestamp = Timestamp(common.MaxUint64)

Variables

This section is empty.

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func FromHex

func FromHex(s string) []byte

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

func HasHexPrefix

func HasHexPrefix(str string) bool

hasHexPrefix validates str begins with '0x' or '0X'.

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func IsHex

func IsHex(str string) bool

isHex validates whether each byte is valid hexadecimal string.

func IsHexCharacter

func IsHexCharacter(c byte) bool

isHexCharacter returns bool of c being a valid hexadecimal.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func ToHex deprecated

func ToHex(b []byte) string

ToHex returns the hex representation of b, prefixed with '0x'. For empty slices, the return value is "0x0".

Deprecated: use hexutil.Encode instead.

func ToHexArray

func ToHexArray(b [][]byte) []string

ToHexArray creates a array of hex-string based on []byte

Types

type Attribute

type Attribute struct {
	Name string
	Dur  *Duration
}

func GenerateTestAttribute

func GenerateTestAttribute() *Attribute

func NewAttribute

func NewAttribute(name string, dur *Duration) *Attribute

func (*Attribute) DeepCopy

func (a *Attribute) DeepCopy() *Attribute

func (*Attribute) ToBytes

func (a *Attribute) ToBytes() []byte

func (*Attribute) ToJson

func (a *Attribute) ToJson() []byte

func (*Attribute) ToMap

func (a *Attribute) ToMap() map[string]interface{}

type Duration

type Duration struct {
	Start Timestamp `json:"s"`
	End   Timestamp `json:"e"`
}

Duration represents a duration between start and end

func GenerateTestDuration

func GenerateTestDuration() *Duration

func NewDuration

func NewDuration(start Timestamp, end Timestamp) *Duration

func (*Duration) Contain

func (d *Duration) Contain(other *Duration) bool

func (*Duration) ContainTime

func (d *Duration) ContainTime(time Timestamp) bool

func (*Duration) Contained

func (d *Duration) Contained(other *Duration) bool

func (*Duration) DeepCopy

func (d *Duration) DeepCopy() *Duration

func (*Duration) ToBytes

func (d *Duration) ToBytes() []byte

func (*Duration) ToJson

func (d *Duration) ToJson() []byte

func (*Duration) ToMap

func (d *Duration) ToMap() map[string]interface{}

func (*Duration) ToString

func (d *Duration) ToString() string

type IntSet

type IntSet struct {
	// contains filtered or unexported fields
}

func NewIntSet

func NewIntSet() *IntSet

func (*IntSet) Add

func (intSet *IntSet) Add(x int)

func (*IntSet) Has

func (intSet *IntSet) Has(item int) bool

func (*IntSet) Remove

func (intSet *IntSet) Remove(x int)

type MyTimer

type MyTimer struct {
	Name   string
	Delay  uint64
	Target func()
	Timer  *time.Timer

	Running   bool
	RunningMu sync.Mutex
	// contains filtered or unexported fields
}

func NewMyTimer

func NewMyTimer(name string, delay uint64, target func(), logger *log.Logger) *MyTimer

func (*MyTimer) Reset

func (mt *MyTimer) Reset(delay uint64)

func (*MyTimer) Start

func (mt *MyTimer) Start(delay uint64)

The target of timer will start in {delay} seconds, when delay is 0, it means that it will start in the default time.

func (*MyTimer) Stop

func (mt *MyTimer) Stop() bool

Stop() stops the timer and returns if it is running now, true for running and false for not running.

type Timestamp

type Timestamp uint64

func BytesToTimestamp

func BytesToTimestamp(t []byte) Timestamp

func CurrentTime

func CurrentTime() Timestamp

func JsonToTimestamp

func JsonToTimestamp(j []byte) Timestamp

func RandomTimestamp

func RandomTimestamp() Timestamp

func TimestampFromUint64

func TimestampFromUint64(t uint64) Timestamp

func (Timestamp) Bytes

func (ts Timestamp) Bytes() []byte

func (Timestamp) DeepCopy

func (ts Timestamp) DeepCopy() Timestamp

func (*Timestamp) ToJson

func (ts *Timestamp) ToJson() []byte

func (Timestamp) Uint64

func (ts Timestamp) Uint64() uint64

type Uint64Set

type Uint64Set struct {
	// contains filtered or unexported fields
}

func NewUint64Set

func NewUint64Set() *Uint64Set

func (*Uint64Set) Add

func (uint64Set *Uint64Set) Add(x uint64)

func (*Uint64Set) Clear

func (uint64Set *Uint64Set) Clear()

func (*Uint64Set) Has

func (uint64Set *Uint64Set) Has(item uint64) bool

func (*Uint64Set) Len

func (uint64Set *Uint64Set) Len() uint64

func (*Uint64Set) Remove

func (uint64Set *Uint64Set) Remove(x uint64)

Jump to

Keyboard shortcuts

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