sideband

package
v4.7.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package sideband implements a sideband mutiplex/demultiplexer

Index

Constants

View Source
const (
	// Sideband legacy sideband type up to 1000-byte messages
	Sideband Type = iota
	// Sideband64k sideband type up to 65519-byte messages
	Sideband64k Type = iota

	// MaxPackedSize for Sideband type
	MaxPackedSize = 1000
	// MaxPackedSize64k for Sideband64k type
	MaxPackedSize64k = 65520
)

Variables

View Source
var ErrMaxPackedExceeded = errors.New("max. packed size exceeded")

ErrMaxPackedExceeded returned by Read, if the maximum packed size is exceeded

Functions

This section is empty.

Types

type Channel

type Channel byte

Channel sideband channel

const (
	// PackData packfile content
	PackData Channel = 1
	// ProgressMessage progress messages
	ProgressMessage Channel = 2
	// ErrorMessage fatal error message just before stream aborts
	ErrorMessage Channel = 3
)

func (Channel) WithPayload

func (ch Channel) WithPayload(payload []byte) []byte

WithPayload encode the payload as a message

type Demuxer

type Demuxer struct {

	// Progress is where the progress messages are stored
	Progress Progress
	// contains filtered or unexported fields
}

Demuxer demultiplexes the progress reports and error info interleaved with the packfile itself.

A sideband has three different channels the main one, called PackData, contains the packfile data; the ErrorMessage channel, that contains server errors; and the last one, ProgressMessage channel, containing information about the ongoing task happening in the server (optional, can be suppressed sending NoProgress or Quiet capabilities to the server)

In order to demultiplex the data stream, method `Read` should be called to retrieve the PackData channel, the incoming data from the ProgressMessage is written at `Progress` (if any), if any message is retrieved from the ErrorMessage channel an error is returned and we can assume that the connection has been closed.

func NewDemuxer

func NewDemuxer(t Type, r io.Reader) *Demuxer

NewDemuxer returns a new Demuxer for the given t and read from r

func (*Demuxer) Read

func (d *Demuxer) Read(b []byte) (n int, err error)

Read reads up to len(p) bytes from the PackData channel into p, an error can be return if an error happens when reading or if a message is sent in the ErrorMessage channel.

When a ProgressMessage is read, is not copy to b, instead of this is written to the Progress

type Muxer

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

Muxer multiplex the packfile along with the progress messages and the error information. The multiplex is perform using pktline format.

func NewMuxer

func NewMuxer(t Type, w io.Writer) *Muxer

NewMuxer returns a new Muxer for the given t that writes on w.

If t is equal to `Sideband` the max pack size is set to MaxPackedSize, in any other value is given, max pack is set to MaxPackedSize64k, that is the maximum length of a line in pktline format.

func (*Muxer) Write

func (m *Muxer) Write(p []byte) (int, error)

Write writes p in the PackData channel

func (*Muxer) WriteChannel

func (m *Muxer) WriteChannel(t Channel, p []byte) (int, error)

WriteChannel writes p in the given channel. This method can be used with any channel, but is recommend use it only for the ProgressMessage and ErrorMessage channels and use Write for the PackData channel

type Progress

type Progress interface {
	io.Writer
}

Progress where the progress information is stored

type Type

type Type int8

Type sideband type "side-band" or "side-band-64k"

Jump to

Keyboard shortcuts

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