summaryrefslogtreecommitdiff
path: root/src/vyconf_pbt.ml
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-10-23 18:50:46 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-10-27 21:47:40 -0500
commita5473033fc8ea92891d6ebab9bdeaccbe742d565 (patch)
tree29b2b3b19e9b9392878b24e106cc657de8589d6f /src/vyconf_pbt.ml
parent73652e2bfc8a785e9b3dc447e0a0ced4716549e3 (diff)
downloadvyconf-a5473033fc8ea92891d6ebab9bdeaccbe742d565.tar.gz
vyconf-a5473033fc8ea92891d6ebab9bdeaccbe742d565.zip
T6718: fix teardown method
An empty protobuf message does not correctly generate encode/decode functions. This appears to be fixed upstream, but for now, use workaround of adding a reasonable field.
Diffstat (limited to 'src/vyconf_pbt.ml')
-rw-r--r--src/vyconf_pbt.ml59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/vyconf_pbt.ml b/src/vyconf_pbt.ml
index 1e481b9..4c7fcc6 100644
--- a/src/vyconf_pbt.ml
+++ b/src/vyconf_pbt.ml
@@ -15,6 +15,10 @@ type request_setup_session = {
on_behalf_of : int32 option;
}
+type request_teardown = {
+ on_behalf_of : int32 option;
+}
+
type request_validate = {
path : string list;
output_format : request_output_format option;
@@ -131,7 +135,7 @@ type request =
| Configure of request_enter_configuration_mode
| Exit_configure
| Validate of request_validate
- | Teardown of string
+ | Teardown of request_teardown
type request_envelope = {
token : string option;
@@ -170,6 +174,12 @@ let rec default_request_setup_session
on_behalf_of;
}
+let rec default_request_teardown
+ ?on_behalf_of:((on_behalf_of:int32 option) = None)
+ () : request_teardown = {
+ on_behalf_of;
+}
+
let rec default_request_validate
?path:((path:string list) = [])
?output_format:((output_format:request_output_format option) = None)
@@ -352,6 +362,14 @@ let default_request_setup_session_mutable () : request_setup_session_mutable = {
on_behalf_of = None;
}
+type request_teardown_mutable = {
+ mutable on_behalf_of : int32 option;
+}
+
+let default_request_teardown_mutable () : request_teardown_mutable = {
+ on_behalf_of = None;
+}
+
type request_validate_mutable = {
mutable path : string list;
mutable output_format : request_output_format option;
@@ -583,6 +601,12 @@ let rec pp_request_setup_session fmt (v:request_setup_session) =
in
Pbrt.Pp.pp_brk pp_i fmt ()
+let rec pp_request_teardown fmt (v:request_teardown) =
+ let pp_i fmt () =
+ Pbrt.Pp.pp_record_field ~first:true "on_behalf_of" (Pbrt.Pp.pp_option Pbrt.Pp.pp_int32) fmt v.on_behalf_of;
+ in
+ Pbrt.Pp.pp_brk pp_i fmt ()
+
let rec pp_request_validate fmt (v:request_validate) =
let pp_i fmt () =
Pbrt.Pp.pp_record_field ~first:true "path" (Pbrt.Pp.pp_list Pbrt.Pp.pp_string) fmt v.path;
@@ -744,7 +768,7 @@ let rec pp_request fmt (v:request) =
| Configure x -> Format.fprintf fmt "@[<hv2>Configure(@,%a)@]" pp_request_enter_configuration_mode x
| Exit_configure -> Format.fprintf fmt "Exit_configure"
| Validate x -> Format.fprintf fmt "@[<hv2>Validate(@,%a)@]" pp_request_validate x
- | Teardown x -> Format.fprintf fmt "@[<hv2>Teardown(@,%a)@]" Pbrt.Pp.pp_string x
+ | Teardown x -> Format.fprintf fmt "@[<hv2>Teardown(@,%a)@]" pp_request_teardown x
let rec pp_request_envelope fmt (v:request_envelope) =
let pp_i fmt () =
@@ -806,6 +830,15 @@ let rec encode_pb_request_setup_session (v:request_setup_session) encoder =
end;
()
+let rec encode_pb_request_teardown (v:request_teardown) encoder =
+ begin match v.on_behalf_of with
+ | Some x ->
+ Pbrt.Encoder.int32_as_varint x encoder;
+ Pbrt.Encoder.key 1 Pbrt.Varint encoder;
+ | None -> ();
+ end;
+ ()
+
let rec encode_pb_request_validate (v:request_validate) encoder =
Pbrt.List_util.rev_iter_with (fun x encoder ->
Pbrt.Encoder.string x encoder;
@@ -1080,7 +1113,7 @@ let rec encode_pb_request (v:request) encoder =
Pbrt.Encoder.nested encode_pb_request_validate x encoder;
Pbrt.Encoder.key 21 Pbrt.Bytes encoder;
| Teardown x ->
- Pbrt.Encoder.string x encoder;
+ Pbrt.Encoder.nested encode_pb_request_teardown x encoder;
Pbrt.Encoder.key 22 Pbrt.Bytes encoder;
end
@@ -1176,6 +1209,24 @@ let rec decode_pb_request_setup_session d =
on_behalf_of = v.on_behalf_of;
} : request_setup_session)
+let rec decode_pb_request_teardown d =
+ let v = default_request_teardown_mutable () in
+ let continue__= ref true in
+ while !continue__ do
+ match Pbrt.Decoder.key d with
+ | None -> (
+ ); continue__ := false
+ | Some (1, Pbrt.Varint) -> begin
+ v.on_behalf_of <- Some (Pbrt.Decoder.int32_as_varint d);
+ end
+ | Some (1, pk) ->
+ Pbrt.Decoder.unexpected_payload "Message(request_teardown), field(1)" pk
+ | Some (_, payload_kind) -> Pbrt.Decoder.skip d payload_kind
+ done;
+ ({
+ on_behalf_of = v.on_behalf_of;
+ } : request_teardown)
+
let rec decode_pb_request_validate d =
let v = default_request_validate_mutable () in
let continue__= ref true in
@@ -1688,7 +1739,7 @@ let rec decode_pb_request d =
(Exit_configure : request)
end
| Some (21, _) -> (Validate (decode_pb_request_validate (Pbrt.Decoder.nested d)) : request)
- | Some (22, _) -> (Teardown (Pbrt.Decoder.string d) : request)
+ | Some (22, _) -> (Teardown (decode_pb_request_teardown (Pbrt.Decoder.nested d)) : request)
| Some (n, payload_kind) -> (
Pbrt.Decoder.skip d payload_kind;
loop ()