bytebuffer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT, MIT Imports: 5 Imported by: 0

README

go-bytebuffer

Byte Buffer struct for Go

自带对象池

使用实例

func GetBuffer() *ByteBuffer // 获取容量为Buffer
func PutBuffer(*ByteBuffer)  // 归还容量为Buffer

func SetDefaultSize(int)     // 设置Buffer的尺寸
func DefaultSize() int       // 获取当前Buffer的尺寸

归还错误尺寸的Buffer不会造成异常,错误的Buffer会被丢弃

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSize

func DefaultSize() int

DefaultSize 默认的Buffer尺寸

func PutBuffer

func PutBuffer(buffer *ByteBuffer)

PutBuffer 归还Buffer,不符合默认尺寸的buffer会被丢弃

func RegisterPool

func RegisterPool(size int)

RegisterPool 注册buffer池

func SetDefaultSize

func SetDefaultSize(size int)

SetDefaultSize 设置默认的Buffer尺寸

Types

type ByteBuffer

type ByteBuffer struct {
	Off    int
	Length int
	// contains filtered or unexported fields
}

ByteBuffer bytes缓冲器

func CreateByteBuffer

func CreateByteBuffer(cap int) *ByteBuffer

CreateByteBuffer 创建ByteBuffer

func GetBuffer

func GetBuffer(size ...int) (buffer *ByteBuffer)

GetBuffer 尝试从Buffer池获取Buffer,如果size参数为空,尺寸为defaultSize

func GetBytesBuffer

func GetBytesBuffer(b []byte) (buffer *ByteBuffer)

GetBytesBuffer 尝试从Buffer池获取Buffer,并拷入b的数据

func GetStringBuffer

func GetStringBuffer(str string) (buffer *ByteBuffer)

GetStringBuffer 尝试从Buffer池获取Buffer,并拷入str的数据

func (ByteBuffer) Buf

func (buffer ByteBuffer) Buf() []byte

Buf 获取buf

func (ByteBuffer) Cap

func (buffer ByteBuffer) Cap() int

Cap 获取容量

func (*ByteBuffer) Clear

func (buffer *ByteBuffer) Clear()

Clear 清空

func (ByteBuffer) Clone

func (buffer ByteBuffer) Clone() (newBuffer *ByteBuffer)

Clone 克隆一个新的ByteBuffer

func (ByteBuffer) Cut

func (buffer ByteBuffer) Cut() []byte

Cut 返回实际数据部分的[]byte,会构造新的数组

func (ByteBuffer) Data

func (buffer ByteBuffer) Data() []byte

Data 返回实际数据部分的[]byte,不会构造新的数组

func (*ByteBuffer) MarshalJSON

func (buffer *ByteBuffer) MarshalJSON() (b []byte, err error)

MarshalJSON JSON序列化器

func (*ByteBuffer) Move

func (buffer *ByteBuffer) Move(step int) (err error)

Move 将数据部分的起点后移step距离,当step为负数,则为前移

func (*ByteBuffer) SetString

func (buffer *ByteBuffer) SetString(data string) (err error)

SetString 将Buffer的值设置为字符串

func (ByteBuffer) String

func (buffer ByteBuffer) String() string

String 字符串

func (*ByteBuffer) UnmarshalJSON

func (buffer *ByteBuffer) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON JSON反序列化器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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