buffer

package
v0.0.0-...-4bf4b70 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Apache-2.0, MIT Imports: 4 Imported by: 0

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

func (vv *VectorisedView) AppendView(v View)

AppendView appends the given view into 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) PullUp

func (vv *VectorisedView) PullUp(count int) (View, bool)

PullUp returns the first "count" bytes of the vectorised view. If those bytes aren't already contiguous inside the vectorised view, PullUp will reallocate as needed to make them contiguous. PullUp fails and returns false when count > vv.Size().

func (*VectorisedView) Read

func (vv *VectorisedView) Read(b []byte) (copied int, err error)

Read implements io.Reader.

func (*VectorisedView) ReadTo

func (vv *VectorisedView) ReadTo(dst io.Writer, peek bool) (int, error)

ReadTo reads up to count bytes from vv to dst. It also removes them from vv unless peek is true.

func (*VectorisedView) ReadToVV

func (vv *VectorisedView) ReadToVV(dstVV *VectorisedView, count int) (copied int)

ReadToVV reads up to n bytes from vv to dstVV and removes them from vv. It returns the number of bytes copied.

func (*VectorisedView) Readers

func (vv *VectorisedView) Readers() []bytes.Reader

Readers returns a bytes.Reader for each of vv's views.

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

func (vv *VectorisedView) StateFields() []string

func (*VectorisedView) StateLoad

func (vv *VectorisedView) StateLoad(stateSourceObject state.Source)

func (*VectorisedView) StateSave

func (vv *VectorisedView) StateSave(stateSinkObject state.Sink)

func (*VectorisedView) StateTypeName

func (vv *VectorisedView) StateTypeName() string

func (*VectorisedView) ToOwnedView

func (vv *VectorisedView) ToOwnedView() View

ToOwnedView returns a single view containing the content of the vectorised view that vv does not own.

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. It panics if count > vv.Size().

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

func (v View) IsEmpty() bool

IsEmpty returns whether v is of length zero.

func (*View) Reader

func (v *View) Reader() bytes.Reader

Reader returns a bytes.Reader for v.

func (View) Size

func (v View) Size() int

Size returns the length of v.

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