Skip to content

Instantly share code, notes, and snippets.

@droyo
Created March 9, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save droyo/81dd28811bf6f279a3429a5792fcf9c3 to your computer and use it in GitHub Desktop.
Save droyo/81dd28811bf6f279a3429a5792fcf9c3 to your computer and use it in GitHub Desktop.
(* service definition
message SeekRequest {
string subscription = 1;
oneof target {
google.protobuf.Timestamp time = 2;
string snapshot = 3;
}
}
message SeekResponse {
}
service Subscriber {
rpc Seek(SeekRequest) returns (SeekResponse);
}
*)
(* option 1: explicit Request/Response messages *)
module SeekRequest : sig
(** The time to seek to. *)
type target = Time of Ptime.t | Snapshot of string
(** Request for the `Seek` method. *)
type t = {
subscription : string;
target : target;
}
end
module SeekResponse : sig
type t = unit
end
module Subscriber : sig
val seek : SeekRequest.t -> SeekResponse.t
end
(* option 2: partial import as labelled arguments *)
module SeekRequest : sig
type target = Time of Ptime.t | Snapshot of string
end
module Subscriber : sig
val seek : subscription:string -> target:SeekRequest.target -> unit
end
(* option 3: full import w/ polymorphic variants *)
module Subscriber : sig
val seek : subscription:string -> target:[< `Time of Ptime.t | `Snapshot of string] -> unit
end
(* option 4: full import w/ optional arguments *)
module Subscriber : sig
val seek : ?time:Ptime.t -> ?snapshot:string -> subscription:string -> unit
end
(* option 5: full import w/ function duplication for every oneof permutation *)
module Subscriber : sig
val seek_time : subscription:string -> time:Ptime.t -> unit
val seek_snapshot : subscription:string -> snapshot:string -> unit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment