Documentation ¶
Index ¶
- func Byte2Int(data []byte) int
- func Byte2Int64(data []byte) int64
- func Byte2Uint16(data []byte) uint16
- func Byte2Uint32(data []byte) uint32
- func Byte2Uint64(data []byte) uint64
- func Int2Bytes(v int) []byte
- func Int2BytesTo(v int, ret []byte)
- func Int64ToBytes(v int64) []byte
- func Int64ToBytesTo(v int64, ret []byte)
- func Uint16ToBytes(v uint16) []byte
- func Uint16ToBytesTo(v uint16, ret []byte)
- func Uint32ToBytes(v uint32) []byte
- func Uint32ToBytesTo(v uint32, ret []byte)
- func Uint64ToBytes(v uint64) []byte
- func Uint64ToBytesTo(v uint64, ret []byte)
- func WriteTo(data []byte, conn io.Writer, copyBuffer int) error
- type Allocator
- type ByteBuf
- func (b *ByteBuf) ClearMark()
- func (b *ByteBuf) Close()
- func (b *ByteBuf) GetMarkIndex() int
- func (b *ByteBuf) GetMarkedDataLen() int
- func (b *ByteBuf) GetReadIndex() int
- func (b *ByteBuf) GetWriteIndex() int
- func (b *ByteBuf) GetWriteOffset() int
- func (b *ByteBuf) Grow(n int)
- func (b *ByteBuf) MustReadByte() byte
- func (b *ByteBuf) MustWrite(value []byte)
- func (b *ByteBuf) MustWriteByte(v byte)
- func (b *ByteBuf) PeekInt(offset int) int
- func (b *ByteBuf) PeekN(offset, bytes int) []byte
- func (b *ByteBuf) RawBuf() []byte
- func (b *ByteBuf) RawSlice(from, to int) []byte
- func (b *ByteBuf) Read(dst []byte) (int, error)
- func (b *ByteBuf) ReadAll() (readed int, data []byte)
- func (b *ByteBuf) ReadByte() (byte, error)
- func (b *ByteBuf) ReadBytes(n int) (readed int, data []byte)
- func (b *ByteBuf) ReadFrom(r io.Reader) (n int64, err error)
- func (b *ByteBuf) ReadInt() int
- func (b *ByteBuf) ReadInt64() int64
- func (b *ByteBuf) ReadMarkedData() []byte
- func (b *ByteBuf) ReadUint16() uint16
- func (b *ByteBuf) ReadUint32() uint32
- func (b *ByteBuf) ReadUint64() uint64
- func (b *ByteBuf) Readable() int
- func (b *ByteBuf) Reset()
- func (b *ByteBuf) SetMarkIndex(markIndex int)
- func (b *ByteBuf) SetReadIndex(readIndex int)
- func (b *ByteBuf) SetWriteIndex(writeIndex int)
- func (b *ByteBuf) SetWriteIndexByOffset(writeOffset int)
- func (b *ByteBuf) Skip(n int)
- func (b *ByteBuf) Slice(from, to int) Slice
- func (b *ByteBuf) Write(src []byte) (int, error)
- func (b *ByteBuf) WriteByte(v byte) error
- func (b *ByteBuf) WriteInt(v int)
- func (b *ByteBuf) WriteInt64(v int64)
- func (b *ByteBuf) WriteString(v string)
- func (b *ByteBuf) WriteTo(dst io.Writer) (int64, error)
- func (b *ByteBuf) WriteUint16(v uint16)
- func (b *ByteBuf) WriteUint32(v uint32)
- func (b *ByteBuf) WriteUint64(v uint64)
- func (b *ByteBuf) Writeable() int
- type Option
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Byte2Int64 ¶
Byte2Int64 byte array to int64 value using big order
func Byte2Uint16 ¶
Byte2Uint16 byte array to uint16 value using big order
func Byte2Uint32 ¶
Byte2Uint32 byte array to uint32 value using big order
func Byte2Uint64 ¶
Byte2Uint64 byte array to int64 value using big order
func Int2BytesTo ¶
Int2BytesTo int value to bytes array using big order
func Int64ToBytes ¶
Int64ToBytes int64 value to bytes array using big order
func Int64ToBytesTo ¶
Int64ToBytesTo int64 value to bytes array using big order
func Uint16ToBytes ¶
Uint16ToBytes uint16 value to bytes array using big order
func Uint16ToBytesTo ¶
Uint16ToBytesTo uint16 value to bytes array using big order
func Uint32ToBytes ¶
Uint32ToBytes uint32 value to bytes array using big order
func Uint32ToBytesTo ¶
Uint32ToBytesTo uint32 value to bytes array using big order
func Uint64ToBytes ¶
Uint64ToBytes uint64 value to bytes array using big order
func Uint64ToBytesTo ¶
Uint64ToBytesTo uint64 value to bytes array using big order
Types ¶
type Allocator ¶
type Allocator interface { // Alloc allocate a []byte with len(data) >= size, and the returned []byte cannot // be expanded in use. Alloc(capacity int) []byte // Free free the allocated memory Free([]byte) }
Allocator memory allocation for ByteBuf
type ByteBuf ¶
type ByteBuf struct {
// contains filtered or unexported fields
}
ByteBuf is a reusable buffer that holds an internal []byte and maintains 2 indexes for read and write data.
| discardable bytes | readable bytes | writeable bytes | | | | | | | | | 0 <= readerIndex <= writerIndex <= capacity
The ByteBuf implemented io.Reader, io.Writer, io.WriterTo, io.ReaderFrom interface
func NewByteBuf ¶
NewByteBuf create bytebuf with options
func (*ByteBuf) GetMarkIndex ¶
GetMarkIndex returns the markIndex.
func (*ByteBuf) GetMarkedDataLen ¶
GetMarkedDataLen returns len of marked data
func (*ByteBuf) GetReadIndex ¶
GetReadIndex returns the read index
func (*ByteBuf) GetWriteIndex ¶
GetWriteIndex get the write index
func (*ByteBuf) GetWriteOffset ¶
GetWriteOffset returns the offset of the current writeIndex relative to the ReadIndex. GetWriteIndex returns an absolute position, which will fail when the underlying buf is expanded.
func (*ByteBuf) MustReadByte ¶
MustReadByte is similar to ReadByte, buf panic if error retrurned
func (*ByteBuf) MustWriteByte ¶
MustWriteByte is similar to WriteByte, but panic if has any error
func (*ByteBuf) RawBuf ¶
RawBuf returns raw buf. This method requires special care, as the ByteBuf may free the internal []byte after the data is written again, causing the slice to fail.
func (*ByteBuf) RawSlice ¶
RawSlice returns raw buf in range [from, to). This method requires special care, as the ByteBuf may free the internal []byte after the data is written again, causing the slice to fail.
func (*ByteBuf) Read ¶
Read implemented io.Reader interface. return n, nil or 0, io.EOF is successful
func (*ByteBuf) ReadBytes ¶
ReadBytes read bytes from buf. It's will copy the data to a new byte array.
func (*ByteBuf) ReadMarkedData ¶
ReadMarkedData returns [readIndex, markIndex) data
func (*ByteBuf) ReadUint16 ¶
ReadUint16 get uint16 value from buf
func (*ByteBuf) ReadUint32 ¶
ReadUint32 get uint32 value from buf
func (*ByteBuf) ReadUint64 ¶
ReadUint64 get uint64 value from buf
func (*ByteBuf) SetMarkIndex ¶
SetMarkIndex mark data in range [readIndex, markIndex)
func (*ByteBuf) SetReadIndex ¶
SetReadIndex set the reader index. The data in the [readIndex, writeIndex] that can be read.
func (*ByteBuf) SetWriteIndex ¶
SetWriteIndex set the write index. The data can write into range [writeIndex, len(buf)). Note, since the underlying buf will expand, the previously held writeIndex will become invalid, and in most cases this method should use SetWriteIndexByOffset instead.
func (*ByteBuf) SetWriteIndexByOffset ¶
SetWriteIndexByOffset Use writeOffset to reset writeIndex, since offset is a relative position to readIndex, so it won't affect correctness when the underlying buf is expanded.
func (*ByteBuf) Slice ¶
Slice returns a read only bytebuf slice. ByteBuf may be continuously written to, causing the internal buf to reapply, thus invalidating the sliced data in buf[s:e]. Slice only records the starting location of the data, and it is safe to read the data when it is certain that the ByteBuf will not be written to.
func (*ByteBuf) WriteString ¶
WriteString write a string value to buf
func (*ByteBuf) WriteUint16 ¶
WriteUint16 write uint16 into buf
func (*ByteBuf) WriteUint32 ¶
WriteUint32 write uint32 into buf
func (*ByteBuf) WriteUint64 ¶
WriteUint64 write uint64 into buf
type Option ¶
type Option func(*ByteBuf)
Option bytebuf option
func WithDisableCompactAfterGrow ¶
disableCompactAfterGrow set Set whether the buffer should be compressed, if it is grow, it will reset the reader and writer index. Default is true.
func WithIOCopyBufferSize ¶
WithIOCopyBufferSize set io copy buffer used to control how much data will written at a time.
func WithMemAllocator ¶
WithMemAllocator Set the memory allocator, when Bytebuf is initialized, it needs to allocate a []byte of the size specified by capacity from memory. When ByteBuf.Release is called, the memory will be freed back to the allocator.
func WithMinGowSize ¶
WithMinGowSize set minimum Grow size. When there is not enough space left in the Bytebuf, write data needs to be expanded.