2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2018-05-03 13:05:06 +04:00
|
|
|
|
2018-05-03 09:52:30 +04:00
|
|
|
module Encoding =
|
|
|
|
struct
|
2018-05-03 08:27:17 +04:00
|
|
|
include Encoding
|
|
|
|
let splitted ~json ~binary = raw_splitted ~json:(Json.convert json) ~binary
|
2016-09-09 19:02:43 +04:00
|
|
|
let assoc enc =
|
2018-05-03 08:27:17 +04:00
|
|
|
let json = Json_encoding.assoc (Json.convert enc) in
|
2016-09-09 19:02:43 +04:00
|
|
|
let binary = list (tup2 string enc) in
|
|
|
|
raw_splitted ~json ~binary
|
2018-05-16 19:46:01 +04:00
|
|
|
|
|
|
|
module Bounded = struct
|
|
|
|
|
|
|
|
let string length =
|
|
|
|
raw_splitted
|
|
|
|
~binary: begin
|
|
|
|
let kind = Binary_size.unsigned_range_to_size length in
|
|
|
|
check_size (length + Binary_size.integer_to_size kind) @@
|
|
|
|
dynamic_size ~kind Variable.string
|
|
|
|
end
|
|
|
|
~json: begin
|
|
|
|
let open Json_encoding in
|
|
|
|
conv
|
|
|
|
(fun s ->
|
|
|
|
if String.length s > length then invalid_arg "oversized string" ;
|
|
|
|
s)
|
|
|
|
(fun s ->
|
|
|
|
if String.length s > length then
|
|
|
|
raise (Cannot_destruct ([], Invalid_argument "oversized string")) ;
|
|
|
|
s)
|
|
|
|
string
|
|
|
|
end
|
|
|
|
|
|
|
|
let bytes length =
|
|
|
|
raw_splitted
|
|
|
|
~binary: begin
|
|
|
|
let kind = Binary_size.unsigned_range_to_size length in
|
|
|
|
check_size (length + Binary_size.integer_to_size kind) @@
|
|
|
|
dynamic_size ~kind Variable.bytes
|
|
|
|
end
|
|
|
|
~json: begin
|
|
|
|
let open Json_encoding in
|
|
|
|
conv
|
|
|
|
(fun s ->
|
|
|
|
if MBytes.length s > length then invalid_arg "oversized string" ;
|
|
|
|
s)
|
|
|
|
(fun s ->
|
|
|
|
if MBytes.length s > length then
|
|
|
|
raise (Cannot_destruct ([], Invalid_argument "oversized string")) ;
|
|
|
|
s)
|
|
|
|
Json.bytes_jsont
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
include Encoding
|
|
|
|
|
2018-05-16 19:46:01 +04:00
|
|
|
|
|
|
|
|
2018-05-03 09:52:30 +04:00
|
|
|
module Json = Json
|
|
|
|
module Bson = Bson
|
2018-05-03 17:29:44 +04:00
|
|
|
module Binary = struct
|
2018-05-12 18:57:39 +04:00
|
|
|
include Binary_error
|
2018-05-12 19:48:06 +04:00
|
|
|
include Binary_length
|
2018-05-12 19:48:50 +04:00
|
|
|
include Binary_writer
|
2018-05-12 18:57:39 +04:00
|
|
|
include Binary_reader
|
|
|
|
include Binary_stream_reader
|
2018-05-03 17:29:44 +04:00
|
|
|
end
|
2018-05-03 08:27:17 +04:00
|
|
|
|
|
|
|
type json = Json.t
|
|
|
|
let json = Json.encoding
|
|
|
|
type json_schema = Json.schema
|
|
|
|
let json_schema = Json.schema_encoding
|
|
|
|
type bson = Bson.t
|