memview

package
v0.0.0-...-f1bff1d Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemView

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

MemView represents a "view" on a collection of byte slices. Conceptually, you may think of it as a [][]byte, with helper methods to make it seem like one contiguous []byte. It is designed to help minimize the amount of copying when dealing with large buffers of data.

Modifying a MemView does not change the underlying data. Instead, it simply changes the pointers to where to read data from.

Copying a MemView or passing memView by value is like copying a slice - it's efficient, but modifications to the copy affect the original MemView and vice versa. Use `DeepCopy` to create a completely independent MemView.

The zero value is an empty MemView ready to use.

func Empty

func Empty() MemView

Make an empty memview

func New

func New(data []byte) MemView

The new MemView does NOT make a copy of data, so the caller MUST ensure that the underlying memory of data remains valid and unmodified after this call returns.

func (*MemView) Append

func (dst *MemView) Append(src MemView)

func (*MemView) Clear

func (mv *MemView) Clear()

func (*MemView) CreateReader

func (mv *MemView) CreateReader() *MemViewReader

func (MemView) DeepCopy

func (mv MemView) DeepCopy() MemView

Creates a MemView that is completely independent from the current one.

func (MemView) Equal

func (left MemView) Equal(right MemView) bool

func (MemView) GetByte

func (mv MemView) GetByte(index int64) byte

Returns the byte at the given index. Returns 0 if index is out of bounds.

func (MemView) GetUint16

func (mv MemView) GetUint16(offset int64) uint16

Returns mv[offset:offset+2], interpreted as a uint16 in network (big endian) order. Returns 0 if offset+1 is out of bounds.

func (MemView) GetUint24

func (mv MemView) GetUint24(offset int64) uint32

Returns mv[offset:offset+3], interpreted as an unsigned 24-bit integer in network (big endian) order. Returns 0 if offset+2 is out of bounds.

func (MemView) GetUint32

func (mv MemView) GetUint32(offset int64) uint32

Returns mv[offset:offset+4], interpreted as a uint32 in network (big endian) order. Returns 0 if offset+3 is out of bounds.

func (MemView) Index

func (mv MemView) Index(start int64, sep []byte) int64

Index returns the index of the first instance of sep in mv after start index, or -1 if sep is not present in mv.

func (MemView) Len

func (mv MemView) Len() int64

func (MemView) String

func (mv MemView) String() string

Returns a string of all the data referenced by this MemView. Note that is creates a COPY of the underlying data.

func (MemView) SubView

func (mv MemView) SubView(start, end int64) MemView

Returns mv[start:end] (end is not inclusive). Returns an empty MemView if range is invalid.

type MemViewReader

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

func (*MemViewReader) Read

func (r *MemViewReader) Read(out []byte) (int, error)

If MemView has no data to return, err is io.EOF (unless len(out) is zero), otherwise it is nil. This behavior matches that of bytes.Buffer.

func (*MemViewReader) ReadByte

func (r *MemViewReader) ReadByte() (byte, error)

func (*MemViewReader) ReadByteAndSeek

func (r *MemViewReader) ReadByteAndSeek() error

Seeks past a variable-length field by reading the next byte value and seeking that number of bytes.

func (*MemViewReader) ReadString

func (r *MemViewReader) ReadString(length int) (string, error)

Reads a string of the given length.

func (*MemViewReader) ReadString_byte

func (r *MemViewReader) ReadString_byte() (string, error)

Reads a string whose length is indicated by the next byte.

func (*MemViewReader) ReadString_uint16

func (r *MemViewReader) ReadString_uint16() (string, error)

Reads a string whose length is indicated by the next uint16.

func (*MemViewReader) ReadUint16

func (r *MemViewReader) ReadUint16() (uint16, error)

func (*MemViewReader) ReadUint16AndSeek

func (r *MemViewReader) ReadUint16AndSeek() error

Seeks past a variable-length field by reading the next uint16 value and seeking that number of bytes.

func (*MemViewReader) ReadUint16AndTruncate

func (r *MemViewReader) ReadUint16AndTruncate() (length uint16, fieldReader *MemViewReader, err error)

Returns a new reader for a field whose length is indicated by the next uint16 value, and the length of that field. On return, this reader will have its position advanced by two bytes and the returned reader will be the result of truncating to the field's length.

func (*MemViewReader) ReadUint24

func (r *MemViewReader) ReadUint24() (uint32, error)

func (*MemViewReader) ReadUint24AndTruncate

func (r *MemViewReader) ReadUint24AndTruncate() (length uint32, fieldReader *MemViewReader, err error)

Returns a new reader for a field whose length is indicated by the next uint24 value, and the length of that field. On return, this reader will have its position advanced by three bytes and the returned reader will be the result of truncating to the field's length.

func (*MemViewReader) ReadUint32

func (r *MemViewReader) ReadUint32() (uint32, error)

func (*MemViewReader) Seek

func (r *MemViewReader) Seek(offset int64, whence int) (absoluteOffset int64, err error)

Implements ReadSeeker.Seek.

func (*MemViewReader) Truncate

func (r *MemViewReader) Truncate(offset int64) (*MemViewReader, error)

Returns a copy of this MemViewReader, except the underlying MemView is a subview from the current position to the given relative offset. Returns an error if the offset is negative or is past the end of the current MemView.

func (*MemViewReader) WriteTo

func (r *MemViewReader) WriteTo(dst io.Writer) (int64, error)

Make MemView more efficient as a source in io.Copy.

Jump to

Keyboard shortcuts

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