package wamp

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

Source file wamp.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(*---------------------------------------------------------------------------
   Copyright (c) 2016 Vincent Bernardoff. All rights reserved.
   Distributed under the ISC license, see terms at the end of the file.
   %%NAME%% %%VERSION%%
  ---------------------------------------------------------------------------*)

open Result

type msgtyp =
  | HELLO
  | WELCOME
  | ABORT
  | GOODBYE
  | ERROR
  | PUBLISH
  | PUBLISHED
  | SUBSCRIBE
  | SUBSCRIBED
  | UNSUBSCRIBE
  | UNSUBSCRIBED
  | EVENT

let msgtyp_of_enum = function
| 1 -> Some HELLO
| 2 -> Some WELCOME
| 3 -> Some ABORT
| 6 -> Some GOODBYE
| 8 -> Some ERROR
| 16 -> Some PUBLISH
| 17 -> Some PUBLISHED
| 32 -> Some SUBSCRIBE
| 33 -> Some SUBSCRIBED
| 34 -> Some UNSUBSCRIBE
| 35 -> Some UNSUBSCRIBED
| 36 -> Some EVENT
| _ -> None

let msgtyp_to_enum = function
| HELLO -> 1
| WELCOME -> 2
| ABORT -> 3
| GOODBYE -> 6
| ERROR -> 8
| PUBLISH -> 16
| PUBLISHED -> 17
| SUBSCRIBE -> 32
| SUBSCRIBED -> 33
| UNSUBSCRIBE -> 34
| UNSUBSCRIBED -> 35
| EVENT -> 36

type 'a dict = (string * 'a) list

type 'a msg =
  | Hello of { realm: Uri.t; details: 'a dict }
  | Welcome of { id: int; details: 'a dict }
  | Abort of { details: 'a dict; reason: Uri.t }
  | Goodbye of { details: 'a dict; reason: Uri.t }
  | Error of { reqtype: int; reqid: int; details: 'a dict; error: Uri.t; args: 'a list; kwArgs: 'a dict }
  | Publish of { reqid: int; options: 'a dict; topic: Uri.t; args: 'a list; kwArgs: 'a dict }
  | Published of { reqid: int; id: int }
  | Subscribe of { reqid: int; options: 'a dict; topic: Uri.t }
  | Subscribed of { reqid: int; id: int }
  | Unsubscribe of { reqid: int; id: int }
  | Unsubscribed of int
  | Event of { subid: int; pubid: int; details: 'a dict; args: 'a list; kwArgs: 'a dict }

let hello ~realm ~details = Hello { realm ; details }
let welcome ~id ~details = Welcome { id ; details }
let abort ~details ~reason = Abort { details ; reason }
let goodbye ~details ~reason = Goodbye { details ; reason }
let error ~reqtype ~reqid ~details ~error ~args ~kwArgs =
  Error { reqtype ; reqid ; details ; error ; args ; kwArgs }
let publish ~reqid ~options ~topic ~args ~kwArgs =
  Publish { reqid ; options ; topic ; args ; kwArgs }
let published ~reqid ~id = Published { reqid ; id }
let subscribe ~reqid ~options ~topic = Subscribe { reqid ; options ; topic }
let subscribed ~reqid ~id = Subscribed { reqid ; id }
let unsubscribe ~reqid ~id = Unsubscribe { reqid ; id }
let unsubscribed ~reqid = Unsubscribed reqid
let event ~subid ~pubid ~details ~args ~kwArgs =
  Event { subid ; pubid ; details ; args ; kwArgs }

let ok_or_failwith = function
  | Ok v -> v
  | Error msg -> failwith msg

type role =
  | Subscriber
  | Publisher

let string_of_role = function
  | Subscriber -> "subscriber"
  | Publisher -> "publisher"
(*---------------------------------------------------------------------------
   Copyright (c) 2016 Vincent Bernardoff

   Permission to use, copy, modify, and/or distribute this software for any
   purpose with or without fee is hereby granted, provided that the above
   copyright notice and this permission notice appear in all copies.

   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  ---------------------------------------------------------------------------*)
OCaml

Innovation. Community. Security.