drop version AV0, AV1; refactor vmm_asn
This commit is contained in:
parent
0f9375dc29
commit
9191d2cf9a
|
@ -307,13 +307,9 @@ let policy_cmd =
|
||||||
|
|
||||||
let version =
|
let version =
|
||||||
let f data = match data with
|
let f data = match data with
|
||||||
| 0 -> `AV0
|
|
||||||
| 1 -> `AV1
|
|
||||||
| 2 -> `AV2
|
| 2 -> `AV2
|
||||||
| _ -> Asn.S.error (`Parse "unknown version number")
|
| _ -> Asn.S.error (`Parse "unknown version number")
|
||||||
and g = function
|
and g = function
|
||||||
| `AV0 -> 0
|
|
||||||
| `AV1 -> 1
|
|
||||||
| `AV2 -> 2
|
| `AV2 -> 2
|
||||||
in
|
in
|
||||||
Asn.S.map f g Asn.S.int
|
Asn.S.map f g Asn.S.int
|
||||||
|
@ -376,43 +372,20 @@ let header =
|
||||||
(required ~label:"sequence" int64)
|
(required ~label:"sequence" int64)
|
||||||
(required ~label:"id" (sequence_of utf8_string)))
|
(required ~label:"id" (sequence_of utf8_string)))
|
||||||
|
|
||||||
let wire =
|
let success =
|
||||||
let f (header, payload) =
|
let f = function
|
||||||
header,
|
|
||||||
match payload with
|
|
||||||
| `C1 cmd -> `Command cmd
|
|
||||||
| `C2 data ->
|
|
||||||
let p = match data with
|
|
||||||
| `C1 () -> `Empty
|
| `C1 () -> `Empty
|
||||||
| `C2 str -> `String str
|
| `C2 str -> `String str
|
||||||
| `C3 policies -> `Policies policies
|
| `C3 policies -> `Policies policies
|
||||||
| `C4 vms -> `Vms vms
|
| `C4 vms -> `Vms vms
|
||||||
in
|
and g = function
|
||||||
`Success p
|
|
||||||
| `C3 str -> `Failure str
|
|
||||||
| `C4 data -> `Data data
|
|
||||||
and g (header, payload) =
|
|
||||||
header,
|
|
||||||
match payload with
|
|
||||||
| `Command cmd -> `C1 cmd
|
|
||||||
| `Success data ->
|
|
||||||
let p = match data with
|
|
||||||
| `Empty -> `C1 ()
|
| `Empty -> `C1 ()
|
||||||
| `String s -> `C2 s
|
| `String s -> `C2 s
|
||||||
| `Policies ps -> `C3 ps
|
| `Policies ps -> `C3 ps
|
||||||
| `Vms vms -> `C4 vms
|
| `Vms vms -> `C4 vms
|
||||||
in
|
in
|
||||||
`C2 p
|
|
||||||
| `Failure str -> `C3 str
|
|
||||||
| `Data d -> `C4 d
|
|
||||||
in
|
|
||||||
Asn.S.map f g @@
|
Asn.S.map f g @@
|
||||||
Asn.S.(sequence2
|
Asn.S.(choice4
|
||||||
(required ~label:"header" header)
|
|
||||||
(required ~label:"payload"
|
|
||||||
(choice4
|
|
||||||
(explicit 0 wire_command)
|
|
||||||
(explicit 1 (choice4
|
|
||||||
(explicit 0 null)
|
(explicit 0 null)
|
||||||
(explicit 1 utf8_string)
|
(explicit 1 utf8_string)
|
||||||
(explicit 2 (sequence_of
|
(explicit 2 (sequence_of
|
||||||
|
@ -422,9 +395,31 @@ let wire =
|
||||||
(explicit 3 (sequence_of
|
(explicit 3 (sequence_of
|
||||||
(sequence2
|
(sequence2
|
||||||
(required ~label:"name" (sequence_of utf8_string))
|
(required ~label:"name" (sequence_of utf8_string))
|
||||||
(required ~label:"vm_config" vm_config))))))
|
(required ~label:"vm_config" vm_config)))))
|
||||||
|
|
||||||
|
let payload =
|
||||||
|
let f = function
|
||||||
|
| `C1 cmd -> `Command cmd
|
||||||
|
| `C2 s -> `Success s
|
||||||
|
| `C3 str -> `Failure str
|
||||||
|
| `C4 data -> `Data data
|
||||||
|
and g = function
|
||||||
|
| `Command cmd -> `C1 cmd
|
||||||
|
| `Success s -> `C2 s
|
||||||
|
| `Failure str -> `C3 str
|
||||||
|
| `Data d -> `C4 d
|
||||||
|
in
|
||||||
|
Asn.S.map f g @@
|
||||||
|
Asn.S.(choice4
|
||||||
|
(explicit 0 wire_command)
|
||||||
|
(explicit 1 success)
|
||||||
(explicit 2 utf8_string)
|
(explicit 2 utf8_string)
|
||||||
(explicit 3 data))))
|
(explicit 3 data))
|
||||||
|
|
||||||
|
let wire =
|
||||||
|
Asn.S.(sequence2
|
||||||
|
(required ~label:"header" header)
|
||||||
|
(required ~label:"payload" payload))
|
||||||
|
|
||||||
let wire_of_cstruct, wire_to_cstruct = projections_of wire
|
let wire_of_cstruct, wire_to_cstruct = projections_of wire
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,15 @@
|
||||||
(* the wire protocol *)
|
(* the wire protocol *)
|
||||||
open Vmm_core
|
open Vmm_core
|
||||||
|
|
||||||
type version = [ `AV0 | `AV1 | `AV2 ]
|
type version = [ `AV2 ]
|
||||||
|
|
||||||
let pp_version ppf v =
|
let pp_version ppf v =
|
||||||
Fmt.int ppf
|
Fmt.int ppf
|
||||||
(match v with
|
(match v with
|
||||||
| `AV0 -> 0
|
|
||||||
| `AV1 -> 1
|
|
||||||
| `AV2 -> 2)
|
| `AV2 -> 2)
|
||||||
|
|
||||||
let version_eq a b =
|
let version_eq a b =
|
||||||
match a, b with
|
match a, b with
|
||||||
| `AV0, `AV0 -> true
|
|
||||||
| `AV1, `AV1 -> true
|
|
||||||
| `AV2, `AV2 -> true
|
| `AV2, `AV2 -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
open Vmm_core
|
open Vmm_core
|
||||||
|
|
||||||
(** The type of versions of the grammar defined below. *)
|
(** The type of versions of the grammar defined below. *)
|
||||||
type version = [ `AV0 | `AV1 | `AV2 ]
|
type version = [ `AV2 ]
|
||||||
|
|
||||||
(** [version_eq a b] is true if [a] and [b] are equal. *)
|
(** [version_eq a b] is true if [a] and [b] are equal. *)
|
||||||
val version_eq : version -> version -> bool
|
val version_eq : version -> version -> bool
|
||||||
|
|
Loading…
Reference in a new issue