Documentation ¶
Index ¶
- type LookAheadBuffer
- func (b *LookAheadBuffer) Buffer() []byte
- func (b *LookAheadBuffer) BytesBuffered() int
- func (b *LookAheadBuffer) Consume(numBytes int) error
- func (b *LookAheadBuffer) ConsumeAll()
- func (b *LookAheadBuffer) Peek(numBytes int) ([]byte, error)
- func (b *LookAheadBuffer) PeekAll() ([]byte, error)
- func (b *LookAheadBuffer) RawBuffer() []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LookAheadBuffer ¶
type LookAheadBuffer struct {
// contains filtered or unexported fields
}
LookAheadBuffer provides I/O look ahead functionality. This is particularly useful for building parsers. NOTE: LookAheadBuffer has similar functionality as bufio.Reader. However, unlike bufio.Reader, LookAheadBuffer's raw buffer size will EXACTLY match the specified size (whereas bufio.Reader's buffer size may differ from the specified size). This property ensures the buffer will not accidentally read beyond the expected size.
func NewLookAheadBuffer ¶
func NewLookAheadBuffer(src io.Reader, bufferSize int) *LookAheadBuffer
NewLookAheadBuffer returns a new LookAheadBuffer whose raw buffer has EXACTLY the specified size.
func NewLookAheadBufferUsing ¶
func NewLookAheadBufferUsing(src io.Reader, rawBuffer []byte) *LookAheadBuffer
NewLookAheadBufferUsing returns a new LookAheadBuffer which uses the provided buffer as its raw buffer. This allows buffer reuse, which reduces unnecessary memory allocation.
func (*LookAheadBuffer) Buffer ¶
func (b *LookAheadBuffer) Buffer() []byte
Buffer returns a slice of the look ahead buffer which holds useful bytes. This call is equivalient to b.RawBuffer()[:b.BytesBuffered()].
func (*LookAheadBuffer) BytesBuffered ¶
func (b *LookAheadBuffer) BytesBuffered() int
BytesBuffered returns the number of bytes in the look ahead buffer populated by Peek() or PeekAll().
func (*LookAheadBuffer) Consume ¶
func (b *LookAheadBuffer) Consume(numBytes int) error
Consume drops the first numBytes number of populated bytes from the look ahead buffer. NOTE: This is an O(n) operation since it requires shifting the remaining bytes to the beginning of the buffer. Avoid consuming the buffer byte by byte.
func (*LookAheadBuffer) ConsumeAll ¶
func (b *LookAheadBuffer) ConsumeAll()
ConsumeAll drops all populated bytes from the look ahead buffer.
func (*LookAheadBuffer) Peek ¶
func (b *LookAheadBuffer) Peek(numBytes int) ([]byte, error)
Peek returns a slice of the look ahead buffer which holds numBytes number of bytes. If the look ahead buffer does not already hold enough bytes, it will read from the underlying reader to populate the rest. NOTE: the returned slice is not a copy of the raw buffer.
func (*LookAheadBuffer) PeekAll ¶
func (b *LookAheadBuffer) PeekAll() ([]byte, error)
PeekAll returns the entire look ahead buffer with all bytes populated. If the look ahead buffer does not already hold enough bytes, it will read from the underlying reader to populate the rest. NOTE: the returned slice is not a copy of the raw buffer.
func (*LookAheadBuffer) RawBuffer ¶
func (b *LookAheadBuffer) RawBuffer() []byte
RawBuffer returns the full look ahead buffer. The raw buffer may not all have bytes populated (i.e., b.BytesBuffered() <= len(b.RawBuffer())).