buffer

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 6 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

func GetRandomString added in v1.1.0

func GetRandomString(l int) string

func ParseUrl added in v1.1.0

func ParseUrl(url string) (ip string, port int, path string, err error)

ResolveUrl parse url to ip port path http://10.0.2.15/test http://10.0.2.15:8080/

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

+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) 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.

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) NextBytes added in v1.2.0

func (v *View) NextBytes(size int) []byte

NextBytes get next bytes

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