Documentation
¶
Index ¶
- type MemView
- func (dst *MemView) Append(src MemView)
- func (mv *MemView) Clear()
- func (mv *MemView) CreateReader() *MemViewReader
- func (mv MemView) DeepCopy() MemView
- func (left MemView) Equal(right MemView) bool
- func (mv MemView) GetByte(index int64) byte
- func (mv MemView) GetUint16(offset int64) uint16
- func (mv MemView) GetUint24(offset int64) uint32
- func (mv MemView) GetUint32(offset int64) uint32
- func (mv MemView) Index(start int64, sep []byte) int64
- func (mv MemView) Len() int64
- func (mv MemView) String() string
- func (mv MemView) SubView(start, end int64) MemView
- type MemViewReader
- func (r *MemViewReader) Read(out []byte) (int, error)
- func (r *MemViewReader) ReadByte() (byte, error)
- func (r *MemViewReader) ReadByteAndSeek() error
- func (r *MemViewReader) ReadString(length int) (string, error)
- func (r *MemViewReader) ReadString_byte() (string, error)
- func (r *MemViewReader) ReadString_uint16() (string, error)
- func (r *MemViewReader) ReadUint16() (uint16, error)
- func (r *MemViewReader) ReadUint16AndSeek() error
- func (r *MemViewReader) ReadUint16AndTruncate() (length uint16, fieldReader *MemViewReader, err error)
- func (r *MemViewReader) ReadUint24() (uint32, error)
- func (r *MemViewReader) ReadUint24AndTruncate() (length uint32, fieldReader *MemViewReader, err error)
- func (r *MemViewReader) ReadUint32() (uint32, error)
- func (r *MemViewReader) Seek(offset int64, whence int) (absoluteOffset int64, err error)
- func (r *MemViewReader) Truncate(offset int64) (*MemViewReader, error)
- func (r *MemViewReader) WriteTo(dst io.Writer) (int64, error)
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 New ¶
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) CreateReader ¶
func (mv *MemView) CreateReader() *MemViewReader
func (MemView) GetUint16 ¶
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 ¶
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 ¶
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 ¶
Index returns the index of the first instance of sep in mv after start index, or -1 if sep is not present in mv.
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.