gvisorgvisor.dev/gvisor/pkg/tcpip/prependable Index | Files

package prependable

import "gvisor.dev/gvisor/pkg/tcpip/prependable"

Package prependable defines a buffer that grows backwards.

Index

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.

Source Files

prependable.go

Version
v0.0.0-20250515200445-d30c58e5b8a4 (latest)
Published
May 15, 2025
Platform
linux/amd64
Last checked
12 hours ago

Tools for package owners.