transport

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-2-Clause-Views Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExistingWriter is returned from MsgWriter when there is already a
	// message io.WriterCloser that hasn't been properly closed yet.
	ErrExistingWriter = errors.New("netconf: existing message writer still open")

	// ErrInvalidIO is returned when a write or read operation is called on
	// message io.Reader or a message io.Writer when they are no longer valid.
	// (i.e a new reader or writer has been obtained)
	ErrInvalidIO = errors.New("netconf: read/write on invalid io")
)
View Source
var ErrMalformedChunk = errors.New("netconf: invalid chunk")

ErrMalformedChunk represents a message that invalid as defined in the chunk framing in RFC6242

Functions

This section is empty.

Types

type Framer

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

Framer is a wrapper used for transports that implement the framing defined in RFC6242. This supports End-of-Message and Chucked framing methods and will move from End-of-Message to Chunked framing after the `Upgrade` method has been called.

This is not a transport on it's own (missing the `Close` method) and is intended to be embedded into other transports.

func NewFramer

func NewFramer(r io.Reader, w io.Writer) *Framer

NewFramer return a new Framer to be used against the given io.Reader and io.Writer.

func (*Framer) DebugCapture

func (f *Framer) DebugCapture(in io.Writer, out io.Writer)

DebugCapture will copy all *framed* input/output to the the given `io.Writers` for sent or recv data. Either sent of recv can be nil to not capture any data. Useful for displaying to a screen or capturing to a file for debugging.

This needs to be called before `MsgReader` or `MsgWriter`.

func (*Framer) MsgReader

func (t *Framer) MsgReader() (io.ReadCloser, error)

MsgReader returns a new io.Reader that is good for reading exactly one netconf message.

Only one reader can be used at a time. When this is called with an existing reader then the underlying reader is advanced to the start of the next message and invalidates the old reader before returning a new one.

func (*Framer) MsgWriter

func (t *Framer) MsgWriter() (io.WriteCloser, error)

MsgWriter returns an io.WriterCloser that is good for writing exactly one netconf message.

One one writer can be used at one time and calling this function with an existing, unclosed, writer will result in an error.

func (*Framer) Upgrade

func (t *Framer) Upgrade()

Upgrade will cause the Framer to switch from End-of-Message framing to Chunked framing. This is usually called after netconf exchanged the hello messages.

type Transport

type Transport interface {
	// MsgReader returns a new io.Reader to read a single netconf message. There
	// can only be a single reader for a transport at a time.  Obtaining a new
	// reader should advance the stream to the start of the next message.`
	MsgReader() (io.ReadCloser, error)

	// MsgWriter returns a new io.WriteCloser to write a single netconf message.
	// After writing a message the writer must be closed. Implementers should
	// make sure only a single writer can be obtained and return a error if
	// multiple writers are attempted.
	MsgWriter() (io.WriteCloser, error)

	// Close will close the underlying transport.
	Close() error
}

Transport is used for a netconf.Session to talk to the device. It is message oriented to allow for framing and other details to happen on a per message basis.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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