Skip to content

Commit d215b36

Browse files
committed
CP-307958: Generate event RPC more directly
Use an attribute to change the name of the fields instead of serializing with one name, and then mapping to the other. `ministat` confirms an improvement on `rpc_of_event`: ``` N Min Max Median Avg Stddev x 922 440.79126 46094.975 467.83727 563.79259 1676.0843 + 1131 51.346821 33407.866 58.715393 115.98006 1105.4178 Difference at 95.0% confidence -447.813 +/- 120.966 -79.4286% +/- 13.1488% (Student's t, pooled s = 1390.95) ``` Signed-off-by: Edwin Török <[email protected]>
1 parent 3da9ef1 commit d215b36

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

ocaml/xapi-types/event_types.ml

+6-28
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,15 @@ let rpc_of_op = API.rpc_of_event_operation
2020
let op_of_rpc = API.event_operation_of_rpc
2121

2222
type event = {
23-
id: string
24-
; ts: string
25-
; ty: string
26-
; op: op
27-
; reference: string
28-
; snapshot: Rpc.t option
23+
id: string [@key "id"]
24+
; ts: string [@key "timestamp"]
25+
; ty: string [@key "class"]
26+
; op: op [@key "operation"]
27+
; reference: string [@key "ref"]
28+
; snapshot: Rpc.t option [@key "snapshot"]
2929
}
3030
[@@deriving rpc]
3131

32-
let ev_struct_remap =
33-
[
34-
("id", "id")
35-
; ("ts", "timestamp")
36-
; ("ty", "class")
37-
; ("op", "operation")
38-
; ("reference", "ref")
39-
; ("snapshot", "snapshot")
40-
]
41-
42-
let remap map str =
43-
match str with
44-
| Rpc.Dict d ->
45-
Rpc.Dict (List.map (fun (k, v) -> (List.assoc k map, v)) d)
46-
| _ ->
47-
str
48-
49-
let rpc_of_event ev = remap ev_struct_remap (rpc_of_event ev)
50-
51-
let event_of_rpc rpc =
52-
event_of_rpc (remap (List.map (fun (k, v) -> (v, k)) ev_struct_remap) rpc)
53-
5432
type events = event list [@@deriving rpc]
5533

5634
type token = string [@@deriving rpc]

0 commit comments

Comments
 (0)