common

package
v0.7.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultKeepaliveInterval is default keepalive interval duration.
	DefaultKeepaliveInterval = 20 * time.Second
	// DefaultKeepaliveMaxLifetime is default keepalive max lifetime.
	DefaultKeepaliveMaxLifetime = 90 * time.Second
)
View Source
const MaxUint24 = 16777215

MaxUint24 is the max value of Uint24.

Variables

This section is empty.

Functions

func AppendPrettyHexDump added in v0.6.0

func AppendPrettyHexDump(dump *strings.Builder, b []byte)

AppendPrettyHexDump appends bytes to string builder.

func CloneBytes added in v0.7.0

func CloneBytes(b []byte) []byte

func CountBorrowed added in v0.7.0

func CountBorrowed() int64

CountBorrowed returns borrowed ByteBuff amount.

func IsExceedMaximumUint24Error added in v0.6.0

func IsExceedMaximumUint24Error(err error) bool

IsExceedMaximumUint24Error returns true if exceed maximum Uint24. (16777215)

func IsNegativeUint24Error added in v0.6.0

func IsNegativeUint24Error(err error) bool

IsNegativeUint24Error returns true if number is negative.

func PrettyHexDump added in v0.6.0

func PrettyHexDump(b []byte) string

PrettyHexDump converts bytes to pretty hex dump string.

func RandAlphabetic

func RandAlphabetic(n int) (s string)

RandAlphabetic returns a string with random alphabets.

func RandAlphanumeric

func RandAlphanumeric(n int) (s string)

RandAlphanumeric returns a string with random alphabets and numbers.

func RandFloat64

func RandFloat64() (v float64)

RandFloat64 returns a random float64.

func RandIntn

func RandIntn(n int) (v int)

RandIntn returns a random int.

func ReturnByteBuff added in v0.7.0

func ReturnByteBuff(b *ByteBuff)

ReturnByteBuff returns a ByteBuff to pool.

func SafeCloseDoneChan added in v0.7.0

func SafeCloseDoneChan(c chan<- struct{}) (ok bool)

func TryRelease added in v0.7.0

func TryRelease(input interface{})

Types

type ByteBuff

type ByteBuff bytebufferpool.ByteBuffer

ByteBuff provides byte buffer, which can be used for minimizing.

func BorrowByteBuff added in v0.7.0

func BorrowByteBuff() *ByteBuff

BorrowByteBuff borrows a ByteBuff from pool.

func (*ByteBuff) Bytes

func (b *ByteBuff) Bytes() []byte

Bytes returns all bytes in ByteBuff.

func (*ByteBuff) Len

func (b *ByteBuff) Len() (n int)

Len returns size of ByteBuff.

func (*ByteBuff) Reset

func (b *ByteBuff) Reset()

Reset resets ByteBuff.

func (*ByteBuff) Write

func (b *ByteBuff) Write(bs []byte) (int, error)

Write writes bytes to current ByteBuff.

func (*ByteBuff) WriteByte

func (b *ByteBuff) WriteByte(c byte) error

WriteByte writes a byte to current ByteBuff.

func (*ByteBuff) WriteString added in v0.6.0

func (b *ByteBuff) WriteString(s string) (err error)

WriteString writes a string to current ByteBuff.

func (*ByteBuff) WriteTo

func (b *ByteBuff) WriteTo(w io.Writer) (int64, error)

WriteTo writes bytes to writer.

func (*ByteBuff) WriteUint24

func (b *ByteBuff) WriteUint24(n int) (err error)

WriteUint24 encode and write Uint24 to current ByteBuff.

type Cond added in v0.6.0

type Cond struct {
	L sync.Locker
	// contains filtered or unexported fields
}

Cond is a customized Cond which support context. See https://gist.github.com/zviadm/c234426882bfc8acba88f3503edaaa36#file-cond2-go

func NewCond added in v0.6.0

func NewCond(l sync.Locker) *Cond

NewCond creates a new Cond.

func (*Cond) Broadcast added in v0.6.0

func (c *Cond) Broadcast()

Broadcast broadcast Cond.

func (*Cond) NotifyChan added in v0.6.0

func (c *Cond) NotifyChan() <-chan struct{}

NotifyChan returns readonly notify chan.

func (*Cond) Wait added in v0.6.0

func (c *Cond) Wait(ctx context.Context) (isCtx bool)

Wait waits Cond.

type Releasable added in v0.7.0

type Releasable interface {
	Release()
}

type Uint24

type Uint24 [3]byte

Uint24 is 3 bytes unsigned integer.

func MustNewUint24 added in v0.6.0

func MustNewUint24(n int) Uint24

MustNewUint24 returns a new uint24.

func NewUint24

func NewUint24(v int) (n Uint24, err error)

NewUint24 returns a new uint24.

func NewUint24Bytes

func NewUint24Bytes(bs []byte) Uint24

NewUint24Bytes returns a new uint24 from bytes.

func (Uint24) AsInt

func (p Uint24) AsInt() int

AsInt converts to int.

func (Uint24) Bytes

func (p Uint24) Bytes() []byte

Bytes returns bytes encoded.

func (Uint24) WriteTo

func (p Uint24) WriteTo(w io.Writer) (int64, error)

WriteTo encode and write bytes to a writer.

Jump to

Keyboard shortcuts

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