channel

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package channel defines a communications channel that can encode/transmit and decode/receive data records with a configurable framing discipline, and provides some simple framing implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel interface {
	Sender
	Receiver

	// Close shuts down the channel, after which no further records may be
	// sent or received.
	Close() error
}

A Channel represents the ability to transmit and receive data records. A channel does not interpret the contents of a record, but may add and remove framing so that records can be embedded in higher-level protocols. The methods of a Channel need not be safe for concurrent use.

func JSON

func JSON(r io.Reader, wc io.WriteCloser) Channel

JSON is a framing that transmits and receives records on r and wc, in which each record is defined by being a complete JSON value. No padding or other separation is added.

func LSP

func LSP(r io.Reader, wc io.WriteCloser) Channel

LSP is a framing that transmits and receives messages on r and wc using the Language Server Protocol (LSP) framing, defined by the LSP specification at http://github.com/Microsoft/language-server-protocol.

Specifically, each message is sent in the format:

Content-Length: <nbytes>\r\n
\r\n
<payload>

The length (nbytes) is encoded as decimal digits. For example, the message "123\n" is transmitted as:

Content-Length: 4\r\n
\r\n
123\n

func Line

func Line(r io.Reader, wc io.WriteCloser) Channel

Line is a framing that transmits and receives messages on r and wc with line framing. Each message is terminated by a Unicode LF (10). This framing has the constraint that outbound records may not contain any LF characters.

func Pipe

func Pipe(framing Framing) (client, server Channel)

Pipe creates a pair of connected in-memory channels using the specified framing discipline. Pipe will panic if framing == nil.

func Varint

func Varint(r io.Reader, wc io.WriteCloser) Channel

Varint is a framing that transmits and receives messages on r and wc, with each message prefixed by its length encoded in a varint as defined by the encoding/binary package.

type Framing

type Framing func(io.Reader, io.WriteCloser) Channel

A Framing converts a reader and a writer into a Channel with a particular message-framing discipline.

type Receiver added in v0.0.6

type Receiver interface {
	// Recv returns the next available record from the channel.  If no further
	// messages are available, it returns io.EOF.  Each call to Recv fetches a
	// single complete record.
	Recv() ([]byte, error)
}

A Receiver represents the ability to receive a message from a channel.

type Sender added in v0.0.6

type Sender interface {
	// Send transmits a record on the channel. Each call to Send transmits one
	// complete record.
	Send([]byte) error
}

A Sender represents the ability to transmit a message on a channel.

Jump to

Keyboard shortcuts

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