Permalink
Browse files

(ocaml) Add support for deserialization options

parse_<typename> functions now accept an addition ?opts parameter with
de-serialization options, similar to gen_<typename>.
  • Loading branch information...
1 parent 5da425c commit 2a9d74131e6fe8d84a6407a291b3cdd7d31506e4 @alavrik committed Apr 29, 2012
Showing with 21 additions and 2 deletions.
  1. +3 −2 piqic/piqic_ocaml_ext.ml
  2. +18 −0 piqilib/piqirun_ext.mli
View
@@ -60,8 +60,9 @@ let gen_convert mlname input_format output_format data =
let gen_parse ocaml_mod def =
let mlname = piqdef_mlname def in
iod " " [
- ios "let parse_" ^^ ios mlname; ios "x (format :Piqirun_ext.input_format) =";
- ios "let x_pb ="; gen_convert mlname "format" "`pb" "x";
+ ios "let parse_" ^^ ios mlname;
+ ios "?opts"; ios "x (format :Piqirun_ext.input_format) =";
+ ios "let x_pb ="; gen_convert mlname "format" "`pb" "x"; ios "?opts";
ios "in";
ios "let buf = Piqirun.init_from_string x_pb";
ios "in";
View
@@ -34,6 +34,24 @@ val init_piqi : string list -> unit
val find_piqtype : string -> piqtype
+
+(* Construct serialization options to be passed as an optional argument to
+ * gen_<typename> and parse_<typename> functions. Available options:
+ *
+ * pretty_print
+ *
+ * Pretty-print generated JSON and XML output (default = true)
+ *
+ * json_omit_null_fields
+ *
+ * Omit missing optional fields from JSON output instead of representing
+ * them as {"field_name": null} JSON fields (default = true)
+ *
+ * use_strict_parsing
+ *
+ * Treat unknown and duplicate fields as errors when parsing JSON,
+ * XML and Piq formats (default = false)
+ *)
val make_options:
?pretty_print:bool ->
?json_omit_null_fields:bool ->

0 comments on commit 2a9d741

Please sign in to comment.