Documentation ¶
Index ¶
- type Buffer
- func (b *Buffer) Allocate(n int) []byte
- func (b *Buffer) AllocateOffset(n int) int
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Data(offset int) []byte
- func (b *Buffer) Grow(n int)
- func (b *Buffer) IsEmpty() bool
- func (b *Buffer) LenNoPadding() int
- func (b *Buffer) LenWithPadding() int
- func (b *Buffer) Release() error
- func (b *Buffer) Reset()
- func (b *Buffer) SliceAllocate(sz int) []byte
- func (b *Buffer) StartOffset() int
- func (b *Buffer) WithMaxSize(size int) *Buffer
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteSlice(slice []byte)
- type Slice
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is equivalent of bytes.Buffer without the ability to read. It is NOT thread-safe.
MaxSize can be set to limit the memory usage.
func (*Buffer) Allocate ¶
Allocate is a way to get a slice of size n back from the buffer. This slice can be directly written to. Warning: Allocate is not thread-safe. The byte slice returned MUST be used before further calls to Buffer.
func (*Buffer) AllocateOffset ¶
AllocateOffset works the same way as allocate, but instead of returning a byte slice, it returns the offset of the allocation.
func (*Buffer) Grow ¶
Grow would grow the buffer to have at least n more bytes. In case the buffer is at capacity, it would reallocate twice the size of current capacity + n, to ensure n bytes can be written to the buffer without further allocation. In UseMmap mode, this might result in underlying file expansion.
func (*Buffer) LenNoPadding ¶
LenNoPadding would return the number of bytes written to the buffer so far (without the padding).
func (*Buffer) LenWithPadding ¶
LenWithPadding would return the number of bytes written to the buffer so far plus the padding at the start of the buffer.
func (*Buffer) Release ¶
Release would free up the memory allocated by the buffer. Once the usage of buffer is done, it is important to call Release, otherwise a memory leak can happen.
func (*Buffer) SliceAllocate ¶
SliceAllocate would encode the size provided into the buffer, followed by a call to Allocate, hence returning the slice of size sz. This can be used to allocate a lot of small buffers into this big buffer. Note that SliceAllocate should NOT be mixed with normal calls to Write.