diff options
| author | Adelyn Breelove <[email protected]> | 2018-12-13 14:11:54 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2018-12-13 14:11:54 -0700 |
| commit | 73d115ce6260e97f5f7ee47f743d842ffd292662 (patch) | |
| tree | 7825358ae1b4736392909cb72ce26cdb26257d23 /lib/models/activity_j.ml | |
| parent | Add rate limit handling (diff) | |
| download | disml-73d115ce6260e97f5f7ee47f743d842ffd292662.tar.xz disml-73d115ce6260e97f5f7ee47f743d842ffd292662.zip | |
Working on deriving types from json
Diffstat (limited to 'lib/models/activity_j.ml')
| -rw-r--r-- | lib/models/activity_j.ml | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/lib/models/activity_j.ml b/lib/models/activity_j.ml new file mode 100644 index 0000000..8a4eb2e --- /dev/null +++ b/lib/models/activity_j.ml @@ -0,0 +1,117 @@ +(* Auto-generated from "activity.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Activity_t.t = { id: snowflake } + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +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 bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + 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 + ) + 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 := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + 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 + ) + 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 := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + ( + { + id = !field_id; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) |