Documentation ¶
Overview ¶
Package buf provides a light-weight memory allocation mechanism.
Index ¶
- Constants
- func Pipe(timer *signal.ActivityTimer, reader Reader, writer Writer) error
- func PipeUntilEOF(timer *signal.ActivityTimer, reader Reader, writer Writer) error
- type Buffer
- func (b *Buffer) Append(data []byte)
- func (b *Buffer) AppendBytes(bytes ...byte)
- func (b *Buffer) AppendSupplier(writer Supplier) error
- func (b *Buffer) Byte(index int) byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) BytesFrom(from int) []byte
- func (b *Buffer) BytesRange(from, to int) []byte
- func (b *Buffer) BytesTo(to int) []byte
- func (b *Buffer) Clear()
- func (b *Buffer) IsEmpty() bool
- func (b *Buffer) IsFull() bool
- func (b *Buffer) Len() int
- func (b *Buffer) Read(data []byte) (int, error)
- func (b *Buffer) Release()
- func (b *Buffer) Reset(writer Supplier) error
- func (b *Buffer) SetByte(index int, value byte)
- func (b *Buffer) Slice(from, to int)
- func (b *Buffer) SliceFrom(from int)
- func (b *Buffer) String() string
- func (b *Buffer) Write(data []byte) (int, error)
- type BufferPool
- type BufferToBytesReader
- type BufferToBytesWriter
- type BytesToBufferReader
- type BytesToBufferWriter
- type Pool
- type Reader
- type Supplier
- type SyncPool
- type Writer
Constants ¶
const ( // Size of a regular buffer. Size = 8 * 1024 // SizeSmall is the size of a small buffer. SizeSmall = 2 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func Pipe ¶
func Pipe(timer *signal.ActivityTimer, reader Reader, writer Writer) error
Pipe dumps all content from reader to writer, until an error happens.
func PipeUntilEOF ¶
func PipeUntilEOF(timer *signal.ActivityTimer, reader Reader, writer Writer) error
PipeUntilEOF behaves the same as Pipe(). The only difference is PipeUntilEOF returns nil on EOF.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a recyclable allocation of a byte array. Buffer.Release() recycles the buffer into an internal buffer pool, in order to recreate a buffer more quickly.
func (*Buffer) AppendBytes ¶
AppendBytes appends one or more bytes to the end of the buffer.
func (*Buffer) AppendSupplier ¶
AppendSupplier appends the content of a BytesWriter to the buffer.
func (*Buffer) BytesFrom ¶
BytesFrom returns a slice of this Buffer starting from the given position.
func (*Buffer) BytesRange ¶
BytesRange returns a slice of this buffer with given from and to bounary.
func (*Buffer) Clear ¶
func (b *Buffer) Clear()
Clear clears the content of the buffer, results an empty buffer with Len() = 0.
func (*Buffer) Release ¶
func (b *Buffer) Release()
Release recycles the buffer into an internal buffer pool.
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool is a Pool that utilizes an internal cache.
func NewBufferPool ¶
func NewBufferPool(bufferSize, poolSize uint32) *BufferPool
NewBufferPool creates a new BufferPool with given buffer size, and internal cache size.
func (*BufferPool) Allocate ¶
func (p *BufferPool) Allocate() *Buffer
Allocate implements Pool.Allocate().
type BufferToBytesReader ¶
type BufferToBytesReader struct {
// contains filtered or unexported fields
}
func NewBytesReader ¶
func NewBytesReader(stream Reader) *BufferToBytesReader
func (*BufferToBytesReader) Fill ¶
func (v *BufferToBytesReader) Fill()
Fill fills in the internal buffer. Private: Visible for testing.
type BufferToBytesWriter ¶
type BufferToBytesWriter struct {
// contains filtered or unexported fields
}
BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
func (*BufferToBytesWriter) Write ¶
func (v *BufferToBytesWriter) Write(buffer *Buffer) error
Write implements Writer.Write(). Write() takes ownership of the given buffer.
type BytesToBufferReader ¶
type BytesToBufferReader struct {
// contains filtered or unexported fields
}
BytesToBufferReader is a Reader that adjusts its reading speed automatically.
func (*BytesToBufferReader) Read ¶
func (v *BytesToBufferReader) Read() (*Buffer, error)
Read implements Reader.Read().
type BytesToBufferWriter ¶
type BytesToBufferWriter struct {
// contains filtered or unexported fields
}
func NewBytesWriter ¶
func NewBytesWriter(writer Writer) *BytesToBufferWriter
type Pool ¶
type Pool interface { // Allocate either returns a unused buffer from the pool, or generates a new one from system. Allocate() *Buffer // Free recycles the given buffer. Free(*Buffer) }
Pool provides functionality to generate and recycle buffers on demand.
type Reader ¶
type Reader interface { // Read reads content from underlying reader, and put it into an alloc.Buffer. Read() (*Buffer, error) }
Reader extends io.Reader with alloc.Buffer.
type Supplier ¶
Supplier is a writer that writes contents into the given buffer.