io

package
v0.0.0-...-d1ba03b Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadTlvStream

func ReadTlvStream(
	reader io.Reader,
	onFrame func([]byte) bool,
	ignoreError func(error) bool,
) error

Reads a TLV-encoded stream from the given reader, processes each complete TLV block via the onFrame callback, and handles errors using the ignoreError callback until EOF or an unignorable error occurs.

Types

type TimedWriter

type TimedWriter struct {
	*bufio.Writer
	// contains filtered or unexported fields
}

TimedWriter is a buffered writer that flushes automatically when a deadline is set and the deadline is exceeded.

func NewTimedWriter

func NewTimedWriter(io io.Writer, bufsize int) *TimedWriter

Constructs a `TimedWriter` with the provided `io.Writer` and buffer size, initialized with a default write deadline of 1 millisecond and a maximum queue size of 8.

func (*TimedWriter) Flush

func (w *TimedWriter) Flush() error

Safely flushes any buffered data from the TimedWriter by acquiring a mutex lock before invoking the internal flush operation, returning any resulting errors.

func (*TimedWriter) SetDeadline

func (w *TimedWriter) SetDeadline(d time.Duration)

Sets the deadline for the TimedWriter to the specified duration, determining the maximum time allowed for write operations.

func (*TimedWriter) SetMaxQueue

func (w *TimedWriter) SetMaxQueue(s int)

Sets the maximum queue size for the TimedWriter to the specified integer value, ensuring thread-safe updates with a mutex lock.

func (*TimedWriter) Write

func (w *TimedWriter) Write(p []byte) (n int, err error)

Writes data to an underlying writer, buffering it and flushing either when the buffer reaches the maximum queue size, the deadline elapses, or an error occurs, ensuring thread-safe and timed/batch-optimized output.

Jump to

Keyboard shortcuts

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