diff options
| author | Adelyn Breelove <[email protected]> | 2018-12-13 15:50:37 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2018-12-13 15:50:37 -0700 |
| commit | 179d9598fe62e2966471b312fd438e98ff3a272a (patch) | |
| tree | cbe69315ccd51dc69912a39fee30dfa767fa491e /lib/models/activity_j.ml | |
| parent | Working on deriving types from json (diff) | |
| download | disml-179d9598fe62e2966471b312fd438e98ff3a272a.tar.xz disml-179d9598fe62e2966471b312fd438e98ff3a272a.zip | |
Fix more dispatch issues
Diffstat (limited to 'lib/models/activity_j.ml')
| -rw-r--r-- | lib/models/activity_j.ml | 223 |
1 files changed, 190 insertions, 33 deletions
diff --git a/lib/models/activity_j.ml b/lib/models/activity_j.ml index 8a4eb2e..eb1a62e 100644 --- a/lib/models/activity_j.ml +++ b/lib/models/activity_j.ml @@ -1,22 +1,65 @@ (* Auto-generated from "activity.atd" *) [@@@ocaml.warning "-27-32-35-39"] -type snowflake = Snowflake_t.t +type t = Activity_t.t = { name: string; kind: int; url: string option } -type t = Activity_t.t = { id: snowflake } - -let write_snowflake = ( - Snowflake_j.write_t +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) ) -let string_of_snowflake ?(len = 1024) x = +let string_of__1 ?(len = 1024) x = let ob = Bi_outbuf.create len in - write_snowflake ob x; + write__1 ob x; Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) ) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_t : _ -> t -> _ = ( fun ob x -> Bi_outbuf.add_char ob '{'; @@ -25,11 +68,31 @@ let write_t : _ -> t -> _ = ( is_first := false else Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; ( - write_snowflake + Yojson.Safe.write_int ) - ob x.id; + ob x.kind; + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); Bi_outbuf.add_char ob '}'; ) let string_of_t ?(len = 1024) x = @@ -40,7 +103,9 @@ let read_t = ( fun p lb -> Yojson.Safe.read_space p lb; Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_url = ref (None) in let bits0 = ref 0 in try Yojson.Safe.read_space p lb; @@ -50,24 +115,69 @@ let read_t = ( fun s pos len -> if pos < 0 || len < 0 || pos + len > String.length s then invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) in let i = Yojson.Safe.map_ident p f lb in Atdgen_runtime.Oj_run.read_until_field_value p lb; ( match i with | 0 -> - field_id := ( + field_name := ( ( - read_snowflake + Atdgen_runtime.Oj_run.read_string ) p lb ); bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) | _ -> ( Yojson.Safe.skip_json p lb ) @@ -80,24 +190,69 @@ let read_t = ( fun s pos len -> if pos < 0 || len < 0 || pos + len > String.length s then invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) in let i = Yojson.Safe.map_ident p f lb in Atdgen_runtime.Oj_run.read_until_field_value p lb; ( match i with | 0 -> - field_id := ( + field_name := ( ( - read_snowflake + Atdgen_runtime.Oj_run.read_string ) p lb ); bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) | _ -> ( Yojson.Safe.skip_json p lb ) @@ -105,10 +260,12 @@ let read_t = ( done; assert false; with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "kind" |]; ( { - id = !field_id; + name = !field_name; + kind = !field_kind; + url = !field_url; } : t) ) |