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
open! Core
type t =
| Continuation
| Text
| Binary
| Close
| Ping
| Pong
| Ctrl of int
| Nonctrl of int
[@@deriving sexp_of]
let of_int i =
match i land 0xf with
| 0x0 -> Continuation
| 0x1 -> Text
| 0x2 -> Binary
| 0x8 -> Close
| 0x9 -> Ping
| 0xA -> Pong
| i when i > 2 && i < 8 -> Nonctrl i
| i -> Ctrl i
;;
let to_int = function
| Continuation -> 0x0
| Text -> 0x1
| Binary -> 0x2
| Close -> 0x8
| Ping -> 0x9
| Pong -> 0xA
| Ctrl i | Nonctrl i -> i
;;