Documentation ¶
Overview ¶
Package buffer provides the implementation of a buffer view.
A view is an flexible buffer, supporting the safecopy operations natively as well as the ability to grow via either prepend or append, as well as shrink.
Index ¶
- type Buffer
- type Range
- type View
- func (v *View) Append(data []byte)
- func (v *View) AppendOwned(data []byte)
- func (v *View) Apply(fn func([]byte))
- func (v *View) Clone() *View
- func (v *View) Copy() (other View)
- func (v *View) Flatten() []byte
- func (v *View) Grow(length int64, zero bool)
- func (v *View) Merge(other *View)
- func (v *View) Prepend(data []byte)
- func (v *View) PullUp(offset, length int) ([]byte, bool)
- func (v *View) ReadAt(p []byte, offset int64) (int, error)
- func (v *View) ReadToWriter(w io.Writer, count int64) (int64, error)
- func (v *View) Remove(offset, length int) bool
- func (v *View) Size() int64
- func (v *View) SubApply(offset, length int, fn func([]byte))
- func (v *View) TrimFront(count int64)
- func (v *View) Truncate(length int64)
- func (v *View) WriteFromReader(r io.Reader, count int64) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
A Range specifies a range of buffer.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View is a non-linear buffer.
All methods are thread compatible.
+stateify savable
func (*View) AppendOwned ¶
AppendOwned takes ownership of data and appends it to v.
func (*View) Clone ¶
Clone makes a more shallow copy compared to Copy. The underlying payload slice (buffer.data) is shared but the buffers themselves are copied.
func (*View) Flatten ¶
Flatten returns a flattened copy of this data.
This method should not be used in any performance-sensitive paths. It may allocate a fresh byte slice sufficiently large to contain all the data in the buffer. This is principally for debugging.
N.B. Tee data still belongs to this view, as if there is a single buffer present, then it will be returned directly. This should be used for temporary use only, and a reference to the given slice should not be held.
func (*View) Grow ¶
Grow grows the given view to the number of bytes, which will be appended. If zero is true, all these bytes will be zero. If zero is false, then this is the caller's responsibility.
Precondition: length must be >= 0.
func (*View) Merge ¶
Merge merges the provided View with this one.
The other view will be appended to v, and other will be empty after this operation completes.
func (*View) ReadToWriter ¶
ReadToWriter reads from the buffer into an io.Writer.
N.B. This does not consume the bytes read. TrimFront should be called appropriately after this call in order to do so.
A minimum write size equal to unsafe.Sizeof(unintptr) is enforced, provided that count is greater than or equal to unsafe.Sizeof(uintptr).
func (*View) Remove ¶
Remove deletes data at specified location in v. It returns false if specified range does not fully reside in v.
func (*View) SubApply ¶
SubApply applies fn to a given range of data in v. Any part of the range outside of v is ignored.