Documentation ¶
Overview ¶
Package buffer provides the implementation of a buffer view.
Index ¶
- type Prependable
- type VectorisedView
- func (vv *VectorisedView) ByteSlice() [][]byte
- 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) SetSize(size int)
- func (vv *VectorisedView) SetViews(views []View)
- 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 (*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) UsedBytes ¶
func (p *Prependable) UsedBytes() []byte
UsedBytes returns a slice of the backing buffer that contains all prepended data so far.
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 contigous memory. It supports all the convenience methods supported by View.
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) ByteSlice ¶
func (vv *VectorisedView) ByteSlice() [][]byte
ByteSlice returns a slice containing the all views as a []byte.
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. It panics if the vectorised view is empty.
func (*VectorisedView) RemoveFirst ¶
func (vv *VectorisedView) RemoveFirst()
RemoveFirst removes the first view of the vectorised view.
func (*VectorisedView) SetSize ¶
func (vv *VectorisedView) SetSize(size int)
SetSize unsafely sets the size of the VectorisedView.
func (*VectorisedView) SetViews ¶
func (vv *VectorisedView) SetViews(views []View)
SetViews unsafely sets the views of the VectorisedView.
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 the a single view containing the content of the vectorised view.
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(views [1]View) VectorisedView
ToVectorisedView transforms a View in a VectorisedView from an already-allocated slice of View.