123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238moduletypeT=sigtype'amessagetype'aenumtype'aoneoftype'aoneof_elemtype'amapendmoduletypeEnum=sigtypetvalname:unit->stringvalto_int:t->intvalfrom_int:int->tResult.tvalfrom_int_exn:int->tvalto_string:t->stringvalfrom_string_exn:string->tendmoduletypeMessage=sigtypettypemake_tvalname:unit->stringvalmake:make_tvalfrom_proto:Reader.t->tResult.tvalfrom_proto_exn:Reader.t->tvalto_proto:t->Writer.tvalto_proto':Writer.t->t->unitvalmerge:t->t->tvalto_json:Json_options.t->t->Json.tvalfrom_json_exn:Json.t->tvalfrom_json:Json.t->tResult.tendmoduleMake(T:T)=structtypepacked=Packed|Not_packedtypeextension_ranges=(int*int)listtypeextensions=(int*Field.t)listtype'amerge='a->'a->'atypefield=(int*string*string)typescalar=[`Scalar]typemessage=[`Message]type(_,_)spec=|Double:(float,scalar)spec|Float:(float,scalar)spec|Int32:(Int32.t,scalar)spec|UInt32:(Int32.t,scalar)spec|SInt32:(Int32.t,scalar)spec|Fixed32:(Int32.t,scalar)spec|SFixed32:(Int32.t,scalar)spec|Int32_int:(int,scalar)spec|UInt32_int:(int,scalar)spec|SInt32_int:(int,scalar)spec|Fixed32_int:(int,scalar)spec|SFixed32_int:(int,scalar)spec|UInt64:(Int64.t,scalar)spec|Int64:(Int64.t,scalar)spec|SInt64:(Int64.t,scalar)spec|Fixed64:(Int64.t,scalar)spec|SFixed64:(Int64.t,scalar)spec|UInt64_int:(int,scalar)spec|Int64_int:(int,scalar)spec|SInt64_int:(int,scalar)spec|Fixed64_int:(int,scalar)spec|SFixed64_int:(int,scalar)spec|Bool:(bool,scalar)spec|String:(string,scalar)spec|Bytes:(bytes,scalar)spec|Enum:(moduleEnumwithtypet='a)T.enum->('a,scalar)spec|Message:(moduleMessagewithtypet='a)T.message->('a,message)spectype_oneof=|Oneof_elem:field*('b,_)spec*(('b->'a)*('a->'b))T.oneof_elem->'aoneoftype'abasic='a*[`Basic]type'aany='a*[`Any]type(_,_)compound=(* A field, where the default value is know. *)|Basic:field*('a,scalar)spec*'a->('a,scalarbasic)compound(* Proto2/proto3 optional fields. *)|Basic_opt:field*('a,'b)spec->('aoption,'bbasic)compound(* Proto2 required fields (and oneof fields) *)|Basic_req:field*('a,'b)spec->('a,'bany)compound(* Repeated fields *)|Repeated:field*('a,'b)spec*packed->('alist,'bany)compound(* Map types. Should we create a message_opt type? *)|Map:field*(('a,scalar)spec*('b,'cbasic)compound)T.map->(('a*'b)list,_any)compound(* Oneofs. A list of fields + function to index the field *)|Oneof:(('aoneoflist)*('a->int))T.oneof->([>`not_set]as'a,_any)compoundtype(_,_)compound_list=(* End of list *)|Nil:('a,'a)compound_list(* Nil_ext denotes that the message contains extensions *)|Nil_ext:extension_ranges->(extensions->'a,'a)compound_list(* List element *)|Cons:(('a,_)compound)*('b,'c)compound_list->('a->'b,'c)compound_listletdouble=Doubleletfloat=Floatletint32=Int32letint64=Int64letuint32=UInt32letuint64=UInt64letsint32=SInt32letsint64=SInt64letfixed32=Fixed32letfixed64=Fixed64letsfixed32=SFixed32letsfixed64=SFixed64letint32_int=Int32_intletint64_int=Int64_intletuint32_int=UInt32_intletuint64_int=UInt64_intletsint32_int=SInt32_intletsint64_int=SInt64_intletfixed32_int=Fixed32_intletfixed64_int=Fixed64_intletsfixed32_int=SFixed32_intletsfixed64_int=SFixed64_intletbool=Boolletstring=Stringletbytes=Bytesletenume=Enumeletmessagem=Messagemletsomev=Somevletnone=Noneletdefault_bytesv=(Some(Bytes.of_stringv))letrepeated(i,s,p)=Repeated(i,s,p)letmap(i,s)=Map(i,s)letbasic(i,s,d)=Basic(i,s,d)letbasic_req(i,s)=Basic_req(i,s)letbasic_opt(i,s)=Basic_opt(i,s)letoneofs=Oneofsletoneof_elem(a,b,c)=Oneof_elem(a,b,c)letpacked=Packedletnot_packed=Not_packedlet(^::)ab=Cons(a,b)letnil=Nilletnil_extextension_ranges=Nil_extextension_rangesletshow:typeab.(a,b)spec->string=function|Double->"Double"|Float->"Float"|Int32->"Int32"|UInt32->"UInt32"|SInt32->"SInt32"|Fixed32->"Fixed32"|SFixed32->"SFixed32"|Int32_int->"Int32_int"|UInt32_int->"UInt32_int"|SInt32_int->"SInt32_int"|Fixed32_int->"Fixed32_int"|SFixed32_int->"SFixed32_int"|UInt64->"UInt64"|Int64->"Int64"|SInt64->"SInt64"|Fixed64->"Fixed64"|SFixed64->"SFixed64"|UInt64_int->"UInt64_int"|Int64_int->"Int64_int"|SInt64_int->"SInt64_int"|Fixed64_int->"Fixed64_int"|SFixed64_int->"SFixed64_int"|Bool->"Bool"|String->"String"|Bytes->"Bytes"|Enum_->"Enum"|Message_->"Message"endincludeMake(structtype'amessage='atype'aenum='atype'aoneof='atype'aoneof_elem='atype'amap='aend)letdefault_of_spec:typea.(a,scalar)spec->a=function|Double->0.0|Float->0.0|Int32->Int32.zero|UInt32->Int32.zero|SInt32->Int32.zero|Fixed32->Int32.zero|SFixed32->Int32.zero|Int32_int->0|UInt32_int->0|SInt32_int->0|Fixed32_int->0|SFixed32_int->0|Int64->Int64.zero|UInt64->Int64.zero|SInt64->Int64.zero|Fixed64->Int64.zero|SFixed64->Int64.zero|UInt64_int->0|Int64_int->0|SInt64_int->0|Fixed64_int->0|SFixed64_int->0|Bool->false|String->""|Bytes->Bytes.create0|Enum(moduleEnum)->Enum.from_int_exn0