Skip to content

Commit 4f60ca1

Browse files
Lupusc-cube
authored andcommitted
Expose one-of per-constructor options
1 parent 55fc03b commit 4f60ca1

File tree

7 files changed

+19
-3
lines changed

7 files changed

+19
-3
lines changed

src/compilerlib/pb_codegen_backend.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ let variant_of_oneof ?include_oneof_name ~outer_message_names ~unsigned_tag
328328
(match field_type with
329329
| Ft_unit -> Vct_nullary
330330
| _ -> Vct_non_nullary_constructor field_type);
331+
vc_options = field.field_options;
331332
})
332333
oneof_field.Tt.oneof_fields
333334
in

src/compilerlib/pb_codegen_decode_binary.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ let gen_rft_variant sc r_name rf_label { Ot.v_constructors; _ } =
161161
vc_field_type;
162162
vc_encoding_number;
163163
vc_payload_kind = pk;
164+
vc_options = _;
164165
} =
165166
variant_constructor
166167
in
@@ -281,6 +282,7 @@ let gen_variant ?and_ { Ot.v_name; v_constructors } sc =
281282
vc_field_type;
282283
vc_encoding_number;
283284
vc_payload_kind = pk;
285+
vc_options = _;
284286
} =
285287
variant_constructor
286288
in

src/compilerlib/pb_codegen_encode_binary.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ let gen_rft_variant sc var_name { Ot.v_constructors; _ } =
139139
vc_field_type;
140140
vc_encoding_number;
141141
vc_payload_kind;
142+
vc_options = _;
142143
} =
143144
constructor
144145
in
@@ -235,6 +236,7 @@ let gen_variant ?and_ variant sc =
235236
vc_field_type;
236237
vc_encoding_number;
237238
vc_payload_kind;
239+
vc_options = _;
238240
} =
239241
variant_constructor
240242
in

src/compilerlib/pb_codegen_ocaml_type.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ and variant_constructor = {
106106
vc_field_type: variant_constructor_type;
107107
vc_encoding_number: encoding_number;
108108
vc_payload_kind: payload_kind;
109+
vc_options: Pb_option.set;
109110
}
110111

111112
and variant_constructor_type =

src/compilerlib/pb_codegen_ocaml_type_dump.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ module PP = struct
170170
F.linep sc " Field Type: %s\n"
171171
(string_of_variant_constructor_type vc.vc_field_type);
172172
F.linep sc " Encoding Number: %d, Payload Kind: %s" vc.vc_encoding_number
173-
(string_of_payload_kind vc.vc_payload_kind)
173+
(string_of_payload_kind vc.vc_payload_kind);
174+
F.linep sc " Options: %s" (string_of_options vc.vc_options)
174175

175176
(* Helper function to convert variant_constructor_type to string *)
176177
and string_of_variant_constructor_type vct =

src/tests/expectation/option_processing.ml.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type person_location = {
1414
type person_id =
1515
| X of string
1616
| Y of int32
17+
| Z of float
1718

1819
and person = {
1920
id : int64;
@@ -96,10 +97,17 @@ and default_person
9697
Field Type: Vct_non_nullary_constructor: Ft_basic_type: Bt_string
9798

9899
Encoding Number: 6, Payload Kind: Pk_bytes
100+
Options: {"validate.rules.string.prefix": Constant_string "foo"}
99101
Constructor: Y
100102
Field Type: Vct_non_nullary_constructor: Ft_basic_type: Bt_int32
101103

102104
Encoding Number: 7, Payload Kind: Pk_varint (zigzag: false)
105+
Options: {"validate.rules.int32.gt": Constant_int 0}
106+
Constructor: Z
107+
Field Type: Vct_non_nullary_constructor: Ft_basic_type: Bt_float
108+
109+
Encoding Number: 8, Payload Kind: Pk_bits32
110+
Options: {}
103111
Options: {}
104112
*)
105113

src/tests/expectation/option_processing.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ message Person {
3535
oneof id {
3636
option (validate.required) = true;
3737

38-
string x = 6;
39-
int32 y = 7;
38+
string x = 6 [(validate.rules).string.prefix = "foo"];
39+
int32 y = 7 [(validate.rules).int32.gt = 0];
40+
float z = 8;
4041
}
4142
}

0 commit comments

Comments
 (0)