pktline

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pktline reads and writes the pkt-line format described in https://git-scm.com/docs/protocol-common#_pkt_line_format.

Index

Constants

View Source
const MaxSize = 65516

MaxSize is the maximum number of bytes permitted in a single pkt-line.

Variables

This section is empty.

Functions

func Append

func Append(dst []byte, line []byte) []byte

Append appends a data-pkt to dst with the given data. It panics if len(line) == 0 or len(line) > MaxSize.

func AppendDelim

func AppendDelim(dst []byte) []byte

AppendDelim appends a delim-pkt to dst.

func AppendFlush

func AppendFlush(dst []byte) []byte

AppendFlush appends a flush-pkt to dst.

func AppendString

func AppendString(dst []byte, line string) []byte

AppendString appends a data-pkt to dst with the given data. It panics if len(line) == 0 or len(line) > MaxSize.

Types

type Reader

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

Reader reads pkt-lines from an io.Reader object. It does not perform any internal buffering and does not read any more bytes than requested.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a new Reader that reads from r.

func (*Reader) Bytes

func (pr *Reader) Bytes() ([]byte, error)

Bytes returns the data of the most recent packet read by a call to Next. It returns an error if Next returned false or the most recent packet is not a Data packet. The underlying array may point to data that will be overwritten by a subsequent call to Next.

func (*Reader) Err

func (pr *Reader) Err() error

Err returns the first error encountered by the Reader.

func (*Reader) Next

func (pr *Reader) Next() bool

Next advances the Reader to the next pkt-line, which will then be available through the Bytes or Text methods. It returns false when the Reader encounters an error. After Next returns false, the Err method will return any error that occurred while reading.

func (*Reader) Text

func (pr *Reader) Text() ([]byte, error)

Text returns the data of the most recent packet read by a call to Next, stripping the trailing line-feed ('\n') if present. It returns an error if Next returned false or the most recent packet is not a Data packet. The underlying array may point to data that will be overwritten by a subsequent call to Next.

func (*Reader) Type

func (pr *Reader) Type() Type

Type returns the type of the most recent packet read by a call to Next.

type Type

type Type int8

Type indicates the type of a packet.

const (
	// Flush indicates the end of a message.
	Flush Type = 0
	// Delim indicates the end of a section in the Version 2 protocol.
	// https://git-scm.com/docs/protocol-v2#_packet_line_framing
	Delim Type = 1
	// Data indicates a packet with data.
	Data Type = 4
)

Packet types.

Jump to

Keyboard shortcuts

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