pktline

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrSidebandNotImplemented strErr = "sideband is not implemented"
	ErrSidebandChannelInvalid strErr = "sideband channel is invalid"

	ErrPktlineTooLong strErr = "pktline is too long to encode"

	ErrScanTooShort          strErr = "pktline scan was too short"
	ErrScanInvalidLineLength strErr = "pktline scan line length is invalid"
)

errors we handle

View Source
const MaxLength = 65516 // the data portion

MaxLength is The maximum length of a pkt-line's data component is 65516 bytes. Implementations MUST NOT send pkt-line whose length exceeds 65520 (65516 bytes of payload + 4 bytes of length data).

Variables

This section is empty.

Functions

func ReportStatus

func ReportStatus(enc *Encoder, status *packp.ReportStatus)

ReportStatus returns the unpacked status from a report status it returns a sideband aware muxed value if necessary.

func WithSideband64kDemuxer

func WithSideband64kDemuxer(scn *Scanner)

WithSideband64kDemuxer adds the Sideband64k demuxer to the scanner that newer clients can use

func WithSideband64kMuxer

func WithSideband64kMuxer(enc *Encoder)

WithSideband64kMuxer adds the Sideband64k muxer to the encoder that newer clients can use

func WithSidebandDemuxer

func WithSidebandDemuxer(scn *Scanner)

WithSidebandDemuxer adds the Sideband demuxer to the scanner that older clients can use

func WithSidebandMuxer

func WithSidebandMuxer(enc *Encoder)

WithSidebandMuxer adds the Sideband muxer to the encoder that older clients can use

Types

type Builder

type Builder struct {
	*strings.Builder
}

Builder wraps the standard library string builder and is a way to build encoded messages that can be sent as sideband data

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a new builder this doesn't require the use of Encode or EncodeString to init the builder

func (*Builder) Encode

func (d *Builder) Encode(b []byte)

Encode encodes the bytes b to the builder

func (*Builder) EncodeString

func (d *Builder) EncodeString(s string)

EncodeString encodes the string s to the builder

func (*Builder) Flush

func (d *Builder) Flush()

Flush adds a non-encoded flush to the string

func (*Builder) FlushString

func (d *Builder) FlushString() string

FlushString returns the fully built string with a trailing flush encoded.

type EncodeSideband

type EncodeSideband interface {
	Encode(SidebandChannel, []byte) error
	EncodeString(SidebandChannel, string) error
	EncodePackfile([]byte) error
	EncodeProgress(string) error
	EncodeError(string) error
	Flush() error

	Write([]byte) (int, error)
	WriteString(string) (int, error)
}

type Encoder

type Encoder struct {
	Sideband EncodeSideband
	// contains filtered or unexported fields
}

Encoder is the underlining structure to encoding data to the added writer

func NewEncoder

func NewEncoder(w io.Writer, opts ...EncoderOption) *Encoder

NewEncoder returns an encoder that will encode packets directly to the underlining writer

func (*Encoder) Encode

func (enc *Encoder) Encode(b []byte) (err error)

Encode encodes bytes to the underlining writer. If a sideband is initiated, then the bytes will be encoded as a sideband mux'd packet line

func (*Encoder) EncodeString

func (enc *Encoder) EncodeString(s string) (err error)

EncodeString encodes a string in the pkline format to the underlining writer. If a sideband is used then the string will be muxed as sideband or sidebadn64k

func (*Encoder) Flush

func (enc *Encoder) Flush()

Flush sends 0000 to the undrtlining writer

func (*Encoder) SidebandCapability

func (enc *Encoder) SidebandCapability() SidebandCapability

SidebandCapability returns if the pktline encoder has any sideband capabilities initiated.

func (*Encoder) WithSidebandCapability

func (enc *Encoder) WithSidebandCapability(cap SidebandCapability) *Encoder

WithSidebandCapability takes a sideband value and sets up the sideband encoding if the value is Sideband or Sideband64k. If the value is empty then no side-band is used. Calls to Sideband encoding will result in an error

func (*Encoder) Write

func (enc *Encoder) Write(d []byte) (n int, err error)

Write writes bytes directly to the underlining writer. No encoding is preformed. It is expected the bytes written this way will have be previously encoded.

func (*Encoder) WriteString

func (enc *Encoder) WriteString(s string) (n int, err error)

WriteString writes the string to the underlining writer. No encoding is preformed. It is expected the bytes written this way will have be previously encoded.

type EncoderOption

type EncoderOption func(*Encoder)

EncoderOption are functional options for encoding

func WithSidebandSkip

func WithSidebandSkip(optFn EncoderOption, ok bool) EncoderOption

WithSidebandSkip allows for you to wrap the Sideband option with a skip option. That is if the client doesn't offer a sideband capability then the sideband information will be skipped. Otherwise there will be an error that there is no sideband information being written to the encoder.

type ScanSideband

type ScanSideband interface {
	Scan() bool
	Bytes() []byte
	Text() string
	Err() error

	Packfile() []byte
	ProgressText() string
	ErrorText() string
}

type Scanner

type Scanner struct {
	Sideband ScanSideband
	// contains filtered or unexported fields
}

Scanner is the object that allows scanning of pktline data

func NewScanner

func NewScanner(r io.Reader, opts ...ScannerOption) *Scanner

NewScanner returns a scanner object that takes functional options

func (*Scanner) Bytes

func (scn *Scanner) Bytes() []byte

Bytes returns the bytes of the line scanned

func (*Scanner) Err

func (scn *Scanner) Err() error

Err returns any errors that occurred while scanning

func (*Scanner) Scan

func (scn *Scanner) Scan() bool

Scan is true while there are items to scan

func (*Scanner) Text

func (scn *Scanner) Text() string

Text returns the string text of the line scanned

type ScannerOption

type ScannerOption func(*Scanner)

ScannerOption are functional options for scanning pktline data

func WithWriter

func WithWriter(w io.Writer) ScannerOption

WithWriter adds a writer that the scanner can write it's output to.

type SidebandCapability

type SidebandCapability int
const (
	SidebandNone SidebandCapability = 0
	Sideband     SidebandCapability = 1
	Sideband64k  SidebandCapability = 64
)

type SidebandChannel

type SidebandChannel byte
const (
	SidebandPackfile SidebandChannel = 0x1
	SidebandProgress SidebandChannel = 0x2
	SidebandError    SidebandChannel = 0x3
)

type SidebandEncoder

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

func (*SidebandEncoder) Data

func (enc *SidebandEncoder) Data(c SidebandChannel, b []byte) (err error)

func (*SidebandEncoder) Encode

func (enc *SidebandEncoder) Encode(c SidebandChannel, b []byte) (err error)

Encode takes a byte slice to encode for the following: If 'side-band' or 'side-band-64k' capabilities have been specified by the client, the server will send the packfile data multiplexed.

Each packet starting with the packet-line length of the amount of data that follows, followed by a single byte specifying the sideband the following data is coming in on.

func (*SidebandEncoder) EncodeError

func (enc *SidebandEncoder) EncodeError(s string) error

EncodeError is a convenience method for EncodeString(Error, s)

func (*SidebandEncoder) EncodePackfile

func (enc *SidebandEncoder) EncodePackfile(b []byte) error

EncodePackfile is a convenience method for Encode(Packfile, b)

func (*SidebandEncoder) EncodeProgress

func (enc *SidebandEncoder) EncodeProgress(s string) error

EncodeProgress is a convenience method for EncodeString(Progress, s)

func (*SidebandEncoder) EncodeString

func (enc *SidebandEncoder) EncodeString(c SidebandChannel, s string) error

EncodeString takes a string to encode for the following: If 'side-band' or 'side-band-64k' capabilities have been specified by the client, the server will send the packfile data multiplexed.

Each packet starting with the packet-line length of the amount of data that follows, followed by a single byte specifying the sideband the following data is coming in on.

func (*SidebandEncoder) Flush

func (enc *SidebandEncoder) Flush() error

Flush sends 0000 to the underlining writer

func (*SidebandEncoder) Write

func (enc *SidebandEncoder) Write(d []byte) (n int, err error)

Write is a pass-through method. All bytes should be previously encoded

func (*SidebandEncoder) WriteString

func (enc *SidebandEncoder) WriteString(s string) (n int, err error)

WriteString is a pass-through convenience method for a string to be passed to the underlining writer. No encoding is happening

type SidebandScanner

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

func (*SidebandScanner) Bytes

func (scn *SidebandScanner) Bytes() []byte

func (*SidebandScanner) Err

func (scn *SidebandScanner) Err() error

func (*SidebandScanner) ErrorText

func (scn *SidebandScanner) ErrorText() string

func (*SidebandScanner) Packfile

func (scn *SidebandScanner) Packfile() []byte

func (*SidebandScanner) ProgressText

func (scn *SidebandScanner) ProgressText() string

func (*SidebandScanner) Scan

func (scn *SidebandScanner) Scan() bool

func (*SidebandScanner) Text

func (scn *SidebandScanner) Text() string

Jump to

Keyboard shortcuts

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