Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file apero.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213includeAtypesincludeAcommonincludeStateincludeOrderedincludeKey_valueincludePropertiesincludeUuidincludeMvarincludeJsonincludeIdentifiersincludeApathmoduleList=AlistmoduleStringable=StringablemoduleEventStream=Event_stream.EventStream.Make(Stream_lwt.Stream)openResultletencode_vle?sizevbuf=letto_charl=char_of_int@@Int64.to_intlinletrecput_positive_vle_rec?size'v'=matchsize',v'with|Some(0),_->raise@@Exception(`OutOfBounds(`Msg(Printf.sprintf"encode_vle: cannot encode %Ld as a %d bytes VLE"v(Option.getsize))))|None,v'whenv'<=Vle.byte_mask->Abuf.write_byte(to_charv')buf|Some(1),v'whenv'<=Vle.byte_mask->Abuf.write_byte(to_charv')buf|_,v'->letmv=Int64.logorVle.more_bytes_flag@@Int64.logandv'Vle.byte_maskinAbuf.write_byte(to_charmv)buf;letsv=Int64.shift_rightv'Vle.shift_leninletsize'=Option.mapsize'(funs->s-1)input_positive_vle_recsv?size'inifv<0Lthenraise@@Exception(`OutOfRange(`Msg"encode_vle: integer to encode must be positive"))elseput_positive_vle_recv?size':sizeletdecode_vlebuf=letfrom_charc=Vle.of_int(int_of_charc)inletmasked_from_charc=Vle.logandVle.byte_mask(Vle.of_int(int_of_charc))inletmergevcn=Vle.logorv(Vle.shift_leftc(n*Vle.shift_len))inletrecdecode_vle_recvn=ifn<Vle.max_bytesthenbeginletc=Abuf.read_bytebufinif(from_charc)<=Vle.byte_maskthen((mergev(masked_from_charc)n))elsedecode_vle_rec(mergev(masked_from_charc)n)(n+1)endelsebeginletrecskipkbuf=letc=Abuf.read_bytebufiniffrom_charc<=Vle.byte_maskthenraise@@Exception(`OutOfBounds(`Msg"vle out of bounds"))elseskip(k+1)bufinskipnbufendindecode_vle_rec0L0letrecfast_encode_vle(v:Vle.t)buf=ifv<=0x7fLthenAbuf.write_byte(char_of_int@@Vle.to_intv)bufelsebeginletc=Vle.logor(Vle.logandv0x7fL)0x80LinAbuf.write_byte(char_of_int@@Vle.to_intc)buf;fast_encode_vle(Vle.shift_rightv7)bufendletfast_decode_vlebuf=letacc=ref0Linletc=ref0Linleti=ref0inc:=Vle.of_int@@int_of_char@@Abuf.read_bytebuf;while!c>0x7fLdoletv=Vle.logand!c0x7fLinacc:=Vle.logor!acc(Vle.shift_leftv!i);c:=Vle.of_int@@int_of_char@@Abuf.read_bytebuf;i:=!i+7done;Vle.logor!acc(Int64.shift_left!c(!i))letrecskip_vlebuf=Abuf.read_bytebuf|>Vle.of_char|>Vle.logandVle.more_bytes_flag<>0L|>function|true->skip_vlebuf|false->()letencode_bufsrcdst=letlen=Abuf.readable_bytessrcinfast_encode_vle(Vle.of_intlen)dst;Abuf.write_bufsrcdstletdecode_bufbuf=letlen=fast_decode_vlebuf|>Vle.to_intinAbuf.read_buflenbufletencode_bytesbsbuf=letlen=Bytes.lengthbsinfast_encode_vle(Vle.of_intlen)buf;Abuf.write_bytesbsbufletdecode_bytesbuf=letlen=fast_decode_vlebuf|>Vle.to_intinAbuf.read_byteslenbufletencode_abytesbsbuf=letlen=Abytes.capacitybsinfast_encode_vle(Vle.of_intlen)buf;Abuf.write_abytesbsbufletdecode_abytesbuf=letlen=fast_decode_vlebuf|>Vle.to_intinAbuf.read_abyteslenbufletencode_strings=encode_bytes(Bytes.unsafe_of_strings)letdecode_stringbuf=decode_bytesbuf|>Bytes.unsafe_to_stringletdecode_seqreadbuf=letrecget_remainingseqlength=matchlengthwith|0->seq|_->letvalue=readbufinget_remaining(value::seq)(length-1)inletlength=fast_decode_vlebufinList.rev@@get_remaining[](Vle.to_intlength)letencode_seqwriteseqbuf=letrecput_remainingseq=matchseqwith|[]->()|head::rem->writeheadbuf;put_remainingreminfast_encode_vle(Vle.of_int(List.lengthseq))buf;put_remainingseqletencode_seq_safewriteseqbuf=letrecput_remainingseqn=if(n=0x3FFF)then(* note: 0x3FFF is the biggest length we can encode in a 2-bytes vle *)(n,seq)elsematchseqwith|[]->(n,[])|head::rem->Abuf.mark_w_posbuf;trywriteheadbuf;put_remainingrem(n+1)with_->Abuf.reset_w_posbuf;(n,seq)in(* reserve space for seq length as a 2-bytes vle *)letlength_pos=Abuf.w_posbufinencode_vle~size:20Lbuf;put_remainingseq0|>fun(n,remain)->Abuf.mark_w_posbuf;Abuf.set_w_poslength_posbuf;encode_vle~size:2(Vle.of_intn)buf;Abuf.reset_w_posbuf;remainletread1_speclogp1cbuf=log;p1buf|>funa1->ca1letread2_speclogp1p2cbuf=log;p1buf|>funa1->p2buf|>funa2->ca1a2letread3_speclogp1p2p3cbuf=log;p1buf|>funa1->p2buf|>funa2->p3buf|>funa3->ca1a2a3letread4_speclogp1p2p3p4cbuf=log;p1buf|>funa1->p2buf|>funa2->p3buf|>funa3->p4buf|>funa4->ca1a2a3a4letread5_speclogp1p2p3p4p5cbuf=log;p1buf|>funa1->p2buf|>funa2->p3buf|>funa3->p4buf|>funa4->p5buf|>funa5->ca1a2a3a4a5letread6_speclogp1p2p3p4p5p6cbuf=log;p1buf|>funa1->p2buf|>funa2->p3buf|>funa3->p4buf|>funa4->p5buf|>funa5->p6buf|>funa6->ca1a2a3a4a5a6letlwt_of_result=function|Okv->Lwt.returnv|Errore->Lwt.fail@@Exceptioneletfailw_with_not_impl()=fail@@Exception`NotImplemented