Documentation ¶
Overview ¶
Package pktline implements reading payloads form pkt-lines and encoding pkt-lines from payloads.
Index ¶
Constants ¶
const ( // MaxPayloadSize is the maximum payload size of a pkt-line in bytes. MaxPayloadSize = 65516 // For compatibility with canonical Git implementation, accept longer pkt-lines OversizePayloadMax = 65520 )
Variables ¶
var ( // FlushPkt are the contents of a flush-pkt pkt-line. FlushPkt = []byte{'0', '0', '0', '0'} // Flush is the payload to use with the Encode method to encode a flush-pkt. Flush = []byte{} // FlushString is the payload to use with the EncodeString method to encode a flush-pkt. FlushString = "" // ErrPayloadTooLong is returned by the Encode methods when any of the // provided payloads is bigger than MaxPayloadSize. ErrPayloadTooLong = errors.New("payload is too long") )
var ( // ErrInvalidErrorLine is returned by Decode when the packet line is not an // error line. ErrInvalidErrorLine = errors.New("expected an error-line") )
var ErrInvalidPktLen = errors.New("invalid pkt-len found")
ErrInvalidPktLen is returned by Err() when an invalid pkt-len is found.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes pkt-lines to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) Encode ¶
Encode encodes a pkt-line with the payload specified and write it to the output stream. If several payloads are specified, each of them will get streamed in their own pkt-lines.
func (*Encoder) EncodeString ¶
EncodeString works similarly as Encode but payloads are specified as strings.
type ErrorLine ¶
type ErrorLine struct {
Text string
}
ErrorLine is a packet line that contains an error message. Once this packet is sent by client or server, the data transfer process is terminated. See https://git-scm.com/docs/pack-protocol#_pkt_line_format
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner provides a convenient interface for reading the payloads of a series of pkt-lines. It takes an io.Reader providing the source, which then can be tokenized through repeated calls to the Scan method.
After each Scan call, the Bytes method will return the payload of the corresponding pkt-line on a shared buffer, which will be 65516 bytes or smaller. Flush pkt-lines are represented by empty byte slices.
Scanning stops at EOF or the first I/O error.
func NewScanner ¶
NewScanner returns a new Scanner to read from r.
func (*Scanner) Bytes ¶
Bytes returns the most recent payload generated by a call to Scan. The underlying array may point to data that will be overwritten by a subsequent call to Scan. It does no allocation.
func (*Scanner) Scan ¶
Scan advances the Scanner to the next pkt-line, whose payload will then be available through the Bytes method. Scanning stops at EOF or the first I/O error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil.