bytebuf

package module
v0.0.0-...-70b26a7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2019 License: MIT Imports: 5 Imported by: 3

README

原作者代码在这里,fork仅供个人学习

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChunkSize how much byte to allocate if there were not enough room
	ChunkSize = 1024
)

Global parameters, users can modify accordingly

View Source
var (
	ErrOutOfBound = errors.New("index is out of bound")
)

Errors

Functions

func FindCRIterator

func FindCRIterator(b byte) bool

FindCRIterator find till \r

func FindCRLFIterator

func FindCRLFIterator(b byte) bool

FindCRLFIterator find till \r or \n

func FindLFIterator

func FindLFIterator(b byte) bool

FindLFIterator find till \n

func FindNotCRIterator

func FindNotCRIterator(b byte) bool

FindNotCRIterator find till not \r

func FindNotCRLFIterator

func FindNotCRLFIterator(b byte) bool

FindNotCRLFIterator find till not \r or \n

func FindNotLFIterator

func FindNotLFIterator(b byte) bool

FindNotLFIterator find till not \n

func FindNotNullIterator

func FindNotNullIterator(b byte) bool

FindNotNullIterator find till not null

func FindNotWhiteSpaceIterator

func FindNotWhiteSpaceIterator(b byte) bool

FindNotWhiteSpaceIterator fdin till \s \t \r\ n

func FindNullIterator

func FindNullIterator(b byte) bool

FindNullIterator find till null

func FindWhiteSpaceIterator

func FindWhiteSpaceIterator(b byte) bool

FindWhiteSpaceIterator fdin till \s \t \r\ n

Types

type ByteBuf

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

ByteBuf ByteBuf itself

func New

func New() *ByteBuf

create new ByteBuf,zero length

func NewByteBuf

func NewByteBuf(bufs ...[]byte) (*ByteBuf, error)

NewByteBuf create new ByteBuf, pass any []byte in as initial buffer, it will be auto capped

func NewReader

func NewReader(reader io.Reader) (*ByteBuf, error)

NewReader create ByteBuf from io.Reader

func (*ByteBuf) AvailableBytes

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

AvailableBytes get available bytes([:size])

func (*ByteBuf) Bytes

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

Bytes get all the bytes in buffer ([:capacity])

func (*ByteBuf) Capacity

func (b *ByteBuf) Capacity() int

Capacity get buffer capacity (how much it could read/write)

func (*ByteBuf) Copy

func (b *ByteBuf) Copy() *ByteBuf

Copy deep copy to create an brand new ByteBuf

func (*ByteBuf) DiscardReadBytes

func (b *ByteBuf) DiscardReadBytes()

DiscardReadBytes discard bytes that are read, adjust readerIndex/writerIndex accordingly

func (*ByteBuf) EnsureCapacity

func (b *ByteBuf) EnsureCapacity(size int)

EnsureCapacity allocate more bytes to ensure the capacity

func (*ByteBuf) Equal

func (b *ByteBuf) Equal(ob *ByteBuf) bool

Equal if current ByteBuf is equal to another ByteBuf, compared by underlying byte slice

func (*ByteBuf) Flush

func (b *ByteBuf) Flush()

Flush flush all bytes and reset indexes

func (*ByteBuf) ForEachByte

func (b *ByteBuf) ForEachByte(iterator ByteIterator, indexes ...int) int

ForEachByte iterate through readable bytes, ForEachByte(iterator, start), ForEachByte(iterator, start, end)

func (*ByteBuf) ForceRelease

func (b *ByteBuf) ForceRelease()

ForceRelease force release bufs

func (*ByteBuf) GetBool

func (b *ByteBuf) GetBool(i int) (bool, error)

GetBool get a bool at given position

func (*ByteBuf) GetByte

func (b *ByteBuf) GetByte(i int) (byte, error)

GetByte get a byte at given position

func (*ByteBuf) GetBytes

func (b *ByteBuf) GetBytes(p []byte, start int, indexes ...int) (int, error)

GetBytes get bytes at given position, GetBytes(p, start), GetBytes(p, start, end)

func (*ByteBuf) GetFloat32BE

func (b *ByteBuf) GetFloat32BE(i int) (float32, error)

GetFloat32BE get a float32 in big endian at given position

func (*ByteBuf) GetFloat32LE

func (b *ByteBuf) GetFloat32LE(i int) (float32, error)

GetFloat32LE get a float32 in little endian at given position

func (*ByteBuf) GetFloat64BE

func (b *ByteBuf) GetFloat64BE(i int) (float64, error)

GetFloat64BE get a float64 in big endian at given position

func (*ByteBuf) GetFloat64LE

func (b *ByteBuf) GetFloat64LE(i int) (float64, error)

GetFloat64LE get a float64 in little endian at given position

func (*ByteBuf) GetInt16BE

func (b *ByteBuf) GetInt16BE(i int) (int16, error)

GetInt16BE get an int16 in big endian at given position

func (*ByteBuf) GetInt16LE

func (b *ByteBuf) GetInt16LE(i int) (int16, error)

GetInt16LE get an int16 in little endian at given position

func (*ByteBuf) GetInt32BE

func (b *ByteBuf) GetInt32BE(i int) (int32, error)

GetInt32BE get an int32 in big endian at given position

func (*ByteBuf) GetInt32LE

func (b *ByteBuf) GetInt32LE(i int) (int32, error)

GetInt32LE get an int32 in little endian at given position

func (*ByteBuf) GetInt64BE

func (b *ByteBuf) GetInt64BE(i int) (int64, error)

GetInt64BE get a int64 in big endian at given position

func (*ByteBuf) GetInt64LE

func (b *ByteBuf) GetInt64LE(i int) (int64, error)

GetInt64LE get a int64 in little endian at given position

func (*ByteBuf) GetInt8

func (b *ByteBuf) GetInt8(i int) (int8, error)

GetInt8 get an int8 at given position

func (*ByteBuf) GetUInt16BE

func (b *ByteBuf) GetUInt16BE(i int) (uint16, error)

GetUInt16BE get an uint16 in big endian at given position

func (*ByteBuf) GetUInt16LE

func (b *ByteBuf) GetUInt16LE(i int) (uint16, error)

GetUInt16LE get an uint16 in little endian at given position

func (*ByteBuf) GetUInt32BE

func (b *ByteBuf) GetUInt32BE(i int) (uint32, error)

GetUInt32BE get an uint32 in big endian at given position

func (*ByteBuf) GetUInt32LE

func (b *ByteBuf) GetUInt32LE(i int) (uint32, error)

GetUInt32LE get an uint32 in little endian at given position

func (*ByteBuf) GetUInt64BE

func (b *ByteBuf) GetUInt64BE(i int) (uint64, error)

GetUInt64BE get an uint64 in big endian at given position

func (*ByteBuf) GetUInt64LE

func (b *ByteBuf) GetUInt64LE(i int) (uint64, error)

GetUInt64LE get an uint64 in little endian at given position

func (*ByteBuf) GetUInt8

func (b *ByteBuf) GetUInt8(i int) (uint8, error)

GetUInt8 get an uint8 at given position

func (*ByteBuf) Index

func (b *ByteBuf) Index(p []byte, indexes ...int) int

Index index a byte slice inside buffer, Index(p), Index(p, start), Index(p, start, end)

func (*ByteBuf) IsReadable

func (b *ByteBuf) IsReadable() bool

IsReadable if buf is readable (b.writerIndex > b.readerIndex)

func (*ByteBuf) MarkReaderIndex

func (b *ByteBuf) MarkReaderIndex()

MarkReaderIndex mark current reader index for reset in the future

func (*ByteBuf) MarkWriterIndex

func (b *ByteBuf) MarkWriterIndex()

MarkWriterIndex mark current writer index for reset in the future

func (*ByteBuf) PutBool

func (b *ByteBuf) PutBool(i int, val bool) error

PutBool put a bool at given position

func (*ByteBuf) PutByte

func (b *ByteBuf) PutByte(i int, val byte) error

PutByte put a byte at given position

func (*ByteBuf) PutBytes

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

PutBytes put a bool at given position

func (*ByteBuf) PutFloat32BE

func (b *ByteBuf) PutFloat32BE(i int, val float32) error

PutFloat32BE put a float32 at given position in big endian

func (*ByteBuf) PutFloat32LE

func (b *ByteBuf) PutFloat32LE(i int, val float32) error

PutFloat32LE put a float32 at given position in little endian

func (*ByteBuf) PutFloat64BE

func (b *ByteBuf) PutFloat64BE(i int, val float64) error

PutFloat64BE put a float64 at given position in big endian

func (*ByteBuf) PutFloat64LE

func (b *ByteBuf) PutFloat64LE(i int, val float64) error

PutFloat64LE put a float64 at given position in little endian

func (*ByteBuf) PutInt16BE

func (b *ByteBuf) PutInt16BE(i int, val int16) error

PutInt16BE put an int16 at given position in big endian

func (*ByteBuf) PutInt16LE

func (b *ByteBuf) PutInt16LE(i int, val int16) error

PutInt16LE put an int16 at given position in little endian

func (*ByteBuf) PutInt32BE

func (b *ByteBuf) PutInt32BE(i int, val int32) error

PutInt32BE put an int32 at given position in big endian

func (*ByteBuf) PutInt32LE

func (b *ByteBuf) PutInt32LE(i int, val int32) error

PutInt32LE put an int32 at given position in little endian

func (*ByteBuf) PutInt64BE

func (b *ByteBuf) PutInt64BE(i int, val int64) error

PutInt64BE put an int64 at given position in big endian

func (*ByteBuf) PutInt64LE

func (b *ByteBuf) PutInt64LE(i int, val int64) error

PutInt64LE put an int64 at given position in little endian

func (*ByteBuf) PutInt8

func (b *ByteBuf) PutInt8(i int, val int8) error

PutInt8 put an int8 at given position

func (*ByteBuf) PutUInt16BE

func (b *ByteBuf) PutUInt16BE(i int, val uint16) error

PutUInt16BE put an uint16 at given position in big endian

func (*ByteBuf) PutUInt16LE

func (b *ByteBuf) PutUInt16LE(i int, val uint16) error

PutUInt16LE put an uint16 at given position in little endian

func (*ByteBuf) PutUInt32BE

func (b *ByteBuf) PutUInt32BE(i int, val uint32) error

PutUInt32BE put an uint32 at given position in big endian

func (*ByteBuf) PutUInt32LE

func (b *ByteBuf) PutUInt32LE(i int, val uint32) error

PutUInt32LE put an uint32 at given position in little endian

func (*ByteBuf) PutUInt64BE

func (b *ByteBuf) PutUInt64BE(i int, val uint64) error

PutUInt64BE put an uint64 at given position in big endian

func (*ByteBuf) PutUInt64LE

func (b *ByteBuf) PutUInt64LE(i int, val uint64) error

PutUInt64LE put an uint64 at given position in little endian

func (*ByteBuf) PutUInt8

func (b *ByteBuf) PutUInt8(i int, val uint8) error

PutUInt8 put an uint8 at given position

func (*ByteBuf) Read

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

Read implements io.Reader

func (*ByteBuf) ReadBool

func (b *ByteBuf) ReadBool() (bool, error)

ReadBool read a bool

func (*ByteBuf) ReadByte

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

ReadByte read a byte

func (*ByteBuf) ReadByteBuf

func (b *ByteBuf) ReadByteBuf(size int) (*ByteBuf, error)

ReadByteBuf read bytes with given size into a new ByteBuf

func (*ByteBuf) ReadBytes

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

ReadBytes read bytes

func (*ByteBuf) ReadFloat32BE

func (b *ByteBuf) ReadFloat32BE() (float32, error)

ReadFloat32BE read a float32 in big endian

func (*ByteBuf) ReadFloat32LE

func (b *ByteBuf) ReadFloat32LE() (float32, error)

ReadFloat32LE read a float32 in little endian

func (*ByteBuf) ReadFloat64BE

func (b *ByteBuf) ReadFloat64BE() (float64, error)

ReadFloat64BE read a float64 in big endian

func (*ByteBuf) ReadFloat64LE

func (b *ByteBuf) ReadFloat64LE() (float64, error)

ReadFloat64LE read a float64 in little endian

func (*ByteBuf) ReadFrom

func (b *ByteBuf) ReadFrom(reader io.Reader) error

ReadFrom read from io.reader

func (*ByteBuf) ReadInt16BE

func (b *ByteBuf) ReadInt16BE() (int16, error)

ReadInt16BE read an int16 in big endian

func (*ByteBuf) ReadInt16LE

func (b *ByteBuf) ReadInt16LE() (int16, error)

ReadInt16LE read an int16 in little endian

func (*ByteBuf) ReadInt32BE

func (b *ByteBuf) ReadInt32BE() (int32, error)

ReadInt32BE read an int32 in big endian

func (*ByteBuf) ReadInt32LE

func (b *ByteBuf) ReadInt32LE() (int32, error)

ReadInt32LE read an int32 in little endian

func (*ByteBuf) ReadInt64BE

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

ReadInt64BE read an int64 in big endian

func (*ByteBuf) ReadInt64LE

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

ReadInt64LE read an int64 in little endian

func (*ByteBuf) ReadInt8

func (b *ByteBuf) ReadInt8() (int8, error)

ReadInt8 read an int8

func (*ByteBuf) ReadUInt16BE

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

ReadUInt16BE read a uint16 in big endian

func (*ByteBuf) ReadUInt16LE

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

ReadUInt16LE read a uint16 in little endian

func (*ByteBuf) ReadUInt32BE

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

ReadUInt32BE read a uint32 in big endian

func (*ByteBuf) ReadUInt32LE

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

ReadUInt32LE read a uint32 in little endian

func (*ByteBuf) ReadUInt64BE

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

ReadUInt64BE read a uint64 in big endian

func (*ByteBuf) ReadUInt64LE

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

ReadUInt64LE read a uint64 in little endian

func (*ByteBuf) ReadUInt8

func (b *ByteBuf) ReadUInt8() (uint8, error)

ReadUInt8 read a uint8

func (*ByteBuf) ReadableBytes

func (b *ByteBuf) ReadableBytes() int

ReadableBytes how much bytes are there to be read

func (*ByteBuf) ReaderIndex

func (b *ByteBuf) ReaderIndex() int

ReaderIndex access current reader index

func (*ByteBuf) Ref

func (b *ByteBuf) Ref()

Ref increment reference counter

func (*ByteBuf) Release

func (b *ByteBuf) Release()

Release decrement reference counter, underlying buf will be cleared once reference count is 0

func (*ByteBuf) ResetReaderIndex

func (b *ByteBuf) ResetReaderIndex()

ResetReaderIndex reset reader index to marked index

func (*ByteBuf) ResetWriterIndex

func (b *ByteBuf) ResetWriterIndex()

ResetWriterIndex reset writer index to marked index

func (*ByteBuf) Size

func (b *ByteBuf) Size() int

Size get current written buffer size

func (*ByteBuf) Skip

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

Skip some bytes

func (*ByteBuf) String

func (b *ByteBuf) String() string

String buf to string

func (*ByteBuf) UnsafeBytes

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

UnsafeBytes DANGER! access underlying buffer directly

func (*ByteBuf) Write

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

Write implements io.Writer

func (*ByteBuf) WriteBool

func (b *ByteBuf) WriteBool(val bool) error

WriteBool write a bool

func (*ByteBuf) WriteByte

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

WriteByte write a byte

func (*ByteBuf) WriteByteBuf

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

func (*ByteBuf) WriteBytes

func (b *ByteBuf) WriteBytes(p []byte) error

WriteBytes write bytes

func (*ByteBuf) WriteFloat32BE

func (b *ByteBuf) WriteFloat32BE(val float32) error

WriteFloat32BE write a float32 in big endian

func (*ByteBuf) WriteFloat32LE

func (b *ByteBuf) WriteFloat32LE(val float32) error

WriteFloat32LE write a float32 in little endian

func (*ByteBuf) WriteFloat64BE

func (b *ByteBuf) WriteFloat64BE(val float64) error

WriteFloat64BE write a float64 in big endian

func (*ByteBuf) WriteFloat64LE

func (b *ByteBuf) WriteFloat64LE(val float64) error

WriteFloat64LE write a float64 in little endian

func (*ByteBuf) WriteInt16BE

func (b *ByteBuf) WriteInt16BE(val int16) error

WriteInt16BE write an int16 in big endian

func (*ByteBuf) WriteInt16LE

func (b *ByteBuf) WriteInt16LE(val int16) error

WriteInt16LE write an int16 in little endian

func (*ByteBuf) WriteInt32BE

func (b *ByteBuf) WriteInt32BE(val int32) error

WriteInt32BE write an int32 in big endian

func (*ByteBuf) WriteInt32LE

func (b *ByteBuf) WriteInt32LE(val int32) error

WriteInt32LE write an int32 in little endian

func (*ByteBuf) WriteInt64BE

func (b *ByteBuf) WriteInt64BE(val int64) error

WriteInt64BE write an int64 in big endian

func (*ByteBuf) WriteInt64LE

func (b *ByteBuf) WriteInt64LE(val int64) error

WriteInt64LE write an int64 in little endian

func (*ByteBuf) WriteInt8

func (b *ByteBuf) WriteInt8(val int8) error

WriteInt8 write an int8

func (*ByteBuf) WriteTo

func (b *ByteBuf) WriteTo(writer io.Writer) (int64, error)

WriteTo write to io.Writer

func (*ByteBuf) WriteUInt16BE

func (b *ByteBuf) WriteUInt16BE(val uint16) error

WriteUInt16BE write an uint16 in big endian

func (*ByteBuf) WriteUInt16LE

func (b *ByteBuf) WriteUInt16LE(val uint16) error

WriteUInt16LE write an uint16 in little endian

func (*ByteBuf) WriteUInt32BE

func (b *ByteBuf) WriteUInt32BE(val uint32) error

WriteUInt32BE write an uint32 in big endian

func (*ByteBuf) WriteUInt32LE

func (b *ByteBuf) WriteUInt32LE(val uint32) error

WriteUInt32LE write an uint32 in little endian

func (*ByteBuf) WriteUInt64BE

func (b *ByteBuf) WriteUInt64BE(val uint64) error

WriteUInt64BE write an uint64 in big endian

func (*ByteBuf) WriteUInt64LE

func (b *ByteBuf) WriteUInt64LE(val uint64) error

WriteUInt64LE write an uint64 in little endian

func (*ByteBuf) WriteUInt8

func (b *ByteBuf) WriteUInt8(val uint8) error

WriteUInt8 write an uint8

func (*ByteBuf) WriterIndex

func (b *ByteBuf) WriterIndex() int

WriterIndex access current writer index

type ByteIterator

type ByteIterator func(byte) bool

ByteIterator type used for byte iteration

Jump to

Keyboard shortcuts

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