123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226open!ImportincludeBinable_intfincludeBin_prot.BinablemoduleShape=Bin_prot.ShapemoduleStable=structmoduleOf_binable=structmoduleV1(Binable:Minimal.S)(M:Conv_without_uuidwithtypebinable:=Binable.t):Swithtypet:=M.t=Bin_prot.Utils.Make_binable_without_uuid(structmoduleBinable=BinableincludeMend)[@@alert"-legacy"]moduleV2(Binable:Minimal.S)(M:Convwithtypebinable:=Binable.t):Swithtypet:=M.t=Bin_prot.Utils.Make_binable_with_uuid(structmoduleBinable=BinableincludeMend)endmoduleOf_binable1=structmoduleV1(Binable:Minimal.S1)(M:Conv1_without_uuidwithtype'abinable:='aBinable.t):S1withtype'at:='aM.t=Bin_prot.Utils.Make_binable1_without_uuid(structmoduleBinable=BinableincludeMend)[@@alert"-legacy"]moduleV2(Binable:Minimal.S1)(M:Conv1withtype'abinable:='aBinable.t):S1withtype'at:='aM.t=Bin_prot.Utils.Make_binable1_with_uuid(structmoduleBinable=BinableincludeMend)endmoduleOf_binable2=structmoduleV1(Binable:Minimal.S2)(M:Conv2_without_uuidwithtype('a,'b)binable:=('a,'b)Binable.t):S2withtype('a,'b)t:=('a,'b)M.t=Bin_prot.Utils.Make_binable2_without_uuid(structmoduleBinable=BinableincludeMend)[@@alert"-legacy"]moduleV2(Binable:Minimal.S2)(M:Conv2withtype('a,'b)binable:=('a,'b)Binable.t):S2withtype('a,'b)t:=('a,'b)M.t=Bin_prot.Utils.Make_binable2_with_uuid(structmoduleBinable=BinableincludeMend)endmoduleOf_binable3=structmoduleV1(Binable:Minimal.S3)(M:Conv3_without_uuidwithtype('a,'b,'c)binable:=('a,'b,'c)Binable.t):S3withtype('a,'b,'c)t:=('a,'b,'c)M.t=Bin_prot.Utils.Make_binable3_without_uuid(structmoduleBinable=BinableincludeMend)[@@alert"-legacy"]moduleV2(Binable:Minimal.S3)(M:Conv3withtype('a,'b,'c)binable:=('a,'b,'c)Binable.t):S3withtype('a,'b,'c)t:=('a,'b,'c)M.t=Bin_prot.Utils.Make_binable3_with_uuid(structmoduleBinable=BinableincludeMend)endmoduleOf_sexpable=structmoduleV1(M:Sexpable.S)=Of_binable.V1(structtypet=Base.Sexp.t=|Atomofstring|Listoftlist[@@derivingbin_io]end)(structtypet=M.tletto_binable=M.sexp_of_tletof_binable=M.t_of_sexpend)moduleV2(M:Conv_sexpable)=Of_binable.V2(structtypet=Base.Sexp.t=|Atomofstring|Listoftlist[@@derivingbin_io]end)(structtypet=M.tletto_binable=M.sexp_of_tletof_binable=M.t_of_sexpletcaller_identity=M.caller_identityend)endmoduleOf_stringable=structmoduleV1(M:Stringable.S)=Bin_prot.Utils.Make_binable_without_uuid(structmoduleBinable=structtypet=string[@@derivingbin_io]endtypet=M.tletto_binable=M.to_string(* Wrap exception for improved diagnostics. *)exceptionOf_binableofstring*exn[@@derivingsexp]letof_binables=tryM.of_stringswith|x->raise(Of_binable(s,x));;end)[@@alert"-legacy"]moduleV2(M:Conv_stringable)=Bin_prot.Utils.Make_binable_with_uuid(structmoduleBinable=structtypet=string[@@derivingbin_io]endtypet=M.tletto_binable=M.to_string(* Wrap exception for improved diagnostics. *)exceptionOf_binableofstring*exn[@@derivingsexp]letof_binables=tryM.of_stringswith|x->raise(Of_binable(s,x));;letcaller_identity=M.caller_identityend)endendopenBigarraytypebigstring=(char,int8_unsigned_elt,c_layout)Array1.ttype'am=(moduleSwithtypet='a)letof_bigstring(typea)mbigstring=letmoduleM=(valm:Swithtypet=a)inletpos_ref=ref0inlett=M.bin_read_tbigstring~pos_refinletbigstring_length=Array1.dimbigstringin(match!pos_ref=bigstring_lengthwith|true->()|false->raise_s[%message"bin_read_t did not consume the entire buffer"~consumed:(!pos_ref:int)(bigstring_length:int)]);t;;(* Using the [Bigstring] module would introduce a cyclic dependency. *)letcreate_bigstringsize=Array1.createBigarray.charBigarray.c_layoutsizeletto_bigstring?(prefix_with_length=false)(typea)mt=letmoduleM=(valm:Swithtypet=a)inlett_length=M.bin_size_ttinletbigstring_length=ifprefix_with_lengththent_length+8(* the size of a 64-bit int *)elset_lengthinletbigstring=create_bigstringbigstring_lengthinletpos=ifprefix_with_lengththenBin_prot.Write.bin_write_int_64bitbigstring~pos:0t_lengthelse0inletpos=M.bin_write_tbigstring~postinassert(pos=bigstring_length);bigstring;;moduleOf_binable_with_uuid=Stable.Of_binable.V2moduleOf_binable1_with_uuid=Stable.Of_binable1.V2moduleOf_binable2_with_uuid=Stable.Of_binable2.V2moduleOf_binable3_with_uuid=Stable.Of_binable3.V2moduleOf_sexpable_with_uuid=Stable.Of_sexpable.V2moduleOf_stringable_with_uuid=Stable.Of_stringable.V2moduleOf_binable_without_uuid=Stable.Of_binable.V1moduleOf_binable1_without_uuid=Stable.Of_binable1.V1moduleOf_binable2_without_uuid=Stable.Of_binable2.V1moduleOf_binable3_without_uuid=Stable.Of_binable3.V1moduleOf_sexpable_without_uuid=Stable.Of_sexpable.V1moduleOf_stringable_without_uuid=Stable.Of_stringable.V1let%test_module_=(modulestructmoduletypeS_only_functions_and_shape=sigincludeS_only_functionsvalbin_shape_t:Shape.tend(* Check that only the functions & shape are sufficient for [@@deriving bin_io]. The
fact that this functor typechecks is, itself, the test. *)module_(X:S_only_functions_and_shape):S=structtypet=X.t[@@derivingbin_io]endend);;