Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file header_protocol.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899(** This file is automatically generated by a target in the build system.
Do not modify it by hand. *)open!Coreletpadding=' 'let_=paddingtype('ty,-'rw)t=('rw,Iobuf.no_seek)Iobuf.tconstraint'rw=[>read]type('ty,'rw)message=('ty,'rw)ttype('ty,'rw)t_no_exn=('ty,'rw)tmoduleR=structtype'messaget=|Need_more_data|Okof'message*int|Junkofexn*(int,exn)Result.t[@@derivingsexp_of]endmoduleMessage_type_and_errors=structtype_t=|New_single:[`New_single]t|New_group:[`New_group]t|New_group_point:[`New_group_point]t|End_of_header:[`End_of_header]t|Epoch:[`Epoch]t|Need_more_data:[`Error]t|Invalid_message_type_or_subtype:[`Error]t|Message_length_too_short:[`Error]t[@@derivingsexp_of]typepacked=T:_t->packed[@@derivingsexp_of][@@unboxed]letto_wire_exn:typety.tyt->char=function|Epoch->'E'|New_single->'N'|New_group_point->'O'|New_group->'P'|End_of_header->'Z'|Need_more_data->invalid_arg"to_wire_exn: received Need_more_data"|Invalid_message_type_or_subtype->invalid_arg"to_wire_exn: received Invalid_message_type_or_subtype"|Message_length_too_short->invalid_arg"to_wire_exn: received Message_length_too_short";;letof_wire=function|'E'->TEpoch|'N'->TNew_single|'O'->TNew_group_point|'P'->TNew_group|'Z'->TEnd_of_header|_->TInvalid_message_type_or_subtype;;letto_index_exn:typety.tyt->int=function|New_single->0|New_group->1|New_group_point->2|End_of_header->3|Epoch->4|Need_more_data->invalid_arg"to_index_exn: received Need_more_data"|Invalid_message_type_or_subtype->invalid_arg"to_index_exn: received Invalid_message_type_or_subtype"|Message_length_too_short->invalid_arg"to_index_exn: received Message_length_too_short";;letof_index_exn=function|0->TNew_single|1->TNew_group|2->TNew_group_point|3->TEnd_of_header|4->TEpoch|_->invalid_arg"of_index_exn: invalid index";;letmax_index=4letall_of_packed=List.init(max_index+1)~f:of_index_exnmodulePacked=structmoduleT=structtype'tymessage_type_and_errors='tyt[@@derivingsexp_of]typet=packed=T:_message_type_and_errors->t[@@derivingsexp_of][@@unboxed]letto_index_exn(Tt)=to_index_exntletcomparet1t2=Int.compare(to_index_exnt1)(to_index_exnt2)lethasht=Int.hash(to_index_exnt)lethash_fold_tstatet=Int.hash_fold_tstate(to_index_exnt)lett_of_sexp_=failwith"unimplemented"letall=all_of_packedendincludeTincludeComparable.Make(T)includeHashable.Make(T)endendletget_message_typebuf=letlen=Iobuf.lengthbufinletpos=0iniflen<2thenMessage_type_and_errors.(TNeed_more_data)else(letmessage_num_bytes=0+Core.Iobuf.Unsafe.Peek.uint8buf~posiniflen<message_num_bytesthenMessage_type_and_errors.(TNeed_more_data)else(matchCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1)with|'E'->ifmessage_num_bytes<10thenTMessage_length_too_shortelseMessage_type_and_errors.(TEpoch)|'N'->ifmessage_num_bytes<69thenTMessage_length_too_shortelseMessage_type_and_errors.(TNew_single)|'O'->ifmessage_num_bytes<72||message_num_bytes<letpos=0in72+(2*Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+70))thenTMessage_length_too_shortelseMessage_type_and_errors.(TNew_group_point)|'P'->ifmessage_num_bytes<69thenTMessage_length_too_shortelseMessage_type_and_errors.(TNew_group)|'Z'->ifmessage_num_bytes<2thenTMessage_length_too_shortelseMessage_type_and_errors.(TEnd_of_header)|other->ignoreother;Message_type_and_errors.(TInvalid_message_type_or_subtype)));;letof_iobufbuf~trusted:_=Iobuf.no_seekbufletof_iobuf_exnbufty=let(Message_type_and_errors.Tmt)=get_message_typebufinifMessage_type_and_errors.to_index_exnmt=Message_type_and_errors.to_index_exntythenof_iobufbuf~trusted:tyelsefailwiths"unexpected message type"mt[%sexp_of:_Message_type_and_errors.t];;moduleNew_single=structtypephantom=[`New_single]typenonrec-'rwt=(phantom,'rw)tletmessage_type='N'letbuffer_length=69letof_iobuf_exnbuf=of_iobuf_exnbufMessage_type_and_errors.New_singleletwrite~id~spec~namebuf=letpos=0inassert(Iobuf.lengthbuf>=69);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+1)message_type;Core.Iobuf.Unsafe.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exnid);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+4)(Probe_type.to_charspec);Core.Iobuf.Unsafe.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5)name;lettotal_bytes_packed=69inCore.Iobuf.Unsafe.Poke.uint8_truncbuf~pos(total_bytes_packed-0);total_bytes_packed;;letcreate~id~spec~name=letiobuf=Iobuf.create~len:69inletsize=write~id~spec~nameiobufinassert(Iobuf.lengthiobuf=size);iobuf;;letget_message_lengthbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint8buf~pos;;letget_message_typebuf=letpos=0inCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1);;letget_idbuf=letpos=0inProbe_id.of_int_exn(Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+2));;letget_specbuf=letpos=0inProbe_type.of_char(Core.Iobuf.Unsafe.Peek.charbuf~pos:(pos+4));;letname_max_len=64letget_namebuf=letpos=0inCore.Iobuf.Unsafe.Peek.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5);;letget_name_zerobuff=letbuf=Iobuf.read_onlybufinletpos=5inletlen=ref64inwhile!len>0&&Char.(=)padding(Iobuf.Unsafe.Peek.charbuf~pos:(pos+!len-1))dodecrlendone;fbuf~safe_pos:pos~safe_len:!len;;letget_name_zero_paddedbuff=letbuf=Iobuf.read_onlybufinletpos=5infbuf~safe_pos:pos~safe_len:64;;letset_idbuffield=letpos=0inCore.Iobuf.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exnfield);;letset_specbuffield=letpos=0inCore.Iobuf.Poke.charbuf~pos:(pos+4)(Probe_type.to_charfield);;letset_namebuffield=letpos=0inCore.Iobuf.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5)field;;letset_name_zerobuffa=letlo=Iobuf.Lo_bound.windowbufinlethi=Iobuf.Hi_bound.windowbufinIobuf.advancebuf5;Iobuf.resizebuf~len:64;fabuf;whilenot(Iobuf.is_emptybuf)doIobuf.Unsafe.Fill.charbufpaddingdone;Iobuf.Lo_bound.restorelobuf;Iobuf.Hi_bound.restorehibuf;;letto_sub_iobuft=Iobuf.sub_sharedt~len:(get_message_lengtht+0)moduleUnpacked=structtypet={message_length:int;message_type:char;id:Probe_id.t;spec:Probe_type.t;name:string}[@@derivingsexp]letnum_bytest=t.message_length+0letwrite(t:t)iobuf=letres=writeiobuf~id:t.id~spec:t.spec~name:t.nameinres;;endletto_unpackedbuf:Unpacked.t={message_length=get_message_lengthbuf;message_type=get_message_typebuf;id=get_idbuf;spec=get_specbuf;name=get_namebuf};;letsexp_of_t_t=Unpacked.sexp_of_t(to_unpackedt)letof_unpacked(unpacked:Unpacked.t)=lett=Iobuf.create~len:69inignore(Unpacked.writeunpackedt:int);Iobuf.of_string(Iobuf.to_stringt);;lett_of_sexp_sexp=of_unpacked(Unpacked.t_of_sexpsexp)endmoduleNew_group=structtypephantom=[`New_group]typenonrec-'rwt=(phantom,'rw)tletmessage_type='P'letbuffer_length=69letof_iobuf_exnbuf=of_iobuf_exnbufMessage_type_and_errors.New_groupletwrite~id~spec~namebuf=letpos=0inassert(Iobuf.lengthbuf>=69);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+1)message_type;Core.Iobuf.Unsafe.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exnid);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+4)(Probe_type.to_charspec);Core.Iobuf.Unsafe.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5)name;lettotal_bytes_packed=69inCore.Iobuf.Unsafe.Poke.uint8_truncbuf~pos(total_bytes_packed-0);total_bytes_packed;;letcreate~id~spec~name=letiobuf=Iobuf.create~len:69inletsize=write~id~spec~nameiobufinassert(Iobuf.lengthiobuf=size);iobuf;;letget_message_lengthbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint8buf~pos;;letget_message_typebuf=letpos=0inCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1);;letget_idbuf=letpos=0inProbe_id.of_int_exn(Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+2));;letget_specbuf=letpos=0inProbe_type.of_char(Core.Iobuf.Unsafe.Peek.charbuf~pos:(pos+4));;letname_max_len=64letget_namebuf=letpos=0inCore.Iobuf.Unsafe.Peek.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5);;letget_name_zerobuff=letbuf=Iobuf.read_onlybufinletpos=5inletlen=ref64inwhile!len>0&&Char.(=)padding(Iobuf.Unsafe.Peek.charbuf~pos:(pos+!len-1))dodecrlendone;fbuf~safe_pos:pos~safe_len:!len;;letget_name_zero_paddedbuff=letbuf=Iobuf.read_onlybufinletpos=5infbuf~safe_pos:pos~safe_len:64;;letset_idbuffield=letpos=0inCore.Iobuf.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exnfield);;letset_specbuffield=letpos=0inCore.Iobuf.Poke.charbuf~pos:(pos+4)(Probe_type.to_charfield);;letset_namebuffield=letpos=0inCore.Iobuf.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+5)field;;letset_name_zerobuffa=letlo=Iobuf.Lo_bound.windowbufinlethi=Iobuf.Hi_bound.windowbufinIobuf.advancebuf5;Iobuf.resizebuf~len:64;fabuf;whilenot(Iobuf.is_emptybuf)doIobuf.Unsafe.Fill.charbufpaddingdone;Iobuf.Lo_bound.restorelobuf;Iobuf.Hi_bound.restorehibuf;;letto_sub_iobuft=Iobuf.sub_sharedt~len:(get_message_lengtht+0)moduleUnpacked=structtypet={message_length:int;message_type:char;id:Probe_id.t;spec:Probe_type.t;name:string}[@@derivingsexp]letnum_bytest=t.message_length+0letwrite(t:t)iobuf=letres=writeiobuf~id:t.id~spec:t.spec~name:t.nameinres;;endletto_unpackedbuf:Unpacked.t={message_length=get_message_lengthbuf;message_type=get_message_typebuf;id=get_idbuf;spec=get_specbuf;name=get_namebuf};;letsexp_of_t_t=Unpacked.sexp_of_t(to_unpackedt)letof_unpacked(unpacked:Unpacked.t)=lett=Iobuf.create~len:69inignore(Unpacked.writeunpackedt:int);Iobuf.of_string(Iobuf.to_stringt);;lett_of_sexp_sexp=of_unpacked(Unpacked.t_of_sexpsexp)endmoduleNew_group_point=structtypephantom=[`New_group_point]typenonrec-'rwt=(phantom,'rw)tletmessage_type='O'letbuffer_length~sources_count=72+(2*sources_count)letof_iobuf_exnbuf=of_iobuf_exnbufMessage_type_and_errors.New_group_pointletwrite~group_id~id~name~sources_countbuf=letpos=0inassert(Iobuf.lengthbuf>=72+(2*sources_count));Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+1)message_type;Core.Iobuf.Unsafe.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exngroup_id);Core.Iobuf.Unsafe.Poke.uint16_le_truncbuf~pos:(pos+4)(Probe_id.to_int_exnid);Core.Iobuf.Unsafe.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+6)name;Core.Iobuf.Unsafe.Poke.uint16_le_truncbuf~pos:(pos+70)sources_count;letpos_after_sources=pos+72+(sources_count*2)inlettotal_bytes_packed=pos_after_sources-posinCore.Iobuf.Unsafe.Poke.uint8_truncbuf~pos(total_bytes_packed-0);total_bytes_packed;;letcreate~group_id~id~name~sources_count=letiobuf=Iobuf.create~len:(72+(2*sources_count))inletsize=write~group_id~id~name~sources_countiobufinassert(Iobuf.lengthiobuf=size);iobuf;;letget_message_lengthbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint8buf~pos;;letget_message_typebuf=letpos=0inCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1);;letget_group_idbuf=letpos=0inProbe_id.of_int_exn(Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+2));;letget_idbuf=letpos=0inProbe_id.of_int_exn(Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+4));;letname_max_len=64letget_namebuf=letpos=0inCore.Iobuf.Unsafe.Peek.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+6);;letget_name_zerobuff=letbuf=Iobuf.read_onlybufinletpos=6inletlen=ref64inwhile!len>0&&Char.(=)padding(Iobuf.Unsafe.Peek.charbuf~pos:(pos+!len-1))dodecrlendone;fbuf~safe_pos:pos~safe_len:!len;;letget_name_zero_paddedbuff=letbuf=Iobuf.read_onlybufinletpos=6infbuf~safe_pos:pos~safe_len:64;;letget_sources_countbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint16_lebuf~pos:(pos+70);;letget_sources_source_idbuf~count~index=ifindex<0||index>=counttheninvalid_arg"index out of bounds";letpos=0inletpos_of_source_id_using_count_and_index=pos+72+(count*0)+(index*2)inProbe_id.of_int_exn(Core.Iobuf.Unsafe.Peek.uint16_lebuf~pos:pos_of_source_id_using_count_and_index);;letset_group_idbuffield=letpos=0inCore.Iobuf.Poke.uint16_le_truncbuf~pos:(pos+2)(Probe_id.to_int_exnfield);;letset_idbuffield=letpos=0inCore.Iobuf.Poke.uint16_le_truncbuf~pos:(pos+4)(Probe_id.to_int_exnfield);;letset_namebuffield=letpos=0inCore.Iobuf.Poke.tail_padded_fixed_string~paddingbuf~len:64~pos:(pos+6)field;;letset_name_zerobuffa=letlo=Iobuf.Lo_bound.windowbufinlethi=Iobuf.Hi_bound.windowbufinIobuf.advancebuf6;Iobuf.resizebuf~len:64;fabuf;whilenot(Iobuf.is_emptybuf)doIobuf.Unsafe.Fill.charbufpaddingdone;Iobuf.Lo_bound.restorelobuf;Iobuf.Hi_bound.restorehibuf;;letset_sources_source_idbuf~count~indexfield=ifindex<0||index>=counttheninvalid_arg"index out of bounds";letpos=0inletpos_of_source_id_using_count_and_index=pos+72+(count*0)+(index*2)inCore.Iobuf.Poke.uint16_le_truncbuf~pos:pos_of_source_id_using_count_and_index(Probe_id.to_int_exnfield);;letwrite_sourcesbuf~count~index~source_id=set_sources_source_idbuf~count~indexsource_id;;letto_sub_iobuft=Iobuf.sub_sharedt~len:(get_message_lengtht+0)moduleUnpacked=structtypet_sources={source_id:Probe_id.t}[@@derivingsexp]typet={message_length:int;message_type:char;group_id:Probe_id.t;id:Probe_id.t;name:string;sources_grp:t_sourcesarray}[@@derivingsexp]letnum_bytest=t.message_length+0letwrite(t:t)iobuf=letres=writeiobuf~group_id:t.group_id~id:t.id~name:t.name~sources_count:(Array.lengtht.sources_grp)inArray.iterit.sources_grp~f:(funi(record:t_sources)->write_sourcesiobuf~count:(Array.lengtht.sources_grp)~index:i~source_id:record.source_id);res;;endletto_unpackedbuf:Unpacked.t={message_length=get_message_lengthbuf;message_type=get_message_typebuf;group_id=get_group_idbuf;id=get_idbuf;name=get_namebuf;sources_grp=(letsources_count=get_sources_countbufinArray.initsources_count~f:(funi->{Unpacked.source_id=get_sources_source_idbuf~count:sources_count~index:i}))};;letsexp_of_t_t=Unpacked.sexp_of_t(to_unpackedt)letof_unpacked(unpacked:Unpacked.t)=lett=Iobuf.create~len:(72+(2*Array.lengthunpacked.sources_grp))inignore(Unpacked.writeunpackedt:int);Iobuf.of_string(Iobuf.to_stringt);;lett_of_sexp_sexp=of_unpacked(Unpacked.t_of_sexpsexp)endmoduleEnd_of_header=structtypephantom=[`End_of_header]typenonrec-'rwt=(phantom,'rw)tletmessage_type='Z'letbuffer_length=2letof_iobuf_exnbuf=of_iobuf_exnbufMessage_type_and_errors.End_of_headerletwritebuf=letpos=0inassert(Iobuf.lengthbuf>=2);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+1)message_type;lettotal_bytes_packed=2inCore.Iobuf.Unsafe.Poke.uint8_truncbuf~pos(total_bytes_packed-0);total_bytes_packed;;letcreate()=letiobuf=Iobuf.create~len:2inletsize=writeiobufinassert(Iobuf.lengthiobuf=size);iobuf;;letget_message_lengthbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint8buf~pos;;letget_message_typebuf=letpos=0inCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1);;letto_sub_iobuft=Iobuf.sub_sharedt~len:(get_message_lengtht+0)moduleUnpacked=structtypet={message_length:int;message_type:char}[@@derivingsexp]letnum_bytest=t.message_length+0letwrite(_:t)iobuf=letres=writeiobufinres;;endletto_unpackedbuf:Unpacked.t={message_length=get_message_lengthbuf;message_type=get_message_typebuf};;letsexp_of_t_t=Unpacked.sexp_of_t(to_unpackedt)letof_unpacked(unpacked:Unpacked.t)=lett=Iobuf.create~len:2inignore(Unpacked.writeunpackedt:int);Iobuf.of_string(Iobuf.to_stringt);;lett_of_sexp_sexp=of_unpacked(Unpacked.t_of_sexpsexp)endmoduleEpoch=structtypephantom=[`Epoch]typenonrec-'rwt=(phantom,'rw)tletmessage_type='E'letbuffer_length=10letof_iobuf_exnbuf=of_iobuf_exnbufMessage_type_and_errors.Epochletwrite~epochbuf=letpos=0inassert(Iobuf.lengthbuf>=10);Core.Iobuf.Unsafe.Poke.charbuf~pos:(pos+1)message_type;Core.Iobuf.Unsafe.Poke.int64_lebuf~pos:(pos+2)(Profiler_epoch.to_intepoch);lettotal_bytes_packed=10inCore.Iobuf.Unsafe.Poke.uint8_truncbuf~pos(total_bytes_packed-0);total_bytes_packed;;letcreate~epoch=letiobuf=Iobuf.create~len:10inletsize=write~epochiobufinassert(Iobuf.lengthiobuf=size);iobuf;;letget_message_lengthbuf=letpos=0inCore.Iobuf.Unsafe.Peek.uint8buf~pos;;letget_message_typebuf=letpos=0inCore.Iobuf.Unsafe.Peek.charbuf~pos:(pos+1);;letget_epochbuf=letpos=0inProfiler_epoch.of_int(Core.Iobuf.Unsafe.Peek.int64_le_exnbuf~pos:(pos+2));;letset_epochbuffield=letpos=0inCore.Iobuf.Poke.int64_lebuf~pos:(pos+2)(Profiler_epoch.to_intfield);;letto_sub_iobuft=Iobuf.sub_sharedt~len:(get_message_lengtht+0)moduleUnpacked=structtypet={message_length:int;message_type:char;epoch:Profiler_epoch.t}[@@derivingsexp]letnum_bytest=t.message_length+0letwrite(t:t)iobuf=letres=writeiobuf~epoch:t.epochinres;;endletto_unpackedbuf:Unpacked.t={message_length=get_message_lengthbuf;message_type=get_message_typebuf;epoch=get_epochbuf};;letsexp_of_t_t=Unpacked.sexp_of_t(to_unpackedt)letof_unpacked(unpacked:Unpacked.t)=lett=Iobuf.create~len:10inignore(Unpacked.writeunpackedt:int);Iobuf.of_string(Iobuf.to_stringt);;lett_of_sexp_sexp=of_unpacked(Unpacked.t_of_sexpsexp)endmoduleUnpacked=structtypet=|New_singleofNew_single.Unpacked.t|New_groupofNew_group.Unpacked.t|New_group_pointofNew_group_point.Unpacked.t|End_of_headerofEnd_of_header.Unpacked.t|EpochofEpoch.Unpacked.t[@@derivingsexp]letnum_bytes=function|New_singlem->New_single.Unpacked.num_bytesm|New_groupm->New_group.Unpacked.num_bytesm|New_group_pointm->New_group_point.Unpacked.num_bytesm|End_of_headerm->End_of_header.Unpacked.num_bytesm|Epochm->Epoch.Unpacked.num_bytesm;;letwritetiobuf=matchtwith|New_singlemsg->New_single.Unpacked.writemsgiobuf|New_groupmsg->New_group.Unpacked.writemsgiobuf|New_group_pointmsg->New_group_point.Unpacked.writemsgiobuf|End_of_headermsg->End_of_header.Unpacked.writemsgiobuf|Epochmsg->Epoch.Unpacked.writemsgiobuf;;endletnum_bytes_needed_for_message_length=1letnum_bytes_in_messagebuf=letpos=0inifIobuf.lengthbuf<1thenfailwith"Not enough data to read a message length!";0+Core.Iobuf.Unsafe.Peek.uint8buf~pos;;letskip_messagebuf=Iobuf.advancebuf(num_bytes_in_messagebuf)letbuffer_contains_full_messagebuf=letlen=Iobuf.lengthbufinlen>=num_bytes_needed_for_message_length&&len>=num_bytes_in_messagebuf;;letof_unpacked(u:Unpacked.t)=matchuwith|New_singlemsg->New_single.of_unpackedmsg|New_groupmsg->New_group.of_unpackedmsg|New_group_pointmsg->New_group_point.of_unpackedmsg|End_of_headermsg->End_of_header.of_unpackedmsg|Epochmsg->Epoch.of_unpackedmsg;;letto_unpackedbuf=let(Message_type_and_errors.Tmt)=get_message_typebufinletm=of_iobufbuf~trusted:mtinmatchmtwith|Message_type_and_errors.Need_more_data->R.Need_more_data|Message_type_and_errors.Invalid_message_type_or_subtype->letlen_or_error=Result.try_with(fun()->num_bytes_in_messagebuf)inR.Junk(Failure"Invalid_message_type_or_subtype",len_or_error)|Message_type_and_errors.Message_length_too_short->letlen_or_error=Result.try_with(fun()->num_bytes_in_messagebuf)inR.Junk(Failure"Message_length_too_short",len_or_error)|Message_type_and_errors.New_single->R.Ok(Unpacked.New_single(New_single.to_unpackedm),num_bytes_in_messagebuf)|Message_type_and_errors.New_group->R.Ok(Unpacked.New_group(New_group.to_unpackedm),num_bytes_in_messagebuf)|Message_type_and_errors.New_group_point->R.Ok(Unpacked.New_group_point(New_group_point.to_unpackedm),num_bytes_in_messagebuf)|Message_type_and_errors.End_of_header->R.Ok(Unpacked.End_of_header(End_of_header.to_unpackedm),num_bytes_in_messagebuf)|Message_type_and_errors.Epoch->R.Ok(Unpacked.Epoch(Epoch.to_unpackedm),num_bytes_in_messagebuf);;letto_unpacked_exnbuf=matchto_unpackedbufwith|Ok(msg,_len)->msg|(Need_more_data|Junk_)asfailure->let(Message_type_and_errors.Tmessage_type)=get_message_typebufinraise_s[%message"[to_unpacked_exn] failure"(message_type:_Message_type_and_errors.t)(failure:_R.t)];;letsexp_of_t__t=matchto_unpackedtwith|(R.Need_more_data|R.Junk_)ase->failwiths"invalid message"e[%sexp_of:Nothing.tR.t]|R.Ok(t,_)->Unpacked.sexp_of_tt;;letsexp_of_t_no_exn__t=letsexp_of_errorerror=letlen=trynum_bytes_in_messagetwith|_->Iobuf.lengthtinletlen=Int.min(Int.min(Iobuf.lengtht)len)1000inletdata=Iobuf.to_stringt~lenin[%sexp("invalid message":string),{error:Error.t;data:string}]inmatchto_unpackedtwith|exceptionexn->sexp_of_error(Error.of_exnexn)|R.Need_more_data->sexp_of_error(Error.of_string"Need_more_data")|R.Junk(exn,_)->sexp_of_error(Error.of_exnexn)|R.Ok(t,_)->Unpacked.sexp_of_tt;;letto_iobuft=t