buffer

package
v0.0.0-...-7585b01 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: Apache-2.0, MIT Imports: 4 Imported by: 1

Documentation

Overview

Package buffer provides the implementation of a buffer view.

A view is an flexible buffer, supporting the safecopy operations natively as well as the ability to grow via either prepend or append, as well as shrink.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer = View

Buffer is an alias to View.

type Range

type Range struct {
	// contains filtered or unexported fields
}

A Range specifies a range of buffer.

func (Range) Intersect

func (x Range) Intersect(y Range) Range

Intersect returns the intersection of x and y.

func (Range) Len

func (x Range) Len() int

Len returns the length of x.

func (Range) Offset

func (x Range) Offset(off int) Range

Offset returns x offset by off.

type View

type View struct {
	// contains filtered or unexported fields
}

View is a non-linear buffer.

All methods are thread compatible.

+stateify savable

func (*View) Append

func (v *View) Append(data []byte)

Append appends the given data.

func (*View) AppendOwned

func (v *View) AppendOwned(data []byte)

AppendOwned takes ownership of data and appends it to v.

func (*View) Apply

func (v *View) Apply(fn func([]byte))

Apply applies the given function across all valid data.

func (*View) Clone

func (v *View) Clone() *View

Clone makes a more shallow copy compared to Copy. The underlying payload slice (buffer.data) is shared but the buffers themselves are copied.

func (*View) Copy

func (v *View) Copy() (other View)

Copy makes a strict copy of this view.

func (*View) Flatten

func (v *View) Flatten() []byte

Flatten returns a flattened copy of this data.

This method should not be used in any performance-sensitive paths. It may allocate a fresh byte slice sufficiently large to contain all the data in the buffer. This is principally for debugging.

N.B. Tee data still belongs to this view, as if there is a single buffer present, then it will be returned directly. This should be used for temporary use only, and a reference to the given slice should not be held.

func (*View) Grow

func (v *View) Grow(length int64, zero bool)

Grow grows the given view to the number of bytes, which will be appended. If zero is true, all these bytes will be zero. If zero is false, then this is the caller's responsibility.

Precondition: length must be >= 0.

func (*View) Merge

func (v *View) Merge(other *View)

Merge merges the provided View with this one.

The other view will be appended to v, and other will be empty after this operation completes.

func (*View) Prepend

func (v *View) Prepend(data []byte)

Prepend prepends the given data.

func (*View) PullUp

func (v *View) PullUp(offset, length int) ([]byte, bool)

PullUp makes the specified range contiguous and returns the backing memory.

func (*View) ReadAt

func (v *View) ReadAt(p []byte, offset int64) (int, error)

ReadAt implements io.ReaderAt.ReadAt.

func (*View) ReadToWriter

func (v *View) ReadToWriter(w io.Writer, count int64) (int64, error)

ReadToWriter reads from the buffer into an io.Writer.

N.B. This does not consume the bytes read. TrimFront should be called appropriately after this call in order to do so.

A minimum write size equal to unsafe.Sizeof(unintptr) is enforced, provided that count is greater than or equal to unsafe.Sizeof(uintptr).

func (*View) Remove

func (v *View) Remove(offset, length int) bool

Remove deletes data at specified location in v. It returns false if specified range does not fully reside in v.

func (*View) Size

func (v *View) Size() int64

Size indicates the total amount of data available in this view.

func (*View) StateFields

func (v *View) StateFields() []string

func (*View) StateLoad

func (v *View) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*View) StateSave

func (v *View) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*View) StateTypeName

func (v *View) StateTypeName() string

func (*View) SubApply

func (v *View) SubApply(offset, length int, fn func([]byte))

SubApply applies fn to a given range of data in v. Any part of the range outside of v is ignored.

func (*View) TrimFront

func (v *View) TrimFront(count int64)

TrimFront removes the first count bytes from the buffer.

func (*View) Truncate

func (v *View) Truncate(length int64)

Truncate truncates the view to the given bytes.

This will not grow the view, only shrink it. If a length is passed that is greater than the current size of the view, then nothing will happen.

Precondition: length must be >= 0.

func (*View) WriteFromReader

func (v *View) WriteFromReader(r io.Reader, count int64) (int64, error)

WriteFromReader writes to the buffer from an io.Reader.

A minimum read size equal to unsafe.Sizeof(unintptr) is enforced, provided that count is greater than or equal to unsafe.Sizeof(uintptr).

Jump to

Keyboard shortcuts

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