internal

package
v0.0.0-...-d996040 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const HeapAllocDebugging = false
View Source
const (
	LevelTrace slog.Level = slog.LevelDebug - 2
)

Variables

This section is empty.

Functions

func LogAttrs

func LogAttrs(l *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr)

LogAttrs is a helper function that is used by all package loggers and that can be switched out with the `debugheaplog` build tag for a non-allocating logger that prints out when heap allocations occur.

func LogEnabled

func LogEnabled(l *slog.Logger, lvl slog.Level) bool

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

func (r *Ring) Buffered() int

Buffered returns amount of bytes ready to read from ring buffer. Always less than [ring.Size].

func (*Ring) Free

func (r *Ring) Free() int

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

func (r *Ring) FreeLimited(limitOffset int) (free int)

SizeLimited returns the amount of bytes that can be written up to the argument offset limitOffset. See Ring.WriteLimited

func (*Ring) Read

func (r *Ring) Read(b []byte) (int, error)

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

func (r *Ring) ReadAt(p []byte, off64 int64) (int, error)

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

func (r *Ring) ReadDiscard(n int) error

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

func (r *Ring) ReadPeek(b []byte) (int, error)

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) Size

func (r *Ring) Size() int

Size returns the capacity of the ring buffer.

func (*Ring) Write

func (r *Ring) Write(b []byte) (int, error)

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

func (r *Ring) WriteLimited(b []byte, limitOffset int) (int, error)

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

func (r *Ring) WriteString(s string) (int, error)

WriteString is a wrapper around Ring.Write that avoids allocation of converting byte slice to string.

type Tap

type Tap struct {
	// contains filtered or unexported fields
}

func NewTap

func NewTap(name string, ip netip.Prefix) (*Tap, error)

func (*Tap) Close

func (tap *Tap) Close() error

func (*Tap) Read

func (tap *Tap) Read(b []byte) (int, error)

func (*Tap) Write

func (tap *Tap) Write(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL