godropbox: github.com/dropbox/godropbox/bufio2 Index | Files

package bufio2

import "github.com/dropbox/godropbox/bufio2"

Index

Package Files

look_ahead_buffer.go

type LookAheadBuffer Uses

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 Uses

func NewLookAheadBuffer(src io.Reader, bufferSize int) *LookAheadBuffer

NewLookAheadBuffer returns a new LookAheadBuffer whose raw buffer has EXACTLY the specified size.

func NewLookAheadBufferUsing Uses

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 Uses

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 Uses

func (b *LookAheadBuffer) BytesBuffered() int

BytesBuffered returns the number of bytes in the look ahead buffer populated by Peek() or PeekAll().

func (*LookAheadBuffer) Consume Uses

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 Uses

func (b *LookAheadBuffer) ConsumeAll()

ConsumeAll drops all populated bytes from the look ahead buffer.

func (*LookAheadBuffer) Peek Uses

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 Uses

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 Uses

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())).

Package bufio2 imports 2 packages (graph) and is imported by 21 packages. Updated 2018-03-02. Refresh now. Tools for package owners.