buf

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// KB kb
	KB = 1024
	// MB mb
	MB = 1024 * 1024
)

Variables

View Source
var ErrTooLarge = errors.New("goetty.ByteBuf: too large")

ErrTooLarge too larger error

Functions

func Byte2Int

func Byte2Int(data []byte) int

Byte2Int byte array to int value using big order

func Byte2Int64

func Byte2Int64(data []byte) int64

Byte2Int64 byte array to int64 value using big order

func Byte2UInt16

func Byte2UInt16(data []byte) uint16

Byte2UInt16 byte array to uint16 value using big order

func Byte2UInt32

func Byte2UInt32(data []byte) uint32

Byte2UInt32 byte array to uint32 value using big order

func Byte2UInt64

func Byte2UInt64(data []byte) uint64

Byte2UInt64 byte array to int64 value using big order

func Int2Bytes

func Int2Bytes(v int) []byte

Int2Bytes int value to bytes array using big order

func Int2BytesTo

func Int2BytesTo(v int, ret []byte)

Int2BytesTo int value to bytes array using big order

func Int64ToBytes

func Int64ToBytes(v int64) []byte

Int64ToBytes int64 value to bytes array using big order

func Int64ToBytesTo

func Int64ToBytesTo(v int64, ret []byte)

Int64ToBytesTo int64 value to bytes array using big order

func ReadInt

func ReadInt(r io.Reader) (int, error)

ReadInt read a int value from a reader

func ReadN

func ReadN(r io.Reader, n int) ([]byte, error)

ReadN read n bytes from a reader

func UInt16ToBytes

func UInt16ToBytes(v uint16) []byte

UInt16ToBytes uint16 value to bytes array using big order

func UInt32ToBytes

func UInt32ToBytes(v uint32) []byte

UInt32ToBytes uint32 value to bytes array using big order

func Uint16ToBytesTo

func Uint16ToBytesTo(v uint16, ret []byte)

Uint16ToBytesTo uint16 value to bytes array using big order

func Uint32ToBytesTo

func Uint32ToBytesTo(v uint32, ret []byte)

Uint32ToBytesTo uint32 value to bytes array using big order

func Uint64ToBytesTo

func Uint64ToBytesTo(v uint64, ret []byte)

Uint64ToBytesTo uint64 value to bytes array using big order

func UseMemPool

func UseMemPool(min, max int)

UseMemPool use the custom mem pool

Types

type ByteBuf

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

ByteBuf a buf with byte arrays

| discardable bytes | readable bytes | writeable bytes | | | | | | | | | 0 <= readerIndex <= writerIndex <= capacity

func NewByteBuf

func NewByteBuf(capacity int) *ByteBuf

NewByteBuf create a new bytebuf

func NewByteBufPool

func NewByteBufPool(capacity int, pool Pool) *ByteBuf

NewByteBufPool create a new bytebuf using a mem pool

func WrapBytes

func WrapBytes(data []byte) *ByteBuf

WrapBytes wrap a bytes as a bytebuf

func (*ByteBuf) Capacity

func (b *ByteBuf) Capacity() int

Capacity get the capacity

func (*ByteBuf) Clear

func (b *ByteBuf) Clear()

Clear reset the write and read index

func (*ByteBuf) Expansion

func (b *ByteBuf) Expansion(n int)

Expansion expansion buf size

func (*ByteBuf) GetMarkedRemind

func (b *ByteBuf) GetMarkedRemind() int

GetMarkedRemind returns size in [readerIndex, markedIndex)

func (*ByteBuf) GetMarkedRemindData

func (b *ByteBuf) GetMarkedRemindData() []byte

GetMarkedRemindData returns data in [readerIndex, markedIndex)

func (*ByteBuf) GetMarkerIndex

func (b *ByteBuf) GetMarkerIndex() int

GetMarkerIndex returns markerIndex

func (*ByteBuf) GetReaderIndex

func (b *ByteBuf) GetReaderIndex() int

GetReaderIndex get the read index

func (*ByteBuf) GetWriteIndex

func (b *ByteBuf) GetWriteIndex() int

GetWriteIndex get the write index

func (*ByteBuf) MarkIndex

func (b *ByteBuf) MarkIndex(index int) error

MarkIndex mark a index

func (*ByteBuf) MarkN

func (b *ByteBuf) MarkN(n int) error

MarkN mark a index offset based by currently read index

func (*ByteBuf) MarkWrite

func (b *ByteBuf) MarkWrite()

MarkWrite mark current write index

func (*ByteBuf) MarkedBytesReaded

func (b *ByteBuf) MarkedBytesReaded()

MarkedBytesReaded reset reader index

func (*ByteBuf) PeekByte

func (b *ByteBuf) PeekByte(offset int) (byte, error)

PeekByte get byte value from buf based on currently read index, after read, read index not modifed

func (*ByteBuf) PeekInt

func (b *ByteBuf) PeekInt(offset int) (int, error)

PeekInt get int value from buf based on currently read index, after read, read index not modifed

func (*ByteBuf) PeekN

func (b *ByteBuf) PeekN(offset int, n int) ([]byte, error)

PeekN get bytes from buf based on currently read index, after read, read index not modifed

func (*ByteBuf) RawBuf

func (b *ByteBuf) RawBuf() []byte

RawBuf get the raw byte array

func (*ByteBuf) Read

func (b *ByteBuf) Read(p []byte) (n int, err error)

Read read bytes return readedBytesCount, byte array, error

func (*ByteBuf) ReadAll

func (b *ByteBuf) ReadAll() (int, []byte, error)

ReadAll read all data from buf It's will copy the data to a new byte arrary return readedBytesCount, byte array, error

func (*ByteBuf) ReadByte

func (b *ByteBuf) ReadByte() (byte, error)

ReadByte read a byte from buf return byte value, error

func (*ByteBuf) ReadBytes

func (b *ByteBuf) ReadBytes(n int) (int, []byte, error)

ReadBytes read bytes from buf It's will copy the data to a new byte arrary return readedBytesCount, byte array, error

func (*ByteBuf) ReadFrom

func (b *ByteBuf) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.

func (*ByteBuf) ReadInt

func (b *ByteBuf) ReadInt() (int, error)

ReadInt get int value from buf

func (*ByteBuf) ReadInt64

func (b *ByteBuf) ReadInt64() (int64, error)

ReadInt64 get int64 value from buf

func (*ByteBuf) ReadMarkedBytes

func (b *ByteBuf) ReadMarkedBytes() (int, []byte, error)

ReadMarkedBytes read data from buf in the range [readerIndex, markedIndex)

func (*ByteBuf) ReadRawBytes

func (b *ByteBuf) ReadRawBytes(n int) (int, []byte, error)

ReadRawBytes read bytes from buf without mem copy Note. If used complete, you must call b.Skip(n) to reset reader index

func (*ByteBuf) ReadUInt16

func (b *ByteBuf) ReadUInt16() (uint16, error)

ReadUInt16 get uint16 value from buf

func (*ByteBuf) ReadUInt32

func (b *ByteBuf) ReadUInt32() (uint32, error)

ReadUInt32 get uint32 value from buf

func (*ByteBuf) ReadUInt64

func (b *ByteBuf) ReadUInt64() (uint64, error)

ReadUInt64 get uint64 value from buf

func (*ByteBuf) Readable

func (b *ByteBuf) Readable() int

Readable current readable byte size

func (*ByteBuf) Release

func (b *ByteBuf) Release()

Release release buf

func (*ByteBuf) Resume

func (b *ByteBuf) Resume(capacity int)

Resume resume the buf

func (*ByteBuf) SetReaderIndex

func (b *ByteBuf) SetReaderIndex(newReaderIndex int) error

SetReaderIndex set the read index

func (*ByteBuf) SetWriterIndex

func (b *ByteBuf) SetWriterIndex(newWriterIndex int) error

SetWriterIndex set the write index

func (*ByteBuf) Skip

func (b *ByteBuf) Skip(n int) error

Skip skip bytes, after this option, read index will change to readerIndex+n

func (*ByteBuf) Slice

func (b *ByteBuf) Slice(from, to int) Slice

Slice returns a read only bytebuf slice

func (*ByteBuf) Wrap

func (b *ByteBuf) Wrap(data []byte)

Wrap wrap a bytes

func (*ByteBuf) Write

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

Write appends the contents of p to the buffer, growing the buffer as needed.

func (*ByteBuf) WriteByte

func (b *ByteBuf) WriteByte(v byte) error

WriteByte write a byte value to buf

func (*ByteBuf) WriteByteBuf

func (b *ByteBuf) WriteByteBuf(from *ByteBuf) error

WriteByteBuf write all readable data to this buf

func (*ByteBuf) WriteInt

func (b *ByteBuf) WriteInt(v int) (n int, err error)

WriteInt write int value to buf using big order return write bytes count, error

func (*ByteBuf) WriteInt64

func (b *ByteBuf) WriteInt64(v int64) (n int, err error)

WriteInt64 write int64 value to buf using big order return write bytes count, error

func (*ByteBuf) WriteString

func (b *ByteBuf) WriteString(v string) error

WriteString write a string value to buf

func (*ByteBuf) WriteUInt16

func (b *ByteBuf) WriteUInt16(v uint16) (n int, err error)

WriteUInt16 write uint16 value to buf using big order return write bytes count, error

func (*ByteBuf) WriteUInt32

func (b *ByteBuf) WriteUInt32(v uint32) (n int, err error)

WriteUInt32 write uint32 value to buf using big order return write bytes count, error

func (*ByteBuf) WriteUInt64

func (b *ByteBuf) WriteUInt64(v uint64) (n int, err error)

WriteUInt64 write uint64 value to buf using big order return write bytes count, error

func (*ByteBuf) WriteUint64

func (b *ByteBuf) WriteUint64(v uint64) (n int, err error)

WriteUint64 write uint64 value to buf using big order return write bytes count, error

func (*ByteBuf) Writeable

func (b *ByteBuf) Writeable() int

Writeable return how many bytes can be wirte into buf

func (*ByteBuf) WrittenDataAfterMark

func (b *ByteBuf) WrittenDataAfterMark() Slice

WrittenDataAfterMark returns the data referance after mark write

type Pool

type Pool interface {
	Alloc(int) []byte
	Free([]byte)
}

Pool a mem pool interface

type Slice

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

Slice the slice of byte buf

func (Slice) Data

func (s Slice) Data() []byte

Data data

type SyncPool

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

SyncPool is a sync.Pool base slab allocation memory pool

func NewSyncPool

func NewSyncPool(minSize, maxSize, factor int) *SyncPool

NewSyncPool create a sync.Pool base slab allocation memory pool. minSize is the smallest chunk size. maxSize is the lagest chunk size. factor is used to control growth of chunk size.

func (*SyncPool) Alloc

func (pool *SyncPool) Alloc(size int) []byte

Alloc try alloc a []byte from internal slab class if no free chunk in slab class Alloc will make one.

func (*SyncPool) Free

func (pool *SyncPool) Free(mem []byte)

Free release a []byte that alloc from Pool.Alloc.

Jump to

Keyboard shortcuts

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