package apero-net

  1. Overview
  2. Docs

Source file locator.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
open Apero
open Iplocator


module Locator = struct
  (** This will become a union time once we'll support non IP-based transpots *)
  type t = 
  | UdpLocator of UdpLocator.t 
  | TcpLocator of TcpLocator.t
  
    
  let to_string = function 
  | UdpLocator ul -> UdpLocator.to_string ul
  | TcpLocator tl -> TcpLocator.to_string tl

  let of_string s = 
    let open Option.Infix in 
    String.index_opt s '/'
    >>= (fun pos -> 
          match String.sub s 0 pos with 
          | "tcp" -> (TcpLocator.of_string s) >>= fun loc -> Some (TcpLocator loc)
          | "udp" -> (UdpLocator.of_string s) >>= fun loc -> Some (UdpLocator loc)
          | _  -> None)
  
  end

module Locators = struct
  type t = Locator.t list
  let empty = []
  let singleton l = [l]
  let add ls l = l::ls
  let length ls = List.length ls
  let to_list ls = ls
  let of_list ls = ls
  let to_string ls = List.to_string ls (fun l -> Locator.to_string l)
end