package git
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=f6c628e3628d25686cec4cdff8132f9433e95938bdcb43975778d28d33a0b077
sha512=779bdd7a1657e859ed47b46ef9da007b5f43f4446f8cea831f29fae662efdd33a39aa2ee90b9f8d8b6360f2abb78038a7592633efa26e8adc5d2ae20d86d8015
doc/pkt_line/Pkt_line/Decoder/index.html
Module Pkt_line.Decoder
Source
Module for decoding Git pkt lines, as specified at https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt
We define a "packet line" (aka a "packet") as
| 4 bytes || (enc-pkt-len)-4 | enc-pkt-len
pkt-content
|------- pkt-len ------|
Example: "0009done\n" where enc-pkt-len = 4
and pkt-content = "done"
given we usually trim LF ("\n").
"Encoded" packet length, enc-pkt-len
, is the first 4 bytes in the packet that encode the length of the packet in hex. It can have specific values of 0, 1, 2 to encode flush, delimiter, and message (response end) packets respectively. Otherwise, it should be >= 4, i.e., 4 length bytes + the length of the packet content.
In the docs, we define min_pkt_len = 4
as in specs.
type error = [
| `End_of_input
| `Expected_char of char
| `Unexpected_char of char
| `Expected_string of string
| `Expected_eol
| `Expected_eol_or_space
| `Unexpected_end_of_input
| `No_enough_space
| `Assert_predicate of char -> bool
| `Invalid_pkt_line of string
]
leave_with d error
raises Leave { error; buffer = d.buffer; committed = d.pos }
safe k decoder
wraps a call k decoder
in a try-with block; if exception Leave err
is raised, the function returns Error of err
returns true if decoder.max - decoder.pos
is >= min_pkt_len
and >= pkt_len
, where pkt_len
is the length of a pkt line starting at decoder.pos
.
increase decoder.pos
by max min_pkt_len pkt_len
, where pkt_len
is the length of the pkt line starting at the current value of decoder.pos
(before increasing) and min_pkt_len = 4
.
/