package git

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Module for decoding Git pkt lines, as specified at https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt

In the docs, we define min_pkt_len = 4 as in specs.

type decoder = {
  1. buffer : bytes;
  2. mutable pos : int;
  3. mutable max : int;
}
val io_buffer_size : int
val create : unit -> decoder
val decoder_from : string -> decoder
val end_of_input : decoder -> int
type error = [
  1. | `End_of_input
  2. | `Expected_char of char
  3. | `Unexpected_char of char
  4. | `Expected_string of string
  5. | `Expected_eol
  6. | `Expected_eol_or_space
  7. | `Unexpected_end_of_input
  8. | `No_enough_space
  9. | `Assert_predicate of char -> bool
  10. | `Invalid_pkt_line
]
val pp_error : error Fmt.t
type 'err info = {
  1. error : 'err;
  2. buffer : bytes;
  3. committed : int;
}
exception Leave of error info
type ('v, 'err) state =
  1. | Done of 'v
  2. | Read of {
    1. buffer : bytes;
    2. off : int;
    3. len : int;
    4. continue : int -> ('v, 'err) state;
    5. eof : unit -> ('v, 'err) state;
    }
  3. | Error of 'err info
val leave_with : decoder -> error -> 'never

leave_with d error raises Leave { error; buffer = d.buffer; committed = d.pos }

val safe : (decoder -> ('v, [> error ] as 'err) state) -> decoder -> ('v, 'err) state

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

val fail : decoder -> [> error ] as 'err -> ('v, 'err) state
val return : 'v -> decoder -> ('v, 'err) state
val peek_char : decoder -> char option
val string : string -> decoder -> unit
val junk_char : decoder -> unit
val while1 : (char -> bool) -> decoder -> bytes * int * int
  • returns

    decoder.buffer, updated decoder.pos, # of bytes read

val at_least_one_pkt : decoder -> bool

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.

val at_least_one_line : decoder -> bool
val prompt : ?strict:bool -> (decoder -> ('v, [> error ] as 'err) state) -> decoder -> ('v, 'err) state
val peek_while_eol : decoder -> bytes * int * int
val peek_while_eol_or_space : decoder -> bytes * int * int
val peek_pkt : decoder -> bytes * int * int
val junk_pkt : decoder -> unit

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.

  • raises Invalid_argument

    if there aren't 4 bytes representing the length

OCaml

Innovation. Community. Security.