Documentation
¶
Index ¶
- Constants
- func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr)
- func LogEnabled(l *slog.Logger, lvl slog.Level) bool
- type Ring
- func (r *Ring) Buffered() int
- func (r *Ring) Free() int
- func (r *Ring) FreeLimited(limitOffset int) (free int)
- func (r *Ring) Read(b []byte) (int, error)
- func (r *Ring) ReadAt(p []byte, off64 int64) (int, error)
- func (r *Ring) ReadDiscard(n int) error
- func (r *Ring) ReadPeek(b []byte) (int, error)
- func (r *Ring) Reset()
- func (r *Ring) Size() int
- func (r *Ring) Write(b []byte) (int, error)
- func (r *Ring) WriteLimited(b []byte, limitOffset int) (int, error)
- func (r *Ring) WriteString(s string) (int, error)
- type Tap
Constants ¶
const HeapAllocDebugging = false
const (
LevelTrace slog.Level = slog.LevelDebug - 2
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ring ¶
type Ring struct { // Buf is used to store data written into Ring // with Write methods and then read out with Read methods. // The capacity of Buf is unused. // There is no readable data when End==0. Buf []byte // Start of readable data which indexes into Buf. // If Off==End and End!=0 the buffer is full and data begins at Off. Off int // End of readable data which indexes into Buf, not including byte at End index. // If End==0 then the buffer is empty. If End==Off and End!=0 the buffer is full. End int }
Ring implements basic Ring buffer functionality.
func (*Ring) Buffered ¶
Buffered returns amount of bytes ready to read from ring buffer. Always less than [ring.Size].
func (*Ring) Free ¶
Free returns amount of bytes that can be read into ring buffer before reaching maximum capacity given by [ring.Size]. Always less than [ring.Size].
func (*Ring) FreeLimited ¶
SizeLimited returns the amount of bytes that can be written up to the argument offset limitOffset. See Ring.WriteLimited
func (*Ring) Read ¶
Read reads up to len(b) bytes from the ring buffer and advances the read pointer. io.EOF returned when no data available.
func (*Ring) ReadAt ¶
ReadAt reads data at an offset from start of readable data but does not advance read pointer. io.EOF returned when no data available.
func (*Ring) ReadDiscard ¶
ReadDiscard is a performance auxiliary method that performs a dummy read or no-op read for advancing the read pointer n bytes without actually copying data. This method panics if amount of bytes is more than buffered (see Ring.Buffered).
func (*Ring) ReadPeek ¶
ReadPeek reads up to len(b) bytes from the ring buffer but does not advance the read pointer. io.EOF returned when no data available.
func (*Ring) Reset ¶
func (r *Ring) Reset()
Reset flushes all data from ring buffer so that no data can be further read.
func (*Ring) Write ¶
Write appends data to the ring buffer that can then be read back in order with Ring.Read methods. An error is returned if length of data too large for buffer. Write is guaranteed to start at buffer index [Ring.Off].
func (*Ring) WriteLimited ¶
WriteLimited performs a write that does not write over the ring buffer's limitOffset index, which points to a position to r.Buf. Up to Ring.FreeLimited bytes can be written.
func (*Ring) WriteString ¶
WriteString is a wrapper around Ring.Write that avoids allocation of converting byte slice to string.