123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384openDecodersmoduleM=MsgpckmoduleMsgpck_decodeable:Decode.Decodeablewithtypevalue=Msgpck.t=structtypevalue=Msgpck.tletppfmtt=Format.fprintffmt"@[%a@]"Msgpck.pptletof_string(input:string):(value,string)result=tryOk(snd@@M.StringBuf.readinput)withInvalid_arguments->Errorsletof_file(file:string):(value,string)result=tryOk(Decoders_util.with_file_infile(funchan->Decoders_util.read_allchan|>M.StringBuf.read|>snd))with|e->Error(Printexc.to_stringe)letget_string=functionM.Stringstr|M.Bytesstr->Somestr|_->None(* note: the other int constructors are only used for values that do
not fit in [int]. *)letget_int=functionM.Intint->Someint|_->Noneletget_float=function|M.Floatfloat->Somefloat|M.Float32f->Some(Int32.float_of_bitsf)|_->Noneletget_null=functionM.Nil->Some()|_->Noneletget_bool=functionM.Boolbool->Somebool|_->Noneletget_list=functionM.Lista->Somea|_->Noneletget_key_value_pairs=functionM.Mapassoc->Someassoc|_->Noneletto_listvs=M.ListvsendincludeDecode.Make(Msgpck_decodeable)letstring_strict:stringdecoder={run=(function|M.Stringb->Okb|m->(fail"Expected string (strict)").runm)}letbytes:stringdecoder={run=(functionM.Bytesb->Okb|m->(fail"Expected bytes").runm)}letint32:_decoder={run=(functionM.Int32i->Oki|m->(fail"Expected int32").runm)}letint64:_decoder={run=(functionM.Int64i->Oki|m->(fail"Expected int64").runm)}letuint32:_decoder={run=(functionM.Uint32i->Oki|m->(fail"Expected uint32").runm)}letuint64:_decoder={run=(functionM.Uint64i->Oki|m->(fail"Expected uint64").runm)}letext:(int*string)decoder={run=(function|M.Ext(i,s)->Ok(i,s)|m->(fail"Expected extension").runm)}