-
Notifications
You must be signed in to change notification settings - Fork 703
/
common.go
56 lines (42 loc) · 1.61 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pktline
import "errors"
const (
// Err is returned when the pktline has encountered an error.
Err = iota - 1
// Flush is the numeric value of a flush packet. It is returned when the
// pktline is a flush packet.
Flush
// Delim is the numeric value of a delim packet. It is returned when the
// pktline is a delim packet.
Delim
// ResponseEnd is the numeric value of a response-end packet. It is
// returned when the pktline is a response-end packet.
ResponseEnd
)
const (
// MaxPayloadSize is the maximum payload size of a pkt-line in bytes.
// See https://git-scm.com/docs/protocol-common#_pkt_line_format
MaxPayloadSize = MaxPacketSize - PacketLenSize
// MaxPacketSize is the maximum packet size of a pkt-line in bytes.
// See https://git-scm.com/docs/protocol-common#_pkt_line_format
MaxPacketSize = 65520
// PacketLenSize is the size of the packet length in bytes.
PacketLenSize = 4
)
var (
// ErrPayloadTooLong is returned by the Encode methods when any of the
// provided payloads is bigger than MaxPayloadSize.
ErrPayloadTooLong = errors.New("payload is too long")
// ErrInvalidPktLen is returned by Err() when an invalid pkt-len is found.
ErrInvalidPktLen = errors.New("invalid pkt-len found")
)
var (
// flushPkt are the contents of a flush-pkt pkt-line.
flushPkt = []byte{'0', '0', '0', '0'}
// delimPkt are the contents of a delim-pkt pkt-line.
delimPkt = []byte{'0', '0', '0', '1'}
// responseEndPkt are the contents of a response-end-pkt pkt-line.
responseEndPkt = []byte{'0', '0', '0', '2'}
// emptyPkt is an empty string pkt-line payload.
emptyPkt = []byte{'0', '0', '0', '4'}
)