internal

package
v2.3.5 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ByteInputAdapterPool shared pool
	ByteInputAdapterPool = sync.Pool{
		New: func() interface{} {
			return &ByteInputAdapter{}
		},
	}

	// ByteBufferPool shared pool
	ByteBufferPool = sync.Pool{
		New: func() interface{} {
			return &ByteBuffer{}
		},
	}
)

Functions

This section is empty.

Types

type ByteBuffer

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

ByteBuffer raw bytes wrapper

func NewByteBuffer

func NewByteBuffer(buf []byte) *ByteBuffer

NewByteBuffer creates a new ByteBuffer.

func (*ByteBuffer) GetReadBytes

func (b *ByteBuffer) GetReadBytes() int64

GetReadBytes returns read bytes

func (*ByteBuffer) Next

func (b *ByteBuffer) Next(n int) ([]byte, error)

Next returns a slice containing the next n bytes from the reader If there are fewer bytes than the given n, io.ErrUnexpectedEOF will be returned

func (*ByteBuffer) NextReturnsSafeSlice

func (b *ByteBuffer) NextReturnsSafeSlice() bool

NextReturnsSafeSlice returns false since ByteBuffer might hold an array owned by some other systems.

func (*ByteBuffer) Read

func (b *ByteBuffer) Read(p []byte) (int, error)

Read implements io.Reader.

func (*ByteBuffer) ReadUInt16

func (b *ByteBuffer) ReadUInt16() (uint16, error)

ReadUInt16 reads uint16 with LittleEndian order

func (*ByteBuffer) ReadUInt32

func (b *ByteBuffer) ReadUInt32() (uint32, error)

ReadUInt32 reads uint32 with LittleEndian order

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset(buf []byte)

Reset resets the given buffer with a new byte slice

func (*ByteBuffer) SkipBytes

func (b *ByteBuffer) SkipBytes(n int) error

SkipBytes skips exactly n bytes

type ByteInput

type ByteInput interface {
	// Next returns a slice containing the next n bytes from the buffer,
	// advancing the buffer as if the bytes had been returned by Read.
	Next(n int) ([]byte, error)
	// NextReturnsSafeSlice returns true if Next() returns a safe slice as opposed
	// to a slice that points to an underlying buffer possibly owned by another system.
	// When NextReturnsSafeSlice returns false, the result from Next() should be copied
	// before it is modified (i.e., it is immutable).
	NextReturnsSafeSlice() bool
	// ReadUInt32 reads uint32 with LittleEndian order
	ReadUInt32() (uint32, error)
	// ReadUInt16 reads uint16 with LittleEndian order
	ReadUInt16() (uint16, error)
	// GetReadBytes returns read bytes
	GetReadBytes() int64
	// SkipBytes skips exactly n bytes
	SkipBytes(n int) error
}

ByteInput typed interface around io.Reader or raw bytes

func NewByteInput

func NewByteInput(buf []byte) ByteInput

NewByteInput creates raw bytes wrapper

func NewByteInputFromReader

func NewByteInputFromReader(reader io.Reader) ByteInput

NewByteInputFromReader creates reader wrapper

type ByteInputAdapter

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

ByteInputAdapter reader wrapper

func (*ByteInputAdapter) GetReadBytes

func (b *ByteInputAdapter) GetReadBytes() int64

GetReadBytes returns read bytes

func (*ByteInputAdapter) Next

func (b *ByteInputAdapter) Next(n int) ([]byte, error)

Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read.

func (*ByteInputAdapter) NextReturnsSafeSlice

func (b *ByteInputAdapter) NextReturnsSafeSlice() bool

NextReturnsSafeSlice returns true since ByteInputAdapter always returns a slice allocated with make([]byte, ...)

func (*ByteInputAdapter) Read

func (b *ByteInputAdapter) Read(buf []byte) (int, error)

Read implements io.Reader.

func (*ByteInputAdapter) ReadUInt16

func (b *ByteInputAdapter) ReadUInt16() (uint16, error)

ReadUInt16 reads uint16 with LittleEndian order

func (*ByteInputAdapter) ReadUInt32

func (b *ByteInputAdapter) ReadUInt32() (uint32, error)

ReadUInt32 reads uint32 with LittleEndian order

func (*ByteInputAdapter) Reset

func (b *ByteInputAdapter) Reset(stream io.Reader)

Reset resets the given buffer with a new stream

func (*ByteInputAdapter) SkipBytes

func (b *ByteInputAdapter) SkipBytes(n int) error

SkipBytes skips exactly n bytes

Jump to

Keyboard shortcuts

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