Documentation
¶
Overview ¶
Package ringbuffer provides a ring buffer for storing blocks of bytes. Bytes are written and read in discrete blocks. If the buffer becomes full, then writing to it will evict the oldest blocks until there is space for a new one.
Index ¶
Constants ¶
const BlockHeaderSize = 5
BlockHeaderSize is the size of the block header, in bytes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockHeader ¶
type BlockHeader struct { // Tag is the block's tag. Tag BlockTag // Size is the size of the block data, in bytes. Size uint32 }
BlockHeader holds a fixed-size block header.
type Buffer ¶
type Buffer struct { // Evicted will be called when an old block is evicted to make place for a new one. Evicted func(BlockHeader) // contains filtered or unexported fields }
Buffer is a ring buffer of byte blocks.
func (*Buffer) Len ¶
Len returns the number of bytes currently in the buffer, including block-accounting bytes.
func (*Buffer) WriteBlock ¶
WriteBlock writes p as a block to b, with tag t.
If len(p)+BlockHeaderSize > b.Cap(), bytes.ErrTooLarge will be returned. If the buffer does not currently have room for the block, then the oldest blocks will be evicted until enough room is available.
func (*Buffer) WriteBlockTo ¶
WriteBlockTo writes the oldest block in b to w, returning the block header and the number of bytes written to w.