aboutsummaryrefslogtreecommitdiff
path: root/lib/models/user_j.ml
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2018-12-13 15:50:37 -0700
committerAdelyn Breelove <[email protected]>2018-12-13 15:50:37 -0700
commit179d9598fe62e2966471b312fd438e98ff3a272a (patch)
treecbe69315ccd51dc69912a39fee30dfa767fa491e /lib/models/user_j.ml
parentWorking on deriving types from json (diff)
downloaddisml-179d9598fe62e2966471b312fd438e98ff3a272a.tar.xz
disml-179d9598fe62e2966471b312fd438e98ff3a272a.zip
Fix more dispatch issues
Diffstat (limited to 'lib/models/user_j.ml')
-rw-r--r--lib/models/user_j.ml100
1 files changed, 100 insertions, 0 deletions
diff --git a/lib/models/user_j.ml b/lib/models/user_j.ml
index 6eb93e6..552a20d 100644
--- a/lib/models/user_j.ml
+++ b/lib/models/user_j.ml
@@ -11,6 +11,8 @@ type t = User_t.t = {
bot: bool
}
+type partial_user = User_t.partial_user = { id: snowflake }
+
let write_snowflake = (
Snowflake_j.write_t
)
@@ -366,3 +368,101 @@ let read_t = (
)
let t_of_string s =
read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
+let write_partial_user : _ -> partial_user -> _ = (
+ 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_partial_user ?(len = 1024) x =
+ let ob = Bi_outbuf.create len in
+ write_partial_user ob x;
+ Bi_outbuf.contents ob
+let read_partial_user = (
+ 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;
+ }
+ : partial_user)
+ )
+)
+let partial_user_of_string s =
+ read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s)