123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduleEncoding=structincludeEncodingtype'amatching_function='a->match_resultletsplitted~json~binary=raw_splitted~json:(Json.convertjson)~binaryletassocenc=letjson=Json_encoding.assoc(Json.convertenc)inletbinary=list(tup2stringenc)inraw_splitted~json~binarymoduleBounded=structletstringlength=raw_splitted~binary:(letkind=Binary_size.unsigned_range_to_sizelengthincheck_size(length+Binary_size.integer_to_sizekind)@@dynamic_size~kindVariable.string)~json:(letopenJson_encodinginconv(funs->ifString.lengths>lengththeninvalid_arg"oversized string";s)(funs->ifString.lengths>lengththenraise(Cannot_destruct([],Invalid_argument"oversized string"));s)string)letbyteslength=raw_splitted~binary:(letkind=Binary_size.unsigned_range_to_sizelengthincheck_size(length+Binary_size.integer_to_sizekind)@@dynamic_size~kindVariable.bytes)~json:(letopenJson_encodinginconv(funs->ifBytes.lengths>lengththeninvalid_arg"oversized string";s)(funs->ifBytes.lengths>lengththenraise(Cannot_destruct([],Invalid_argument"oversized string"));s)Json.bytes_jsont)endtype'alazy_state=Valueof'a|BytesofBytes.t|BothofBytes.t*'atype'alazy_t={mutablestate:'alazy_state;encoding:'at}letforce_decodele=matchle.statewith|Valuevalue->Somevalue|Both(_,value)->Somevalue|Bytesbytes->(matchBinary_reader.of_bytes_optle.encodingbyteswith|Someexpr->le.state<-Both(bytes,expr);Someexpr|None->None)letforce_bytesle=matchle.statewith|Bytesbytes->bytes|Both(bytes,_)->bytes|Valuevalue->letbytes=Binary_writer.to_bytes_exnle.encodingvalueinle.state<-Both(bytes,value);bytesletlazy_encodingencoding=letbinary=Encoding.convforce_bytes(funbytes->{state=Bytesbytes;encoding})Encoding.bytesinletjson=Encoding.conv(funle->matchforce_decodelewithSomer->r|None->raiseExit)(funvalue->{state=Valuevalue;encoding})encodinginsplitted~json~binaryletmake_lazyencodingvalue={encoding;state=Valuevalue}letapply_lazy~fun_value~fun_bytes~fun_combinele=matchle.statewith|Valuevalue->fun_valuevalue|Bytesbytes->fun_bytesbytes|Both(bytes,value)->fun_combine(fun_valuevalue)(fun_bytesbytes)endincludeEncodingmoduleWith_version=With_versionmoduleRegistration=RegistrationmoduleJson=structincludeJsonincludeJson_streamendmoduleBson=BsonmoduleBinary_schema=Binary_schemamoduleBinary=structincludeBinary_error_typesincludeBinary_errorincludeBinary_lengthincludeBinary_writerincludeBinary_readerincludeBinary_stream_readerletdescribe=Binary_description.describeendtypejson=Json.tletjson=Json.encodingtypejson_schema=Json.schemaletjson_schema=Json.schema_encodingtypebson=Bson.t