aboutsummaryrefslogtreecommitdiff
path: root/lib/models/member_j.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/member_j.ml')
-rw-r--r--lib/models/member_j.ml404
1 files changed, 353 insertions, 51 deletions
diff --git a/lib/models/member_j.ml b/lib/models/member_j.ml
index 3826c93..7fd4aec 100644
--- a/lib/models/member_j.ml
+++ b/lib/models/member_j.ml
@@ -6,7 +6,15 @@ type user = User_t.t
type snowflake = Snowflake_t.t
type t = Member_t.t = {
- user: user;
+ nick: string option;
+ roles: snowflake list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: user
+}
+
+type partial_member = Member_t.partial_member = {
nick: string option;
roles: snowflake list;
joined_at: string;
@@ -115,15 +123,6 @@ 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 "\"user\":";
- (
- write_user
- )
- ob x.user;
(match x.nick with None -> () | Some x ->
if !is_first then
is_first := false
@@ -171,6 +170,15 @@ let write_t : _ -> t -> _ = (
Yojson.Safe.write_bool
)
ob x.mute;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"user\":";
+ (
+ write_user
+ )
+ ob x.user;
Bi_outbuf.add_char ob '}';
)
let string_of_t ?(len = 1024) x =
@@ -181,12 +189,12 @@ let read_t = (
fun p lb ->
Yojson.Safe.read_space p lb;
Yojson.Safe.read_lcurl p lb;
- let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_nick = ref (None) in
let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let bits0 = ref 0 in
try
Yojson.Safe.read_space p lb;
@@ -201,7 +209,7 @@ let read_t = (
match String.unsafe_get s pos with
| 'd' -> (
if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then (
- 4
+ 3
)
else (
-1
@@ -209,7 +217,7 @@ let read_t = (
)
| 'm' -> (
if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then (
- 5
+ 4
)
else (
-1
@@ -217,7 +225,7 @@ let read_t = (
)
| 'n' -> (
if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then (
- 1
+ 0
)
else (
-1
@@ -225,7 +233,7 @@ let read_t = (
)
| 'u' -> (
if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then (
- 0
+ 5
)
else (
-1
@@ -237,7 +245,7 @@ let read_t = (
)
| 5 -> (
if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then (
- 2
+ 1
)
else (
-1
@@ -245,7 +253,7 @@ let read_t = (
)
| 9 -> (
if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then (
- 3
+ 2
)
else (
-1
@@ -260,13 +268,6 @@ let read_t = (
(
match i with
| 0 ->
- field_user := (
- (
- read_user
- ) p lb
- );
- bits0 := !bits0 lor 0x1;
- | 1 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_nick := (
Some (
@@ -276,31 +277,38 @@ let read_t = (
)
);
)
- | 2 ->
+ | 1 ->
field_roles := (
(
read__2
) p lb
);
- bits0 := !bits0 lor 0x2;
- | 3 ->
+ bits0 := !bits0 lor 0x1;
+ | 2 ->
field_joined_at := (
(
Atdgen_runtime.Oj_run.read_string
) p lb
);
+ bits0 := !bits0 lor 0x2;
+ | 3 ->
+ field_deaf := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
bits0 := !bits0 lor 0x4;
| 4 ->
- field_deaf := (
+ field_mute := (
(
Atdgen_runtime.Oj_run.read_bool
) p lb
);
bits0 := !bits0 lor 0x8;
| 5 ->
- field_mute := (
+ field_user := (
(
- Atdgen_runtime.Oj_run.read_bool
+ read_user
) p lb
);
bits0 := !bits0 lor 0x10;
@@ -321,7 +329,7 @@ let read_t = (
match String.unsafe_get s pos with
| 'd' -> (
if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then (
- 4
+ 3
)
else (
-1
@@ -329,7 +337,7 @@ let read_t = (
)
| 'm' -> (
if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then (
- 5
+ 4
)
else (
-1
@@ -337,7 +345,7 @@ let read_t = (
)
| 'n' -> (
if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then (
- 1
+ 0
)
else (
-1
@@ -345,7 +353,7 @@ let read_t = (
)
| 'u' -> (
if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then (
- 0
+ 5
)
else (
-1
@@ -357,7 +365,7 @@ let read_t = (
)
| 5 -> (
if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then (
- 2
+ 1
)
else (
-1
@@ -365,7 +373,7 @@ let read_t = (
)
| 9 -> (
if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then (
- 3
+ 2
)
else (
-1
@@ -380,13 +388,6 @@ let read_t = (
(
match i with
| 0 ->
- field_user := (
- (
- read_user
- ) p lb
- );
- bits0 := !bits0 lor 0x1;
- | 1 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_nick := (
Some (
@@ -396,31 +397,38 @@ let read_t = (
)
);
)
- | 2 ->
+ | 1 ->
field_roles := (
(
read__2
) p lb
);
- bits0 := !bits0 lor 0x2;
- | 3 ->
+ bits0 := !bits0 lor 0x1;
+ | 2 ->
field_joined_at := (
(
Atdgen_runtime.Oj_run.read_string
) p lb
);
+ bits0 := !bits0 lor 0x2;
+ | 3 ->
+ field_deaf := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
bits0 := !bits0 lor 0x4;
| 4 ->
- field_deaf := (
+ field_mute := (
(
Atdgen_runtime.Oj_run.read_bool
) p lb
);
bits0 := !bits0 lor 0x8;
| 5 ->
- field_mute := (
+ field_user := (
(
- Atdgen_runtime.Oj_run.read_bool
+ read_user
) p lb
);
bits0 := !bits0 lor 0x10;
@@ -431,18 +439,312 @@ let read_t = (
done;
assert false;
with Yojson.End_of_object -> (
- if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "joined_at"; "deaf"; "mute" |];
+ if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute"; "user" |];
(
{
- user = !field_user;
nick = !field_nick;
roles = !field_roles;
joined_at = !field_joined_at;
deaf = !field_deaf;
mute = !field_mute;
+ user = !field_user;
}
: t)
)
)
let t_of_string s =
read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
+let write_partial_member : _ -> partial_member -> _ = (
+ fun ob x ->
+ Bi_outbuf.add_char ob '{';
+ let is_first = ref true in
+ (match x.nick with None -> () | Some x ->
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"nick\":";
+ (
+ Yojson.Safe.write_string
+ )
+ ob x;
+ );
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"roles\":";
+ (
+ write__2
+ )
+ ob x.roles;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"joined_at\":";
+ (
+ Yojson.Safe.write_string
+ )
+ ob x.joined_at;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"deaf\":";
+ (
+ Yojson.Safe.write_bool
+ )
+ ob x.deaf;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"mute\":";
+ (
+ Yojson.Safe.write_bool
+ )
+ ob x.mute;
+ Bi_outbuf.add_char ob '}';
+)
+let string_of_partial_member ?(len = 1024) x =
+ let ob = Bi_outbuf.create len in
+ write_partial_member ob x;
+ Bi_outbuf.contents ob
+let read_partial_member = (
+ fun p lb ->
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_lcurl p lb;
+ let field_nick = ref (None) in
+ let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_mute = 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";
+ match len with
+ | 4 -> (
+ match String.unsafe_get s pos with
+ | 'd' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then (
+ 3
+ )
+ else (
+ -1
+ )
+ )
+ | 'm' -> (
+ if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then (
+ 4
+ )
+ else (
+ -1
+ )
+ )
+ | 'n' -> (
+ if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 5 -> (
+ if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 9 -> (
+ if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then (
+ 2
+ )
+ else (
+ -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 ->
+ if not (Yojson.Safe.read_null_if_possible p lb) then (
+ field_nick := (
+ Some (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ )
+ );
+ )
+ | 1 ->
+ field_roles := (
+ (
+ read__2
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 2 ->
+ field_joined_at := (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | 3 ->
+ field_deaf := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x4;
+ | 4 ->
+ field_mute := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x8;
+ | _ -> (
+ 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";
+ match len with
+ | 4 -> (
+ match String.unsafe_get s pos with
+ | 'd' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then (
+ 3
+ )
+ else (
+ -1
+ )
+ )
+ | 'm' -> (
+ if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then (
+ 4
+ )
+ else (
+ -1
+ )
+ )
+ | 'n' -> (
+ if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 5 -> (
+ if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 9 -> (
+ if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then (
+ 2
+ )
+ else (
+ -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 ->
+ if not (Yojson.Safe.read_null_if_possible p lb) then (
+ field_nick := (
+ Some (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ )
+ );
+ )
+ | 1 ->
+ field_roles := (
+ (
+ read__2
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 2 ->
+ field_joined_at := (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | 3 ->
+ field_deaf := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x4;
+ | 4 ->
+ field_mute := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x8;
+ | _ -> (
+ Yojson.Safe.skip_json p lb
+ )
+ );
+ done;
+ assert false;
+ with Yojson.End_of_object -> (
+ if !bits0 <> 0xf then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute" |];
+ (
+ {
+ nick = !field_nick;
+ roles = !field_roles;
+ joined_at = !field_joined_at;
+ deaf = !field_deaf;
+ mute = !field_mute;
+ }
+ : partial_member)
+ )
+)
+let partial_member_of_string s =
+ read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s)