buffer

package
v0.0.0-...-55fcc16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2019 License: Apache-2.0 Imports: 0 Imported by: 192

Documentation

Overview

Package buffer provides the implementation of a buffer view.

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 NewEmptyPrependableFromView

func NewEmptyPrependableFromView(v View) Prependable

NewEmptyPrependableFromView creates a new prependable buffer from a View.

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) 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() 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

func NewView(size int) View

NewView allocates a new buffer and returns an initialized view that covers the whole buffer.

func NewViewFromBytes

func NewViewFromBytes(b []byte) View

NewViewFromBytes allocates a new buffer and copies in the given bytes.

func (*View) CapLength

func (v *View) CapLength(length int)

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.

func (*View) TrimFront

func (v *View) TrimFront(count int)

TrimFront removes the first "count" bytes from the visible section of the buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL