pktline

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: BSD-3-Clause Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pktline implements Git's pkt-line framing as specified by gitprotocol-common(5) and the protocol v2 special packets of gitprotocol-v2(5): flush-pkt "0000", delim-pkt "0001" and response-end-pkt "0002".

The reader is bounded: a packet longer than MaxPacket (65520 bytes, header included) is refused before any payload is read or allocated, and so is any length field that is not four lowercase hexadecimal digits or that falls on the unassigned values 0003.

Index

Constants

View Source
const (
	// MaxPacket is the largest pkt-line, length header included.
	MaxPacket = 65520
	// MaxData is the largest payload of a data pkt-line.
	MaxData = MaxPacket - 4
	// MaxSidebandData is the largest payload that fits in a pkt-line that
	// also carries a one-byte side-band stream code.
	MaxSidebandData = MaxData - 1
)

Variables

View Source
var (
	ErrBadLength  = errors.New("pktline: length field is not four lowercase hex digits")
	ErrReserved   = errors.New("pktline: reserved length 0003")
	ErrTooLong    = errors.New("pktline: packet exceeds 65520 bytes")
	ErrDataTooBig = errors.New("pktline: payload exceeds 65516 bytes")
)

Refusals. All are wrapped with %w by the reader and writer.

Functions

func Text

func Text(p []byte) []byte

Text returns the payload of a data packet with one trailing LF removed, as gitprotocol-common(5) requires receivers to do.

Types

type Kind

type Kind int

Kind is the kind of a packet.

const (
	// Data is a data pkt-line (possibly empty: "0004").
	Data Kind = iota
	// Flush is "0000".
	Flush
	// Delim is "0001".
	Delim
	// ResponseEnd is "0002".
	ResponseEnd
)

func (Kind) String

func (k Kind) String() string

type Packet

type Packet struct {
	Kind Kind
	Data []byte
}

Packet is one decoded packet. Data aliases the reader's buffer and is valid until the next call to Read.

type Reader

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

Reader decodes pkt-lines from an io.Reader.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a Reader. r should be buffered by the caller if it is expensive to read from in small pieces.

func (*Reader) Consumed

func (r *Reader) Consumed() int64

Consumed returns the number of bytes read from the underlying reader.

func (*Reader) Read

func (r *Reader) Read() (Packet, error)

Read returns the next packet. It returns io.EOF only when the stream ends exactly between two packets; a stream cut inside a packet yields io.ErrUnexpectedEOF.

func (*Reader) Source added in v0.2.0

func (r *Reader) Source() io.Reader

Source returns the reader r reads from, so that a caller can bound a blocked read (a net.Conn's deadline) without wrapping it.

type Writer

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

Writer encodes pkt-lines.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a Writer.

func (*Writer) Data

func (w *Writer) Data(p []byte) error

Data writes one data pkt-line. A payload over MaxData is refused.

func (*Writer) Delim

func (w *Writer) Delim() error

Delim writes "0001".

func (*Writer) Err

func (w *Writer) Err() error

Err returns the first write error, if any. Once set, every later write returns it without touching the underlying writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes "0000".

func (*Writer) ResponseEnd

func (w *Writer) ResponseEnd() error

ResponseEnd writes "0002".

func (*Writer) Sideband

func (w *Writer) Sideband(ch byte, p []byte) error

Sideband writes p on side-band channel ch (1, 2 or 3), splitting it into packets of at most MaxSidebandData payload bytes.

func (*Writer) Text

func (w *Writer) Text(s string) error

Text writes s followed by LF as one data pkt-line.

Jump to

Keyboard shortcuts

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