transport

package module
v0.0.0-...-8696d9c Latest Latest
Warning

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

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

README

transport-go

Go Reference GoReportCard codecov

transport-go facilitates Commands/Results delivery for the cmd-stream client and server.

It provides implementations of the delegate.ClientTransport and delegate.ServerTransport interfaces.

A key feature of this module is its use of bufio.Writer and bufio.Reader,
along with a user-defined codec, to convert raw bytes into base.Cmd or base.Result.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ops []SetOption, o *Options)

Types

type Codec

type Codec[T, V any] interface {
	Encode(seq core.Seq, t T, w Writer) (n int, err error)
	Decode(r Reader) (seq core.Seq, v V, n int, err error)
}

Codec is responsible for encoding and decoding data transmitted over a connection:

  • On the client side: encodes Commands to send and decodes Results received from the server.
  • On the server side: decodes Commands from clients, validates them, and encodes Results to send back.

type Options

type Options struct {
	WriterBufSize int
	ReaderBufSize int
}

type Reader

type Reader interface {
	io.Reader
	io.ByteReader
}

Reader is an interface that extends io.Reader and io.ByteReader.

type SetOption

type SetOption func(o *Options)

func WithReaderBufSize

func WithReaderBufSize(size int) SetOption

WithReaderBufSize sets the buffer size for the Reader. If set to 0, the default bufio.Reader size is used.

func WithWriterBufSize

func WithWriterBufSize(size int) SetOption

WithWriterBufSize sets the buffer size for the Writer. If set to 0, the default bufio.Writer size is used.

type Transport

type Transport[T, V any] struct {
	W Writer
	R Reader
	// contains filtered or unexported fields
}

Transport is a common transport for both client and server.

It uses a user-defined codec to encode and decode data over the connection.

func New

func New[T, V any](conn net.Conn, w Writer, r Reader,
	codec Codec[T, V]) *Transport[T, V]

New creates a new Transport.

func (*Transport[T, V]) Close

func (tn *Transport[T, V]) Close() error

Close closes the underlying connection.

func (*Transport[T, V]) Flush

func (tn *Transport[T, V]) Flush() (err error)

Flush flushes any buffered data.

func (*Transport[T, V]) LocalAddr

func (tn *Transport[T, V]) LocalAddr() net.Addr

LocalAddr returns the connection local network address.

func (*Transport[T, V]) Receive

func (tn *Transport[T, V]) Receive() (seq core.Seq, v V, n int, err error)

Receive receives data using the codec.

func (*Transport[T, V]) RemoteAddr

func (tn *Transport[T, V]) RemoteAddr() net.Addr

RemoteAddr returns the connection remote network address.

func (*Transport[T, V]) Send

func (tn *Transport[T, V]) Send(seq core.Seq, t T) (n int, err error)

Send sends data using the codec.

func (*Transport[T, V]) SetReceiveDeadline

func (tn *Transport[T, V]) SetReceiveDeadline(deadline time.Time) error

SetReceiveDeadline sets a receive deadline.

func (*Transport[T, V]) SetSendDeadline

func (tn *Transport[T, V]) SetSendDeadline(deadline time.Time) error

SetSendDeadline sets a send deadline.

type Writer

type Writer interface {
	io.ByteWriter
	io.Writer
	io.StringWriter
	Flush() error
}

Writer is an interface that extends io.ByteWriter, io.Writer, and io.StringWriter. It also includes a Flush method to ensure buffered data is written out.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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