drop version AV0, AV1; refactor vmm_asn

This commit is contained in:
Hannes Mehnert 2018-10-28 22:52:20 +01:00
parent 0f9375dc29
commit 9191d2cf9a
3 changed files with 40 additions and 49 deletions

View File

@ -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,55 +372,54 @@ 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, | `C1 () -> `Empty
match payload with | `C2 str -> `String str
| `C3 policies -> `Policies policies
| `C4 vms -> `Vms vms
and g = function
| `Empty -> `C1 ()
| `String s -> `C2 s
| `Policies ps -> `C3 ps
| `Vms vms -> `C4 vms
in
Asn.S.map f g @@
Asn.S.(choice4
(explicit 0 null)
(explicit 1 utf8_string)
(explicit 2 (sequence_of
(sequence2
(required ~label:"name" (sequence_of utf8_string))
(required ~label:"policy" policy))))
(explicit 3 (sequence_of
(sequence2
(required ~label:"name" (sequence_of utf8_string))
(required ~label:"vm_config" vm_config)))))
let payload =
let f = function
| `C1 cmd -> `Command cmd | `C1 cmd -> `Command cmd
| `C2 data -> | `C2 s -> `Success s
let p = match data with
| `C1 () -> `Empty
| `C2 str -> `String str
| `C3 policies -> `Policies policies
| `C4 vms -> `Vms vms
in
`Success p
| `C3 str -> `Failure str | `C3 str -> `Failure str
| `C4 data -> `Data data | `C4 data -> `Data data
and g (header, payload) = and g = function
header,
match payload with
| `Command cmd -> `C1 cmd | `Command cmd -> `C1 cmd
| `Success data -> | `Success s -> `C2 s
let p = match data with
| `Empty -> `C1 ()
| `String s -> `C2 s
| `Policies ps -> `C3 ps
| `Vms vms -> `C4 vms
in
`C2 p
| `Failure str -> `C3 str | `Failure str -> `C3 str
| `Data d -> `C4 d | `Data d -> `C4 d
in in
Asn.S.map f g @@ Asn.S.map f g @@
Asn.S.(choice4
(explicit 0 wire_command)
(explicit 1 success)
(explicit 2 utf8_string)
(explicit 3 data))
let wire =
Asn.S.(sequence2 Asn.S.(sequence2
(required ~label:"header" header) (required ~label:"header" header)
(required ~label:"payload" (required ~label:"payload" payload))
(choice4
(explicit 0 wire_command)
(explicit 1 (choice4
(explicit 0 null)
(explicit 1 utf8_string)
(explicit 2 (sequence_of
(sequence2
(required ~label:"name" (sequence_of utf8_string))
(required ~label:"policy" policy))))
(explicit 3 (sequence_of
(sequence2
(required ~label:"name" (sequence_of utf8_string))
(required ~label:"vm_config" vm_config))))))
(explicit 2 utf8_string)
(explicit 3 data))))
let wire_of_cstruct, wire_to_cstruct = projections_of wire let wire_of_cstruct, wire_to_cstruct = projections_of wire

View File

@ -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

View File

@ -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