10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-05 13:43:57 +01:00
quantum_package/ocaml/Address.ml

60 lines
1.2 KiB
OCaml
Raw Normal View History

2015-12-03 23:51:10 +01:00
module Tcp : sig
type t
val of_string : string -> t
val to_string : t -> string
2016-02-19 00:20:28 +01:00
val create : host:string -> port:int -> t
2015-12-03 23:51:10 +01:00
end = struct
type t = string
let of_string x =
2017-08-18 19:43:52 +02:00
if not (String_ext.is_prefix ~prefix:"tcp://" x) then
2017-05-17 21:19:43 +02:00
invalid_arg "Address Invalid"
;
2015-12-03 23:51:10 +01:00
x
2016-02-19 00:20:28 +01:00
let create ~host ~port =
assert (port > 0);
Printf.sprintf "tcp://%s:%d" host port
2015-12-03 23:51:10 +01:00
let to_string x = x
end
module Ipc : sig
type t
val of_string : string -> t
val to_string : t -> string
2016-02-19 00:20:28 +01:00
val create : string -> t
2015-12-03 23:51:10 +01:00
end = struct
type t = string
let of_string x =
2017-08-18 19:43:52 +02:00
assert (String_ext.is_prefix ~prefix:"ipc://" x);
2015-12-03 23:51:10 +01:00
x
2016-02-19 00:20:28 +01:00
let create name =
Printf.sprintf "ipc://%s" name
2015-12-03 23:51:10 +01:00
let to_string x = x
end
module Inproc : sig
type t
val of_string : string -> t
val to_string : t -> string
2016-02-19 00:20:28 +01:00
val create : string -> t
2015-12-03 23:51:10 +01:00
end = struct
type t = string
let of_string x =
2017-08-18 19:43:52 +02:00
assert (String_ext.is_prefix ~prefix:"inproc://" x);
2015-12-03 23:51:10 +01:00
x
2016-02-19 00:20:28 +01:00
let create name =
2016-07-15 15:31:16 +02:00
Printf.sprintf "inproc://%s" name
2015-12-03 23:51:10 +01:00
let to_string x = x
end
type t =
| Tcp of Tcp.t
| Ipc of Ipc.t
| Inproc of Inproc.t
let to_string = function
| Tcp x -> Tcp.to_string x
| Ipc x -> Ipc.to_string x
| Inproc x -> Inproc.to_string x