data

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const MaxSize = uint16(65535)

MaxSize 最大支持的大小

Variables

View Source
var (
	MaxBytesLimit = errors.New("Max bytes limit of bytebufffer")
)

Functions

func Bytes2String added in v1.0.35

func Bytes2String(b []byte) string

Byte2String []byte -> string

func NewLoopQueue

func NewLoopQueue[T any](size int) *loopQueue[T]

func NewStack

func NewStack[T any](size int) *stack[T]

func Put added in v1.0.32

func Put(b *ByteBuffer)

Put returns byte buffer to the pool.

ByteBuffer.B mustn't be touched after returning it to the pool. Otherwise, data races will occur.

func String2Bytes added in v1.0.35

func String2Bytes(s string) []byte

String2Bytes string -> []byte

Types

type Bitmap added in v1.0.44

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

Bitmap Bitmap结构体

func New added in v1.0.44

func New(size uint16) *Bitmap

New 初始化一个Bitmap

func (*Bitmap) Get added in v1.0.44

func (b *Bitmap) Get(offset uint16) uint8

Get 获取offset位置处的value值

func (*Bitmap) Set added in v1.0.44

func (b *Bitmap) Set(offset uint16, value uint8) bool

Set 将offset位置的值设置为value(0/1)

func (*Bitmap) Size added in v1.0.44

func (b *Bitmap) Size() uint16

Size 返回Bitmap大小

type ByteBuffer added in v1.0.32

type ByteBuffer struct {

	// B is a byte buffer to use in append-like workloads.
	// See example code for details.
	B []byte
}
Example
bb := Get()

bb.WriteString("first line\n")
bb.Write([]byte("second line\n"))
bb.B = append(bb.B, "third line\n"...)

fmt.Printf("bytebuffer contents=%q", bb.B)

// It is safe to release byte buffer now, since it is
// no longer used.
Put(bb)

func Get added in v1.0.32

func Get() *ByteBuffer

Get returns an empty byte buffer from the pool.

Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.

func (*ByteBuffer) Bytes added in v1.0.32

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

Bytes returns b.B, i.e. all the bytes accumulated in the buffer.

The purpose of this function is bytes.Buffer compatibility.

func (*ByteBuffer) Compact added in v1.0.37

func (b *ByteBuffer) Compact(w io.Writer, nwrite int) (int64, error)

func (*ByteBuffer) Flip added in v1.0.37

func (b *ByteBuffer) Flip(n int) (rtn []byte)

func (*ByteBuffer) Len added in v1.0.32

func (b *ByteBuffer) Len() int

Len returns the size of the byte buffer.

func (*ByteBuffer) ReadFrom added in v1.0.32

func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

The function appends all the data read from r to b.

func (*ByteBuffer) Reset added in v1.0.32

func (b *ByteBuffer) Reset()

Reset makes ByteBuffer.B empty.

func (*ByteBuffer) Set added in v1.0.32

func (b *ByteBuffer) Set(p []byte)

Set sets ByteBuffer.B to p.

func (*ByteBuffer) SetString added in v1.0.32

func (b *ByteBuffer) SetString(s string)

SetString sets ByteBuffer.B to s.

func (*ByteBuffer) String added in v1.0.32

func (b *ByteBuffer) String() string

String returns string representation of ByteBuffer.B.

func (*ByteBuffer) Write added in v1.0.32

func (b *ByteBuffer) Write(p []byte) (int, error)

Write implements io.Writer - it appends p to ByteBuffer.B

func (*ByteBuffer) WriteByte added in v1.0.32

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

WriteByte appends the byte c to the buffer.

The purpose of this function is bytes.Buffer compatibility.

The function always returns nil.

func (*ByteBuffer) WriteString added in v1.0.32

func (b *ByteBuffer) WriteString(s string) (int, error)

WriteString appends s to ByteBuffer.B.

func (*ByteBuffer) WriteTo added in v1.0.32

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

WriteTo implements io.WriterTo.

type CacheUnit

type CacheUnit[T any] struct {
	// contains filtered or unexported fields
}

type Pool added in v1.0.32

type Pool struct {
	DefaultSize uint64

	BufferMaxSize uint
	// contains filtered or unexported fields
}

Pool represents byte buffer pool.

Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.

func (*Pool) Get added in v1.0.32

func (p *Pool) Get() *ByteBuffer

Get returns new byte buffer with zero length.

The byte buffer may be returned to the pool via Put after the use in order to minimize GC overhead.

func (*Pool) Put added in v1.0.32

func (p *Pool) Put(b *ByteBuffer)

Put releases byte buffer obtained via Get to the pool.

The buffer mustn't be accessed after returning to the pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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