Documentation ¶
Overview ¶
Package buffer provides the implementation of a buffer view.
Index ¶
- type Prependable
- type VectorisedView
- func (vv *VectorisedView) Append(vv2 VectorisedView)
- func (vv *VectorisedView) CapLength(length int)
- func (vv VectorisedView) Clone(buffer []View) VectorisedView
- func (vv VectorisedView) First() View
- func (vv *VectorisedView) RemoveFirst()
- func (vv VectorisedView) Size() int
- func (vv VectorisedView) ToView() View
- func (vv *VectorisedView) TrimFront(count int)
- func (vv VectorisedView) Views() []View
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Prependable ¶
type Prependable struct {
// contains filtered or unexported fields
}
Prependable is a buffer that grows backwards, that is, more data can be prepended to it. It is useful when building networking packets, where each protocol adds its own headers to the front of the higher-level protocol header and payload; for example, TCP would prepend its header to the payload, then IP would prepend its own, then ethernet.
func NewPrependable ¶
func NewPrependable(size int) Prependable
NewPrependable allocates a new prependable buffer with the given size.
func NewPrependableFromView ¶
func NewPrependableFromView(v View) Prependable
NewPrependableFromView creates an entirely-used Prependable from a View.
NewPrependableFromView takes ownership of v. Note that since the entire prependable is used, further attempts to call Prepend will note that size > p.usedIdx and return nil.
func (Prependable) AvailableLength ¶
func (p Prependable) AvailableLength() int
AvailableLength returns the number of bytes used so far.
func (*Prependable) Prepend ¶
func (p *Prependable) Prepend(size int) []byte
Prepend reserves the requested space in front of the buffer, returning a slice that represents the reserved space.
func (*Prependable) TrimBack ¶
func (p *Prependable) TrimBack(size int)
TrimBack removes size bytes from the end.
func (Prependable) UsedLength ¶
func (p Prependable) UsedLength() int
UsedLength returns the number of bytes used so far.
func (Prependable) View ¶
func (p Prependable) View() View
View returns a View of the backing buffer that contains all prepended data so far.
type VectorisedView ¶
type VectorisedView struct {
// contains filtered or unexported fields
}
VectorisedView is a vectorised version of View using non contiguous memory. It supports all the convenience methods supported by View.
+stateify savable
func NewVectorisedView ¶
func NewVectorisedView(size int, views []View) VectorisedView
NewVectorisedView creates a new vectorised view from an already-allocated slice of View and sets its size.
func (*VectorisedView) Append ¶
func (vv *VectorisedView) Append(vv2 VectorisedView)
Append appends the views in a vectorised view to this vectorised view.
func (*VectorisedView) CapLength ¶
func (vv *VectorisedView) CapLength(length int)
CapLength irreversibly reduces the length of the vectorised view.
func (VectorisedView) Clone ¶
func (vv VectorisedView) Clone(buffer []View) VectorisedView
Clone returns a clone of this VectorisedView. If the buffer argument is large enough to contain all the Views of this VectorisedView, the method will avoid allocations and use the buffer to store the Views of the clone.
func (VectorisedView) First ¶
func (vv VectorisedView) First() View
First returns the first view of the vectorised view.
func (*VectorisedView) RemoveFirst ¶
func (vv *VectorisedView) RemoveFirst()
RemoveFirst removes the first view of the vectorised view.
func (VectorisedView) Size ¶
func (vv VectorisedView) Size() int
Size returns the size in bytes of the entire content stored in the vectorised view.
func (VectorisedView) ToView ¶
func (vv VectorisedView) ToView() View
ToView returns a single view containing the content of the vectorised view.
If the vectorised view contains a single view, that view will be returned directly.
func (*VectorisedView) TrimFront ¶
func (vv *VectorisedView) TrimFront(count int)
TrimFront removes the first "count" bytes of the vectorised view.
func (VectorisedView) Views ¶
func (vv VectorisedView) Views() []View
Views returns the slice containing the all views.
type View ¶
type View []byte
View is a slice of a buffer, with convenience methods.
func NewView ¶
NewView allocates a new buffer and returns an initialized view that covers the whole buffer.
func NewViewFromBytes ¶
NewViewFromBytes allocates a new buffer and copies in the given bytes.
func (*View) CapLength ¶
CapLength irreversibly reduces the length of the visible section of the buffer to the value specified.
func (View) ToVectorisedView ¶
func (v View) ToVectorisedView() VectorisedView
ToVectorisedView returns a VectorisedView containing the receiver.