lineproto

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncWriter

type AsyncWriter struct {
	*Writer
	// contains filtered or unexported fields
}

func NewAsyncWriter

func NewAsyncWriter(w io.Writer) *AsyncWriter

func (*AsyncWriter) Flush

func (w *AsyncWriter) Flush() error

Flush waits for all async writes to complete and forces the flush of internal buffers.

func (*AsyncWriter) WriteLineAsync

func (w *AsyncWriter) WriteLineAsync(data []byte) error

WriteLineAsync writes a single protocol message. The message won't be written immediately and will be batched with other similar messages.

type ErrProtocolViolation

type ErrProtocolViolation struct {
	Err error
}

func (*ErrProtocolViolation) Error

func (e *ErrProtocolViolation) Error() string

type Reader

type Reader struct {

	// Safe can be set to disable internal mutex.
	Safe bool

	// OnLine is called each time a raw protocol line is read from the connection.
	// The buffer will contain a delimiter and is in the connection encoding.
	// The function may return (false, nil) to ignore the message.
	OnLine func(line []byte) (bool, error)
	// contains filtered or unexported fields
}

Reader is safe for concurrent use.

func NewReader

func NewReader(r io.Reader, delim byte) *Reader

func (*Reader) ReadLine

func (r *Reader) ReadLine() ([]byte, error)

ReadLine reads a single raw message until the delimiter. The returned buffer contains a delimiter and is in the connection encoding. The buffer is only valid until the next call to Read or ReadLine.

func (*Reader) SetMaxLine

func (r *Reader) SetMaxLine(n int)

SetMaxLine sets a maximal length of the protocol messages in bytes, including the delimiter.

type Writer

type Writer struct {
	// OnLine is called each time a raw protocol message is written.
	// The function may return (false, nil) to skip writing the message.
	OnLine func(line []byte) (bool, error)
	// contains filtered or unexported fields
}

Writer is safe for concurrent use.

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) EndBatch

func (w *Writer) EndBatch(force bool) error

EndBatch flushes a batch of messages. If force is set, the batch will be flushed immediately instead of interleaving with other batches.

func (*Writer) Err

func (w *Writer) Err() error

func (*Writer) Flush added in v0.3.0

func (w *Writer) Flush() error

Flush forces all buffered writes to be flushed. Partial batch data will be flushed as well.

func (*Writer) StartBatch

func (w *Writer) StartBatch() error

StartBatch starts a batch of messages. Caller should call EndBatch to flush the buffer.

func (*Writer) WriteLine

func (w *Writer) WriteLine(data []byte) error

WriteLine writes a single protocol message.

Jump to

Keyboard shortcuts

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