@@ -25,7 +25,7 @@ let field_pattern_match ~r_name ~rf_label field_type =
25
25
| Ot. Bt_bool -> decode " bool"
26
26
| Ot. Bt_bytes -> decode " bytes"
27
27
in
28
- ( " json_value" , exp)
28
+ " json_value" , exp
29
29
| Ot. Ft_unit ->
30
30
" json_value" , sp " Pbrt_yojson.unit json_value \" %s\" \" %s\" " r_name rf_label
31
31
(* TODO Wrapper: add similar one for wrapper type (with different
@@ -103,44 +103,42 @@ let gen_rft_assoc_field sc ~r_name ~rf_label ~assoc_type ~key_type ~value_type =
103
103
let json_label = Pb_codegen_util. camel_case_of_label rf_label in
104
104
F. linep sc " | (\" %s\" , `Assoc assoc) ->" json_label;
105
105
F. sub_scope sc (fun sc ->
106
- let value_name, value_exp = field_pattern_match ~r_name ~rf_label value_type in
107
- let key_name = " key" in
108
- let key_exp =
109
- match key_type with
110
- | Ot. Bt_string -> " key"
111
- | Ot. Bt_int -> " (Int.of_string key)"
112
- | Ot. Bt_int32 -> " (Int32.of_string key)"
113
- | Ot. Bt_int64 -> " (Int64.of_string key)"
114
- | Ot. Bt_uint32 -> " (`unsigned (Int32.of_string key))"
115
- | Ot. Bt_uint64 -> " (`unsigned (Int64.of_string key))"
116
- | Ot. Bt_bool -> " (Bool.of_string key)"
117
- | Ot. Bt_float ->
118
- Printf. eprintf " float cannot be used as a map key type" ;
119
- exit 1
120
- | Ot. Bt_bytes ->
121
- Printf. eprintf " bytes cannot be used as a map key type" ;
122
- exit 1
123
- in
124
- F. line sc " let assoc =" ;
125
- F. sub_scope sc (fun sc ->
126
- F. line sc " assoc" ;
127
- F. linep sc " |> List.map (fun (%s, %s) -> (%s, %s)) "
128
- key_name
129
- value_name
130
- key_exp
131
- value_exp;
132
- F. line sc " |> List.to_seq" ;
133
- (* Passing through [Hashtbl.of_seq] even in the [At_list] case ensures that if there
134
- is a repeated key we take the last value associated with it. *)
135
- F. line sc " |> Hashtbl.of_seq" );
136
- F. line sc " in" ;
137
- let assoc_exp =
138
- match assoc_type with
139
- | Ot. At_hashtable -> " assoc"
140
- | Ot. At_list -> " assoc |> Hashtbl.to_seq |> List.of_seq"
141
- in
142
- F. linep sc " v.%s <- %s" rf_label assoc_exp);
143
- ;;
106
+ let value_name, value_exp =
107
+ field_pattern_match ~r_name ~rf_label value_type
108
+ in
109
+ let key_name = " key" in
110
+ let key_exp =
111
+ match key_type with
112
+ | Ot. Bt_string -> " key"
113
+ | Ot. Bt_int -> " (Int.of_string key)"
114
+ | Ot. Bt_int32 -> " (Int32.of_string key)"
115
+ | Ot. Bt_int64 -> " (Int64.of_string key)"
116
+ | Ot. Bt_uint32 -> " (`unsigned (Int32.of_string key))"
117
+ | Ot. Bt_uint64 -> " (`unsigned (Int64.of_string key))"
118
+ | Ot. Bt_bool -> " (Bool.of_string key)"
119
+ | Ot. Bt_float ->
120
+ Printf. eprintf " float cannot be used as a map key type" ;
121
+ exit 1
122
+ | Ot. Bt_bytes ->
123
+ Printf. eprintf " bytes cannot be used as a map key type" ;
124
+ exit 1
125
+ in
126
+ F. line sc " let assoc =" ;
127
+ F. sub_scope sc (fun sc ->
128
+ F. line sc " assoc" ;
129
+ F. linep sc " |> List.map (fun (%s, %s) -> (%s, %s)) " key_name
130
+ value_name key_exp value_exp;
131
+ F. line sc " |> List.to_seq" ;
132
+ (* Passing through [Hashtbl.of_seq] even in the [At_list] case ensures that if there
133
+ is a repeated key we take the last value associated with it. *)
134
+ F. line sc " |> Hashtbl.of_seq" );
135
+ F. line sc " in" ;
136
+ let assoc_exp =
137
+ match assoc_type with
138
+ | Ot. At_hashtable -> " assoc"
139
+ | Ot. At_list -> " assoc |> Hashtbl.to_seq |> List.of_seq"
140
+ in
141
+ F. linep sc " v.%s <- %s" rf_label assoc_exp)
144
142
145
143
(* Generate decode function for a record *)
146
144
let gen_record ?and_ { Ot. r_name; r_fields } sc =
@@ -174,8 +172,10 @@ let gen_record ?and_ { Ot.r_name; r_fields } sc =
174
172
| Ot. Rft_required _ ->
175
173
Printf. eprintf " Only proto3 syntax supported in JSON encoding" ;
176
174
exit 1
177
- | Ot. Rft_associative (assoc_type , _ , (key_type , _ ), (value_type , _ )) ->
178
- gen_rft_assoc_field sc ~r_name ~rf_label ~assoc_type ~key_type ~value_type )
175
+ | Ot. Rft_associative
176
+ (assoc_type, _, (key_type, _), (value_type, _)) ->
177
+ gen_rft_assoc_field sc ~r_name ~rf_label ~assoc_type ~key_type
178
+ ~value_type )
179
179
r_fields;
180
180
181
181
(* Unknown fields are simply ignored *)
0 commit comments