Documentation ¶
Overview ¶
Package prependable defines a buffer that grows backwards.
Index ¶
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 New ¶
func New(size int) Prependable
New allocates a new prependable buffer with the given size.
func NewEmptyFromSlice ¶
func NewEmptyFromSlice(v []byte) Prependable
NewEmptyFromSlice creates a new prependable buffer from a slice.
func NewFromSlice ¶
func NewFromSlice(v []byte) Prependable
NewFromSlice creates an entirely-used Prependable from a slice.
NewFromSlice 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) DeepCopy ¶
func (p Prependable) DeepCopy() Prependable
DeepCopy copies p and the bytes backing it.
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() []byte
View returns a slice of the backing buffer that contains all prepended data so far.