···4242(** Get XDG directories for session storage *)
4343let with_xdg ~env f =
4444 let fs = Eio.Stdenv.fs env in
4545- let xdg = Xdge.create fs "matrix" in
4545+ let xdg = Xdge.v fs "matrix" in
4646 f xdg
47474848(** Load a stored session, returning the store and session data *)
+3-3
examples/simple_bot.ml
···20202121(** Helper to extract string from JSON.
2222 Returns [Some value] if the key exists and is a string, [None] otherwise. *)
2323-let json_get_string key (json : Jsont.json) =
2323+let json_get_string key (json : Json.t) =
2424 match json with
2525- | Jsont.Object (mems, _) ->
2525+ | Json.Object (mems, _) ->
2626 List.find_map (fun ((name, _), value) ->
2727 if name = key then
2828 match value with
2929- | Jsont.String (s, _) -> Some s
2929+ | Json.String (s, _) -> Some s
3030 | _ -> None
3131 else None
3232 ) mems
+53-54
lib/matrix_client/account.ml
···1212 in
1313 match Client.get client ~path () with
1414 | Error e -> Error e
1515- | Ok body -> Client.decode_response Jsont.json body
1515+ | Ok body -> Client.decode_response Json.Codec.Value.t body
16161717let set_account_data client ~event_type ~content =
1818 match Client.user_id client with
···2323 (Uri.pct_encode user_id_str)
2424 (Uri.pct_encode event_type)
2525 in
2626- match Client.encode_body Jsont.json content with
2626+ match Client.encode_body Json.Codec.Value.t content with
2727 | Error e -> Error e
2828 | Ok body ->
2929 match Client.put client ~path ~body () with
···4343 in
4444 match Client.get client ~path () with
4545 | Error e -> Error e
4646- | Ok body -> Client.decode_response Jsont.json body
4646+ | Ok body -> Client.decode_response Json.Codec.Value.t body
47474848let set_room_account_data client ~room_id ~event_type ~content =
4949 match Client.user_id client with
···5656 (Uri.pct_encode room_id_str)
5757 (Uri.pct_encode event_type)
5858 in
5959- match Client.encode_body Jsont.json content with
5959+ match Client.encode_body Json.Codec.Value.t content with
6060 | Error e -> Error e
6161 | Ok body ->
6262 match Client.put client ~path ~body () with
···7272}
73737474let threepid_jsont =
7575- Jsont.Object.(
7575+ Json.Codec.Object.(
7676 map (fun medium address validated_at added_at ->
7777 { medium; address; validated_at; added_at })
7878- |> mem "medium" Jsont.string
7979- |> mem "address" Jsont.string
8080- |> mem "validated_at" Jsont.int64
8181- |> mem "added_at" Jsont.int64
8282- |> finish)
7878+ |> member "medium" Json.Codec.string
7979+ |> member "address" Json.Codec.string
8080+ |> member "validated_at" Json.Codec.int64
8181+ |> member "added_at" Json.Codec.int64
8282+ |> seal)
83838484type threepids_response = {
8585 threepids : threepid list;
8686}
87878888let threepids_response_jsont =
8989- Jsont.Object.(
8989+ Json.Codec.Object.(
9090 map (fun threepids -> { threepids })
9191- |> mem "threepids" (Jsont.list threepid_jsont) ~dec_absent:[]
9292- |> finish)
9191+ |> member "threepids" (Json.Codec.list threepid_jsont) ~dec_absent:[]
9292+ |> seal)
93939494let get_3pids client =
9595 match Client.get client ~path:"/account/3pid" () with
···107107} [@@warning "-69"]
108108109109let email_token_request_jsont =
110110- Jsont.Object.(
110110+ Json.Codec.Object.(
111111 map (fun email client_secret send_attempt ->
112112 { email; client_secret; send_attempt })
113113- |> mem "email" Jsont.string
114114- |> mem "client_secret" Jsont.string
115115- |> mem "send_attempt" Jsont.int
116116- |> finish)
113113+ |> member "email" Json.Codec.string
114114+ |> member "client_secret" Json.Codec.string
115115+ |> member "send_attempt" Json.Codec.int
116116+ |> seal)
117117118118type token_response = {
119119 sid : string;
120120}
121121122122let token_response_jsont =
123123- Jsont.Object.(
123123+ Json.Codec.Object.(
124124 map (fun sid -> { sid })
125125- |> mem "sid" Jsont.string
126126- |> finish)
125125+ |> member "sid" Json.Codec.string
126126+ |> seal)
127127128128let request_email_token client ~email ~client_secret ~send_attempt =
129129 let request = { email; client_secret; send_attempt } in
···146146} [@@warning "-69"]
147147148148let msisdn_token_request_jsont =
149149- Jsont.Object.(
149149+ Json.Codec.Object.(
150150 map (fun country phone_number client_secret send_attempt ->
151151 { country; phone_number; client_secret; send_attempt })
152152- |> mem "country" Jsont.string
153153- |> mem "phone_number" Jsont.string
154154- |> mem "client_secret" Jsont.string
155155- |> mem "send_attempt" Jsont.int
156156- |> finish)
152152+ |> member "country" Json.Codec.string
153153+ |> member "phone_number" Json.Codec.string
154154+ |> member "client_secret" Json.Codec.string
155155+ |> member "send_attempt" Json.Codec.int
156156+ |> seal)
157157158158let request_msisdn_token client ~country ~phone_number ~client_secret ~send_attempt =
159159 let request = { country; phone_number; client_secret; send_attempt } in
···174174} [@@warning "-69"]
175175176176let add_3pid_request_jsont =
177177- Jsont.Object.(
177177+ Json.Codec.Object.(
178178 map (fun client_secret sid -> { client_secret; sid })
179179- |> mem "client_secret" Jsont.string
180180- |> mem "sid" Jsont.string
181181- |> finish)
179179+ |> member "client_secret" Json.Codec.string
180180+ |> member "sid" Json.Codec.string
181181+ |> seal)
182182183183let add_3pid client ~client_secret ~sid =
184184 let request = { client_secret; sid } in
···196196} [@@warning "-69"]
197197198198let delete_3pid_request_jsont =
199199- Jsont.Object.(
199199+ Json.Codec.Object.(
200200 map (fun medium address -> { medium; address })
201201- |> mem "medium" Jsont.string
202202- |> mem "address" Jsont.string
203203- |> finish)
201201+ |> member "medium" Json.Codec.string
202202+ |> member "address" Json.Codec.string
203203+ |> seal)
204204205205let delete_3pid client ~medium ~address =
206206 let request = { medium; address } in
···218218} [@@warning "-69"]
219219220220let change_password_request_jsont =
221221- Jsont.Object.(
221221+ Json.Codec.Object.(
222222 map (fun new_password logout_devices -> { new_password; logout_devices })
223223- |> mem "new_password" Jsont.string
224224- |> mem "logout_devices" Jsont.bool ~dec_absent:false
225225- |> finish)
223223+ |> member "new_password" Json.Codec.string
224224+ |> member "logout_devices" Json.Codec.bool ~dec_absent:false
225225+ |> seal)
226226227227let change_password client ~new_password ?(logout_devices = false) () =
228228 let request = { new_password; logout_devices } in
···239239} [@@warning "-69"]
240240241241let deactivate_request_jsont =
242242- Jsont.Object.(
242242+ Json.Codec.Object.(
243243 map (fun erase -> { erase })
244244- |> mem "erase" Jsont.bool ~dec_absent:false
245245- |> finish)
244244+ |> member "erase" Json.Codec.bool ~dec_absent:false
245245+ |> seal)
246246247247let deactivate client ?(erase = false) () =
248248 let request = { erase } in
···255255256256(* Ignored users - stored in account data *)
257257type ignored_users_content = {
258258- ignored_users : (string * Jsont.json) list;
258258+ ignored_users : (string * Json.t) list;
259259}
260260261261let ignored_users_content_jsont =
262262 let module StringMap = Map.Make(String) in
263263 let map_jsont =
264264- Jsont.Object.as_string_map Jsont.json
265265- |> Jsont.map
264264+ Json.Codec.Object.as_string_map Json.Codec.Value.t
265265+ |> Json.Codec.map
266266 ~dec:(fun m -> StringMap.bindings m)
267267 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq)
268268 in
269269- Jsont.Object.(
269269+ Json.Codec.Object.(
270270 map (fun ignored_users -> { ignored_users })
271271- |> mem "ignored_users" map_jsont ~dec_absent:[]
272272- |> finish)
271271+ |> member "ignored_users" map_jsont ~dec_absent:[]
272272+ |> seal)
273273274274let get_ignored_users client =
275275 match get_account_data client ~event_type:"m.ignored_user_list" with
276276 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok []
277277 | Error e -> Error e
278278 | Ok json ->
279279- match Jsont_bytesrw.decode_string ignored_users_content_jsont
280280- (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with
279279+ match (Json.of_string ignored_users_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with
281280 | Error _ -> Ok []
282281 | Ok content ->
283282 let user_ids = List.filter_map (fun (uid, _) ->
···297296 else
298297 let new_list = user_id :: current in
299298 let ignored_map = List.map (fun u ->
300300- (Matrix_proto.Id.User_id.to_string u, Jsont.Json.object' [])
299299+ (Matrix_proto.Id.User_id.to_string u, Json.Value.object' [])
301300 ) new_list in
302301 let content = { ignored_users = ignored_map } in
303302 match Client.encode_body ignored_users_content_jsont content with
304303 | Error e -> Error e
305304 | Ok body ->
306306- match Client.decode_response Jsont.json body with
305305+ match Client.decode_response Json.Codec.Value.t body with
307306 | Error e -> Error e
308307 | Ok json ->
309308 set_account_data client ~event_type:"m.ignored_user_list" ~content:json
···317316 Matrix_proto.Id.User_id.to_string u <> user_id_str
318317 ) current in
319318 let ignored_map = List.map (fun u ->
320320- (Matrix_proto.Id.User_id.to_string u, Jsont.Json.object' [])
319319+ (Matrix_proto.Id.User_id.to_string u, Json.Value.object' [])
321320 ) new_list in
322321 let content = { ignored_users = ignored_map } in
323322 match Client.encode_body ignored_users_content_jsont content with
324323 | Error e -> Error e
325324 | Ok body ->
326326- match Client.decode_response Jsont.json body with
325325+ match Client.decode_response Json.Codec.Value.t body with
327326 | Error e -> Error e
328327 | Ok json ->
329328 set_account_data client ~event_type:"m.ignored_user_list" ~content:json
+4-4
lib/matrix_client/account.mli
···66val get_account_data :
77 Client.t ->
88 event_type:string ->
99- (Jsont.json, Error.t) result
99+ (Json.t, Error.t) result
10101111(** Set global account data. *)
1212val set_account_data :
1313 Client.t ->
1414 event_type:string ->
1515- content:Jsont.json ->
1515+ content:Json.t ->
1616 (unit, Error.t) result
17171818(** Get room-specific account data. *)
···2020 Client.t ->
2121 room_id:Matrix_proto.Id.Room_id.t ->
2222 event_type:string ->
2323- (Jsont.json, Error.t) result
2323+ (Json.t, Error.t) result
24242525(** Set room-specific account data. *)
2626val set_room_account_data :
2727 Client.t ->
2828 room_id:Matrix_proto.Id.Room_id.t ->
2929 event_type:string ->
3030- content:Jsont.json ->
3030+ content:Json.t ->
3131 (unit, Error.t) result
32323333(** {1 Third-Party Identifiers} *)
···99 Note: Due to various known flaws in this algorithm, it is provided mainly
1010 for backwards compatibility with existing backups. *)
11111212-open Mirage_crypto_ec
1212+open Crypto_ec
13131414(** {1 Backup Key Types} *)
1515···6767(** Room key backup info - describes the backup algorithm and parameters *)
6868type backup_info =
6969 | Megolm_v1_curve25519_aes_sha2 of megolm_v1_auth_data
7070- | Other of { algorithm : string; auth_data : Jsont.json }
7070+ | Other of { algorithm : string; auth_data : Json.t }
71717272(** Backup version info from server *)
7373type backup_version_info = {
7474 version : string;
7575 algorithm : string;
7676- auth_data : Jsont.json;
7676+ auth_data : Json.t;
7777 count : int;
7878 etag : string;
7979}
···181181 let padded = payload ^ String.make pad_len (Char.chr pad_len) in
182182183183 (* Generate random IV *)
184184- let iv = Mirage_crypto_rng.generate 16 in
184184+ let iv = Crypto_rng.generate 16 in
185185186186 (* Encrypt with AES-256-CBC *)
187187- let key = Mirage_crypto.AES.CBC.of_secret aes_key in
188188- let ciphertext = Mirage_crypto.AES.CBC.encrypt ~key ~iv padded in
187187+ let key = Crypto.AES.CBC.of_secret aes_key in
188188+ let ciphertext = Crypto.AES.CBC.encrypt ~key ~iv padded in
189189190190 (* Prepend IV to ciphertext for MAC calculation *)
191191 let mac_input = iv ^ ciphertext in
···241241 let ciphertext = String.sub ciphertext_with_iv 16 (String.length ciphertext_with_iv - 16) in
242242243243 (* Decrypt with AES-256-CBC *)
244244- let key = Mirage_crypto.AES.CBC.of_secret aes_key in
245245- let plaintext = Mirage_crypto.AES.CBC.decrypt ~key ~iv ciphertext in
244244+ let key = Crypto.AES.CBC.of_secret aes_key in
245245+ let plaintext = Crypto.AES.CBC.decrypt ~key ~iv ciphertext in
246246247247 (* Remove PKCS#7 padding *)
248248 let pad_len = Char.code (String.get plaintext (String.length plaintext - 1)) in
···379379 match String.split_on_char '"' str with
380380 | _ -> None
381381 in
382382- (* Simplified - would use Jsont in real implementation *)
383383- match Jsont_bytesrw.decode_string Jsont.json json_str with
382382+ (* Simplified - would use Json in real implementation *)
383383+ match (Json.of_string Json.Codec.Value.t json_str |> Result.map_error Json.Error.to_string) with
384384 | Error _ -> None
385385 | Ok _json -> None (* Would extract fields from JSON *)
386386
+2-2
lib/matrix_client/backup.mli
···5555(** Room key backup info - describes the backup algorithm and parameters. *)
5656type backup_info =
5757 | Megolm_v1_curve25519_aes_sha2 of megolm_v1_auth_data
5858- | Other of { algorithm : string; auth_data : Jsont.json }
5858+ | Other of { algorithm : string; auth_data : Json.t }
59596060(** Backup version info from server. *)
6161type backup_version_info = {
6262 version : string;
6363 algorithm : string;
6464- auth_data : Jsont.json;
6464+ auth_data : Json.t;
6565 count : int;
6666 etag : string;
6767}
+6-6
lib/matrix_client/calls.ml
···177177}
178178179179let turn_server_jsont =
180180- Jsont.Object.(
180180+ Json.Codec.Object.(
181181 map (fun username password uris ttl ->
182182 { username; password; uris; ttl })
183183- |> mem "username" Jsont.string ~enc:(fun t -> t.username)
184184- |> mem "password" Jsont.string ~enc:(fun t -> t.password)
185185- |> mem "uris" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.uris)
186186- |> mem "ttl" Jsont.int ~enc:(fun t -> t.ttl)
187187- |> finish)
183183+ |> member "username" Json.Codec.string ~enc:(fun t -> t.username)
184184+ |> member "password" Json.Codec.string ~enc:(fun t -> t.password)
185185+ |> member "uris" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.uris)
186186+ |> member "ttl" Json.Codec.int ~enc:(fun t -> t.ttl)
187187+ |> seal)
188188189189(** Get TURN server credentials from the homeserver. *)
190190let get_turn_server client =
···2020}
21212222let create ~sw ~config env =
2323- let http = Requests.create ~sw env in
2323+ let http = Requests.v ~sw env in
2424 { http; config; session = None }
25252626let with_session t session =
···6969 else begin
7070 Log.warn (fun m -> m "HTTP error: status=%d body=%s" status body);
7171 (* Try to parse as Matrix error *)
7272- match Jsont_bytesrw.decode_string Error.matrix_error_jsont body with
7272+ match (Json.of_string Error.matrix_error_jsont body |> Result.map_error Json.Error.to_string) with
7373 | Ok matrix_err -> Error (Error.Matrix_error matrix_err)
7474 | Error _ -> Error (Error.Http_error { status; body })
7575 end
···153153 Error (Error.Network_error (Printexc.to_string exn))
154154155155let decode_response jsont body =
156156- match Jsont_bytesrw.decode_string jsont body with
156156+ match (Json.of_string jsont body |> Result.map_error Json.Error.to_string) with
157157 | Ok v -> Ok v
158158 | Error e ->
159159 Log.err (fun m -> m "JSON decode error: %s" e);
160160 Error (Error.Json_error e)
161161162162let encode_body jsont value =
163163- match Jsont_bytesrw.encode_string jsont value with
163163+ match (try Ok (Json.to_string jsont value) with Json.Error e -> Error (Json.Error.to_string e)) with
164164 | Ok s -> Ok s
165165 | Error e ->
166166 Log.err (fun m -> m "JSON encode error: %s" e);
+2-2
lib/matrix_client/client.mli
···103103 (string, Error.t) result
104104105105(** Decode a JSON response using a jsont codec. *)
106106-val decode_response : 'a Jsont.t -> string -> ('a, Error.t) result
106106+val decode_response : 'a Json.codec -> string -> ('a, Error.t) result
107107108108(** Encode a value to JSON string using a jsont codec.
109109 Returns Error if encoding fails. *)
110110-val encode_body : 'a Jsont.t -> 'a -> (string, Error.t) result
110110+val encode_body : 'a Json.codec -> 'a -> (string, Error.t) result
···33 This module implements the Olm double-ratchet algorithm for encrypted
44 to-device messages, and Megolm for encrypted room messages. *)
5566-module Ed25519 = Mirage_crypto_ec.Ed25519
77-module X25519 = Mirage_crypto_ec.X25519
66+module Ed25519 = Crypto_ec.Ed25519
77+module X25519 = Crypto_ec.X25519
8899(* Base64 encoding/decoding - Matrix uses unpadded base64 *)
1010let base64_encode s = Base64.encode_string ~pad:false s
···359359 let pad_len = block_size - (String.length plaintext mod block_size) in
360360 let padded = plaintext ^ String.make pad_len (Char.chr pad_len) in
361361 (* Encrypt using mirage-crypto AES.CBC *)
362362- let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in
363363- let encrypted = Mirage_crypto.AES.CBC.encrypt ~key:cipher ~iv padded in
362362+ let cipher = Crypto.AES.CBC.of_secret aes_key in
363363+ let encrypted = Crypto.AES.CBC.encrypt ~key:cipher ~iv padded in
364364 iv ^ encrypted
365365366366 (** Decrypt a message *)
···371371 let iv = String.sub ciphertext 0 16 in
372372 let data = String.sub ciphertext 16 (String.length ciphertext - 16) in
373373 let aes_key = String.sub key 0 32 in
374374- let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in
375375- let decrypted = Mirage_crypto.AES.CBC.decrypt ~key:cipher ~iv data in
374374+ let cipher = Crypto.AES.CBC.of_secret aes_key in
375375+ let decrypted = Crypto.AES.CBC.decrypt ~key:cipher ~iv data in
376376 (* Remove PKCS7 padding *)
377377 if String.length decrypted = 0 then
378378 Error "Empty plaintext"
···534534 | _ ->
535535 (* Generate random initial state if parsing fails *)
536536 let random_part () =
537537- Mirage_crypto_rng.generate 32
537537+ Crypto_rng.generate 32
538538 in
539539 [| random_part (); random_part (); random_part (); random_part () |]
540540 in
···583583 Error "MAC verification failed"
584584 else begin
585585 (* Decrypt using mirage-crypto AES.CBC *)
586586- let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in
587587- let decrypted = Mirage_crypto.AES.CBC.decrypt ~key:cipher ~iv ct_data in
586586+ let cipher = Crypto.AES.CBC.of_secret aes_key in
587587+ let decrypted = Crypto.AES.CBC.decrypt ~key:cipher ~iv ct_data in
588588 (* Remove PKCS7 padding *)
589589 let pad_len = Char.code decrypted.[String.length decrypted - 1] in
590590 if pad_len > 16 then
···622622 (** Create a new outbound session for a room *)
623623 let create ~room_id =
624624 let session_id =
625625- Mirage_crypto_rng.generate 16
625625+ Crypto_rng.generate 16
626626 |> base64_encode
627627 in
628628 let random_part () =
629629- Mirage_crypto_rng.generate 32
629629+ Crypto_rng.generate 32
630630 in
631631 let ratchet = [| random_part (); random_part (); random_part (); random_part () |] in
632632 let signing_priv, signing_pub = Ed25519.generate () in
···696696 let pad_len = block_size - (String.length plaintext mod block_size) in
697697 let padded = plaintext ^ String.make pad_len (Char.chr pad_len) in
698698 (* Encrypt using mirage-crypto AES.CBC *)
699699- let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in
700700- let ct_data = Mirage_crypto.AES.CBC.encrypt ~key:cipher ~iv padded in
699699+ let cipher = Crypto.AES.CBC.of_secret aes_key in
700700+ let ct_data = Crypto.AES.CBC.encrypt ~key:cipher ~iv padded in
701701 (* Add HMAC (first 8 bytes) *)
702702 let mac =
703703 Digestif.SHA256.hmac_string ~key:hmac_key ct_data
···2626}
27272828let child_state_jsont =
2929- Jsont.Object.(
2929+ Json.Codec.Object.(
3030 map (fun state_key via order suggested ->
3131 { state_key; via; order; suggested })
3232- |> mem "state_key" Jsont.string ~enc:(fun t -> t.state_key)
3333- |> mem "via" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.via)
3434- |> opt_mem "order" Jsont.string ~enc:(fun t -> t.order)
3535- |> mem "suggested" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.suggested)
3636- |> finish)
3232+ |> member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key)
3333+ |> member "via" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.via)
3434+ |> opt_member "order" Json.Codec.string ~enc:(fun t -> t.order)
3535+ |> member "suggested" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.suggested)
3636+ |> seal)
37373838let space_room_jsont =
3939- Jsont.Object.(
3939+ Json.Codec.Object.(
4040 map (fun room_id name topic canonical_alias avatar_url num_joined_members
4141 room_type join_rule children_state world_readable guest_can_join ->
4242 { room_id; name; topic; canonical_alias; avatar_url; num_joined_members;
4343 room_type; join_rule; children_state; world_readable; guest_can_join })
4444- |> mem "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id)
4545- |> opt_mem "name" Jsont.string ~enc:(fun t -> t.name)
4646- |> opt_mem "topic" Jsont.string ~enc:(fun t -> t.topic)
4747- |> opt_mem "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias)
4848- |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url)
4949- |> mem "num_joined_members" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members)
5050- |> opt_mem "room_type" Jsont.string ~enc:(fun t -> t.room_type)
5151- |> opt_mem "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule)
5252- |> mem "children_state" (Jsont.list child_state_jsont) ~dec_absent:[]
4444+ |> member "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id)
4545+ |> opt_member "name" Json.Codec.string ~enc:(fun t -> t.name)
4646+ |> opt_member "topic" Json.Codec.string ~enc:(fun t -> t.topic)
4747+ |> opt_member "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias)
4848+ |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url)
4949+ |> member "num_joined_members" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members)
5050+ |> opt_member "room_type" Json.Codec.string ~enc:(fun t -> t.room_type)
5151+ |> opt_member "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule)
5252+ |> member "children_state" (Json.Codec.list child_state_jsont) ~dec_absent:[]
5353 ~enc:(fun t -> t.children_state)
5454- |> mem "world_readable" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.world_readable)
5555- |> mem "guest_can_join" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join)
5656- |> finish)
5454+ |> member "world_readable" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.world_readable)
5555+ |> member "guest_can_join" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join)
5656+ |> seal)
57575858(** Response from [GET /_matrix/client/v1/rooms/\{roomId\}/hierarchy]. *)
5959type hierarchy_response = {
···6262}
63636464let hierarchy_response_jsont =
6565- Jsont.Object.(
6565+ Json.Codec.Object.(
6666 map (fun rooms next_batch -> { rooms; next_batch })
6767- |> mem "rooms" (Jsont.list space_room_jsont) ~dec_absent:[] ~enc:(fun t -> t.rooms)
6868- |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch)
6969- |> finish)
6767+ |> member "rooms" (Json.Codec.list space_room_jsont) ~dec_absent:[] ~enc:(fun t -> t.rooms)
6868+ |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch)
6969+ |> seal)
70707171(** Get the hierarchy of a space.
7272···111111}
112112113113let set_state_response_jsont =
114114- Jsont.Object.(
114114+ Json.Codec.Object.(
115115 map (fun event_id -> { event_id })
116116- |> mem "event_id" Matrix_proto.Id.Event_id.jsont
117117- |> finish)
116116+ |> member "event_id" Matrix_proto.Id.Event_id.jsont
117117+ |> seal)
118118119119let add_child client ~space_id ~child_id ?(via = []) ?order ?(suggested = false) () =
120120 let space_id_str = Matrix_proto.Id.Room_id.to_string space_id in
+21-24
lib/matrix_client/state.ml
···66 let path = Printf.sprintf "/rooms/%s/state" (Uri.pct_encode room_id_str) in
77 match Client.get client ~path () with
88 | Error e -> Error e
99- | Ok body -> Client.decode_response (Jsont.list Matrix_proto.Event.Raw_event.jsont) body
99+ | Ok body -> Client.decode_response (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) body
10101111(* Get specific state event *)
1212let get_state_event client ~room_id ~event_type ?(state_key = "") () =
···1818 in
1919 match Client.get client ~path () with
2020 | Error e -> Error e
2121- | Ok body -> Client.decode_response Jsont.json body
2121+ | Ok body -> Client.decode_response Json.Codec.Value.t body
22222323(* Set state event *)
2424type set_state_response = {
···2626}
27272828let set_state_response_jsont =
2929- Jsont.Object.(
2929+ Json.Codec.Object.(
3030 map (fun event_id -> { event_id })
3131- |> mem "event_id" Matrix_proto.Id.Event_id.jsont
3232- |> finish)
3131+ |> member "event_id" Matrix_proto.Id.Event_id.jsont
3232+ |> seal)
33333434let set_state client ~room_id ~event_type ?(state_key = "") ~content () =
3535 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in
···3838 (Uri.pct_encode event_type)
3939 (Uri.pct_encode state_key)
4040 in
4141- match Client.encode_body Jsont.json content with
4141+ match Client.encode_body Json.Codec.Value.t content with
4242 | Error e -> Error e
4343 | Ok body ->
4444 match Client.put client ~path ~body () with
···5454} [@@warning "-69"]
55555656let name_content_jsont =
5757- Jsont.Object.(
5757+ Json.Codec.Object.(
5858 map (fun name -> { name })
5959- |> mem "name" Jsont.string
6060- |> finish)
5959+ |> member "name" Json.Codec.string
6060+ |> seal)
61616262let get_name client ~room_id =
6363 match get_state_event client ~room_id ~event_type:"m.room.name" () with
6464 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None
6565 | Error e -> Error e
6666 | Ok json ->
6767- match Jsont_bytesrw.decode_string name_content_jsont
6868- (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with
6767+ match (Json.of_string name_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with
6968 | Ok c -> Ok (Some c.name)
7069 | Error _ -> Ok None
7170···7473 match Client.encode_body name_content_jsont content with
7574 | Error e -> Error e
7675 | Ok body ->
7777- match Client.decode_response Jsont.json body with
7676+ match Client.decode_response Json.Codec.Value.t body with
7877 | Error e -> Error e
7978 | Ok json -> set_state client ~room_id ~event_type:"m.room.name" ~content:json ()
8079···8483} [@@warning "-69"]
85848685let topic_content_jsont =
8787- Jsont.Object.(
8686+ Json.Codec.Object.(
8887 map (fun topic -> { topic })
8989- |> mem "topic" Jsont.string
9090- |> finish)
8888+ |> member "topic" Json.Codec.string
8989+ |> seal)
91909291let get_topic client ~room_id =
9392 match get_state_event client ~room_id ~event_type:"m.room.topic" () with
9493 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None
9594 | Error e -> Error e
9695 | Ok json ->
9797- match Jsont_bytesrw.decode_string topic_content_jsont
9898- (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with
9696+ match (Json.of_string topic_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with
9997 | Ok c -> Ok (Some c.topic)
10098 | Error _ -> Ok None
10199···104102 match Client.encode_body topic_content_jsont content with
105103 | Error e -> Error e
106104 | Ok body ->
107107- match Client.decode_response Jsont.json body with
105105+ match Client.decode_response Json.Codec.Value.t body with
108106 | Error e -> Error e
109107 | Ok json -> set_state client ~room_id ~event_type:"m.room.topic" ~content:json ()
110108···114112} [@@warning "-69"]
115113116114let avatar_content_jsont =
117117- Jsont.Object.(
115115+ Json.Codec.Object.(
118116 map (fun url -> { url })
119119- |> mem "url" Jsont.string
120120- |> finish)
117117+ |> member "url" Json.Codec.string
118118+ |> seal)
121119122120let get_avatar client ~room_id =
123121 match get_state_event client ~room_id ~event_type:"m.room.avatar" () with
124122 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None
125123 | Error e -> Error e
126124 | Ok json ->
127127- match Jsont_bytesrw.decode_string avatar_content_jsont
128128- (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with
125125+ match (Json.of_string avatar_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with
129126 | Ok c -> Ok (Some c.url)
130127 | Error _ -> Ok None
131128···134131 match Client.encode_body avatar_content_jsont content with
135132 | Error e -> Error e
136133 | Ok body ->
137137- match Client.decode_response Jsont.json body with
134134+ match Client.decode_response Json.Codec.Value.t body with
138135 | Error e -> Error e
139136 | Ok json -> set_state client ~room_id ~event_type:"m.room.avatar" ~content:json ()
+2-2
lib/matrix_client/state.mli
···1515 event_type:string ->
1616 ?state_key:string ->
1717 unit ->
1818- (Jsont.json, Error.t) result
1818+ (Json.t, Error.t) result
19192020(** Set a state event.
2121···2525 room_id:Matrix_proto.Id.Room_id.t ->
2626 event_type:string ->
2727 ?state_key:string ->
2828- content:Jsont.json ->
2828+ content:Json.t ->
2929 unit ->
3030 (Matrix_proto.Id.Event_id.t, Error.t) result
3131
···66 - User identity verification
77 - SAS (Short Authentication String) verification protocol *)
8899-open Mirage_crypto_ec
99+open Crypto_ec
10101111(** {1 Trust States} *)
1212···166166(** Canonicalize JSON for signing (simplified) *)
167167let canonicalize_json json =
168168 (* Simplified canonicalization - remove signatures and unsigned *)
169169- Jsont_bytesrw.encode_string Jsont.json json
169169+ (try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e))
170170 |> Result.value ~default:""
171171172172(** Verify that a cross-signing key is signed by another key *)
···320320321321(** Generate a random flow ID *)
322322let generate_flow_id () =
323323- let random_bytes = Mirage_crypto_rng.generate 16 in
323323+ let random_bytes = Crypto_rng.generate 16 in
324324 Base64.encode_string ~pad:false random_bytes
325325326326(** Create a new SAS verification session *)
···450450(** Create QR verification for self-verification *)
451451let create_self_qr_verification ~our_user_id ~our_master_key ~mode =
452452 let flow_id = generate_flow_id () in
453453- let secret = Mirage_crypto_rng.generate 32 |> Base64.encode_string in
453453+ let secret = Crypto_rng.generate 32 |> Base64.encode_string in
454454 {
455455 flow_id;
456456 state = Qr_started;
···465465(** Create QR verification for verifying another user *)
466466let create_user_qr_verification ~our_user_id ~their_user_id ~our_master_key ~their_master_key =
467467 let flow_id = generate_flow_id () in
468468- let secret = Mirage_crypto_rng.generate 32 |> Base64.encode_string in
468468+ let secret = Crypto_rng.generate 32 |> Base64.encode_string in
469469 {
470470 flow_id;
471471 state = Qr_started;
···52525353 let pp ppf t = Format.fprintf ppf "%Ld" t
54545555- let jsont = Jsont.int64
5555+ let jsont = Json.Codec.int64
5656end
57575858(** {1 Unsigned Event Data} *)
···66666767 type t = {
6868 age : int64 option;
6969- prev_content : Jsont.json option;
6969+ prev_content : Json.t option;
7070 prev_sender : User_id.t option;
7171- redacted_because : Jsont.json option;
7171+ redacted_because : Json.t option;
7272 transaction_id : Transaction_id.t option;
7373 }
7474···9494 Format.fprintf ppf "@]"
95959696 let jsont =
9797- Jsont.Object.(
9797+ Json.Codec.Object.(
9898 map (fun age prev_content prev_sender redacted_because transaction_id ->
9999 { age; prev_content; prev_sender; redacted_because; transaction_id })
100100- |> opt_mem "age" Jsont.int64 ~enc:(fun t -> t.age)
101101- |> opt_mem "prev_content" Jsont.json ~enc:(fun t -> t.prev_content)
102102- |> opt_mem "prev_sender" User_id.jsont ~enc:(fun t -> t.prev_sender)
103103- |> opt_mem "redacted_because" Jsont.json ~enc:(fun t -> t.redacted_because)
104104- |> opt_mem "transaction_id" Transaction_id.jsont ~enc:(fun t -> t.transaction_id)
105105- |> finish)
100100+ |> opt_member "age" Json.Codec.int64 ~enc:(fun t -> t.age)
101101+ |> opt_member "prev_content" Json.Codec.Value.t ~enc:(fun t -> t.prev_content)
102102+ |> opt_member "prev_sender" User_id.jsont ~enc:(fun t -> t.prev_sender)
103103+ |> opt_member "redacted_because" Json.Codec.Value.t ~enc:(fun t -> t.redacted_because)
104104+ |> opt_member "transaction_id" Transaction_id.jsont ~enc:(fun t -> t.transaction_id)
105105+ |> seal)
106106end
107107108108(** {1 Room Membership} *)
···137137 let pp ppf t = Format.pp_print_string ppf (to_string t)
138138139139 let jsont =
140140- Jsont.enum [
140140+ Json.Codec.enum [
141141 ("join", Join);
142142 ("invite", Invite);
143143 ("leave", Leave);
···172172 let pp ppf t = Format.pp_print_string ppf (to_string t)
173173174174 let jsont =
175175- Jsont.enum [
175175+ Json.Codec.enum [
176176 ("public", Public);
177177 ("invite", Invite);
178178 ("knock", Knock);
···204204 let pp ppf t = Format.pp_print_string ppf (to_string t)
205205206206 let jsont =
207207- Jsont.enum [
207207+ Json.Codec.enum [
208208 ("invited", Invited);
209209 ("joined", Joined);
210210 ("shared", Shared);
···236236 Room_id.pp t.room_id Event_id.pp t.event_id
237237238238 let jsont =
239239- Jsont.Object.(
239239+ Json.Codec.Object.(
240240 map (fun room_id event_id -> { room_id; event_id })
241241- |> mem "room_id" Room_id.jsont ~enc:(fun p -> p.room_id)
242242- |> mem "event_id" Event_id.jsont ~enc:(fun p -> p.event_id)
243243- |> finish)
241241+ |> member "room_id" Room_id.jsont ~enc:(fun p -> p.room_id)
242242+ |> member "event_id" Event_id.jsont ~enc:(fun p -> p.event_id)
243243+ |> seal)
244244 end
245245246246 type predecessor = Predecessor.t
···277277 Format.fprintf ppf "@]"
278278279279 let jsont =
280280- Jsont.Object.(
280280+ Json.Codec.Object.(
281281 map (fun creator room_version predecessor type_ ->
282282 { creator; room_version; predecessor; type_ })
283283- |> opt_mem "creator" User_id.jsont ~enc:(fun t -> t.creator)
284284- |> opt_mem "room_version" Jsont.string ~enc:(fun t -> t.room_version)
285285- |> opt_mem "predecessor" Predecessor.jsont ~enc:(fun t -> t.predecessor)
286286- |> opt_mem "type" Jsont.string ~enc:(fun t -> t.type_)
287287- |> finish)
283283+ |> opt_member "creator" User_id.jsont ~enc:(fun t -> t.creator)
284284+ |> opt_member "room_version" Json.Codec.string ~enc:(fun t -> t.room_version)
285285+ |> opt_member "predecessor" Predecessor.jsont ~enc:(fun t -> t.predecessor)
286286+ |> opt_member "type" Json.Codec.string ~enc:(fun t -> t.type_)
287287+ |> seal)
288288end
289289290290module Room_name_content = struct
···300300 let pp ppf t = Format.fprintf ppf "name: %s" t.name
301301302302 let jsont =
303303- Jsont.Object.(
303303+ Json.Codec.Object.(
304304 map (fun name -> { name })
305305- |> mem "name" Jsont.string ~enc:(fun t -> t.name)
306306- |> finish)
305305+ |> member "name" Json.Codec.string ~enc:(fun t -> t.name)
306306+ |> seal)
307307end
308308309309module Room_topic_content = struct
···319319 let pp ppf t = Format.fprintf ppf "topic: %s" t.topic
320320321321 let jsont =
322322- Jsont.Object.(
322322+ Json.Codec.Object.(
323323 map (fun topic -> { topic })
324324- |> mem "topic" Jsont.string ~enc:(fun t -> t.topic)
325325- |> finish)
324324+ |> member "topic" Json.Codec.string ~enc:(fun t -> t.topic)
325325+ |> seal)
326326end
327327328328module Room_avatar_content = struct
···360360 Format.fprintf ppf "@]"
361361362362 let jsont =
363363- Jsont.Object.(
363363+ Json.Codec.Object.(
364364 map (fun h w mimetype size -> { h; w; mimetype; size })
365365- |> opt_mem "h" Jsont.int ~enc:(fun t -> t.h)
366366- |> opt_mem "w" Jsont.int ~enc:(fun t -> t.w)
367367- |> opt_mem "mimetype" Jsont.string ~enc:(fun t -> t.mimetype)
368368- |> opt_mem "size" Jsont.int ~enc:(fun t -> t.size)
369369- |> finish)
365365+ |> opt_member "h" Json.Codec.int ~enc:(fun t -> t.h)
366366+ |> opt_member "w" Json.Codec.int ~enc:(fun t -> t.w)
367367+ |> opt_member "mimetype" Json.Codec.string ~enc:(fun t -> t.mimetype)
368368+ |> opt_member "size" Json.Codec.int ~enc:(fun t -> t.size)
369369+ |> seal)
370370 end
371371372372 type image_info = Image_info.t
···391391 Format.fprintf ppf "@]"
392392393393 let jsont =
394394- Jsont.Object.(
394394+ Json.Codec.Object.(
395395 map (fun url info -> { url; info })
396396- |> opt_mem "url" Jsont.string ~enc:(fun t -> t.url)
397397- |> opt_mem "info" Image_info.jsont ~enc:(fun t -> t.info)
398398- |> finish)
396396+ |> opt_member "url" Json.Codec.string ~enc:(fun t -> t.url)
397397+ |> opt_member "info" Image_info.jsont ~enc:(fun t -> t.info)
398398+ |> seal)
399399end
400400401401module Room_member_content = struct
···437437 Format.fprintf ppf "@]"
438438439439 let jsont =
440440- Jsont.Object.(
440440+ Json.Codec.Object.(
441441 map (fun membership displayname avatar_url is_direct reason ->
442442 { membership; displayname; avatar_url; is_direct; reason })
443443- |> mem "membership" Membership.jsont ~enc:(fun t -> t.membership)
444444- |> opt_mem "displayname" Jsont.string ~enc:(fun t -> t.displayname)
445445- |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url)
446446- |> opt_mem "is_direct" Jsont.bool ~enc:(fun t -> t.is_direct)
447447- |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason)
448448- |> finish)
443443+ |> member "membership" Membership.jsont ~enc:(fun t -> t.membership)
444444+ |> opt_member "displayname" Json.Codec.string ~enc:(fun t -> t.displayname)
445445+ |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url)
446446+ |> opt_member "is_direct" Json.Codec.bool ~enc:(fun t -> t.is_direct)
447447+ |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason)
448448+ |> seal)
449449end
450450451451module Room_join_rules_content = struct
···473473 Format.fprintf ppf "@]"
474474475475 let jsont =
476476- Jsont.Object.(
476476+ Json.Codec.Object.(
477477 map (fun type_ room_id -> { type_; room_id })
478478- |> mem "type" Jsont.string ~enc:(fun c -> c.type_)
479479- |> opt_mem "room_id" Room_id.jsont ~enc:(fun c -> c.room_id)
480480- |> finish)
478478+ |> member "type" Json.Codec.string ~enc:(fun c -> c.type_)
479479+ |> opt_member "room_id" Room_id.jsont ~enc:(fun c -> c.room_id)
480480+ |> seal)
481481 end
482482483483 type allow_condition = Allow_condition.t
···502502 Format.fprintf ppf "@]"
503503504504 let jsont =
505505- Jsont.Object.(
505505+ Json.Codec.Object.(
506506 map (fun join_rule allow -> { join_rule; allow })
507507- |> mem "join_rule" Join_rule.jsont ~enc:(fun t -> t.join_rule)
508508- |> opt_mem "allow" (Jsont.list Allow_condition.jsont) ~enc:(fun t -> t.allow)
509509- |> finish)
507507+ |> member "join_rule" Join_rule.jsont ~enc:(fun t -> t.join_rule)
508508+ |> opt_member "allow" (Json.Codec.list Allow_condition.jsont) ~enc:(fun t -> t.allow)
509509+ |> seal)
510510end
511511512512module Room_history_visibility_content = struct
···523523 Format.fprintf ppf "history_visibility: %a" History_visibility.pp t.history_visibility
524524525525 let jsont =
526526- Jsont.Object.(
526526+ Json.Codec.Object.(
527527 map (fun history_visibility -> { history_visibility })
528528- |> mem "history_visibility" History_visibility.jsont
528528+ |> member "history_visibility" History_visibility.jsont
529529 ~enc:(fun t -> t.history_visibility)
530530- |> finish)
530530+ |> seal)
531531end
532532533533module Room_canonical_alias_content = struct
···558558 Format.fprintf ppf "@]"
559559560560 let jsont =
561561- Jsont.Object.(
561561+ Json.Codec.Object.(
562562 map (fun alias alt_aliases -> { alias; alt_aliases })
563563- |> opt_mem "alias" Room_alias.jsont ~enc:(fun t -> t.alias)
564564- |> opt_mem "alt_aliases" (Jsont.list Room_alias.jsont) ~enc:(fun t -> t.alt_aliases)
565565- |> finish)
563563+ |> opt_member "alias" Room_alias.jsont ~enc:(fun t -> t.alias)
564564+ |> opt_member "alt_aliases" (Json.Codec.list Room_alias.jsont) ~enc:(fun t -> t.alt_aliases)
565565+ |> seal)
566566end
567567568568module Room_power_levels_content = struct
···611611 module StringMap = Map.Make(String)
612612613613 let int_map_jsont =
614614- Jsont.Object.as_string_map Jsont.int
615615- |> Jsont.map
614614+ Json.Codec.Object.as_string_map Json.Codec.int
615615+ |> Json.Codec.map
616616 ~dec:(fun m -> StringMap.bindings m)
617617 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq)
618618619619 let jsont =
620620- Jsont.Object.(
620620+ Json.Codec.Object.(
621621 map (fun ban events events_default invite kick redact
622622 state_default users users_default ->
623623 { ban; events; events_default; invite; kick; redact;
624624 state_default; users; users_default })
625625- |> opt_mem "ban" Jsont.int ~enc:(fun t -> t.ban)
626626- |> opt_mem "events" int_map_jsont ~enc:(fun t -> t.events)
627627- |> opt_mem "events_default" Jsont.int ~enc:(fun t -> t.events_default)
628628- |> opt_mem "invite" Jsont.int ~enc:(fun t -> t.invite)
629629- |> opt_mem "kick" Jsont.int ~enc:(fun t -> t.kick)
630630- |> opt_mem "redact" Jsont.int ~enc:(fun t -> t.redact)
631631- |> opt_mem "state_default" Jsont.int ~enc:(fun t -> t.state_default)
632632- |> opt_mem "users" int_map_jsont ~enc:(fun t -> t.users)
633633- |> opt_mem "users_default" Jsont.int ~enc:(fun t -> t.users_default)
634634- |> finish)
625625+ |> opt_member "ban" Json.Codec.int ~enc:(fun t -> t.ban)
626626+ |> opt_member "events" int_map_jsont ~enc:(fun t -> t.events)
627627+ |> opt_member "events_default" Json.Codec.int ~enc:(fun t -> t.events_default)
628628+ |> opt_member "invite" Json.Codec.int ~enc:(fun t -> t.invite)
629629+ |> opt_member "kick" Json.Codec.int ~enc:(fun t -> t.kick)
630630+ |> opt_member "redact" Json.Codec.int ~enc:(fun t -> t.redact)
631631+ |> opt_member "state_default" Json.Codec.int ~enc:(fun t -> t.state_default)
632632+ |> opt_member "users" int_map_jsont ~enc:(fun t -> t.users)
633633+ |> opt_member "users_default" Json.Codec.int ~enc:(fun t -> t.users_default)
634634+ |> seal)
635635end
636636637637module Room_encryption_content = struct
···663663 Format.fprintf ppf "@]"
664664665665 let jsont =
666666- Jsont.Object.(
666666+ Json.Codec.Object.(
667667 map (fun algorithm rotation_period_ms rotation_period_msgs ->
668668 { algorithm; rotation_period_ms; rotation_period_msgs })
669669- |> mem "algorithm" Jsont.string ~enc:(fun t -> t.algorithm)
670670- |> opt_mem "rotation_period_ms" Jsont.int64 ~enc:(fun t -> t.rotation_period_ms)
671671- |> opt_mem "rotation_period_msgs" Jsont.int ~enc:(fun t -> t.rotation_period_msgs)
672672- |> finish)
669669+ |> member "algorithm" Json.Codec.string ~enc:(fun t -> t.algorithm)
670670+ |> opt_member "rotation_period_ms" Json.Codec.int64 ~enc:(fun t -> t.rotation_period_ms)
671671+ |> opt_member "rotation_period_msgs" Json.Codec.int ~enc:(fun t -> t.rotation_period_msgs)
672672+ |> seal)
673673end
674674675675module Room_pinned_events_content = struct
···686686 Format.fprintf ppf "pinned: [%s]" (String.concat ", " t.pinned)
687687688688 let jsont =
689689- Jsont.Object.(
689689+ Json.Codec.Object.(
690690 map (fun pinned -> { pinned })
691691- |> mem "pinned" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.pinned)
692692- |> finish)
691691+ |> member "pinned" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.pinned)
692692+ |> seal)
693693end
694694695695module Room_server_acl_content = struct
···715715 (String.concat ", " t.allow) t.allow_ip_literals (String.concat ", " t.deny)
716716717717 let jsont =
718718- Jsont.Object.(
718718+ Json.Codec.Object.(
719719 map (fun allow allow_ip_literals deny ->
720720 { allow; allow_ip_literals; deny })
721721- |> mem "allow" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.allow)
722722- |> mem "allow_ip_literals" Jsont.bool ~dec_absent:true ~enc:(fun t -> t.allow_ip_literals)
723723- |> mem "deny" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.deny)
724724- |> finish)
721721+ |> member "allow" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.allow)
722722+ |> member "allow_ip_literals" Json.Codec.bool ~dec_absent:true ~enc:(fun t -> t.allow_ip_literals)
723723+ |> member "deny" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.deny)
724724+ |> seal)
725725end
726726727727module Room_tombstone_content = struct
···743743 t.body Room_id.pp t.replacement_room
744744745745 let jsont =
746746- Jsont.Object.(
746746+ Json.Codec.Object.(
747747 map (fun body replacement_room -> { body; replacement_room })
748748- |> mem "body" Jsont.string ~enc:(fun t -> t.body)
749749- |> mem "replacement_room" Room_id.jsont ~enc:(fun t -> t.replacement_room)
750750- |> finish)
748748+ |> member "body" Json.Codec.string ~enc:(fun t -> t.body)
749749+ |> member "replacement_room" Room_id.jsont ~enc:(fun t -> t.replacement_room)
750750+ |> seal)
751751end
752752753753module Room_guest_access_content = struct
···766766 let pp_access ppf a = Format.pp_print_string ppf (access_to_string a)
767767768768 let access_jsont =
769769- Jsont.enum [
769769+ Json.Codec.enum [
770770 ("can_join", Can_join);
771771 ("forbidden", Forbidden);
772772 ]
···779779 let pp ppf t = Format.fprintf ppf "guest_access: %a" pp_access t.guest_access
780780781781 let jsont =
782782- Jsont.Object.(
782782+ Json.Codec.Object.(
783783 map (fun guest_access -> { guest_access })
784784- |> mem "guest_access" access_jsont ~enc:(fun t -> t.guest_access)
785785- |> finish)
784784+ |> member "guest_access" access_jsont ~enc:(fun t -> t.guest_access)
785785+ |> seal)
786786end
787787788788(** {1 Space Event Contents} *)
···813813 Format.fprintf ppf "@]"
814814815815 let jsont =
816816- Jsont.Object.(
816816+ Json.Codec.Object.(
817817 map (fun via order suggested -> { via; order; suggested })
818818- |> opt_mem "via" (Jsont.list Jsont.string) ~enc:(fun t -> t.via)
819819- |> opt_mem "order" Jsont.string ~enc:(fun t -> t.order)
820820- |> opt_mem "suggested" Jsont.bool ~enc:(fun t -> t.suggested)
821821- |> finish)
818818+ |> opt_member "via" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.via)
819819+ |> opt_member "order" Json.Codec.string ~enc:(fun t -> t.order)
820820+ |> opt_member "suggested" Json.Codec.bool ~enc:(fun t -> t.suggested)
821821+ |> seal)
822822end
823823824824module Space_parent_content = struct
···844844 Format.fprintf ppf "@]"
845845846846 let jsont =
847847- Jsont.Object.(
847847+ Json.Codec.Object.(
848848 map (fun via canonical -> { via; canonical })
849849- |> opt_mem "via" (Jsont.list Jsont.string) ~enc:(fun t -> t.via)
850850- |> opt_mem "canonical" Jsont.bool ~enc:(fun t -> t.canonical)
851851- |> finish)
849849+ |> opt_member "via" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.via)
850850+ |> opt_member "canonical" Json.Codec.bool ~enc:(fun t -> t.canonical)
851851+ |> seal)
852852end
853853854854(** {1 Call Event Contents}
···893893 t.call_id t.version t.lifetime
894894895895 let sdp_content_jsont =
896896- Jsont.Object.(
896896+ Json.Codec.Object.(
897897 map (fun type_ sdp -> { type_; sdp })
898898- |> mem "type" Jsont.string ~enc:(fun t -> t.type_)
899899- |> mem "sdp" Jsont.string ~enc:(fun t -> t.sdp)
900900- |> finish)
898898+ |> member "type" Json.Codec.string ~enc:(fun t -> t.type_)
899899+ |> member "sdp" Json.Codec.string ~enc:(fun t -> t.sdp)
900900+ |> seal)
901901902902 let jsont =
903903- Jsont.Object.(
903903+ Json.Codec.Object.(
904904 map (fun call_id party_id version lifetime offer invitee ->
905905 { call_id; party_id; version; lifetime; offer; invitee })
906906- |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id)
907907- |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id)
908908- |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version)
909909- |> mem "lifetime" Jsont.int ~enc:(fun t -> t.lifetime)
910910- |> mem "offer" sdp_content_jsont ~enc:(fun t -> t.offer)
911911- |> opt_mem "invitee" Jsont.string ~enc:(fun t -> t.invitee)
912912- |> finish)
906906+ |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id)
907907+ |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id)
908908+ |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version)
909909+ |> member "lifetime" Json.Codec.int ~enc:(fun t -> t.lifetime)
910910+ |> member "offer" sdp_content_jsont ~enc:(fun t -> t.offer)
911911+ |> opt_member "invitee" Json.Codec.string ~enc:(fun t -> t.invitee)
912912+ |> seal)
913913end
914914915915module Call_answer_content = struct
···943943 Format.fprintf ppf "@[<v>call_id: %s@,version: %d@]" t.call_id t.version
944944945945 let sdp_content_jsont =
946946- Jsont.Object.(
946946+ Json.Codec.Object.(
947947 map (fun type_ sdp -> { type_; sdp })
948948- |> mem "type" Jsont.string ~enc:(fun t -> t.type_)
949949- |> mem "sdp" Jsont.string ~enc:(fun t -> t.sdp)
950950- |> finish)
948948+ |> member "type" Json.Codec.string ~enc:(fun t -> t.type_)
949949+ |> member "sdp" Json.Codec.string ~enc:(fun t -> t.sdp)
950950+ |> seal)
951951952952 let jsont =
953953- Jsont.Object.(
953953+ Json.Codec.Object.(
954954 map (fun call_id party_id version answer ->
955955 { call_id; party_id; version; answer })
956956- |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id)
957957- |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id)
958958- |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version)
959959- |> mem "answer" sdp_content_jsont ~enc:(fun t -> t.answer)
960960- |> finish)
956956+ |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id)
957957+ |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id)
958958+ |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version)
959959+ |> member "answer" sdp_content_jsont ~enc:(fun t -> t.answer)
960960+ |> seal)
961961end
962962963963module Call_hangup_content = struct
···984984 let pp_reason ppf r = Format.pp_print_string ppf (reason_to_string r)
985985986986 let reason_jsont =
987987- Jsont.enum [
987987+ Json.Codec.enum [
988988 ("ice_failed", Ice_failed);
989989 ("invite_timeout", Invite_timeout);
990990 ("user_hangup", User_hangup);
···10141014 Format.fprintf ppf "@]"
1015101510161016 let jsont =
10171017- Jsont.Object.(
10171017+ Json.Codec.Object.(
10181018 map (fun call_id party_id version reason ->
10191019 { call_id; party_id; version; reason })
10201020- |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id)
10211021- |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id)
10221022- |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version)
10231023- |> opt_mem "reason" reason_jsont ~enc:(fun t -> t.reason)
10241024- |> finish)
10201020+ |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id)
10211021+ |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id)
10221022+ |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version)
10231023+ |> opt_member "reason" reason_jsont ~enc:(fun t -> t.reason)
10241024+ |> seal)
10251025end
1026102610271027module Call_candidates_content = struct
···10391039 { candidate; sdp_mid; sdp_m_line_index }
1040104010411041 let candidate_jsont =
10421042- Jsont.Object.(
10421042+ Json.Codec.Object.(
10431043 map (fun candidate sdp_mid sdp_m_line_index ->
10441044 { candidate; sdp_mid; sdp_m_line_index })
10451045- |> mem "candidate" Jsont.string ~enc:(fun t -> t.candidate)
10461046- |> mem "sdpMid" Jsont.string ~enc:(fun t -> t.sdp_mid)
10471047- |> mem "sdpMLineIndex" Jsont.int ~enc:(fun t -> t.sdp_m_line_index)
10481048- |> finish)
10451045+ |> member "candidate" Json.Codec.string ~enc:(fun t -> t.candidate)
10461046+ |> member "sdpMid" Json.Codec.string ~enc:(fun t -> t.sdp_mid)
10471047+ |> member "sdpMLineIndex" Json.Codec.int ~enc:(fun t -> t.sdp_m_line_index)
10481048+ |> seal)
1049104910501050 type t = {
10511051 call_id : string;
···10671067 t.call_id t.version (List.length t.candidates)
1068106810691069 let jsont =
10701070- Jsont.Object.(
10701070+ Json.Codec.Object.(
10711071 map (fun call_id party_id version candidates ->
10721072 { call_id; party_id; version; candidates })
10731073- |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id)
10741074- |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id)
10751075- |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version)
10761076- |> mem "candidates" (Jsont.list candidate_jsont) ~dec_absent:[]
10731073+ |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id)
10741074+ |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id)
10751075+ |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version)
10761076+ |> member "candidates" (Json.Codec.list candidate_jsont) ~dec_absent:[]
10771077 ~enc:(fun t -> t.candidates)
10781078- |> finish)
10781078+ |> seal)
10791079end
1080108010811081(** {1 Call Member Content (m.call.member)} *)
···10951095 { type_; livekit_service_url; livekit_alias }
1096109610971097 let focus_jsont =
10981098- Jsont.Object.(
10981098+ Json.Codec.Object.(
10991099 map (fun type_ livekit_service_url livekit_alias ->
11001100 { type_; livekit_service_url; livekit_alias })
11011101- |> mem "type" Jsont.string ~enc:(fun t -> t.type_)
11021102- |> opt_mem "livekit_service_url" Jsont.string ~enc:(fun t -> t.livekit_service_url)
11031103- |> opt_mem "livekit_alias" Jsont.string ~enc:(fun t -> t.livekit_alias)
11041104- |> finish)
11011101+ |> member "type" Json.Codec.string ~enc:(fun t -> t.type_)
11021102+ |> opt_member "livekit_service_url" Json.Codec.string ~enc:(fun t -> t.livekit_service_url)
11031103+ |> opt_member "livekit_alias" Json.Codec.string ~enc:(fun t -> t.livekit_alias)
11041104+ |> seal)
1105110511061106 type membership = {
11071107 call_id : string;
···11181118 { call_id; scope; application; device_id; expires; foci_active; membership_id }
1119111911201120 let membership_jsont =
11211121- Jsont.Object.(
11211121+ Json.Codec.Object.(
11221122 map (fun call_id scope application device_id expires foci_active membership_id ->
11231123 { call_id; scope; application; device_id; expires; foci_active; membership_id })
11241124- |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id)
11251125- |> mem "scope" Jsont.string ~dec_absent:"m.room" ~enc:(fun t -> t.scope)
11261126- |> mem "application" Jsont.string ~enc:(fun t -> t.application)
11271127- |> mem "device_id" Jsont.string ~enc:(fun t -> t.device_id)
11281128- |> mem "expires" Jsont.int64 ~enc:(fun t -> t.expires)
11291129- |> opt_mem "foci_active" (Jsont.list focus_jsont) ~enc:(fun t -> t.foci_active)
11301130- |> opt_mem "membership_id" Jsont.string ~enc:(fun t -> t.membership_id)
11311131- |> finish)
11241124+ |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id)
11251125+ |> member "scope" Json.Codec.string ~dec_absent:"m.room" ~enc:(fun t -> t.scope)
11261126+ |> member "application" Json.Codec.string ~enc:(fun t -> t.application)
11271127+ |> member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id)
11281128+ |> member "expires" Json.Codec.int64 ~enc:(fun t -> t.expires)
11291129+ |> opt_member "foci_active" (Json.Codec.list focus_jsont) ~enc:(fun t -> t.foci_active)
11301130+ |> opt_member "membership_id" Json.Codec.string ~enc:(fun t -> t.membership_id)
11311131+ |> seal)
1132113211331133 type t = { memberships : membership list }
11341134···11391139 Format.fprintf ppf "@[<v>memberships: %d entries@]" (List.length t.memberships)
1140114011411141 let jsont =
11421142- Jsont.Object.(
11421142+ Json.Codec.Object.(
11431143 map (fun memberships -> { memberships })
11441144- |> mem "memberships" (Jsont.list membership_jsont) ~dec_absent:[]
11441144+ |> member "memberships" (Json.Codec.list membership_jsont) ~dec_absent:[]
11451145 ~enc:(fun t -> t.memberships)
11461146- |> finish)
11461146+ |> seal)
11471147end
1148114811491149(** {1 Key Verification Event Contents}
···11671167 }
1168116811691169 let jsont =
11701170- Jsont.Object.(
11701170+ Json.Codec.Object.(
11711171 map (fun from_device methods transaction_id ->
11721172 { from_device; methods; transaction_id })
11731173- |> mem "from_device" Jsont.string ~enc:(fun t -> t.from_device)
11741174- |> mem "methods" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.methods)
11751175- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
11761176- |> finish)
11731173+ |> member "from_device" Json.Codec.string ~enc:(fun t -> t.from_device)
11741174+ |> member "methods" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.methods)
11751175+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
11761176+ |> seal)
11771177end
1178117811791179module Key_verification_start_content = struct
···11881188 }
1189118911901190 let jsont =
11911191- Jsont.Object.(
11911191+ Json.Codec.Object.(
11921192 map (fun from_device method_ transaction_id key_agreement_protocols hashes
11931193 message_authentication_codes short_authentication_string ->
11941194 { from_device; method_; transaction_id; key_agreement_protocols; hashes;
11951195 message_authentication_codes; short_authentication_string })
11961196- |> mem "from_device" Jsont.string ~enc:(fun t -> t.from_device)
11971197- |> mem "method" Jsont.string ~enc:(fun t -> t.method_)
11981198- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
11991199- |> opt_mem "key_agreement_protocols" (Jsont.list Jsont.string)
11961196+ |> member "from_device" Json.Codec.string ~enc:(fun t -> t.from_device)
11971197+ |> member "method" Json.Codec.string ~enc:(fun t -> t.method_)
11981198+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
11991199+ |> opt_member "key_agreement_protocols" (Json.Codec.list Json.Codec.string)
12001200 ~enc:(fun t -> t.key_agreement_protocols)
12011201- |> opt_mem "hashes" (Jsont.list Jsont.string) ~enc:(fun t -> t.hashes)
12021202- |> opt_mem "message_authentication_codes" (Jsont.list Jsont.string)
12011201+ |> opt_member "hashes" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.hashes)
12021202+ |> opt_member "message_authentication_codes" (Json.Codec.list Json.Codec.string)
12031203 ~enc:(fun t -> t.message_authentication_codes)
12041204- |> opt_mem "short_authentication_string" (Jsont.list Jsont.string)
12041204+ |> opt_member "short_authentication_string" (Json.Codec.list Json.Codec.string)
12051205 ~enc:(fun t -> t.short_authentication_string)
12061206- |> finish)
12061206+ |> seal)
12071207end
1208120812091209module Key_verification_accept_content = struct
···12181218 }
1219121912201220 let jsont =
12211221- Jsont.Object.(
12211221+ Json.Codec.Object.(
12221222 map (fun transaction_id method_ key_agreement_protocol hash
12231223 message_authentication_code short_authentication_string commitment ->
12241224 { transaction_id; method_; key_agreement_protocol; hash;
12251225 message_authentication_code; short_authentication_string; commitment })
12261226- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
12271227- |> mem "method" Jsont.string ~enc:(fun t -> t.method_)
12281228- |> mem "key_agreement_protocol" Jsont.string ~enc:(fun t -> t.key_agreement_protocol)
12291229- |> mem "hash" Jsont.string ~enc:(fun t -> t.hash)
12301230- |> mem "message_authentication_code" Jsont.string
12261226+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
12271227+ |> member "method" Json.Codec.string ~enc:(fun t -> t.method_)
12281228+ |> member "key_agreement_protocol" Json.Codec.string ~enc:(fun t -> t.key_agreement_protocol)
12291229+ |> member "hash" Json.Codec.string ~enc:(fun t -> t.hash)
12301230+ |> member "message_authentication_code" Json.Codec.string
12311231 ~enc:(fun t -> t.message_authentication_code)
12321232- |> mem "short_authentication_string" (Jsont.list Jsont.string)
12321232+ |> member "short_authentication_string" (Json.Codec.list Json.Codec.string)
12331233 ~enc:(fun t -> t.short_authentication_string)
12341234- |> mem "commitment" Jsont.string ~enc:(fun t -> t.commitment)
12351235- |> finish)
12341234+ |> member "commitment" Json.Codec.string ~enc:(fun t -> t.commitment)
12351235+ |> seal)
12361236end
1237123712381238module Key_verification_key_content = struct
···12421242 }
1243124312441244 let jsont =
12451245- Jsont.Object.(
12451245+ Json.Codec.Object.(
12461246 map (fun transaction_id key -> { transaction_id; key })
12471247- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
12481248- |> mem "key" Jsont.string ~enc:(fun t -> t.key)
12491249- |> finish)
12471247+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
12481248+ |> member "key" Json.Codec.string ~enc:(fun t -> t.key)
12491249+ |> seal)
12501250end
1251125112521252module Key_verification_mac_content = struct
12531253 module StringMap = Map.Make(String)
1254125412551255 let string_map_jsont =
12561256- Jsont.Object.as_string_map Jsont.string
12571257- |> Jsont.map
12561256+ Json.Codec.Object.as_string_map Json.Codec.string
12571257+ |> Json.Codec.map
12581258 ~dec:(fun m -> StringMap.bindings m)
12591259 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq)
12601260···12651265 }
1266126612671267 let jsont =
12681268- Jsont.Object.(
12681268+ Json.Codec.Object.(
12691269 map (fun transaction_id mac keys -> { transaction_id; mac; keys })
12701270- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
12711271- |> mem "mac" string_map_jsont ~enc:(fun t -> t.mac)
12721272- |> mem "keys" Jsont.string ~enc:(fun t -> t.keys)
12731273- |> finish)
12701270+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
12711271+ |> member "mac" string_map_jsont ~enc:(fun t -> t.mac)
12721272+ |> member "keys" Json.Codec.string ~enc:(fun t -> t.keys)
12731273+ |> seal)
12741274end
1275127512761276module Key_verification_cancel_content = struct
···12811281 }
1282128212831283 let jsont =
12841284- Jsont.Object.(
12841284+ Json.Codec.Object.(
12851285 map (fun transaction_id code reason -> { transaction_id; code; reason })
12861286- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
12871287- |> mem "code" Jsont.string ~enc:(fun t -> t.code)
12881288- |> mem "reason" Jsont.string ~enc:(fun t -> t.reason)
12891289- |> finish)
12861286+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
12871287+ |> member "code" Json.Codec.string ~enc:(fun t -> t.code)
12881288+ |> member "reason" Json.Codec.string ~enc:(fun t -> t.reason)
12891289+ |> seal)
12901290end
1291129112921292module Key_verification_done_content = struct
···12951295 }
1296129612971297 let jsont =
12981298- Jsont.Object.(
12981298+ Json.Codec.Object.(
12991299 map (fun transaction_id -> { transaction_id })
13001300- |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id)
13011301- |> finish)
13001300+ |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id)
13011301+ |> seal)
13021302end
1303130313041304(** {1 Policy Rule Event Contents}
···13271327 | s -> Unknown s
1328132813291329 let recommendation_jsont =
13301330- Jsont.of_of_string ~kind:"recommendation"
13301330+ Json.Codec.of_of_string ~kind:"recommendation"
13311331 ~enc:recommendation_to_string
13321332 (fun s -> Ok (recommendation_of_string s))
13331333···13381338 }
1339133913401340 let jsont =
13411341- Jsont.Object.(
13411341+ Json.Codec.Object.(
13421342 map (fun entity reason recommendation -> { entity; reason; recommendation })
13431343- |> mem "entity" Jsont.string ~enc:(fun t -> t.entity)
13441344- |> mem "reason" Jsont.string ~enc:(fun t -> t.reason)
13451345- |> mem "recommendation" recommendation_jsont ~enc:(fun t -> t.recommendation)
13461346- |> finish)
13431343+ |> member "entity" Json.Codec.string ~enc:(fun t -> t.entity)
13441344+ |> member "reason" Json.Codec.string ~enc:(fun t -> t.reason)
13451345+ |> member "recommendation" recommendation_jsont ~enc:(fun t -> t.recommendation)
13461346+ |> seal)
13471347end
1348134813491349(** {1 Account Data Contents}
···13631363 }
1364136413651365 let jsont =
13661366- Jsont.Object.(
13661366+ Json.Codec.Object.(
13671367 map (fun unread -> { unread })
13681368- |> mem "unread" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.unread)
13691369- |> finish)
13681368+ |> member "unread" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.unread)
13691369+ |> seal)
13701370end
1371137113721372(** {1 Encrypted Event Content} *)
···13881388 | s -> Unknown s
1389138913901390 let algorithm_jsont =
13911391- Jsont.of_of_string ~kind:"algorithm"
13911391+ Json.Codec.of_of_string ~kind:"algorithm"
13921392 ~enc:algorithm_to_string
13931393 (fun s -> Ok (algorithm_of_string s))
1394139413951395 type t = {
13961396 algorithm : algorithm;
13971397 sender_key : string;
13981398- ciphertext : Jsont.json; (* Can be string or object depending on algorithm *)
13981398+ ciphertext : Json.t; (* Can be string or object depending on algorithm *)
13991399 session_id : string option; (* Megolm only *)
14001400 device_id : string option;
14011401 }
1402140214031403 let jsont =
14041404- Jsont.Object.(
14041404+ Json.Codec.Object.(
14051405 map (fun algorithm sender_key ciphertext session_id device_id ->
14061406 { algorithm; sender_key; ciphertext; session_id; device_id })
14071407- |> mem "algorithm" algorithm_jsont ~enc:(fun t -> t.algorithm)
14081408- |> mem "sender_key" Jsont.string ~enc:(fun t -> t.sender_key)
14091409- |> mem "ciphertext" Jsont.json ~enc:(fun t -> t.ciphertext)
14101410- |> opt_mem "session_id" Jsont.string ~enc:(fun t -> t.session_id)
14111411- |> opt_mem "device_id" Jsont.string ~enc:(fun t -> t.device_id)
14121412- |> finish)
14071407+ |> member "algorithm" algorithm_jsont ~enc:(fun t -> t.algorithm)
14081408+ |> member "sender_key" Json.Codec.string ~enc:(fun t -> t.sender_key)
14091409+ |> member "ciphertext" Json.Codec.Value.t ~enc:(fun t -> t.ciphertext)
14101410+ |> opt_member "session_id" Json.Codec.string ~enc:(fun t -> t.session_id)
14111411+ |> opt_member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id)
14121412+ |> seal)
14131413end
1414141414151415(** {1 Reaction Content} *)
···14221422 }
1423142314241424 let relates_to_jsont =
14251425- Jsont.Object.(
14251425+ Json.Codec.Object.(
14261426 map (fun rel_type event_id key -> { rel_type; event_id; key })
14271427- |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type)
14281428- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
14291429- |> mem "key" Jsont.string ~enc:(fun t -> t.key)
14301430- |> finish)
14271427+ |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type)
14281428+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
14291429+ |> member "key" Json.Codec.string ~enc:(fun t -> t.key)
14301430+ |> seal)
1431143114321432 type t = {
14331433 relates_to : relates_to;
14341434 }
1435143514361436 let jsont =
14371437- Jsont.Object.(
14371437+ Json.Codec.Object.(
14381438 map (fun relates_to -> { relates_to })
14391439- |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
14401440- |> finish)
14391439+ |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
14401440+ |> seal)
14411441end
1442144214431443(** {1 Beacon/Live Location Content} *)
···14511451 }
1452145214531453 let jsont =
14541454- Jsont.Object.(
14541454+ Json.Codec.Object.(
14551455 map (fun description live timeout asset_type ->
14561456 { description; live; timeout; asset_type })
14571457- |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description)
14581458- |> mem "live" Jsont.bool ~dec_absent:true ~enc:(fun t -> t.live)
14591459- |> mem "timeout" Jsont.int64 ~enc:(fun t -> t.timeout)
14601460- |> opt_mem "org.matrix.msc3488.asset" Jsont.string ~enc:(fun t -> t.asset_type)
14611461- |> finish)
14571457+ |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description)
14581458+ |> member "live" Json.Codec.bool ~dec_absent:true ~enc:(fun t -> t.live)
14591459+ |> member "timeout" Json.Codec.int64 ~enc:(fun t -> t.timeout)
14601460+ |> opt_member "org.matrix.msc3488.asset" Json.Codec.string ~enc:(fun t -> t.asset_type)
14611461+ |> seal)
14621462end
1463146314641464module Beacon_content = struct
···14681468 }
1469146914701470 let location_jsont =
14711471- Jsont.Object.(
14711471+ Json.Codec.Object.(
14721472 map (fun uri description -> { uri; description })
14731473- |> mem "uri" Jsont.string ~enc:(fun t -> t.uri)
14741474- |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description)
14751475- |> finish)
14731473+ |> member "uri" Json.Codec.string ~enc:(fun t -> t.uri)
14741474+ |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description)
14751475+ |> seal)
1476147614771477 type relates_to = {
14781478 rel_type : string;
···14801480 }
1481148114821482 let relates_to_jsont =
14831483- Jsont.Object.(
14831483+ Json.Codec.Object.(
14841484 map (fun rel_type event_id -> { rel_type; event_id })
14851485- |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type)
14861486- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
14871487- |> finish)
14851485+ |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type)
14861486+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
14871487+ |> seal)
1488148814891489 type t = {
14901490 location : location;
···14931493 }
1494149414951495 let jsont =
14961496- Jsont.Object.(
14961496+ Json.Codec.Object.(
14971497 map (fun location timestamp relates_to ->
14981498 { location; timestamp; relates_to })
14991499- |> mem "org.matrix.msc3488.location" location_jsont ~enc:(fun t -> t.location)
15001500- |> mem "org.matrix.msc3488.ts" Jsont.int64 ~enc:(fun t -> t.timestamp)
15011501- |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
15021502- |> finish)
14991499+ |> member "org.matrix.msc3488.location" location_jsont ~enc:(fun t -> t.location)
15001500+ |> member "org.matrix.msc3488.ts" Json.Codec.int64 ~enc:(fun t -> t.timestamp)
15011501+ |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
15021502+ |> seal)
15031503end
1504150415051505(** {1 Poll Event Contents} *)
···15111511 }
1512151215131513 let poll_answer_jsont =
15141514- Jsont.Object.(
15141514+ Json.Codec.Object.(
15151515 map (fun id text -> { id; text })
15161516- |> mem "id" Jsont.string ~enc:(fun t -> t.id)
15171517- |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text)
15181518- |> finish)
15161516+ |> member "id" Json.Codec.string ~enc:(fun t -> t.id)
15171517+ |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text)
15181518+ |> seal)
1519151915201520 type poll_kind =
15211521 | Disclosed
15221522 | Undisclosed
1523152315241524 let poll_kind_jsont =
15251525- Jsont.enum [
15251525+ Json.Codec.enum [
15261526 ("org.matrix.msc3381.poll.disclosed", Disclosed);
15271527 ("org.matrix.msc3381.poll.undisclosed", Undisclosed);
15281528 ]
···15351535 }
1536153615371537 let poll_start_jsont =
15381538- Jsont.Object.(
15381538+ Json.Codec.Object.(
15391539 map (fun question kind max_selections answers ->
15401540 { question; kind; max_selections; answers })
15411541- |> mem "question" Jsont.string ~enc:(fun t -> t.question)
15421542- |> mem "kind" poll_kind_jsont ~dec_absent:Disclosed ~enc:(fun t -> t.kind)
15431543- |> mem "max_selections" Jsont.int ~dec_absent:1 ~enc:(fun t -> t.max_selections)
15441544- |> mem "answers" (Jsont.list poll_answer_jsont) ~enc:(fun t -> t.answers)
15451545- |> finish)
15411541+ |> member "question" Json.Codec.string ~enc:(fun t -> t.question)
15421542+ |> member "kind" poll_kind_jsont ~dec_absent:Disclosed ~enc:(fun t -> t.kind)
15431543+ |> member "max_selections" Json.Codec.int ~dec_absent:1 ~enc:(fun t -> t.max_selections)
15441544+ |> member "answers" (Json.Codec.list poll_answer_jsont) ~enc:(fun t -> t.answers)
15451545+ |> seal)
1546154615471547 type t = {
15481548 poll_start : poll_start;
···15501550 }
1551155115521552 let jsont =
15531553- Jsont.Object.(
15531553+ Json.Codec.Object.(
15541554 map (fun poll_start text -> { poll_start; text })
15551555- |> mem "org.matrix.msc3381.poll.start" poll_start_jsont ~enc:(fun t -> t.poll_start)
15561556- |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text)
15571557- |> finish)
15551555+ |> member "org.matrix.msc3381.poll.start" poll_start_jsont ~enc:(fun t -> t.poll_start)
15561556+ |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text)
15571557+ |> seal)
15581558end
1559155915601560module Poll_response_content = struct
···15641564 }
1565156515661566 let relates_to_jsont =
15671567- Jsont.Object.(
15671567+ Json.Codec.Object.(
15681568 map (fun rel_type event_id -> { rel_type; event_id })
15691569- |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type)
15701570- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
15711571- |> finish)
15691569+ |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type)
15701570+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
15711571+ |> seal)
1572157215731573 type t = {
15741574 relates_to : relates_to;
···15761576 }
1577157715781578 let jsont =
15791579- Jsont.Object.(
15791579+ Json.Codec.Object.(
15801580 map (fun relates_to answers -> { relates_to; answers })
15811581- |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
15821582- |> mem "org.matrix.msc3381.poll.response" (Jsont.list Jsont.string)
15811581+ |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
15821582+ |> member "org.matrix.msc3381.poll.response" (Json.Codec.list Json.Codec.string)
15831583 ~dec_absent:[] ~enc:(fun t -> t.answers)
15841584- |> finish)
15841584+ |> seal)
15851585end
1586158615871587module Poll_end_content = struct
···15911591 }
1592159215931593 let relates_to_jsont =
15941594- Jsont.Object.(
15941594+ Json.Codec.Object.(
15951595 map (fun rel_type event_id -> { rel_type; event_id })
15961596- |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type)
15971597- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
15981598- |> finish)
15961596+ |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type)
15971597+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
15981598+ |> seal)
1599159916001600 type t = {
16011601 relates_to : relates_to;
···16031603 }
1604160416051605 let jsont =
16061606- Jsont.Object.(
16061606+ Json.Codec.Object.(
16071607 map (fun relates_to text -> { relates_to; text })
16081608- |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
16091609- |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text)
16101610- |> finish)
16081608+ |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to)
16091609+ |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text)
16101610+ |> seal)
16111611end
1612161216131613(** {1 Message Event Contents} *)
···16531653 let pp ppf t = Format.pp_print_string ppf (to_string t)
1654165416551655 let jsont =
16561656- Jsont.of_of_string ~kind:"msgtype"
16561656+ Json.Codec.of_of_string ~kind:"msgtype"
16571657 ~enc:to_string
16581658 (fun s -> Ok (of_string s))
16591659end
···16841684 Format.fprintf ppf "@[<v>msgtype: %a@,body: %s@]" Msgtype.pp t.msgtype t.body
1685168516861686 let jsont =
16871687- Jsont.Object.(
16871687+ Json.Codec.Object.(
16881688 map (fun body msgtype format formatted_body ->
16891689 { body; msgtype; format; formatted_body })
16901690- |> mem "body" Jsont.string ~enc:(fun t -> t.body)
16911691- |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
16921692- |> opt_mem "format" Jsont.string ~enc:(fun t -> t.format)
16931693- |> opt_mem "formatted_body" Jsont.string ~enc:(fun t -> t.formatted_body)
16941694- |> finish)
16901690+ |> member "body" Json.Codec.string ~enc:(fun t -> t.body)
16911691+ |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
16921692+ |> opt_member "format" Json.Codec.string ~enc:(fun t -> t.format)
16931693+ |> opt_member "formatted_body" Json.Codec.string ~enc:(fun t -> t.formatted_body)
16941694+ |> seal)
16951695end
1696169616971697module Media_info = struct
···17111711 w : int option;
17121712 }
1713171317141714- let thumbnail_info_jsont : thumbnail_info Jsont.t =
17151715- Jsont.Object.(
17141714+ let thumbnail_info_jsont : thumbnail_info Json.codec =
17151715+ Json.Codec.Object.(
17161716 map (fun mimetype size h w -> { mimetype; size; h; w })
17171717- |> opt_mem "mimetype" Jsont.string ~enc:(fun (t : thumbnail_info) -> t.mimetype)
17181718- |> opt_mem "size" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.size)
17191719- |> opt_mem "h" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.h)
17201720- |> opt_mem "w" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.w)
17211721- |> finish)
17171717+ |> opt_member "mimetype" Json.Codec.string ~enc:(fun (t : thumbnail_info) -> t.mimetype)
17181718+ |> opt_member "size" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.size)
17191719+ |> opt_member "h" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.h)
17201720+ |> opt_member "w" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.w)
17211721+ |> seal)
1722172217231723 let jsont =
17241724- Jsont.Object.(
17241724+ Json.Codec.Object.(
17251725 map (fun mimetype size duration h w thumbnail_url thumbnail_info ->
17261726 { mimetype; size; duration; h; w; thumbnail_url; thumbnail_info })
17271727- |> opt_mem "mimetype" Jsont.string ~enc:(fun t -> t.mimetype)
17281728- |> opt_mem "size" Jsont.int ~enc:(fun t -> t.size)
17291729- |> opt_mem "duration" Jsont.int ~enc:(fun t -> t.duration)
17301730- |> opt_mem "h" Jsont.int ~enc:(fun t -> t.h)
17311731- |> opt_mem "w" Jsont.int ~enc:(fun t -> t.w)
17321732- |> opt_mem "thumbnail_url" Jsont.string ~enc:(fun t -> t.thumbnail_url)
17331733- |> opt_mem "thumbnail_info" thumbnail_info_jsont ~enc:(fun t -> t.thumbnail_info)
17341734- |> finish)
17271727+ |> opt_member "mimetype" Json.Codec.string ~enc:(fun t -> t.mimetype)
17281728+ |> opt_member "size" Json.Codec.int ~enc:(fun t -> t.size)
17291729+ |> opt_member "duration" Json.Codec.int ~enc:(fun t -> t.duration)
17301730+ |> opt_member "h" Json.Codec.int ~enc:(fun t -> t.h)
17311731+ |> opt_member "w" Json.Codec.int ~enc:(fun t -> t.w)
17321732+ |> opt_member "thumbnail_url" Json.Codec.string ~enc:(fun t -> t.thumbnail_url)
17331733+ |> opt_member "thumbnail_info" thumbnail_info_jsont ~enc:(fun t -> t.thumbnail_info)
17341734+ |> seal)
17351735end
1736173617371737module Media_message_content = struct
···17441744 }
17451745 and encrypted_file = {
17461746 url : string;
17471747- key : Jsont.json; (* JWK *)
17471747+ key : Json.t; (* JWK *)
17481748 iv : string;
17491749 hashes : (string * string) list;
17501750 v : string;
···17531753 module StringMap = Map.Make(String)
1754175417551755 let string_map_jsont =
17561756- Jsont.Object.as_string_map Jsont.string
17571757- |> Jsont.map
17561756+ Json.Codec.Object.as_string_map Json.Codec.string
17571757+ |> Json.Codec.map
17581758 ~dec:(fun m -> StringMap.bindings m)
17591759 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq)
1760176017611761- let encrypted_file_jsont : encrypted_file Jsont.t =
17621762- Jsont.Object.(
17611761+ let encrypted_file_jsont : encrypted_file Json.codec =
17621762+ Json.Codec.Object.(
17631763 map (fun url key iv hashes v -> { url; key; iv; hashes; v })
17641764- |> mem "url" Jsont.string ~enc:(fun (f : encrypted_file) -> f.url)
17651765- |> mem "key" Jsont.json ~enc:(fun (f : encrypted_file) -> f.key)
17661766- |> mem "iv" Jsont.string ~enc:(fun (f : encrypted_file) -> f.iv)
17671767- |> mem "hashes" string_map_jsont ~enc:(fun (f : encrypted_file) -> f.hashes)
17681768- |> mem "v" Jsont.string ~enc:(fun (f : encrypted_file) -> f.v)
17691769- |> finish)
17641764+ |> member "url" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.url)
17651765+ |> member "key" Json.Codec.Value.t ~enc:(fun (f : encrypted_file) -> f.key)
17661766+ |> member "iv" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.iv)
17671767+ |> member "hashes" string_map_jsont ~enc:(fun (f : encrypted_file) -> f.hashes)
17681768+ |> member "v" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.v)
17691769+ |> seal)
1770177017711771 let jsont =
17721772- Jsont.Object.(
17721772+ Json.Codec.Object.(
17731773 map (fun body msgtype url info file ->
17741774 { body; msgtype; url; info; file })
17751775- |> mem "body" Jsont.string ~enc:(fun t -> t.body)
17761776- |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
17771777- |> opt_mem "url" Jsont.string ~enc:(fun t -> t.url)
17781778- |> opt_mem "info" Media_info.jsont ~enc:(fun t -> t.info)
17791779- |> opt_mem "file" encrypted_file_jsont ~enc:(fun t -> t.file)
17801780- |> finish)
17751775+ |> member "body" Json.Codec.string ~enc:(fun t -> t.body)
17761776+ |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
17771777+ |> opt_member "url" Json.Codec.string ~enc:(fun t -> t.url)
17781778+ |> opt_member "info" Media_info.jsont ~enc:(fun t -> t.info)
17791779+ |> opt_member "file" encrypted_file_jsont ~enc:(fun t -> t.file)
17801780+ |> seal)
17811781end
1782178217831783(** {1 Sticker Content} *)
···17901790 }
1791179117921792 let jsont =
17931793- Jsont.Object.(
17931793+ Json.Codec.Object.(
17941794 map (fun body info url -> { body; info; url })
17951795- |> mem "body" Jsont.string ~enc:(fun t -> t.body)
17961796- |> opt_mem "info" Media_info.jsont ~enc:(fun t -> t.info)
17971797- |> mem "url" Jsont.string ~enc:(fun t -> t.url)
17981798- |> finish)
17951795+ |> member "body" Json.Codec.string ~enc:(fun t -> t.body)
17961796+ |> opt_member "info" Media_info.jsont ~enc:(fun t -> t.info)
17971797+ |> member "url" Json.Codec.string ~enc:(fun t -> t.url)
17981798+ |> seal)
17991799end
1800180018011801(** {1 Location Content} *)
···18071807 }
1808180818091809 let location_info_jsont =
18101810- Jsont.Object.(
18101810+ Json.Codec.Object.(
18111811 map (fun uri description -> { uri; description })
18121812- |> mem "uri" Jsont.string ~enc:(fun t -> t.uri)
18131813- |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description)
18141814- |> finish)
18121812+ |> member "uri" Json.Codec.string ~enc:(fun t -> t.uri)
18131813+ |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description)
18141814+ |> seal)
1815181518161816 type t = {
18171817 body : string;
···18211821 }
1822182218231823 let jsont =
18241824- Jsont.Object.(
18241824+ Json.Codec.Object.(
18251825 map (fun body msgtype geo_uri info ->
18261826 { body; msgtype; geo_uri; info })
18271827- |> mem "body" Jsont.string ~enc:(fun t -> t.body)
18281828- |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
18291829- |> mem "geo_uri" Jsont.string ~enc:(fun t -> t.geo_uri)
18301830- |> opt_mem "info" location_info_jsont ~enc:(fun t -> t.info)
18311831- |> finish)
18271827+ |> member "body" Json.Codec.string ~enc:(fun t -> t.body)
18281828+ |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype)
18291829+ |> member "geo_uri" Json.Codec.string ~enc:(fun t -> t.geo_uri)
18301830+ |> opt_member "info" location_info_jsont ~enc:(fun t -> t.info)
18311831+ |> seal)
18321832end
1833183318341834(** {1 Event Types}
···20442044 let pp ppf t = Format.pp_print_string ppf (to_string t)
2045204520462046 let jsont =
20472047- Jsont.of_of_string ~kind:"event_type"
20472047+ Json.Codec.of_of_string ~kind:"event_type"
20482048 ~enc:to_string
20492049 (fun s -> Ok (of_string s))
20502050end
···20652065 }
2066206620672067 let make_jsont content_jsont =
20682068- Jsont.Object.(
20682068+ Json.Codec.Object.(
20692069 map (fun event_id sender origin_server_ts state_key type_ content unsigned ->
20702070 { event_id; sender; origin_server_ts; state_key; type_; content; unsigned })
20712071- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
20722072- |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender)
20732073- |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
20742074- |> mem "state_key" Jsont.string ~enc:(fun t -> t.state_key)
20752075- |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_)
20762076- |> mem "content" content_jsont ~enc:(fun t -> t.content)
20772077- |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
20782078- |> finish)
20712071+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
20722072+ |> member "sender" User_id.jsont ~enc:(fun t -> t.sender)
20732073+ |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
20742074+ |> member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key)
20752075+ |> member "type" Event_type.jsont ~enc:(fun t -> t.type_)
20762076+ |> member "content" content_jsont ~enc:(fun t -> t.content)
20772077+ |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
20782078+ |> seal)
20792079end
2080208020812081(** {1 Room Events} *)
···20932093 }
2094209420952095 let make_jsont content_jsont =
20962096- Jsont.Object.(
20962096+ Json.Codec.Object.(
20972097 map (fun event_id sender origin_server_ts type_ content unsigned ->
20982098 { event_id; sender; origin_server_ts; type_; content; unsigned })
20992099- |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
21002100- |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender)
21012101- |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
21022102- |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_)
21032103- |> mem "content" content_jsont ~enc:(fun t -> t.content)
21042104- |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
21052105- |> finish)
20992099+ |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
21002100+ |> member "sender" User_id.jsont ~enc:(fun t -> t.sender)
21012101+ |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
21022102+ |> member "type" Event_type.jsont ~enc:(fun t -> t.type_)
21032103+ |> member "content" content_jsont ~enc:(fun t -> t.content)
21042104+ |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
21052105+ |> seal)
21062106end
2107210721082108(** {1 Raw/Untyped Events}
···21162116 origin_server_ts : Timestamp.t;
21172117 type_ : Event_type.t;
21182118 state_key : string option;
21192119- content : Jsont.json;
21192119+ content : Json.t;
21202120 unsigned : Unsigned.t option;
21212121 room_id : Room_id.t option;
21222122 }
2123212321242124 let jsont =
21252125- Jsont.Object.(
21252125+ Json.Codec.Object.(
21262126 map (fun event_id sender origin_server_ts type_ state_key content unsigned room_id ->
21272127 { event_id; sender; origin_server_ts; type_; state_key; content; unsigned; room_id })
21282128- |> opt_mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
21292129- |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender)
21302130- |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
21312131- |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_)
21322132- |> opt_mem "state_key" Jsont.string ~enc:(fun t -> t.state_key)
21332133- |> mem "content" Jsont.json ~enc:(fun t -> t.content)
21342134- |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
21352135- |> opt_mem "room_id" Room_id.jsont ~enc:(fun t -> t.room_id)
21362136- |> finish)
21282128+ |> opt_member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id)
21292129+ |> member "sender" User_id.jsont ~enc:(fun t -> t.sender)
21302130+ |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts)
21312131+ |> member "type" Event_type.jsont ~enc:(fun t -> t.type_)
21322132+ |> opt_member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key)
21332133+ |> member "content" Json.Codec.Value.t ~enc:(fun t -> t.content)
21342134+ |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned)
21352135+ |> opt_member "room_id" Room_id.jsont ~enc:(fun t -> t.room_id)
21362136+ |> seal)
21372137end
+63-63
lib/matrix_proto/matrix_event.mli
···2121 val of_ptime : Ptime.t -> t
2222 val to_ptime_opt : t -> Ptime.t option
2323 val pp : Format.formatter -> t -> unit
2424- val jsont : t Jsont.t
2424+ val jsont : t Json.codec
2525end
26262727(** {1 Unsigned Event Data} *)
···36363737 val make :
3838 ?age:int64 ->
3939- ?prev_content:Jsont.json ->
3939+ ?prev_content:Json.t ->
4040 ?prev_sender:Matrix_id.User_id.t ->
4141- ?redacted_because:Jsont.json ->
4141+ ?redacted_because:Json.t ->
4242 ?transaction_id:Matrix_id.Transaction_id.t ->
4343 unit -> t
44444545 val empty : t
46464747 val age : t -> int64 option
4848- val prev_content : t -> Jsont.json option
4848+ val prev_content : t -> Json.t option
4949 val prev_sender : t -> Matrix_id.User_id.t option
5050- val redacted_because : t -> Jsont.json option
5050+ val redacted_because : t -> Json.t option
5151 val transaction_id : t -> Matrix_id.Transaction_id.t option
52525353 val pp : Format.formatter -> t -> unit
5454- val jsont : t Jsont.t
5454+ val jsont : t Json.codec
5555end
56565757(** {1 Room Membership} *)
···6666 val to_string : t -> string
6767 val of_string : string -> (t, [> `Unknown_membership of string ]) result
6868 val pp : Format.formatter -> t -> unit
6969- val jsont : t Jsont.t
6969+ val jsont : t Json.codec
7070end
71717272(** {1 Join Rules} *)
···80808181 val to_string : t -> string
8282 val pp : Format.formatter -> t -> unit
8383- val jsont : t Jsont.t
8383+ val jsont : t Json.codec
8484end
85858686(** {1 History Visibility} *)
···94949595 val to_string : t -> string
9696 val pp : Format.formatter -> t -> unit
9797- val jsont : t Jsont.t
9797+ val jsont : t Json.codec
9898end
9999100100(** {1 Room State Event Contents} *)
···113113 val room_id : t -> Matrix_id.Room_id.t
114114 val event_id : t -> Matrix_id.Event_id.t
115115 val pp : Format.formatter -> t -> unit
116116- val jsont : t Jsont.t
116116+ val jsont : t Json.codec
117117 end
118118119119 type predecessor = Predecessor.t
···132132 val room_type : t -> string option
133133134134 val pp : Format.formatter -> t -> unit
135135- val jsont : t Jsont.t
135135+ val jsont : t Json.codec
136136end
137137138138module Room_name_content : sig
···145145 val make : name:string -> t
146146 val name : t -> string
147147 val pp : Format.formatter -> t -> unit
148148- val jsont : t Jsont.t
148148+ val jsont : t Json.codec
149149end
150150151151module Room_topic_content : sig
···158158 val make : topic:string -> t
159159 val topic : t -> string
160160 val pp : Format.formatter -> t -> unit
161161- val jsont : t Jsont.t
161161+ val jsont : t Json.codec
162162end
163163164164module Room_avatar_content : sig
···177177 val mimetype : t -> string option
178178 val size : t -> int option
179179 val pp : Format.formatter -> t -> unit
180180- val jsont : t Jsont.t
180180+ val jsont : t Json.codec
181181 end
182182183183 type image_info = Image_info.t
···187187 val url : t -> string option
188188 val info : t -> Image_info.t option
189189 val pp : Format.formatter -> t -> unit
190190- val jsont : t Jsont.t
190190+ val jsont : t Json.codec
191191end
192192193193module Room_member_content : sig
···212212 val reason : t -> string option
213213214214 val pp : Format.formatter -> t -> unit
215215- val jsont : t Jsont.t
215215+ val jsont : t Json.codec
216216end
217217218218module Room_join_rules_content : sig
···229229 val condition_type : t -> string
230230 val room_id : t -> Matrix_id.Room_id.t option
231231 val pp : Format.formatter -> t -> unit
232232- val jsont : t Jsont.t
232232+ val jsont : t Json.codec
233233 end
234234235235 type allow_condition = Allow_condition.t
···240240 val allow : t -> Allow_condition.t list option
241241242242 val pp : Format.formatter -> t -> unit
243243- val jsont : t Jsont.t
243243+ val jsont : t Json.codec
244244end
245245246246module Room_history_visibility_content : sig
···253253 val make : history_visibility:History_visibility.t -> t
254254 val history_visibility : t -> History_visibility.t
255255 val pp : Format.formatter -> t -> unit
256256- val jsont : t Jsont.t
256256+ val jsont : t Json.codec
257257end
258258259259module Room_canonical_alias_content : sig
···272272 val alt_aliases : t -> Matrix_id.Room_alias.t list option
273273274274 val pp : Format.formatter -> t -> unit
275275- val jsont : t Jsont.t
275275+ val jsont : t Json.codec
276276end
277277278278module Room_power_levels_content : sig
···305305 val users_default : t -> int option
306306307307 val pp : Format.formatter -> t -> unit
308308- val jsont : t Jsont.t
308308+ val jsont : t Json.codec
309309end
310310311311module Room_encryption_content : sig
···326326 val rotation_period_msgs : t -> int option
327327328328 val pp : Format.formatter -> t -> unit
329329- val jsont : t Jsont.t
329329+ val jsont : t Json.codec
330330end
331331332332module Room_pinned_events_content : sig
···339339 val make : ?pinned:string list -> unit -> t
340340 val pinned : t -> string list
341341 val pp : Format.formatter -> t -> unit
342342- val jsont : t Jsont.t
342342+ val jsont : t Json.codec
343343end
344344345345module Room_server_acl_content : sig
···360360 val deny : t -> string list
361361362362 val pp : Format.formatter -> t -> unit
363363- val jsont : t Jsont.t
363363+ val jsont : t Json.codec
364364end
365365366366module Room_tombstone_content : sig
···375375 val replacement_room : t -> Matrix_id.Room_id.t
376376377377 val pp : Format.formatter -> t -> unit
378378- val jsont : t Jsont.t
378378+ val jsont : t Json.codec
379379end
380380381381module Room_guest_access_content : sig
···387387388388 val access_to_string : access -> string
389389 val pp_access : Format.formatter -> access -> unit
390390- val access_jsont : access Jsont.t
390390+ val access_jsont : access Json.codec
391391392392 type t
393393···395395 val guest_access : t -> access
396396397397 val pp : Format.formatter -> t -> unit
398398- val jsont : t Jsont.t
398398+ val jsont : t Json.codec
399399end
400400401401(** {1 Space Event Contents} *)
···416416 val order : t -> string option
417417 val suggested : t -> bool option
418418 val pp : Format.formatter -> t -> unit
419419- val jsont : t Jsont.t
419419+ val jsont : t Json.codec
420420end
421421422422module Space_parent_content : sig
···433433 val via : t -> string list option
434434 val canonical : t -> bool option
435435 val pp : Format.formatter -> t -> unit
436436- val jsont : t Jsont.t
436436+ val jsont : t Json.codec
437437end
438438439439(** {1 Call Event Contents}
···467467 val offer : t -> sdp_content
468468 val invitee : t -> string option
469469 val pp : Format.formatter -> t -> unit
470470- val jsont : t Jsont.t
470470+ val jsont : t Json.codec
471471end
472472473473module Call_answer_content : sig
···491491 val version : t -> int
492492 val answer : t -> sdp_content
493493 val pp : Format.formatter -> t -> unit
494494- val jsont : t Jsont.t
494494+ val jsont : t Json.codec
495495end
496496497497module Call_hangup_content : sig
···520520 val version : t -> int
521521 val reason : t -> reason option
522522 val pp : Format.formatter -> t -> unit
523523- val jsont : t Jsont.t
523523+ val jsont : t Json.codec
524524end
525525526526module Call_candidates_content : sig
···551551 val version : t -> int
552552 val candidates : t -> candidate list
553553 val pp : Format.formatter -> t -> unit
554554- val jsont : t Jsont.t
554554+ val jsont : t Json.codec
555555end
556556557557(** {1 Call Member Content (m.call.member)} *)
···589589 val make : ?memberships:membership list -> unit -> t
590590 val memberships : t -> membership list
591591 val pp : Format.formatter -> t -> unit
592592- val jsont : t Jsont.t
592592+ val jsont : t Json.codec
593593end
594594595595(** {1 Key Verification Event Contents} *)
···600600 methods : string list;
601601 transaction_id : string option;
602602 }
603603- val jsont : t Jsont.t
603603+ val jsont : t Json.codec
604604end
605605606606module Key_verification_start_content : sig
···613613 message_authentication_codes : string list option;
614614 short_authentication_string : string list option;
615615 }
616616- val jsont : t Jsont.t
616616+ val jsont : t Json.codec
617617end
618618619619module Key_verification_accept_content : sig
···626626 short_authentication_string : string list;
627627 commitment : string;
628628 }
629629- val jsont : t Jsont.t
629629+ val jsont : t Json.codec
630630end
631631632632module Key_verification_key_content : sig
···634634 transaction_id : string option;
635635 key : string;
636636 }
637637- val jsont : t Jsont.t
637637+ val jsont : t Json.codec
638638end
639639640640module Key_verification_mac_content : sig
···643643 mac : (string * string) list;
644644 keys : string;
645645 }
646646- val jsont : t Jsont.t
646646+ val jsont : t Json.codec
647647end
648648649649module Key_verification_cancel_content : sig
···652652 code : string;
653653 reason : string;
654654 }
655655- val jsont : t Jsont.t
655655+ val jsont : t Json.codec
656656end
657657658658module Key_verification_done_content : sig
659659 type t = { transaction_id : string option }
660660- val jsont : t Jsont.t
660660+ val jsont : t Json.codec
661661end
662662663663(** {1 Policy Rule Event Contents} *)
···671671 reason : string;
672672 recommendation : recommendation;
673673 }
674674- val jsont : t Jsont.t
674674+ val jsont : t Json.codec
675675end
676676677677(** {1 Account Data Contents} *)
678678679679module Marked_unread_content : sig
680680 type t = { unread : bool }
681681- val jsont : t Jsont.t
681681+ val jsont : t Json.codec
682682end
683683684684(** {1 Encrypted Event Content} *)
···693693 type t = {
694694 algorithm : algorithm;
695695 sender_key : string;
696696- ciphertext : Jsont.json;
696696+ ciphertext : Json.t;
697697 session_id : string option;
698698 device_id : string option;
699699 }
700700- val jsont : t Jsont.t
700700+ val jsont : t Json.codec
701701end
702702703703(** {1 Reaction Content} *)
···709709 key : string;
710710 }
711711 type t = { relates_to : relates_to }
712712- val jsont : t Jsont.t
712712+ val jsont : t Json.codec
713713end
714714715715(** {1 Beacon/Live Location Content} *)
···721721 timeout : int64;
722722 asset_type : string option;
723723 }
724724- val jsont : t Jsont.t
724724+ val jsont : t Json.codec
725725end
726726727727module Beacon_content : sig
···732732 timestamp : int64;
733733 relates_to : relates_to;
734734 }
735735- val jsont : t Jsont.t
735735+ val jsont : t Json.codec
736736end
737737738738(** {1 Poll Event Contents} *)
···747747 answers : poll_answer list;
748748 }
749749 type t = { poll_start : poll_start; text : string }
750750- val jsont : t Jsont.t
750750+ val jsont : t Json.codec
751751end
752752753753module Poll_response_content : sig
754754 type relates_to = { rel_type : string; event_id : Matrix_id.Event_id.t }
755755 type t = { relates_to : relates_to; answers : string list }
756756- val jsont : t Jsont.t
756756+ val jsont : t Json.codec
757757end
758758759759module Poll_end_content : sig
760760 type relates_to = { rel_type : string; event_id : Matrix_id.Event_id.t }
761761 type t = { relates_to : relates_to; text : string }
762762- val jsont : t Jsont.t
762762+ val jsont : t Json.codec
763763end
764764765765(** {1 Message Event Contents} *)
···776776 val to_string : t -> string
777777 val of_string : string -> t
778778 val pp : Format.formatter -> t -> unit
779779- val jsont : t Jsont.t
779779+ val jsont : t Json.codec
780780end
781781782782module Text_message_content : sig
···798798 val format : t -> string option
799799 val formatted_body : t -> string option
800800 val pp : Format.formatter -> t -> unit
801801- val jsont : t Jsont.t
801801+ val jsont : t Json.codec
802802end
803803804804module Media_info : sig
···817817 h : int option;
818818 w : int option;
819819 }
820820- val jsont : t Jsont.t
820820+ val jsont : t Json.codec
821821end
822822823823module Media_message_content : sig
···830830 }
831831 and encrypted_file = {
832832 url : string;
833833- key : Jsont.json;
833833+ key : Json.t;
834834 iv : string;
835835 hashes : (string * string) list;
836836 v : string;
837837 }
838838- val jsont : t Jsont.t
838838+ val jsont : t Json.codec
839839end
840840841841(** {1 Sticker Content} *)
···846846 info : Media_info.t option;
847847 url : string;
848848 }
849849- val jsont : t Jsont.t
849849+ val jsont : t Json.codec
850850end
851851852852(** {1 Location Content} *)
···859859 geo_uri : string;
860860 info : location_info option;
861861 }
862862- val jsont : t Jsont.t
862862+ val jsont : t Json.codec
863863end
864864865865(** {1 Event Types} *)
···906906 val to_string : t -> string
907907 val of_string : string -> t
908908 val pp : Format.formatter -> t -> unit
909909- val jsont : t Jsont.t
909909+ val jsont : t Json.codec
910910end
911911912912(** {1 State Events} *)
···921921 content : 'content;
922922 unsigned : Unsigned.t option;
923923 }
924924- val make_jsont : 'content Jsont.t -> 'content t Jsont.t
924924+ val make_jsont : 'content Json.codec -> 'content t Json.codec
925925end
926926927927(** {1 Room Events} *)
···935935 content : 'content;
936936 unsigned : Unsigned.t option;
937937 }
938938- val make_jsont : 'content Jsont.t -> 'content t Jsont.t
938938+ val make_jsont : 'content Json.codec -> 'content t Json.codec
939939end
940940941941(** {1 Raw Events} *)
···947947 origin_server_ts : Timestamp.t;
948948 type_ : Event_type.t;
949949 state_key : string option;
950950- content : Jsont.json;
950950+ content : Json.t;
951951 unsigned : Unsigned.t option;
952952 room_id : Matrix_id.Room_id.t option;
953953 }
954954- val jsont : t Jsont.t
954954+ val jsont : t Json.codec
955955end
+8-8
lib/matrix_proto/matrix_id.ml
···61616262 (** JSON codec for server names. *)
6363 let jsont =
6464- Jsont.of_of_string ~kind:"server_name"
6464+ Json.Codec.of_of_string ~kind:"server_name"
6565 ~enc:to_string
6666 (fun s -> Result.map_error (fun (`Invalid_server_name s) -> s) (of_string s))
6767end
···134134135135 (** JSON codec for user IDs. *)
136136 let jsont =
137137- Jsont.of_of_string ~kind:"user_id"
137137+ Json.Codec.of_of_string ~kind:"user_id"
138138 ~enc:to_string
139139 (fun s -> Result.map_error (fun (`Invalid_user_id msg) -> msg) (of_string s))
140140end
···196196197197 (** JSON codec for room IDs. *)
198198 let jsont =
199199- Jsont.of_of_string ~kind:"room_id"
199199+ Json.Codec.of_of_string ~kind:"room_id"
200200 ~enc:to_string
201201 (fun s -> Result.map_error (fun (`Invalid_room_id msg) -> msg) (of_string s))
202202end
···264264265265 (** JSON codec for event IDs. *)
266266 let jsont =
267267- Jsont.of_of_string ~kind:"event_id"
267267+ Json.Codec.of_of_string ~kind:"event_id"
268268 ~enc:to_string
269269 (fun s -> Result.map_error (fun (`Invalid_event_id msg) -> msg) (of_string s))
270270end
···328328329329 (** JSON codec for room aliases. *)
330330 let jsont =
331331- Jsont.of_of_string ~kind:"room_alias"
331331+ Json.Codec.of_of_string ~kind:"room_alias"
332332 ~enc:to_string
333333 (fun s -> Result.map_error (fun (`Invalid_room_alias msg) -> msg) (of_string s))
334334end
···369369 let pp ppf t = Format.pp_print_string ppf t
370370371371 (** JSON codec for device IDs. *)
372372- let jsont = Jsont.string
372372+ let jsont = Json.Codec.string
373373end
374374375375(** {1 Session IDs}
···400400 let pp ppf t = Format.pp_print_string ppf t
401401402402 (** JSON codec for session IDs. *)
403403- let jsont = Jsont.string
403403+ let jsont = Json.Codec.string
404404end
405405406406(** {1 Transaction IDs}
···441441 let pp ppf t = Format.pp_print_string ppf t
442442443443 (** JSON codec for transaction IDs. *)
444444- let jsont = Jsont.string
444444+ let jsont = Json.Codec.string
445445end
+8-8
lib/matrix_proto/matrix_id.mli
···1212 val of_string_exn : string -> t
1313 val to_string : t -> string
1414 val pp : Format.formatter -> t -> unit
1515- val jsont : t Jsont.t
1515+ val jsont : t Json.codec
1616end
17171818(** {1 User IDs}
···2828 val localpart : t -> string
2929 val server_name : t -> Server_name.t
3030 val pp : Format.formatter -> t -> unit
3131- val jsont : t Jsont.t
3131+ val jsont : t Json.codec
3232end
33333434(** {1 Room IDs}
···4444 val opaque_id : t -> string
4545 val server_name : t -> Server_name.t
4646 val pp : Format.formatter -> t -> unit
4747- val jsont : t Jsont.t
4747+ val jsont : t Json.codec
4848end
49495050(** {1 Event IDs}
···6060 val of_string_exn : string -> t
6161 val to_string : t -> string
6262 val pp : Format.formatter -> t -> unit
6363- val jsont : t Jsont.t
6363+ val jsont : t Json.codec
6464end
65656666(** {1 Room Aliases}
···7676 val alias : t -> string
7777 val server_name : t -> Server_name.t
7878 val pp : Format.formatter -> t -> unit
7979- val jsont : t Jsont.t
7979+ val jsont : t Json.codec
8080end
81818282(** {1 Device IDs}
···9090 val of_string_exn : string -> t
9191 val to_string : t -> string
9292 val pp : Format.formatter -> t -> unit
9393- val jsont : t Jsont.t
9393+ val jsont : t Json.codec
9494end
95959696(** {1 Session IDs}
···103103 val of_string : string -> (t, [> `Invalid_session_id of string ]) result
104104 val to_string : t -> string
105105 val pp : Format.formatter -> t -> unit
106106- val jsont : t Jsont.t
106106+ val jsont : t Json.codec
107107end
108108109109(** {1 Transaction IDs}
···117117 val of_string : string -> t
118118 val to_string : t -> string
119119 val pp : Format.formatter -> t -> unit
120120- val jsont : t Jsont.t
120120+ val jsont : t Json.codec
121121end
···1111 limited : bool option;
1212 prev_batch : string option;
1313 }
1414- val jsont : t Jsont.t
1414+ val jsont : t Json.codec
1515end
16161717(** {1 Ephemeral Events} *)
18181919module Ephemeral : sig
2020- type t = { events : Jsont.json list }
2121- val jsont : t Jsont.t
2020+ type t = { events : Json.t list }
2121+ val jsont : t Json.codec
2222end
23232424(** {1 Account Data} *)
25252626module Account_data : sig
2727- type t = { events : Jsont.json list }
2828- val jsont : t Jsont.t
2727+ type t = { events : Json.t list }
2828+ val jsont : t Json.codec
2929end
30303131(** {1 Room State} *)
32323333module Room_state : sig
3434 type t = { events : Matrix_event.Raw_event.t list }
3535- val jsont : t Jsont.t
3535+ val jsont : t Json.codec
3636end
37373838(** {1 Unread Notification Counts} *)
···4242 highlight_count : int option;
4343 notification_count : int option;
4444 }
4545- val jsont : t Jsont.t
4545+ val jsont : t Json.codec
4646end
47474848(** {1 Room Summary} *)
···5353 joined_member_count : int option;
5454 invited_member_count : int option;
5555 }
5656- val jsont : t Jsont.t
5656+ val jsont : t Json.codec
5757end
58585959(** {1 Joined Room} *)
···6767 account_data : Account_data.t option;
6868 unread_notifications : Unread_notification_counts.t option;
6969 }
7070- val jsont : t Jsont.t
7070+ val jsont : t Json.codec
7171end
72727373(** {1 Invited Room} *)
74747575module Invited_room : sig
7676 type t = { invite_state : invite_state option }
7777- and invite_state = { events : Jsont.json list }
7878- val jsont : t Jsont.t
7777+ and invite_state = { events : Json.t list }
7878+ val jsont : t Json.codec
7979end
80808181(** {1 Left Room} *)
···8686 timeline : Timeline.t option;
8787 account_data : Account_data.t option;
8888 }
8989- val jsont : t Jsont.t
8989+ val jsont : t Json.codec
9090end
91919292(** {1 Knocked Room} *)
93939494module Knocked_room : sig
9595 type t = { knock_state : knock_state option }
9696- and knock_state = { events : Jsont.json list }
9797- val jsont : t Jsont.t
9696+ and knock_state = { events : Json.t list }
9797+ val jsont : t Json.codec
9898end
9999100100(** {1 Rooms} *)
···106106 leave : (string * Left_room.t) list;
107107 knock : (string * Knocked_room.t) list;
108108 }
109109- val jsont : t Jsont.t
109109+ val jsont : t Json.codec
110110end
111111112112(** {1 Device Lists} *)
···116116 changed : Matrix_id.User_id.t list;
117117 left : Matrix_id.User_id.t list;
118118 }
119119- val jsont : t Jsont.t
119119+ val jsont : t Json.codec
120120end
121121122122(** {1 To-Device Events} *)
123123124124module To_device : sig
125125- type t = { events : Jsont.json list }
126126- val jsont : t Jsont.t
125125+ type t = { events : Json.t list }
126126+ val jsont : t Json.codec
127127end
128128129129(** {1 Presence} *)
130130131131module Presence : sig
132132- type t = { events : Jsont.json list }
133133- val jsont : t Jsont.t
132132+ type t = { events : Json.t list }
133133+ val jsont : t Json.codec
134134end
135135136136(** {1 Sync Response} *)
···146146 device_one_time_keys_count : (string * int) list;
147147 device_unused_fallback_key_types : string list option;
148148 }
149149- val jsont : t Jsont.t
149149+ val jsont : t Json.codec
150150end
···3838 In_channel.with_open_bin path In_channel.input_all
39394040let roundtrip_test jsont json_str =
4141- match Jsont_bytesrw.decode_string jsont json_str with
4141+ match (Json.of_string jsont json_str |> Result.map_error Json.Error.to_string) with
4242 | Error e -> failwith ("decode: " ^ e)
4343 | Ok value ->
4444- match Jsont_bytesrw.encode_string jsont value with
4444+ match (try Ok (Json.to_string jsont value) with Json.Error e -> Error (Json.Error.to_string e)) with
4545 | Error e -> failwith ("encode: " ^ e)
4646 | Ok encoded ->
4747- match Jsont_bytesrw.decode_string jsont encoded with
4747+ match (Json.of_string jsont encoded |> Result.map_error Json.Error.to_string) with
4848 | Error e -> failwith ("re-decode: " ^ e)
4949 | Ok _ -> ()
5050