Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a collection of ordered Chunks that can cheaply read and shifted as if it were a continuous byte stream.
A Buffer is not goroutine-safe.
The primary means of interacting with a Buffer is to construct a View and then use it to access the Buffer's contents. Views can be used concurrently, and View operations are goroutine-safe.
func (*Buffer) Append ¶
Append adds additional Chunks to the buffer.
After completion, the Chunk is now owned by the Buffer and should not be used anymore externally.
func (*Buffer) Bytes ¶
Bytes constructs a byte slice containing the contents of the Buffer.
This is a potentially expensive operation, and should generally be used only for debugging and tests, as it defeats most of the purpose of this package.
func (*Buffer) Consume ¶
Consume removes the specified number of bytes from the beginning of the Buffer. If Consume skips past all of the data in a Chunk is no longer needed, it is Release()d.
func (*Buffer) FirstChunk ¶
FirstChunk returns the first Chunk in the Buffer, or nil if the Buffer has no Chunks.
func (*Buffer) View ¶
View returns a View instance bound to this Buffer and spanning all data currently in the Buffer.
The View is no longer valid after Consume is called on the Buffer.
type Chunk ¶
type Chunk interface { // Bytes returns the underlying byte slice contained by this Chunk. Bytes() []byte // Release releases the Chunk. After being released, a Chunk's methods must no // longer be used. // // It is a good idea to set your chunk variable to nil after releasing it. Release() }
Chunk wraps a fixed-size byte buffer. It is the primary interface used by the chunk library.
A Chunk reference should be released once the user is finished with it. After being released, it may no longer be accessed.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View is static read-only snapshot of the contents of the Buffer, presented as a contiguous stream of bytes.
View implements the io.Reader and io.ByteReader interfaces. It also offers a series of utility functions optimized for the chunks.
func (*View) Clone ¶
Clone returns a copy of the View view.
The clone is bound to the same underlying Buffer as the source.
func (*View) CloneLimit ¶
CloneLimit returns a copy of the View view, optionally truncating it.
The clone is bound to the same underlying Buffer as the source.
func (*View) Consumed ¶
Consumed returns the number of bytes that have been skipped via Skip or higher-level calls.
func (*View) Index ¶
Index scans the View for the specified needle bytes. If they are found, their index in the View is returned. Otherwise, Index returns -1.
The View is not modified during the search.