diff --git a/src/not-so-smart/dune b/src/not-so-smart/dune index 4c0577d37..250b5a0d0 100644 --- a/src/not-so-smart/dune +++ b/src/not-so-smart/dune @@ -1,8 +1,15 @@ +(library + (name pkt_line) + (public_name git-nss.pkt-line) + (modules decoder encoder) + (libraries astring fmt)) + (library (name smart) (public_name git-nss.smart) - (modules smart filter capability state protocol encoder decoder) - (libraries conduit stdlib-shims result rresult domain-name astring fmt)) + (modules smart filter capability state protocol) + (libraries git-nss.pkt-line conduit stdlib-shims result rresult domain-name + astring fmt)) (library (name sigs) diff --git a/src/not-so-smart/protocol.ml b/src/not-so-smart/protocol.ml index 345378967..85ac21ee9 100644 --- a/src/not-so-smart/protocol.ml +++ b/src/not-so-smart/protocol.ml @@ -267,10 +267,10 @@ end module Decoder = struct open Astring - open Decoder + open Pkt_line.Decoder - type error = - [ Decoder.error + type nonrec error = + [ error | `Invalid_advertised_ref of string | `Invalid_shallow of string | `Invalid_negotiation_result of string @@ -282,7 +282,7 @@ module Decoder = struct | `Invalid_pkt_line ] let pp_error ppf = function - | #Decoder.error as err -> Decoder.pp_error ppf err + | #Pkt_line.Decoder.error as err -> Pkt_line.Decoder.pp_error ppf err | `Invalid_advertised_ref raw -> Fmt.pf ppf "Invalid advertised refererence (%S)" raw | `Invalid_shallow raw -> Fmt.pf ppf "Invalid shallow (%S)" raw @@ -630,12 +630,12 @@ module Decoder = struct let rec bind x ~f = match x with - | Decoder.Done v -> f v - | Decoder.Read { buffer; off; len; continue; eof } -> + | Done v -> f v + | Read { buffer; off; len; continue; eof } -> let continue len = bind (continue len) ~f in let eof () = bind (eof ()) ~f in - Decoder.Read { buffer; off; len; continue; eof } - | Decoder.Error _ as err -> err + Read { buffer; off; len; continue; eof } + | Error _ as err -> err let ( >>= ) x f = bind x ~f @@ -696,7 +696,7 @@ module Decoder = struct match String.Sub.head pkt with | Some '\001' -> let str = String.Sub.(to_string (tail pkt)) in - let decoder' = Decoder.decoder_from str in + let decoder' = decoder_from str in decode_status decoder' >>= fun res -> junk_pkt decoder; prompt_pkt (return res) decoder @@ -707,11 +707,11 @@ module Decoder = struct end module Encoder = struct - open Encoder + open Pkt_line.Encoder - type error = Encoder.error + type nonrec error = error - let pp_error = Encoder.pp_error + let pp_error = pp_error let write_space encoder = write encoder " " let write_zero encoder = write encoder "\000" let write_new_line encoder = write encoder "\n" @@ -858,7 +858,7 @@ module Encoder = struct let unsafe_encode_packet encoder ~packet = let pos = encoder.pos in encoder.pos <- encoder.pos + 4; - Encoder.write encoder packet; + write encoder packet; let len = encoder.pos - pos in Bytes.blit_string (Fmt.strf "%04X" len) 0 encoder.payload pos 4 diff --git a/src/not-so-smart/protocol.mli b/src/not-so-smart/protocol.mli index c062abdf8..6bd37f634 100644 --- a/src/not-so-smart/protocol.mli +++ b/src/not-so-smart/protocol.mli @@ -141,10 +141,10 @@ module Status : sig end module Decoder : sig - open Decoder + open Pkt_line.Decoder - type error = - [ Decoder.error + type nonrec error = + [ error | `Invalid_advertised_ref of string | `Invalid_shallow of string | `Invalid_negotiation_result of string @@ -177,9 +177,9 @@ module Decoder : sig end module Encoder : sig - open Encoder + open Pkt_line.Encoder - type error = Encoder.error + type nonrec error = error val pp_error : error Fmt.t val encode_proto_request : encoder -> Proto_request.t -> error state diff --git a/src/not-so-smart/smart.ml b/src/not-so-smart/smart.ml index dfe778408..819222e7b 100644 --- a/src/not-so-smart/smart.ml +++ b/src/not-so-smart/smart.ml @@ -37,6 +37,8 @@ module Witness = struct end module Value = struct + open Pkt_line + type encoder = Encoder.encoder type decoder = Decoder.decoder diff --git a/src/not-so-smart/state.ml b/src/not-so-smart/state.ml index 4f51a18ac..d6240586d 100644 --- a/src/not-so-smart/state.ml +++ b/src/not-so-smart/state.ml @@ -35,6 +35,8 @@ module type S = sig end module Context = struct + open Pkt_line + type t = { encoder : Encoder.encoder; decoder : Decoder.decoder; diff --git a/src/not-so-smart/state.mli b/src/not-so-smart/state.mli index e3641ebf5..4ab007c3c 100644 --- a/src/not-so-smart/state.mli +++ b/src/not-so-smart/state.mli @@ -33,6 +33,8 @@ module type S = sig end module Context : sig + open Pkt_line + include CONTEXT with type encoder = Encoder.encoder