protobuf.js 272 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066
  1. /*!
  2. * protobuf.js v7.1.0 (c) 2016, daniel wirtz
  3. * compiled fri, 09 sep 2022 03:02:57 utc
  4. * licensed under the bsd-3-clause license
  5. * see: https://github.com/dcodeio/protobuf.js for details
  6. */
  7. (function(undefined){"use strict";(function prelude(modules, cache, entries) {
  8. // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
  9. // sources through a conflict-free require shim and is again wrapped within an iife that
  10. // provides a minification-friendly `undefined` var plus a global "use strict" directive
  11. // so that minification can remove the directives of each module.
  12. function $require(name) {
  13. var $module = cache[name];
  14. if (!$module)
  15. modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
  16. return $module.exports;
  17. }
  18. var protobuf = $require(entries[0]);
  19. // Expose globally
  20. protobuf.util.global.protobuf = protobuf;
  21. // Be nice to AMD
  22. if (typeof define === "function" && define.amd)
  23. define(["long"], function(Long) {
  24. if (Long && Long.isLong) {
  25. protobuf.util.Long = Long;
  26. protobuf.configure();
  27. }
  28. return protobuf;
  29. });
  30. // Be nice to CommonJS
  31. if (typeof module === "object" && module && module.exports)
  32. module.exports = protobuf;
  33. })/* end of prelude */({1:[function(require,module,exports){
  34. "use strict";
  35. module.exports = asPromise;
  36. /**
  37. * Callback as used by {@link util.asPromise}.
  38. * @typedef asPromiseCallback
  39. * @type {function}
  40. * @param {Error|null} error Error, if any
  41. * @param {...*} params Additional arguments
  42. * @returns {undefined}
  43. */
  44. /**
  45. * Returns a promise from a node-style callback function.
  46. * @memberof util
  47. * @param {asPromiseCallback} fn Function to call
  48. * @param {*} ctx Function context
  49. * @param {...*} params Function arguments
  50. * @returns {Promise<*>} Promisified function
  51. */
  52. function asPromise(fn, ctx/*, varargs */) {
  53. var params = new Array(arguments.length - 1),
  54. offset = 0,
  55. index = 2,
  56. pending = true;
  57. while (index < arguments.length)
  58. params[offset++] = arguments[index++];
  59. return new Promise(function executor(resolve, reject) {
  60. params[offset] = function callback(err/*, varargs */) {
  61. if (pending) {
  62. pending = false;
  63. if (err)
  64. reject(err);
  65. else {
  66. var params = new Array(arguments.length - 1),
  67. offset = 0;
  68. while (offset < params.length)
  69. params[offset++] = arguments[offset];
  70. resolve.apply(null, params);
  71. }
  72. }
  73. };
  74. try {
  75. fn.apply(ctx || null, params);
  76. } catch (err) {
  77. if (pending) {
  78. pending = false;
  79. reject(err);
  80. }
  81. }
  82. });
  83. }
  84. },{}],2:[function(require,module,exports){
  85. "use strict";
  86. /**
  87. * A minimal base64 implementation for number arrays.
  88. * @memberof util
  89. * @namespace
  90. */
  91. var base64 = exports;
  92. /**
  93. * Calculates the byte length of a base64 encoded string.
  94. * @param {string} string Base64 encoded string
  95. * @returns {number} Byte length
  96. */
  97. base64.length = function length(string) {
  98. var p = string.length;
  99. if (!p)
  100. return 0;
  101. var n = 0;
  102. while (--p % 4 > 1 && string.charAt(p) === "=")
  103. ++n;
  104. return Math.ceil(string.length * 3) / 4 - n;
  105. };
  106. // Base64 encoding table
  107. var b64 = new Array(64);
  108. // Base64 decoding table
  109. var s64 = new Array(123);
  110. // 65..90, 97..122, 48..57, 43, 47
  111. for (var i = 0; i < 64;)
  112. s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
  113. /**
  114. * Encodes a buffer to a base64 encoded string.
  115. * @param {Uint8Array} buffer Source buffer
  116. * @param {number} start Source start
  117. * @param {number} end Source end
  118. * @returns {string} Base64 encoded string
  119. */
  120. base64.encode = function encode(buffer, start, end) {
  121. var parts = null,
  122. chunk = [];
  123. var i = 0, // output index
  124. j = 0, // goto index
  125. t; // temporary
  126. while (start < end) {
  127. var b = buffer[start++];
  128. switch (j) {
  129. case 0:
  130. chunk[i++] = b64[b >> 2];
  131. t = (b & 3) << 4;
  132. j = 1;
  133. break;
  134. case 1:
  135. chunk[i++] = b64[t | b >> 4];
  136. t = (b & 15) << 2;
  137. j = 2;
  138. break;
  139. case 2:
  140. chunk[i++] = b64[t | b >> 6];
  141. chunk[i++] = b64[b & 63];
  142. j = 0;
  143. break;
  144. }
  145. if (i > 8191) {
  146. (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
  147. i = 0;
  148. }
  149. }
  150. if (j) {
  151. chunk[i++] = b64[t];
  152. chunk[i++] = 61;
  153. if (j === 1)
  154. chunk[i++] = 61;
  155. }
  156. if (parts) {
  157. if (i)
  158. parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
  159. return parts.join("");
  160. }
  161. return String.fromCharCode.apply(String, chunk.slice(0, i));
  162. };
  163. var invalidEncoding = "invalid encoding";
  164. /**
  165. * Decodes a base64 encoded string to a buffer.
  166. * @param {string} string Source string
  167. * @param {Uint8Array} buffer Destination buffer
  168. * @param {number} offset Destination offset
  169. * @returns {number} Number of bytes written
  170. * @throws {Error} If encoding is invalid
  171. */
  172. base64.decode = function decode(string, buffer, offset) {
  173. var start = offset;
  174. var j = 0, // goto index
  175. t; // temporary
  176. for (var i = 0; i < string.length;) {
  177. var c = string.charCodeAt(i++);
  178. if (c === 61 && j > 1)
  179. break;
  180. if ((c = s64[c]) === undefined)
  181. throw Error(invalidEncoding);
  182. switch (j) {
  183. case 0:
  184. t = c;
  185. j = 1;
  186. break;
  187. case 1:
  188. buffer[offset++] = t << 2 | (c & 48) >> 4;
  189. t = c;
  190. j = 2;
  191. break;
  192. case 2:
  193. buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
  194. t = c;
  195. j = 3;
  196. break;
  197. case 3:
  198. buffer[offset++] = (t & 3) << 6 | c;
  199. j = 0;
  200. break;
  201. }
  202. }
  203. if (j === 1)
  204. throw Error(invalidEncoding);
  205. return offset - start;
  206. };
  207. /**
  208. * Tests if the specified string appears to be base64 encoded.
  209. * @param {string} string String to test
  210. * @returns {boolean} `true` if probably base64 encoded, otherwise false
  211. */
  212. base64.test = function test(string) {
  213. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
  214. };
  215. },{}],3:[function(require,module,exports){
  216. "use strict";
  217. module.exports = codegen;
  218. /**
  219. * Begins generating a function.
  220. * @memberof util
  221. * @param {string[]} functionParams Function parameter names
  222. * @param {string} [functionName] Function name if not anonymous
  223. * @returns {Codegen} Appender that appends code to the function's body
  224. */
  225. function codegen(functionParams, functionName) {
  226. /* istanbul ignore if */
  227. if (typeof functionParams === "string") {
  228. functionName = functionParams;
  229. functionParams = undefined;
  230. }
  231. var body = [];
  232. /**
  233. * Appends code to the function's body or finishes generation.
  234. * @typedef Codegen
  235. * @type {function}
  236. * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
  237. * @param {...*} [formatParams] Format parameters
  238. * @returns {Codegen|Function} Itself or the generated function if finished
  239. * @throws {Error} If format parameter counts do not match
  240. */
  241. function Codegen(formatStringOrScope) {
  242. // note that explicit array handling below makes this ~50% faster
  243. // finish the function
  244. if (typeof formatStringOrScope !== "string") {
  245. var source = toString();
  246. if (codegen.verbose)
  247. console.log("codegen: " + source); // eslint-disable-line no-console
  248. source = "return " + source;
  249. if (formatStringOrScope) {
  250. var scopeKeys = Object.keys(formatStringOrScope),
  251. scopeParams = new Array(scopeKeys.length + 1),
  252. scopeValues = new Array(scopeKeys.length),
  253. scopeOffset = 0;
  254. while (scopeOffset < scopeKeys.length) {
  255. scopeParams[scopeOffset] = scopeKeys[scopeOffset];
  256. scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
  257. }
  258. scopeParams[scopeOffset] = source;
  259. return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
  260. }
  261. return Function(source)(); // eslint-disable-line no-new-func
  262. }
  263. // otherwise append to body
  264. var formatParams = new Array(arguments.length - 1),
  265. formatOffset = 0;
  266. while (formatOffset < formatParams.length)
  267. formatParams[formatOffset] = arguments[++formatOffset];
  268. formatOffset = 0;
  269. formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
  270. var value = formatParams[formatOffset++];
  271. switch ($1) {
  272. case "d": case "f": return String(Number(value));
  273. case "i": return String(Math.floor(value));
  274. case "j": return JSON.stringify(value);
  275. case "s": return String(value);
  276. }
  277. return "%";
  278. });
  279. if (formatOffset !== formatParams.length)
  280. throw Error("parameter count mismatch");
  281. body.push(formatStringOrScope);
  282. return Codegen;
  283. }
  284. function toString(functionNameOverride) {
  285. return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
  286. }
  287. Codegen.toString = toString;
  288. return Codegen;
  289. }
  290. /**
  291. * Begins generating a function.
  292. * @memberof util
  293. * @function codegen
  294. * @param {string} [functionName] Function name if not anonymous
  295. * @returns {Codegen} Appender that appends code to the function's body
  296. * @variation 2
  297. */
  298. /**
  299. * When set to `true`, codegen will log generated code to console. Useful for debugging.
  300. * @name util.codegen.verbose
  301. * @type {boolean}
  302. */
  303. codegen.verbose = false;
  304. },{}],4:[function(require,module,exports){
  305. "use strict";
  306. module.exports = EventEmitter;
  307. /**
  308. * Constructs a new event emitter instance.
  309. * @classdesc A minimal event emitter.
  310. * @memberof util
  311. * @constructor
  312. */
  313. function EventEmitter() {
  314. /**
  315. * Registered listeners.
  316. * @type {Object.<string,*>}
  317. * @private
  318. */
  319. this._listeners = {};
  320. }
  321. /**
  322. * Registers an event listener.
  323. * @param {string} evt Event name
  324. * @param {function} fn Listener
  325. * @param {*} [ctx] Listener context
  326. * @returns {util.EventEmitter} `this`
  327. */
  328. EventEmitter.prototype.on = function on(evt, fn, ctx) {
  329. (this._listeners[evt] || (this._listeners[evt] = [])).push({
  330. fn : fn,
  331. ctx : ctx || this
  332. });
  333. return this;
  334. };
  335. /**
  336. * Removes an event listener or any matching listeners if arguments are omitted.
  337. * @param {string} [evt] Event name. Removes all listeners if omitted.
  338. * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
  339. * @returns {util.EventEmitter} `this`
  340. */
  341. EventEmitter.prototype.off = function off(evt, fn) {
  342. if (evt === undefined)
  343. this._listeners = {};
  344. else {
  345. if (fn === undefined)
  346. this._listeners[evt] = [];
  347. else {
  348. var listeners = this._listeners[evt];
  349. for (var i = 0; i < listeners.length;)
  350. if (listeners[i].fn === fn)
  351. listeners.splice(i, 1);
  352. else
  353. ++i;
  354. }
  355. }
  356. return this;
  357. };
  358. /**
  359. * Emits an event by calling its listeners with the specified arguments.
  360. * @param {string} evt Event name
  361. * @param {...*} args Arguments
  362. * @returns {util.EventEmitter} `this`
  363. */
  364. EventEmitter.prototype.emit = function emit(evt) {
  365. var listeners = this._listeners[evt];
  366. if (listeners) {
  367. var args = [],
  368. i = 1;
  369. for (; i < arguments.length;)
  370. args.push(arguments[i++]);
  371. for (i = 0; i < listeners.length;)
  372. listeners[i].fn.apply(listeners[i++].ctx, args);
  373. }
  374. return this;
  375. };
  376. },{}],5:[function(require,module,exports){
  377. "use strict";
  378. module.exports = fetch;
  379. var asPromise = require(1),
  380. inquire = require(7);
  381. var fs = inquire("fs");
  382. /**
  383. * Node-style callback as used by {@link util.fetch}.
  384. * @typedef FetchCallback
  385. * @type {function}
  386. * @param {?Error} error Error, if any, otherwise `null`
  387. * @param {string} [contents] File contents, if there hasn't been an error
  388. * @returns {undefined}
  389. */
  390. /**
  391. * Options as used by {@link util.fetch}.
  392. * @typedef FetchOptions
  393. * @type {Object}
  394. * @property {boolean} [binary=false] Whether expecting a binary response
  395. * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
  396. */
  397. /**
  398. * Fetches the contents of a file.
  399. * @memberof util
  400. * @param {string} filename File path or url
  401. * @param {FetchOptions} options Fetch options
  402. * @param {FetchCallback} callback Callback function
  403. * @returns {undefined}
  404. */
  405. function fetch(filename, options, callback) {
  406. if (typeof options === "function") {
  407. callback = options;
  408. options = {};
  409. } else if (!options)
  410. options = {};
  411. if (!callback)
  412. return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
  413. // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
  414. if (!options.xhr && fs && fs.readFile)
  415. return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
  416. return err && typeof XMLHttpRequest !== "undefined"
  417. ? fetch.xhr(filename, options, callback)
  418. : err
  419. ? callback(err)
  420. : callback(null, options.binary ? contents : contents.toString("utf8"));
  421. });
  422. // use the XHR version otherwise.
  423. return fetch.xhr(filename, options, callback);
  424. }
  425. /**
  426. * Fetches the contents of a file.
  427. * @name util.fetch
  428. * @function
  429. * @param {string} path File path or url
  430. * @param {FetchCallback} callback Callback function
  431. * @returns {undefined}
  432. * @variation 2
  433. */
  434. /**
  435. * Fetches the contents of a file.
  436. * @name util.fetch
  437. * @function
  438. * @param {string} path File path or url
  439. * @param {FetchOptions} [options] Fetch options
  440. * @returns {Promise<string|Uint8Array>} Promise
  441. * @variation 3
  442. */
  443. /**/
  444. fetch.xhr = function fetch_xhr(filename, options, callback) {
  445. var xhr = new XMLHttpRequest();
  446. xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
  447. if (xhr.readyState !== 4)
  448. return undefined;
  449. // local cors security errors return status 0 / empty string, too. afaik this cannot be
  450. // reliably distinguished from an actually empty file for security reasons. feel free
  451. // to send a pull request if you are aware of a solution.
  452. if (xhr.status !== 0 && xhr.status !== 200)
  453. return callback(Error("status " + xhr.status));
  454. // if binary data is expected, make sure that some sort of array is returned, even if
  455. // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
  456. if (options.binary) {
  457. var buffer = xhr.response;
  458. if (!buffer) {
  459. buffer = [];
  460. for (var i = 0; i < xhr.responseText.length; ++i)
  461. buffer.push(xhr.responseText.charCodeAt(i) & 255);
  462. }
  463. return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
  464. }
  465. return callback(null, xhr.responseText);
  466. };
  467. if (options.binary) {
  468. // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
  469. if ("overrideMimeType" in xhr)
  470. xhr.overrideMimeType("text/plain; charset=x-user-defined");
  471. xhr.responseType = "arraybuffer";
  472. }
  473. xhr.open("GET", filename);
  474. xhr.send();
  475. };
  476. },{"1":1,"7":7}],6:[function(require,module,exports){
  477. "use strict";
  478. module.exports = factory(factory);
  479. /**
  480. * Reads / writes floats / doubles from / to buffers.
  481. * @name util.float
  482. * @namespace
  483. */
  484. /**
  485. * Writes a 32 bit float to a buffer using little endian byte order.
  486. * @name util.float.writeFloatLE
  487. * @function
  488. * @param {number} val Value to write
  489. * @param {Uint8Array} buf Target buffer
  490. * @param {number} pos Target buffer offset
  491. * @returns {undefined}
  492. */
  493. /**
  494. * Writes a 32 bit float to a buffer using big endian byte order.
  495. * @name util.float.writeFloatBE
  496. * @function
  497. * @param {number} val Value to write
  498. * @param {Uint8Array} buf Target buffer
  499. * @param {number} pos Target buffer offset
  500. * @returns {undefined}
  501. */
  502. /**
  503. * Reads a 32 bit float from a buffer using little endian byte order.
  504. * @name util.float.readFloatLE
  505. * @function
  506. * @param {Uint8Array} buf Source buffer
  507. * @param {number} pos Source buffer offset
  508. * @returns {number} Value read
  509. */
  510. /**
  511. * Reads a 32 bit float from a buffer using big endian byte order.
  512. * @name util.float.readFloatBE
  513. * @function
  514. * @param {Uint8Array} buf Source buffer
  515. * @param {number} pos Source buffer offset
  516. * @returns {number} Value read
  517. */
  518. /**
  519. * Writes a 64 bit double to a buffer using little endian byte order.
  520. * @name util.float.writeDoubleLE
  521. * @function
  522. * @param {number} val Value to write
  523. * @param {Uint8Array} buf Target buffer
  524. * @param {number} pos Target buffer offset
  525. * @returns {undefined}
  526. */
  527. /**
  528. * Writes a 64 bit double to a buffer using big endian byte order.
  529. * @name util.float.writeDoubleBE
  530. * @function
  531. * @param {number} val Value to write
  532. * @param {Uint8Array} buf Target buffer
  533. * @param {number} pos Target buffer offset
  534. * @returns {undefined}
  535. */
  536. /**
  537. * Reads a 64 bit double from a buffer using little endian byte order.
  538. * @name util.float.readDoubleLE
  539. * @function
  540. * @param {Uint8Array} buf Source buffer
  541. * @param {number} pos Source buffer offset
  542. * @returns {number} Value read
  543. */
  544. /**
  545. * Reads a 64 bit double from a buffer using big endian byte order.
  546. * @name util.float.readDoubleBE
  547. * @function
  548. * @param {Uint8Array} buf Source buffer
  549. * @param {number} pos Source buffer offset
  550. * @returns {number} Value read
  551. */
  552. // Factory function for the purpose of node-based testing in modified global environments
  553. function factory(exports) {
  554. // float: typed array
  555. if (typeof Float32Array !== "undefined") (function() {
  556. var f32 = new Float32Array([ -0 ]),
  557. f8b = new Uint8Array(f32.buffer),
  558. le = f8b[3] === 128;
  559. function writeFloat_f32_cpy(val, buf, pos) {
  560. f32[0] = val;
  561. buf[pos ] = f8b[0];
  562. buf[pos + 1] = f8b[1];
  563. buf[pos + 2] = f8b[2];
  564. buf[pos + 3] = f8b[3];
  565. }
  566. function writeFloat_f32_rev(val, buf, pos) {
  567. f32[0] = val;
  568. buf[pos ] = f8b[3];
  569. buf[pos + 1] = f8b[2];
  570. buf[pos + 2] = f8b[1];
  571. buf[pos + 3] = f8b[0];
  572. }
  573. /* istanbul ignore next */
  574. exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
  575. /* istanbul ignore next */
  576. exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
  577. function readFloat_f32_cpy(buf, pos) {
  578. f8b[0] = buf[pos ];
  579. f8b[1] = buf[pos + 1];
  580. f8b[2] = buf[pos + 2];
  581. f8b[3] = buf[pos + 3];
  582. return f32[0];
  583. }
  584. function readFloat_f32_rev(buf, pos) {
  585. f8b[3] = buf[pos ];
  586. f8b[2] = buf[pos + 1];
  587. f8b[1] = buf[pos + 2];
  588. f8b[0] = buf[pos + 3];
  589. return f32[0];
  590. }
  591. /* istanbul ignore next */
  592. exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
  593. /* istanbul ignore next */
  594. exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
  595. // float: ieee754
  596. })(); else (function() {
  597. function writeFloat_ieee754(writeUint, val, buf, pos) {
  598. var sign = val < 0 ? 1 : 0;
  599. if (sign)
  600. val = -val;
  601. if (val === 0)
  602. writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
  603. else if (isNaN(val))
  604. writeUint(2143289344, buf, pos);
  605. else if (val > 3.4028234663852886e+38) // +-Infinity
  606. writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
  607. else if (val < 1.1754943508222875e-38) // denormal
  608. writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
  609. else {
  610. var exponent = Math.floor(Math.log(val) / Math.LN2),
  611. mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
  612. writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
  613. }
  614. }
  615. exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
  616. exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
  617. function readFloat_ieee754(readUint, buf, pos) {
  618. var uint = readUint(buf, pos),
  619. sign = (uint >> 31) * 2 + 1,
  620. exponent = uint >>> 23 & 255,
  621. mantissa = uint & 8388607;
  622. return exponent === 255
  623. ? mantissa
  624. ? NaN
  625. : sign * Infinity
  626. : exponent === 0 // denormal
  627. ? sign * 1.401298464324817e-45 * mantissa
  628. : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
  629. }
  630. exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
  631. exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
  632. })();
  633. // double: typed array
  634. if (typeof Float64Array !== "undefined") (function() {
  635. var f64 = new Float64Array([-0]),
  636. f8b = new Uint8Array(f64.buffer),
  637. le = f8b[7] === 128;
  638. function writeDouble_f64_cpy(val, buf, pos) {
  639. f64[0] = val;
  640. buf[pos ] = f8b[0];
  641. buf[pos + 1] = f8b[1];
  642. buf[pos + 2] = f8b[2];
  643. buf[pos + 3] = f8b[3];
  644. buf[pos + 4] = f8b[4];
  645. buf[pos + 5] = f8b[5];
  646. buf[pos + 6] = f8b[6];
  647. buf[pos + 7] = f8b[7];
  648. }
  649. function writeDouble_f64_rev(val, buf, pos) {
  650. f64[0] = val;
  651. buf[pos ] = f8b[7];
  652. buf[pos + 1] = f8b[6];
  653. buf[pos + 2] = f8b[5];
  654. buf[pos + 3] = f8b[4];
  655. buf[pos + 4] = f8b[3];
  656. buf[pos + 5] = f8b[2];
  657. buf[pos + 6] = f8b[1];
  658. buf[pos + 7] = f8b[0];
  659. }
  660. /* istanbul ignore next */
  661. exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
  662. /* istanbul ignore next */
  663. exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
  664. function readDouble_f64_cpy(buf, pos) {
  665. f8b[0] = buf[pos ];
  666. f8b[1] = buf[pos + 1];
  667. f8b[2] = buf[pos + 2];
  668. f8b[3] = buf[pos + 3];
  669. f8b[4] = buf[pos + 4];
  670. f8b[5] = buf[pos + 5];
  671. f8b[6] = buf[pos + 6];
  672. f8b[7] = buf[pos + 7];
  673. return f64[0];
  674. }
  675. function readDouble_f64_rev(buf, pos) {
  676. f8b[7] = buf[pos ];
  677. f8b[6] = buf[pos + 1];
  678. f8b[5] = buf[pos + 2];
  679. f8b[4] = buf[pos + 3];
  680. f8b[3] = buf[pos + 4];
  681. f8b[2] = buf[pos + 5];
  682. f8b[1] = buf[pos + 6];
  683. f8b[0] = buf[pos + 7];
  684. return f64[0];
  685. }
  686. /* istanbul ignore next */
  687. exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
  688. /* istanbul ignore next */
  689. exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
  690. // double: ieee754
  691. })(); else (function() {
  692. function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
  693. var sign = val < 0 ? 1 : 0;
  694. if (sign)
  695. val = -val;
  696. if (val === 0) {
  697. writeUint(0, buf, pos + off0);
  698. writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
  699. } else if (isNaN(val)) {
  700. writeUint(0, buf, pos + off0);
  701. writeUint(2146959360, buf, pos + off1);
  702. } else if (val > 1.7976931348623157e+308) { // +-Infinity
  703. writeUint(0, buf, pos + off0);
  704. writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
  705. } else {
  706. var mantissa;
  707. if (val < 2.2250738585072014e-308) { // denormal
  708. mantissa = val / 5e-324;
  709. writeUint(mantissa >>> 0, buf, pos + off0);
  710. writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
  711. } else {
  712. var exponent = Math.floor(Math.log(val) / Math.LN2);
  713. if (exponent === 1024)
  714. exponent = 1023;
  715. mantissa = val * Math.pow(2, -exponent);
  716. writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
  717. writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
  718. }
  719. }
  720. }
  721. exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
  722. exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
  723. function readDouble_ieee754(readUint, off0, off1, buf, pos) {
  724. var lo = readUint(buf, pos + off0),
  725. hi = readUint(buf, pos + off1);
  726. var sign = (hi >> 31) * 2 + 1,
  727. exponent = hi >>> 20 & 2047,
  728. mantissa = 4294967296 * (hi & 1048575) + lo;
  729. return exponent === 2047
  730. ? mantissa
  731. ? NaN
  732. : sign * Infinity
  733. : exponent === 0 // denormal
  734. ? sign * 5e-324 * mantissa
  735. : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
  736. }
  737. exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
  738. exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
  739. })();
  740. return exports;
  741. }
  742. // uint helpers
  743. function writeUintLE(val, buf, pos) {
  744. buf[pos ] = val & 255;
  745. buf[pos + 1] = val >>> 8 & 255;
  746. buf[pos + 2] = val >>> 16 & 255;
  747. buf[pos + 3] = val >>> 24;
  748. }
  749. function writeUintBE(val, buf, pos) {
  750. buf[pos ] = val >>> 24;
  751. buf[pos + 1] = val >>> 16 & 255;
  752. buf[pos + 2] = val >>> 8 & 255;
  753. buf[pos + 3] = val & 255;
  754. }
  755. function readUintLE(buf, pos) {
  756. return (buf[pos ]
  757. | buf[pos + 1] << 8
  758. | buf[pos + 2] << 16
  759. | buf[pos + 3] << 24) >>> 0;
  760. }
  761. function readUintBE(buf, pos) {
  762. return (buf[pos ] << 24
  763. | buf[pos + 1] << 16
  764. | buf[pos + 2] << 8
  765. | buf[pos + 3]) >>> 0;
  766. }
  767. },{}],7:[function(require,module,exports){
  768. "use strict";
  769. module.exports = inquire;
  770. /**
  771. * Requires a module only if available.
  772. * @memberof util
  773. * @param {string} moduleName Module to require
  774. * @returns {?Object} Required module if available and not empty, otherwise `null`
  775. */
  776. function inquire(moduleName) {
  777. try {
  778. var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
  779. if (mod && (mod.length || Object.keys(mod).length))
  780. return mod;
  781. } catch (e) {} // eslint-disable-line no-empty
  782. return null;
  783. }
  784. },{}],8:[function(require,module,exports){
  785. "use strict";
  786. /**
  787. * A minimal path module to resolve Unix, Windows and URL paths alike.
  788. * @memberof util
  789. * @namespace
  790. */
  791. var path = exports;
  792. var isAbsolute =
  793. /**
  794. * Tests if the specified path is absolute.
  795. * @param {string} path Path to test
  796. * @returns {boolean} `true` if path is absolute
  797. */
  798. path.isAbsolute = function isAbsolute(path) {
  799. return /^(?:\/|\w+:)/.test(path);
  800. };
  801. var normalize =
  802. /**
  803. * Normalizes the specified path.
  804. * @param {string} path Path to normalize
  805. * @returns {string} Normalized path
  806. */
  807. path.normalize = function normalize(path) {
  808. path = path.replace(/\\/g, "/")
  809. .replace(/\/{2,}/g, "/");
  810. var parts = path.split("/"),
  811. absolute = isAbsolute(path),
  812. prefix = "";
  813. if (absolute)
  814. prefix = parts.shift() + "/";
  815. for (var i = 0; i < parts.length;) {
  816. if (parts[i] === "..") {
  817. if (i > 0 && parts[i - 1] !== "..")
  818. parts.splice(--i, 2);
  819. else if (absolute)
  820. parts.splice(i, 1);
  821. else
  822. ++i;
  823. } else if (parts[i] === ".")
  824. parts.splice(i, 1);
  825. else
  826. ++i;
  827. }
  828. return prefix + parts.join("/");
  829. };
  830. /**
  831. * Resolves the specified include path against the specified origin path.
  832. * @param {string} originPath Path to the origin file
  833. * @param {string} includePath Include path relative to origin path
  834. * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
  835. * @returns {string} Path to the include file
  836. */
  837. path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
  838. if (!alreadyNormalized)
  839. includePath = normalize(includePath);
  840. if (isAbsolute(includePath))
  841. return includePath;
  842. if (!alreadyNormalized)
  843. originPath = normalize(originPath);
  844. return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
  845. };
  846. },{}],9:[function(require,module,exports){
  847. "use strict";
  848. module.exports = pool;
  849. /**
  850. * An allocator as used by {@link util.pool}.
  851. * @typedef PoolAllocator
  852. * @type {function}
  853. * @param {number} size Buffer size
  854. * @returns {Uint8Array} Buffer
  855. */
  856. /**
  857. * A slicer as used by {@link util.pool}.
  858. * @typedef PoolSlicer
  859. * @type {function}
  860. * @param {number} start Start offset
  861. * @param {number} end End offset
  862. * @returns {Uint8Array} Buffer slice
  863. * @this {Uint8Array}
  864. */
  865. /**
  866. * A general purpose buffer pool.
  867. * @memberof util
  868. * @function
  869. * @param {PoolAllocator} alloc Allocator
  870. * @param {PoolSlicer} slice Slicer
  871. * @param {number} [size=8192] Slab size
  872. * @returns {PoolAllocator} Pooled allocator
  873. */
  874. function pool(alloc, slice, size) {
  875. var SIZE = size || 8192;
  876. var MAX = SIZE >>> 1;
  877. var slab = null;
  878. var offset = SIZE;
  879. return function pool_alloc(size) {
  880. if (size < 1 || size > MAX)
  881. return alloc(size);
  882. if (offset + size > SIZE) {
  883. slab = alloc(SIZE);
  884. offset = 0;
  885. }
  886. var buf = slice.call(slab, offset, offset += size);
  887. if (offset & 7) // align to 32 bit
  888. offset = (offset | 7) + 1;
  889. return buf;
  890. };
  891. }
  892. },{}],10:[function(require,module,exports){
  893. "use strict";
  894. /**
  895. * A minimal UTF8 implementation for number arrays.
  896. * @memberof util
  897. * @namespace
  898. */
  899. var utf8 = exports;
  900. /**
  901. * Calculates the UTF8 byte length of a string.
  902. * @param {string} string String
  903. * @returns {number} Byte length
  904. */
  905. utf8.length = function utf8_length(string) {
  906. var len = 0,
  907. c = 0;
  908. for (var i = 0; i < string.length; ++i) {
  909. c = string.charCodeAt(i);
  910. if (c < 128)
  911. len += 1;
  912. else if (c < 2048)
  913. len += 2;
  914. else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
  915. ++i;
  916. len += 4;
  917. } else
  918. len += 3;
  919. }
  920. return len;
  921. };
  922. /**
  923. * Reads UTF8 bytes as a string.
  924. * @param {Uint8Array} buffer Source buffer
  925. * @param {number} start Source start
  926. * @param {number} end Source end
  927. * @returns {string} String read
  928. */
  929. utf8.read = function utf8_read(buffer, start, end) {
  930. var len = end - start;
  931. if (len < 1)
  932. return "";
  933. var parts = null,
  934. chunk = [],
  935. i = 0, // char offset
  936. t; // temporary
  937. while (start < end) {
  938. t = buffer[start++];
  939. if (t < 128)
  940. chunk[i++] = t;
  941. else if (t > 191 && t < 224)
  942. chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
  943. else if (t > 239 && t < 365) {
  944. t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
  945. chunk[i++] = 0xD800 + (t >> 10);
  946. chunk[i++] = 0xDC00 + (t & 1023);
  947. } else
  948. chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
  949. if (i > 8191) {
  950. (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
  951. i = 0;
  952. }
  953. }
  954. if (parts) {
  955. if (i)
  956. parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
  957. return parts.join("");
  958. }
  959. return String.fromCharCode.apply(String, chunk.slice(0, i));
  960. };
  961. /**
  962. * Writes a string as UTF8 bytes.
  963. * @param {string} string Source string
  964. * @param {Uint8Array} buffer Destination buffer
  965. * @param {number} offset Destination offset
  966. * @returns {number} Bytes written
  967. */
  968. utf8.write = function utf8_write(string, buffer, offset) {
  969. var start = offset,
  970. c1, // character 1
  971. c2; // character 2
  972. for (var i = 0; i < string.length; ++i) {
  973. c1 = string.charCodeAt(i);
  974. if (c1 < 128) {
  975. buffer[offset++] = c1;
  976. } else if (c1 < 2048) {
  977. buffer[offset++] = c1 >> 6 | 192;
  978. buffer[offset++] = c1 & 63 | 128;
  979. } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
  980. c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
  981. ++i;
  982. buffer[offset++] = c1 >> 18 | 240;
  983. buffer[offset++] = c1 >> 12 & 63 | 128;
  984. buffer[offset++] = c1 >> 6 & 63 | 128;
  985. buffer[offset++] = c1 & 63 | 128;
  986. } else {
  987. buffer[offset++] = c1 >> 12 | 224;
  988. buffer[offset++] = c1 >> 6 & 63 | 128;
  989. buffer[offset++] = c1 & 63 | 128;
  990. }
  991. }
  992. return offset - start;
  993. };
  994. },{}],11:[function(require,module,exports){
  995. "use strict";
  996. module.exports = common;
  997. var commonRe = /\/|\./;
  998. /**
  999. * Provides common type definitions.
  1000. * Can also be used to provide additional google types or your own custom types.
  1001. * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name
  1002. * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
  1003. * @returns {undefined}
  1004. * @property {INamespace} google/protobuf/any.proto Any
  1005. * @property {INamespace} google/protobuf/duration.proto Duration
  1006. * @property {INamespace} google/protobuf/empty.proto Empty
  1007. * @property {INamespace} google/protobuf/field_mask.proto FieldMask
  1008. * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
  1009. * @property {INamespace} google/protobuf/timestamp.proto Timestamp
  1010. * @property {INamespace} google/protobuf/wrappers.proto Wrappers
  1011. * @example
  1012. * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension)
  1013. * protobuf.common("descriptor", descriptorJson);
  1014. *
  1015. * // manually provides a custom definition (uses my.foo namespace)
  1016. * protobuf.common("my/foo/bar.proto", myFooBarJson);
  1017. */
  1018. function common(name, json) {
  1019. if (!commonRe.test(name)) {
  1020. name = "google/protobuf/" + name + ".proto";
  1021. json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
  1022. }
  1023. common[name] = json;
  1024. }
  1025. // Not provided because of limited use (feel free to discuss or to provide yourself):
  1026. //
  1027. // google/protobuf/descriptor.proto
  1028. // google/protobuf/source_context.proto
  1029. // google/protobuf/type.proto
  1030. //
  1031. // Stripped and pre-parsed versions of these non-bundled files are instead available as part of
  1032. // the repository or package within the google/protobuf directory.
  1033. common("any", {
  1034. /**
  1035. * Properties of a google.protobuf.Any message.
  1036. * @interface IAny
  1037. * @type {Object}
  1038. * @property {string} [typeUrl]
  1039. * @property {Uint8Array} [bytes]
  1040. * @memberof common
  1041. */
  1042. Any: {
  1043. fields: {
  1044. type_url: {
  1045. type: "string",
  1046. id: 1
  1047. },
  1048. value: {
  1049. type: "bytes",
  1050. id: 2
  1051. }
  1052. }
  1053. }
  1054. });
  1055. var timeType;
  1056. common("duration", {
  1057. /**
  1058. * Properties of a google.protobuf.Duration message.
  1059. * @interface IDuration
  1060. * @type {Object}
  1061. * @property {number|Long} [seconds]
  1062. * @property {number} [nanos]
  1063. * @memberof common
  1064. */
  1065. Duration: timeType = {
  1066. fields: {
  1067. seconds: {
  1068. type: "int64",
  1069. id: 1
  1070. },
  1071. nanos: {
  1072. type: "int32",
  1073. id: 2
  1074. }
  1075. }
  1076. }
  1077. });
  1078. common("timestamp", {
  1079. /**
  1080. * Properties of a google.protobuf.Timestamp message.
  1081. * @interface ITimestamp
  1082. * @type {Object}
  1083. * @property {number|Long} [seconds]
  1084. * @property {number} [nanos]
  1085. * @memberof common
  1086. */
  1087. Timestamp: timeType
  1088. });
  1089. common("empty", {
  1090. /**
  1091. * Properties of a google.protobuf.Empty message.
  1092. * @interface IEmpty
  1093. * @memberof common
  1094. */
  1095. Empty: {
  1096. fields: {}
  1097. }
  1098. });
  1099. common("struct", {
  1100. /**
  1101. * Properties of a google.protobuf.Struct message.
  1102. * @interface IStruct
  1103. * @type {Object}
  1104. * @property {Object.<string,IValue>} [fields]
  1105. * @memberof common
  1106. */
  1107. Struct: {
  1108. fields: {
  1109. fields: {
  1110. keyType: "string",
  1111. type: "Value",
  1112. id: 1
  1113. }
  1114. }
  1115. },
  1116. /**
  1117. * Properties of a google.protobuf.Value message.
  1118. * @interface IValue
  1119. * @type {Object}
  1120. * @property {string} [kind]
  1121. * @property {0} [nullValue]
  1122. * @property {number} [numberValue]
  1123. * @property {string} [stringValue]
  1124. * @property {boolean} [boolValue]
  1125. * @property {IStruct} [structValue]
  1126. * @property {IListValue} [listValue]
  1127. * @memberof common
  1128. */
  1129. Value: {
  1130. oneofs: {
  1131. kind: {
  1132. oneof: [
  1133. "nullValue",
  1134. "numberValue",
  1135. "stringValue",
  1136. "boolValue",
  1137. "structValue",
  1138. "listValue"
  1139. ]
  1140. }
  1141. },
  1142. fields: {
  1143. nullValue: {
  1144. type: "NullValue",
  1145. id: 1
  1146. },
  1147. numberValue: {
  1148. type: "double",
  1149. id: 2
  1150. },
  1151. stringValue: {
  1152. type: "string",
  1153. id: 3
  1154. },
  1155. boolValue: {
  1156. type: "bool",
  1157. id: 4
  1158. },
  1159. structValue: {
  1160. type: "Struct",
  1161. id: 5
  1162. },
  1163. listValue: {
  1164. type: "ListValue",
  1165. id: 6
  1166. }
  1167. }
  1168. },
  1169. NullValue: {
  1170. values: {
  1171. NULL_VALUE: 0
  1172. }
  1173. },
  1174. /**
  1175. * Properties of a google.protobuf.ListValue message.
  1176. * @interface IListValue
  1177. * @type {Object}
  1178. * @property {Array.<IValue>} [values]
  1179. * @memberof common
  1180. */
  1181. ListValue: {
  1182. fields: {
  1183. values: {
  1184. rule: "repeated",
  1185. type: "Value",
  1186. id: 1
  1187. }
  1188. }
  1189. }
  1190. });
  1191. common("wrappers", {
  1192. /**
  1193. * Properties of a google.protobuf.DoubleValue message.
  1194. * @interface IDoubleValue
  1195. * @type {Object}
  1196. * @property {number} [value]
  1197. * @memberof common
  1198. */
  1199. DoubleValue: {
  1200. fields: {
  1201. value: {
  1202. type: "double",
  1203. id: 1
  1204. }
  1205. }
  1206. },
  1207. /**
  1208. * Properties of a google.protobuf.FloatValue message.
  1209. * @interface IFloatValue
  1210. * @type {Object}
  1211. * @property {number} [value]
  1212. * @memberof common
  1213. */
  1214. FloatValue: {
  1215. fields: {
  1216. value: {
  1217. type: "float",
  1218. id: 1
  1219. }
  1220. }
  1221. },
  1222. /**
  1223. * Properties of a google.protobuf.Int64Value message.
  1224. * @interface IInt64Value
  1225. * @type {Object}
  1226. * @property {number|Long} [value]
  1227. * @memberof common
  1228. */
  1229. Int64Value: {
  1230. fields: {
  1231. value: {
  1232. type: "int64",
  1233. id: 1
  1234. }
  1235. }
  1236. },
  1237. /**
  1238. * Properties of a google.protobuf.UInt64Value message.
  1239. * @interface IUInt64Value
  1240. * @type {Object}
  1241. * @property {number|Long} [value]
  1242. * @memberof common
  1243. */
  1244. UInt64Value: {
  1245. fields: {
  1246. value: {
  1247. type: "uint64",
  1248. id: 1
  1249. }
  1250. }
  1251. },
  1252. /**
  1253. * Properties of a google.protobuf.Int32Value message.
  1254. * @interface IInt32Value
  1255. * @type {Object}
  1256. * @property {number} [value]
  1257. * @memberof common
  1258. */
  1259. Int32Value: {
  1260. fields: {
  1261. value: {
  1262. type: "int32",
  1263. id: 1
  1264. }
  1265. }
  1266. },
  1267. /**
  1268. * Properties of a google.protobuf.UInt32Value message.
  1269. * @interface IUInt32Value
  1270. * @type {Object}
  1271. * @property {number} [value]
  1272. * @memberof common
  1273. */
  1274. UInt32Value: {
  1275. fields: {
  1276. value: {
  1277. type: "uint32",
  1278. id: 1
  1279. }
  1280. }
  1281. },
  1282. /**
  1283. * Properties of a google.protobuf.BoolValue message.
  1284. * @interface IBoolValue
  1285. * @type {Object}
  1286. * @property {boolean} [value]
  1287. * @memberof common
  1288. */
  1289. BoolValue: {
  1290. fields: {
  1291. value: {
  1292. type: "bool",
  1293. id: 1
  1294. }
  1295. }
  1296. },
  1297. /**
  1298. * Properties of a google.protobuf.StringValue message.
  1299. * @interface IStringValue
  1300. * @type {Object}
  1301. * @property {string} [value]
  1302. * @memberof common
  1303. */
  1304. StringValue: {
  1305. fields: {
  1306. value: {
  1307. type: "string",
  1308. id: 1
  1309. }
  1310. }
  1311. },
  1312. /**
  1313. * Properties of a google.protobuf.BytesValue message.
  1314. * @interface IBytesValue
  1315. * @type {Object}
  1316. * @property {Uint8Array} [value]
  1317. * @memberof common
  1318. */
  1319. BytesValue: {
  1320. fields: {
  1321. value: {
  1322. type: "bytes",
  1323. id: 1
  1324. }
  1325. }
  1326. }
  1327. });
  1328. common("field_mask", {
  1329. /**
  1330. * Properties of a google.protobuf.FieldMask message.
  1331. * @interface IDoubleValue
  1332. * @type {Object}
  1333. * @property {number} [value]
  1334. * @memberof common
  1335. */
  1336. FieldMask: {
  1337. fields: {
  1338. paths: {
  1339. rule: "repeated",
  1340. type: "string",
  1341. id: 1
  1342. }
  1343. }
  1344. }
  1345. });
  1346. /**
  1347. * Gets the root definition of the specified common proto file.
  1348. *
  1349. * Bundled definitions are:
  1350. * - google/protobuf/any.proto
  1351. * - google/protobuf/duration.proto
  1352. * - google/protobuf/empty.proto
  1353. * - google/protobuf/field_mask.proto
  1354. * - google/protobuf/struct.proto
  1355. * - google/protobuf/timestamp.proto
  1356. * - google/protobuf/wrappers.proto
  1357. *
  1358. * @param {string} file Proto file name
  1359. * @returns {INamespace|null} Root definition or `null` if not defined
  1360. */
  1361. common.get = function get(file) {
  1362. return common[file] || null;
  1363. };
  1364. },{}],12:[function(require,module,exports){
  1365. "use strict";
  1366. /**
  1367. * Runtime message from/to plain object converters.
  1368. * @namespace
  1369. */
  1370. var converter = exports;
  1371. var Enum = require(15),
  1372. util = require(37);
  1373. /**
  1374. * Generates a partial value fromObject conveter.
  1375. * @param {Codegen} gen Codegen instance
  1376. * @param {Field} field Reflected field
  1377. * @param {number} fieldIndex Field index
  1378. * @param {string} prop Property reference
  1379. * @returns {Codegen} Codegen instance
  1380. * @ignore
  1381. */
  1382. function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
  1383. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1384. if (field.resolvedType) {
  1385. if (field.resolvedType instanceof Enum) { gen
  1386. ("switch(d%s){", prop);
  1387. for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
  1388. // enum unknown values passthrough
  1389. if (values[keys[i]] === field.typeDefault) { gen
  1390. ("default:")
  1391. ("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
  1392. if (!field.repeated) gen // fallback to default value only for
  1393. // arrays, to avoid leaving holes.
  1394. ("break"); // for non-repeated fields, just ignore
  1395. }
  1396. gen
  1397. ("case%j:", keys[i])
  1398. ("case %i:", values[keys[i]])
  1399. ("m%s=%j", prop, values[keys[i]])
  1400. ("break");
  1401. } gen
  1402. ("}");
  1403. } else gen
  1404. ("if(typeof d%s!==\"object\")", prop)
  1405. ("throw TypeError(%j)", field.fullName + ": object expected")
  1406. ("m%s=types[%i].fromObject(d%s)", prop, fieldIndex, prop);
  1407. } else {
  1408. var isUnsigned = false;
  1409. switch (field.type) {
  1410. case "double":
  1411. case "float": gen
  1412. ("m%s=Number(d%s)", prop, prop); // also catches "NaN", "Infinity"
  1413. break;
  1414. case "uint32":
  1415. case "fixed32": gen
  1416. ("m%s=d%s>>>0", prop, prop);
  1417. break;
  1418. case "int32":
  1419. case "sint32":
  1420. case "sfixed32": gen
  1421. ("m%s=d%s|0", prop, prop);
  1422. break;
  1423. case "uint64":
  1424. isUnsigned = true;
  1425. // eslint-disable-line no-fallthrough
  1426. case "int64":
  1427. case "sint64":
  1428. case "fixed64":
  1429. case "sfixed64": gen
  1430. ("if(util.Long)")
  1431. ("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned)
  1432. ("else if(typeof d%s===\"string\")", prop)
  1433. ("m%s=parseInt(d%s,10)", prop, prop)
  1434. ("else if(typeof d%s===\"number\")", prop)
  1435. ("m%s=d%s", prop, prop)
  1436. ("else if(typeof d%s===\"object\")", prop)
  1437. ("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
  1438. break;
  1439. case "bytes": gen
  1440. ("if(typeof d%s===\"string\")", prop)
  1441. ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
  1442. ("else if(d%s.length >= 0)", prop)
  1443. ("m%s=d%s", prop, prop);
  1444. break;
  1445. case "string": gen
  1446. ("m%s=String(d%s)", prop, prop);
  1447. break;
  1448. case "bool": gen
  1449. ("m%s=Boolean(d%s)", prop, prop);
  1450. break;
  1451. /* default: gen
  1452. ("m%s=d%s", prop, prop);
  1453. break; */
  1454. }
  1455. }
  1456. return gen;
  1457. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1458. }
  1459. /**
  1460. * Generates a plain object to runtime message converter specific to the specified message type.
  1461. * @param {Type} mtype Message type
  1462. * @returns {Codegen} Codegen instance
  1463. */
  1464. converter.fromObject = function fromObject(mtype) {
  1465. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1466. var fields = mtype.fieldsArray;
  1467. var gen = util.codegen(["d"], mtype.name + "$fromObject")
  1468. ("if(d instanceof this.ctor)")
  1469. ("return d");
  1470. if (!fields.length) return gen
  1471. ("return new this.ctor");
  1472. gen
  1473. ("var m=new this.ctor");
  1474. for (var i = 0; i < fields.length; ++i) {
  1475. var field = fields[i].resolve(),
  1476. prop = util.safeProp(field.name);
  1477. // Map fields
  1478. if (field.map) { gen
  1479. ("if(d%s){", prop)
  1480. ("if(typeof d%s!==\"object\")", prop)
  1481. ("throw TypeError(%j)", field.fullName + ": object expected")
  1482. ("m%s={}", prop)
  1483. ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
  1484. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")
  1485. ("}")
  1486. ("}");
  1487. // Repeated fields
  1488. } else if (field.repeated) { gen
  1489. ("if(d%s){", prop)
  1490. ("if(!Array.isArray(d%s))", prop)
  1491. ("throw TypeError(%j)", field.fullName + ": array expected")
  1492. ("m%s=[]", prop)
  1493. ("for(var i=0;i<d%s.length;++i){", prop);
  1494. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
  1495. ("}")
  1496. ("}");
  1497. // Non-repeated fields
  1498. } else {
  1499. if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch)
  1500. ("if(d%s!=null){", prop); // !== undefined && !== null
  1501. genValuePartial_fromObject(gen, field, /* not sorted */ i, prop);
  1502. if (!(field.resolvedType instanceof Enum)) gen
  1503. ("}");
  1504. }
  1505. } return gen
  1506. ("return m");
  1507. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1508. };
  1509. /**
  1510. * Generates a partial value toObject converter.
  1511. * @param {Codegen} gen Codegen instance
  1512. * @param {Field} field Reflected field
  1513. * @param {number} fieldIndex Field index
  1514. * @param {string} prop Property reference
  1515. * @returns {Codegen} Codegen instance
  1516. * @ignore
  1517. */
  1518. function genValuePartial_toObject(gen, field, fieldIndex, prop) {
  1519. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1520. if (field.resolvedType) {
  1521. if (field.resolvedType instanceof Enum) gen
  1522. ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
  1523. else gen
  1524. ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
  1525. } else {
  1526. var isUnsigned = false;
  1527. switch (field.type) {
  1528. case "double":
  1529. case "float": gen
  1530. ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", prop, prop, prop, prop);
  1531. break;
  1532. case "uint64":
  1533. isUnsigned = true;
  1534. // eslint-disable-line no-fallthrough
  1535. case "int64":
  1536. case "sint64":
  1537. case "fixed64":
  1538. case "sfixed64": gen
  1539. ("if(typeof m%s===\"number\")", prop)
  1540. ("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
  1541. ("else") // Long-like
  1542. ("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
  1543. break;
  1544. case "bytes": gen
  1545. ("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", prop, prop, prop, prop, prop);
  1546. break;
  1547. default: gen
  1548. ("d%s=m%s", prop, prop);
  1549. break;
  1550. }
  1551. }
  1552. return gen;
  1553. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1554. }
  1555. /**
  1556. * Generates a runtime message to plain object converter specific to the specified message type.
  1557. * @param {Type} mtype Message type
  1558. * @returns {Codegen} Codegen instance
  1559. */
  1560. converter.toObject = function toObject(mtype) {
  1561. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1562. var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);
  1563. if (!fields.length)
  1564. return util.codegen()("return {}");
  1565. var gen = util.codegen(["m", "o"], mtype.name + "$toObject")
  1566. ("if(!o)")
  1567. ("o={}")
  1568. ("var d={}");
  1569. var repeatedFields = [],
  1570. mapFields = [],
  1571. normalFields = [],
  1572. i = 0;
  1573. for (; i < fields.length; ++i)
  1574. if (!fields[i].partOf)
  1575. ( fields[i].resolve().repeated ? repeatedFields
  1576. : fields[i].map ? mapFields
  1577. : normalFields).push(fields[i]);
  1578. if (repeatedFields.length) { gen
  1579. ("if(o.arrays||o.defaults){");
  1580. for (i = 0; i < repeatedFields.length; ++i) gen
  1581. ("d%s=[]", util.safeProp(repeatedFields[i].name));
  1582. gen
  1583. ("}");
  1584. }
  1585. if (mapFields.length) { gen
  1586. ("if(o.objects||o.defaults){");
  1587. for (i = 0; i < mapFields.length; ++i) gen
  1588. ("d%s={}", util.safeProp(mapFields[i].name));
  1589. gen
  1590. ("}");
  1591. }
  1592. if (normalFields.length) { gen
  1593. ("if(o.defaults){");
  1594. for (i = 0; i < normalFields.length; ++i) {
  1595. var field = normalFields[i],
  1596. prop = util.safeProp(field.name);
  1597. if (field.resolvedType instanceof Enum) gen
  1598. ("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
  1599. else if (field.long) gen
  1600. ("if(util.Long){")
  1601. ("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
  1602. ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
  1603. ("}else")
  1604. ("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
  1605. else if (field.bytes) {
  1606. var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
  1607. gen
  1608. ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
  1609. ("else{")
  1610. ("d%s=%s", prop, arrayDefault)
  1611. ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
  1612. ("}");
  1613. } else gen
  1614. ("d%s=%j", prop, field.typeDefault); // also messages (=null)
  1615. } gen
  1616. ("}");
  1617. }
  1618. var hasKs2 = false;
  1619. for (i = 0; i < fields.length; ++i) {
  1620. var field = fields[i],
  1621. index = mtype._fieldsArray.indexOf(field),
  1622. prop = util.safeProp(field.name);
  1623. if (field.map) {
  1624. if (!hasKs2) { hasKs2 = true; gen
  1625. ("var ks2");
  1626. } gen
  1627. ("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)
  1628. ("d%s={}", prop)
  1629. ("for(var j=0;j<ks2.length;++j){");
  1630. genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[ks2[j]]")
  1631. ("}");
  1632. } else if (field.repeated) { gen
  1633. ("if(m%s&&m%s.length){", prop, prop)
  1634. ("d%s=[]", prop)
  1635. ("for(var j=0;j<m%s.length;++j){", prop);
  1636. genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
  1637. ("}");
  1638. } else { gen
  1639. ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null
  1640. genValuePartial_toObject(gen, field, /* sorted */ index, prop);
  1641. if (field.partOf) gen
  1642. ("if(o.oneofs)")
  1643. ("d%s=%j", util.safeProp(field.partOf.name), field.name);
  1644. }
  1645. gen
  1646. ("}");
  1647. }
  1648. return gen
  1649. ("return d");
  1650. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1651. };
  1652. },{"15":15,"37":37}],13:[function(require,module,exports){
  1653. "use strict";
  1654. module.exports = decoder;
  1655. var Enum = require(15),
  1656. types = require(36),
  1657. util = require(37);
  1658. function missing(field) {
  1659. return "missing required '" + field.name + "'";
  1660. }
  1661. /**
  1662. * Generates a decoder specific to the specified message type.
  1663. * @param {Type} mtype Message type
  1664. * @returns {Codegen} Codegen instance
  1665. */
  1666. function decoder(mtype) {
  1667. /* eslint-disable no-unexpected-multiline */
  1668. var gen = util.codegen(["r", "l"], mtype.name + "$decode")
  1669. ("if(!(r instanceof Reader))")
  1670. ("r=Reader.create(r)")
  1671. ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
  1672. ("while(r.pos<c){")
  1673. ("var t=r.uint32()");
  1674. if (mtype.group) gen
  1675. ("if((t&7)===4)")
  1676. ("break");
  1677. gen
  1678. ("switch(t>>>3){");
  1679. var i = 0;
  1680. for (; i < /* initializes */ mtype.fieldsArray.length; ++i) {
  1681. var field = mtype._fieldsArray[i].resolve(),
  1682. type = field.resolvedType instanceof Enum ? "int32" : field.type,
  1683. ref = "m" + util.safeProp(field.name); gen
  1684. ("case %i: {", field.id);
  1685. // Map fields
  1686. if (field.map) { gen
  1687. ("if(%s===util.emptyObject)", ref)
  1688. ("%s={}", ref)
  1689. ("var c2 = r.uint32()+r.pos");
  1690. if (types.defaults[field.keyType] !== undefined) gen
  1691. ("k=%j", types.defaults[field.keyType]);
  1692. else gen
  1693. ("k=null");
  1694. if (types.defaults[type] !== undefined) gen
  1695. ("value=%j", types.defaults[type]);
  1696. else gen
  1697. ("value=null");
  1698. gen
  1699. ("while(r.pos<c2){")
  1700. ("var tag2=r.uint32()")
  1701. ("switch(tag2>>>3){")
  1702. ("case 1: k=r.%s(); break", field.keyType)
  1703. ("case 2:");
  1704. if (types.basic[type] === undefined) gen
  1705. ("value=types[%i].decode(r,r.uint32())", i); // can't be groups
  1706. else gen
  1707. ("value=r.%s()", type);
  1708. gen
  1709. ("break")
  1710. ("default:")
  1711. ("r.skipType(tag2&7)")
  1712. ("break")
  1713. ("}")
  1714. ("}");
  1715. if (types.long[field.keyType] !== undefined) gen
  1716. ("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
  1717. else gen
  1718. ("%s[k]=value", ref);
  1719. // Repeated fields
  1720. } else if (field.repeated) { gen
  1721. ("if(!(%s&&%s.length))", ref, ref)
  1722. ("%s=[]", ref);
  1723. // Packable (always check for forward and backward compatiblity)
  1724. if (types.packed[type] !== undefined) gen
  1725. ("if((t&7)===2){")
  1726. ("var c2=r.uint32()+r.pos")
  1727. ("while(r.pos<c2)")
  1728. ("%s.push(r.%s())", ref, type)
  1729. ("}else");
  1730. // Non-packed
  1731. if (types.basic[type] === undefined) gen(field.resolvedType.group
  1732. ? "%s.push(types[%i].decode(r))"
  1733. : "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
  1734. else gen
  1735. ("%s.push(r.%s())", ref, type);
  1736. // Non-repeated
  1737. } else if (types.basic[type] === undefined) gen(field.resolvedType.group
  1738. ? "%s=types[%i].decode(r)"
  1739. : "%s=types[%i].decode(r,r.uint32())", ref, i);
  1740. else gen
  1741. ("%s=r.%s()", ref, type);
  1742. gen
  1743. ("break")
  1744. ("}");
  1745. // Unknown fields
  1746. } gen
  1747. ("default:")
  1748. ("r.skipType(t&7)")
  1749. ("break")
  1750. ("}")
  1751. ("}");
  1752. // Field presence
  1753. for (i = 0; i < mtype._fieldsArray.length; ++i) {
  1754. var rfield = mtype._fieldsArray[i];
  1755. if (rfield.required) gen
  1756. ("if(!m.hasOwnProperty(%j))", rfield.name)
  1757. ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
  1758. }
  1759. return gen
  1760. ("return m");
  1761. /* eslint-enable no-unexpected-multiline */
  1762. }
  1763. },{"15":15,"36":36,"37":37}],14:[function(require,module,exports){
  1764. "use strict";
  1765. module.exports = encoder;
  1766. var Enum = require(15),
  1767. types = require(36),
  1768. util = require(37);
  1769. /**
  1770. * Generates a partial message type encoder.
  1771. * @param {Codegen} gen Codegen instance
  1772. * @param {Field} field Reflected field
  1773. * @param {number} fieldIndex Field index
  1774. * @param {string} ref Variable reference
  1775. * @returns {Codegen} Codegen instance
  1776. * @ignore
  1777. */
  1778. function genTypePartial(gen, field, fieldIndex, ref) {
  1779. return field.resolvedType.group
  1780. ? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
  1781. : gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
  1782. }
  1783. /**
  1784. * Generates an encoder specific to the specified message type.
  1785. * @param {Type} mtype Message type
  1786. * @returns {Codegen} Codegen instance
  1787. */
  1788. function encoder(mtype) {
  1789. /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1790. var gen = util.codegen(["m", "w"], mtype.name + "$encode")
  1791. ("if(!w)")
  1792. ("w=Writer.create()");
  1793. var i, ref;
  1794. // "when a message is serialized its known fields should be written sequentially by field number"
  1795. var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);
  1796. for (var i = 0; i < fields.length; ++i) {
  1797. var field = fields[i].resolve(),
  1798. index = mtype._fieldsArray.indexOf(field),
  1799. type = field.resolvedType instanceof Enum ? "int32" : field.type,
  1800. wireType = types.basic[type];
  1801. ref = "m" + util.safeProp(field.name);
  1802. // Map fields
  1803. if (field.map) {
  1804. gen
  1805. ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name) // !== undefined && !== null
  1806. ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
  1807. ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
  1808. if (wireType === undefined) gen
  1809. ("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
  1810. else gen
  1811. (".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
  1812. gen
  1813. ("}")
  1814. ("}");
  1815. // Repeated fields
  1816. } else if (field.repeated) { gen
  1817. ("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null
  1818. // Packed repeated
  1819. if (field.packed && types.packed[type] !== undefined) { gen
  1820. ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
  1821. ("for(var i=0;i<%s.length;++i)", ref)
  1822. ("w.%s(%s[i])", type, ref)
  1823. ("w.ldelim()");
  1824. // Non-packed
  1825. } else { gen
  1826. ("for(var i=0;i<%s.length;++i)", ref);
  1827. if (wireType === undefined)
  1828. genTypePartial(gen, field, index, ref + "[i]");
  1829. else gen
  1830. ("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
  1831. } gen
  1832. ("}");
  1833. // Non-repeated
  1834. } else {
  1835. if (field.optional) gen
  1836. ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
  1837. if (wireType === undefined)
  1838. genTypePartial(gen, field, index, ref);
  1839. else gen
  1840. ("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
  1841. }
  1842. }
  1843. return gen
  1844. ("return w");
  1845. /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
  1846. }
  1847. },{"15":15,"36":36,"37":37}],15:[function(require,module,exports){
  1848. "use strict";
  1849. module.exports = Enum;
  1850. // extends ReflectionObject
  1851. var ReflectionObject = require(24);
  1852. ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
  1853. var Namespace = require(23),
  1854. util = require(37);
  1855. /**
  1856. * Constructs a new enum instance.
  1857. * @classdesc Reflected enum.
  1858. * @extends ReflectionObject
  1859. * @constructor
  1860. * @param {string} name Unique name within its namespace
  1861. * @param {Object.<string,number>} [values] Enum values as an object, by name
  1862. * @param {Object.<string,*>} [options] Declared options
  1863. * @param {string} [comment] The comment for this enum
  1864. * @param {Object.<string,string>} [comments] The value comments for this enum
  1865. * @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
  1866. */
  1867. function Enum(name, values, options, comment, comments, valuesOptions) {
  1868. ReflectionObject.call(this, name, options);
  1869. if (values && typeof values !== "object")
  1870. throw TypeError("values must be an object");
  1871. /**
  1872. * Enum values by id.
  1873. * @type {Object.<number,string>}
  1874. */
  1875. this.valuesById = {};
  1876. /**
  1877. * Enum values by name.
  1878. * @type {Object.<string,number>}
  1879. */
  1880. this.values = Object.create(this.valuesById); // toJSON, marker
  1881. /**
  1882. * Enum comment text.
  1883. * @type {string|null}
  1884. */
  1885. this.comment = comment;
  1886. /**
  1887. * Value comment texts, if any.
  1888. * @type {Object.<string,string>}
  1889. */
  1890. this.comments = comments || {};
  1891. /**
  1892. * Values options, if any
  1893. * @type {Object<string, Object<string, *>>|undefined}
  1894. */
  1895. this.valuesOptions = valuesOptions;
  1896. /**
  1897. * Reserved ranges, if any.
  1898. * @type {Array.<number[]|string>}
  1899. */
  1900. this.reserved = undefined; // toJSON
  1901. // Note that values inherit valuesById on their prototype which makes them a TypeScript-
  1902. // compatible enum. This is used by pbts to write actual enum definitions that work for
  1903. // static and reflection code alike instead of emitting generic object definitions.
  1904. if (values)
  1905. for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
  1906. if (typeof values[keys[i]] === "number") // use forward entries only
  1907. this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
  1908. }
  1909. /**
  1910. * Enum descriptor.
  1911. * @interface IEnum
  1912. * @property {Object.<string,number>} values Enum values
  1913. * @property {Object.<string,*>} [options] Enum options
  1914. */
  1915. /**
  1916. * Constructs an enum from an enum descriptor.
  1917. * @param {string} name Enum name
  1918. * @param {IEnum} json Enum descriptor
  1919. * @returns {Enum} Created enum
  1920. * @throws {TypeError} If arguments are invalid
  1921. */
  1922. Enum.fromJSON = function fromJSON(name, json) {
  1923. var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
  1924. enm.reserved = json.reserved;
  1925. return enm;
  1926. };
  1927. /**
  1928. * Converts this enum to an enum descriptor.
  1929. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  1930. * @returns {IEnum} Enum descriptor
  1931. */
  1932. Enum.prototype.toJSON = function toJSON(toJSONOptions) {
  1933. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  1934. return util.toObject([
  1935. "options" , this.options,
  1936. "valuesOptions" , this.valuesOptions,
  1937. "values" , this.values,
  1938. "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
  1939. "comment" , keepComments ? this.comment : undefined,
  1940. "comments" , keepComments ? this.comments : undefined
  1941. ]);
  1942. };
  1943. /**
  1944. * Adds a value to this enum.
  1945. * @param {string} name Value name
  1946. * @param {number} id Value id
  1947. * @param {string} [comment] Comment, if any
  1948. * @param {Object.<string, *>|undefined} [options] Options, if any
  1949. * @returns {Enum} `this`
  1950. * @throws {TypeError} If arguments are invalid
  1951. * @throws {Error} If there is already a value with this name or id
  1952. */
  1953. Enum.prototype.add = function add(name, id, comment, options) {
  1954. // utilized by the parser but not by .fromJSON
  1955. if (!util.isString(name))
  1956. throw TypeError("name must be a string");
  1957. if (!util.isInteger(id))
  1958. throw TypeError("id must be an integer");
  1959. if (this.values[name] !== undefined)
  1960. throw Error("duplicate name '" + name + "' in " + this);
  1961. if (this.isReservedId(id))
  1962. throw Error("id " + id + " is reserved in " + this);
  1963. if (this.isReservedName(name))
  1964. throw Error("name '" + name + "' is reserved in " + this);
  1965. if (this.valuesById[id] !== undefined) {
  1966. if (!(this.options && this.options.allow_alias))
  1967. throw Error("duplicate id " + id + " in " + this);
  1968. this.values[name] = id;
  1969. } else
  1970. this.valuesById[this.values[name] = id] = name;
  1971. if (options) {
  1972. if (this.valuesOptions === undefined)
  1973. this.valuesOptions = {};
  1974. this.valuesOptions[name] = options || null;
  1975. }
  1976. this.comments[name] = comment || null;
  1977. return this;
  1978. };
  1979. /**
  1980. * Removes a value from this enum
  1981. * @param {string} name Value name
  1982. * @returns {Enum} `this`
  1983. * @throws {TypeError} If arguments are invalid
  1984. * @throws {Error} If `name` is not a name of this enum
  1985. */
  1986. Enum.prototype.remove = function remove(name) {
  1987. if (!util.isString(name))
  1988. throw TypeError("name must be a string");
  1989. var val = this.values[name];
  1990. if (val == null)
  1991. throw Error("name '" + name + "' does not exist in " + this);
  1992. delete this.valuesById[val];
  1993. delete this.values[name];
  1994. delete this.comments[name];
  1995. if (this.valuesOptions)
  1996. delete this.valuesOptions[name];
  1997. return this;
  1998. };
  1999. /**
  2000. * Tests if the specified id is reserved.
  2001. * @param {number} id Id to test
  2002. * @returns {boolean} `true` if reserved, otherwise `false`
  2003. */
  2004. Enum.prototype.isReservedId = function isReservedId(id) {
  2005. return Namespace.isReservedId(this.reserved, id);
  2006. };
  2007. /**
  2008. * Tests if the specified name is reserved.
  2009. * @param {string} name Name to test
  2010. * @returns {boolean} `true` if reserved, otherwise `false`
  2011. */
  2012. Enum.prototype.isReservedName = function isReservedName(name) {
  2013. return Namespace.isReservedName(this.reserved, name);
  2014. };
  2015. },{"23":23,"24":24,"37":37}],16:[function(require,module,exports){
  2016. "use strict";
  2017. module.exports = Field;
  2018. // extends ReflectionObject
  2019. var ReflectionObject = require(24);
  2020. ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
  2021. var Enum = require(15),
  2022. types = require(36),
  2023. util = require(37);
  2024. var Type; // cyclic
  2025. var ruleRe = /^required|optional|repeated$/;
  2026. /**
  2027. * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
  2028. * @name Field
  2029. * @classdesc Reflected message field.
  2030. * @extends FieldBase
  2031. * @constructor
  2032. * @param {string} name Unique name within its namespace
  2033. * @param {number} id Unique id within its namespace
  2034. * @param {string} type Value type
  2035. * @param {string|Object.<string,*>} [rule="optional"] Field rule
  2036. * @param {string|Object.<string,*>} [extend] Extended type if different from parent
  2037. * @param {Object.<string,*>} [options] Declared options
  2038. */
  2039. /**
  2040. * Constructs a field from a field descriptor.
  2041. * @param {string} name Field name
  2042. * @param {IField} json Field descriptor
  2043. * @returns {Field} Created field
  2044. * @throws {TypeError} If arguments are invalid
  2045. */
  2046. Field.fromJSON = function fromJSON(name, json) {
  2047. return new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment);
  2048. };
  2049. /**
  2050. * Not an actual constructor. Use {@link Field} instead.
  2051. * @classdesc Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions.
  2052. * @exports FieldBase
  2053. * @extends ReflectionObject
  2054. * @constructor
  2055. * @param {string} name Unique name within its namespace
  2056. * @param {number} id Unique id within its namespace
  2057. * @param {string} type Value type
  2058. * @param {string|Object.<string,*>} [rule="optional"] Field rule
  2059. * @param {string|Object.<string,*>} [extend] Extended type if different from parent
  2060. * @param {Object.<string,*>} [options] Declared options
  2061. * @param {string} [comment] Comment associated with this field
  2062. */
  2063. function Field(name, id, type, rule, extend, options, comment) {
  2064. if (util.isObject(rule)) {
  2065. comment = extend;
  2066. options = rule;
  2067. rule = extend = undefined;
  2068. } else if (util.isObject(extend)) {
  2069. comment = options;
  2070. options = extend;
  2071. extend = undefined;
  2072. }
  2073. ReflectionObject.call(this, name, options);
  2074. if (!util.isInteger(id) || id < 0)
  2075. throw TypeError("id must be a non-negative integer");
  2076. if (!util.isString(type))
  2077. throw TypeError("type must be a string");
  2078. if (rule !== undefined && !ruleRe.test(rule = rule.toString().toLowerCase()))
  2079. throw TypeError("rule must be a string rule");
  2080. if (extend !== undefined && !util.isString(extend))
  2081. throw TypeError("extend must be a string");
  2082. /**
  2083. * Field rule, if any.
  2084. * @type {string|undefined}
  2085. */
  2086. if (rule === "proto3_optional") {
  2087. rule = "optional";
  2088. }
  2089. this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON
  2090. /**
  2091. * Field type.
  2092. * @type {string}
  2093. */
  2094. this.type = type; // toJSON
  2095. /**
  2096. * Unique field id.
  2097. * @type {number}
  2098. */
  2099. this.id = id; // toJSON, marker
  2100. /**
  2101. * Extended type if different from parent.
  2102. * @type {string|undefined}
  2103. */
  2104. this.extend = extend || undefined; // toJSON
  2105. /**
  2106. * Whether this field is required.
  2107. * @type {boolean}
  2108. */
  2109. this.required = rule === "required";
  2110. /**
  2111. * Whether this field is optional.
  2112. * @type {boolean}
  2113. */
  2114. this.optional = !this.required;
  2115. /**
  2116. * Whether this field is repeated.
  2117. * @type {boolean}
  2118. */
  2119. this.repeated = rule === "repeated";
  2120. /**
  2121. * Whether this field is a map or not.
  2122. * @type {boolean}
  2123. */
  2124. this.map = false;
  2125. /**
  2126. * Message this field belongs to.
  2127. * @type {Type|null}
  2128. */
  2129. this.message = null;
  2130. /**
  2131. * OneOf this field belongs to, if any,
  2132. * @type {OneOf|null}
  2133. */
  2134. this.partOf = null;
  2135. /**
  2136. * The field type's default value.
  2137. * @type {*}
  2138. */
  2139. this.typeDefault = null;
  2140. /**
  2141. * The field's default value on prototypes.
  2142. * @type {*}
  2143. */
  2144. this.defaultValue = null;
  2145. /**
  2146. * Whether this field's value should be treated as a long.
  2147. * @type {boolean}
  2148. */
  2149. this.long = util.Long ? types.long[type] !== undefined : /* istanbul ignore next */ false;
  2150. /**
  2151. * Whether this field's value is a buffer.
  2152. * @type {boolean}
  2153. */
  2154. this.bytes = type === "bytes";
  2155. /**
  2156. * Resolved type if not a basic type.
  2157. * @type {Type|Enum|null}
  2158. */
  2159. this.resolvedType = null;
  2160. /**
  2161. * Sister-field within the extended type if a declaring extension field.
  2162. * @type {Field|null}
  2163. */
  2164. this.extensionField = null;
  2165. /**
  2166. * Sister-field within the declaring namespace if an extended field.
  2167. * @type {Field|null}
  2168. */
  2169. this.declaringField = null;
  2170. /**
  2171. * Internally remembers whether this field is packed.
  2172. * @type {boolean|null}
  2173. * @private
  2174. */
  2175. this._packed = null;
  2176. /**
  2177. * Comment for this field.
  2178. * @type {string|null}
  2179. */
  2180. this.comment = comment;
  2181. }
  2182. /**
  2183. * Determines whether this field is packed. Only relevant when repeated and working with proto2.
  2184. * @name Field#packed
  2185. * @type {boolean}
  2186. * @readonly
  2187. */
  2188. Object.defineProperty(Field.prototype, "packed", {
  2189. get: function() {
  2190. // defaults to packed=true if not explicity set to false
  2191. if (this._packed === null)
  2192. this._packed = this.getOption("packed") !== false;
  2193. return this._packed;
  2194. }
  2195. });
  2196. /**
  2197. * @override
  2198. */
  2199. Field.prototype.setOption = function setOption(name, value, ifNotSet) {
  2200. if (name === "packed") // clear cached before setting
  2201. this._packed = null;
  2202. return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet);
  2203. };
  2204. /**
  2205. * Field descriptor.
  2206. * @interface IField
  2207. * @property {string} [rule="optional"] Field rule
  2208. * @property {string} type Field type
  2209. * @property {number} id Field id
  2210. * @property {Object.<string,*>} [options] Field options
  2211. */
  2212. /**
  2213. * Extension field descriptor.
  2214. * @interface IExtensionField
  2215. * @extends IField
  2216. * @property {string} extend Extended type
  2217. */
  2218. /**
  2219. * Converts this field to a field descriptor.
  2220. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2221. * @returns {IField} Field descriptor
  2222. */
  2223. Field.prototype.toJSON = function toJSON(toJSONOptions) {
  2224. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  2225. return util.toObject([
  2226. "rule" , this.rule !== "optional" && this.rule || undefined,
  2227. "type" , this.type,
  2228. "id" , this.id,
  2229. "extend" , this.extend,
  2230. "options" , this.options,
  2231. "comment" , keepComments ? this.comment : undefined
  2232. ]);
  2233. };
  2234. /**
  2235. * Resolves this field's type references.
  2236. * @returns {Field} `this`
  2237. * @throws {Error} If any reference cannot be resolved
  2238. */
  2239. Field.prototype.resolve = function resolve() {
  2240. if (this.resolved)
  2241. return this;
  2242. if ((this.typeDefault = types.defaults[this.type]) === undefined) { // if not a basic type, resolve it
  2243. this.resolvedType = (this.declaringField ? this.declaringField.parent : this.parent).lookupTypeOrEnum(this.type);
  2244. if (this.resolvedType instanceof Type)
  2245. this.typeDefault = null;
  2246. else // instanceof Enum
  2247. this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
  2248. } else if (this.options && this.options.proto3_optional) {
  2249. // proto3 scalar value marked optional; should default to null
  2250. this.typeDefault = null;
  2251. }
  2252. // use explicitly set default value if present
  2253. if (this.options && this.options["default"] != null) {
  2254. this.typeDefault = this.options["default"];
  2255. if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
  2256. this.typeDefault = this.resolvedType.values[this.typeDefault];
  2257. }
  2258. // remove unnecessary options
  2259. if (this.options) {
  2260. if (this.options.packed === true || this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum))
  2261. delete this.options.packed;
  2262. if (!Object.keys(this.options).length)
  2263. this.options = undefined;
  2264. }
  2265. // convert to internal data type if necesssary
  2266. if (this.long) {
  2267. this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type.charAt(0) === "u");
  2268. /* istanbul ignore else */
  2269. if (Object.freeze)
  2270. Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
  2271. } else if (this.bytes && typeof this.typeDefault === "string") {
  2272. var buf;
  2273. if (util.base64.test(this.typeDefault))
  2274. util.base64.decode(this.typeDefault, buf = util.newBuffer(util.base64.length(this.typeDefault)), 0);
  2275. else
  2276. util.utf8.write(this.typeDefault, buf = util.newBuffer(util.utf8.length(this.typeDefault)), 0);
  2277. this.typeDefault = buf;
  2278. }
  2279. // take special care of maps and repeated fields
  2280. if (this.map)
  2281. this.defaultValue = util.emptyObject;
  2282. else if (this.repeated)
  2283. this.defaultValue = util.emptyArray;
  2284. else
  2285. this.defaultValue = this.typeDefault;
  2286. // ensure proper value on prototype
  2287. if (this.parent instanceof Type)
  2288. this.parent.ctor.prototype[this.name] = this.defaultValue;
  2289. return ReflectionObject.prototype.resolve.call(this);
  2290. };
  2291. /**
  2292. * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
  2293. * @typedef FieldDecorator
  2294. * @type {function}
  2295. * @param {Object} prototype Target prototype
  2296. * @param {string} fieldName Field name
  2297. * @returns {undefined}
  2298. */
  2299. /**
  2300. * Field decorator (TypeScript).
  2301. * @name Field.d
  2302. * @function
  2303. * @param {number} fieldId Field id
  2304. * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|Object} fieldType Field type
  2305. * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
  2306. * @param {T} [defaultValue] Default value
  2307. * @returns {FieldDecorator} Decorator function
  2308. * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]
  2309. */
  2310. Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
  2311. // submessage: decorate the submessage and use its name as the type
  2312. if (typeof fieldType === "function")
  2313. fieldType = util.decorateType(fieldType).name;
  2314. // enum reference: create a reflected copy of the enum and keep reuseing it
  2315. else if (fieldType && typeof fieldType === "object")
  2316. fieldType = util.decorateEnum(fieldType).name;
  2317. return function fieldDecorator(prototype, fieldName) {
  2318. util.decorateType(prototype.constructor)
  2319. .add(new Field(fieldName, fieldId, fieldType, fieldRule, { "default": defaultValue }));
  2320. };
  2321. };
  2322. /**
  2323. * Field decorator (TypeScript).
  2324. * @name Field.d
  2325. * @function
  2326. * @param {number} fieldId Field id
  2327. * @param {Constructor<T>|string} fieldType Field type
  2328. * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
  2329. * @returns {FieldDecorator} Decorator function
  2330. * @template T extends Message<T>
  2331. * @variation 2
  2332. */
  2333. // like Field.d but without a default value
  2334. // Sets up cyclic dependencies (called in index-light)
  2335. Field._configure = function configure(Type_) {
  2336. Type = Type_;
  2337. };
  2338. },{"15":15,"24":24,"36":36,"37":37}],17:[function(require,module,exports){
  2339. "use strict";
  2340. var protobuf = module.exports = require(18);
  2341. protobuf.build = "light";
  2342. /**
  2343. * A node-style callback as used by {@link load} and {@link Root#load}.
  2344. * @typedef LoadCallback
  2345. * @type {function}
  2346. * @param {Error|null} error Error, if any, otherwise `null`
  2347. * @param {Root} [root] Root, if there hasn't been an error
  2348. * @returns {undefined}
  2349. */
  2350. /**
  2351. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  2352. * @param {string|string[]} filename One or multiple files to load
  2353. * @param {Root} root Root namespace, defaults to create a new one if omitted.
  2354. * @param {LoadCallback} callback Callback function
  2355. * @returns {undefined}
  2356. * @see {@link Root#load}
  2357. */
  2358. function load(filename, root, callback) {
  2359. if (typeof root === "function") {
  2360. callback = root;
  2361. root = new protobuf.Root();
  2362. } else if (!root)
  2363. root = new protobuf.Root();
  2364. return root.load(filename, callback);
  2365. }
  2366. /**
  2367. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
  2368. * @name load
  2369. * @function
  2370. * @param {string|string[]} filename One or multiple files to load
  2371. * @param {LoadCallback} callback Callback function
  2372. * @returns {undefined}
  2373. * @see {@link Root#load}
  2374. * @variation 2
  2375. */
  2376. // function load(filename:string, callback:LoadCallback):undefined
  2377. /**
  2378. * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
  2379. * @name load
  2380. * @function
  2381. * @param {string|string[]} filename One or multiple files to load
  2382. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  2383. * @returns {Promise<Root>} Promise
  2384. * @see {@link Root#load}
  2385. * @variation 3
  2386. */
  2387. // function load(filename:string, [root:Root]):Promise<Root>
  2388. protobuf.load = load;
  2389. /**
  2390. * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
  2391. * @param {string|string[]} filename One or multiple files to load
  2392. * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
  2393. * @returns {Root} Root namespace
  2394. * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
  2395. * @see {@link Root#loadSync}
  2396. */
  2397. function loadSync(filename, root) {
  2398. if (!root)
  2399. root = new protobuf.Root();
  2400. return root.loadSync(filename);
  2401. }
  2402. protobuf.loadSync = loadSync;
  2403. // Serialization
  2404. protobuf.encoder = require(14);
  2405. protobuf.decoder = require(13);
  2406. protobuf.verifier = require(40);
  2407. protobuf.converter = require(12);
  2408. // Reflection
  2409. protobuf.ReflectionObject = require(24);
  2410. protobuf.Namespace = require(23);
  2411. protobuf.Root = require(29);
  2412. protobuf.Enum = require(15);
  2413. protobuf.Type = require(35);
  2414. protobuf.Field = require(16);
  2415. protobuf.OneOf = require(25);
  2416. protobuf.MapField = require(20);
  2417. protobuf.Service = require(33);
  2418. protobuf.Method = require(22);
  2419. // Runtime
  2420. protobuf.Message = require(21);
  2421. protobuf.wrappers = require(41);
  2422. // Utility
  2423. protobuf.types = require(36);
  2424. protobuf.util = require(37);
  2425. // Set up possibly cyclic reflection dependencies
  2426. protobuf.ReflectionObject._configure(protobuf.Root);
  2427. protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
  2428. protobuf.Root._configure(protobuf.Type);
  2429. protobuf.Field._configure(protobuf.Type);
  2430. },{"12":12,"13":13,"14":14,"15":15,"16":16,"18":18,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"29":29,"33":33,"35":35,"36":36,"37":37,"40":40,"41":41}],18:[function(require,module,exports){
  2431. "use strict";
  2432. var protobuf = exports;
  2433. /**
  2434. * Build type, one of `"full"`, `"light"` or `"minimal"`.
  2435. * @name build
  2436. * @type {string}
  2437. * @const
  2438. */
  2439. protobuf.build = "minimal";
  2440. // Serialization
  2441. protobuf.Writer = require(42);
  2442. protobuf.BufferWriter = require(43);
  2443. protobuf.Reader = require(27);
  2444. protobuf.BufferReader = require(28);
  2445. // Utility
  2446. protobuf.util = require(39);
  2447. protobuf.rpc = require(31);
  2448. protobuf.roots = require(30);
  2449. protobuf.configure = configure;
  2450. /* istanbul ignore next */
  2451. /**
  2452. * Reconfigures the library according to the environment.
  2453. * @returns {undefined}
  2454. */
  2455. function configure() {
  2456. protobuf.util._configure();
  2457. protobuf.Writer._configure(protobuf.BufferWriter);
  2458. protobuf.Reader._configure(protobuf.BufferReader);
  2459. }
  2460. // Set up buffer utility according to the environment
  2461. configure();
  2462. },{"27":27,"28":28,"30":30,"31":31,"39":39,"42":42,"43":43}],19:[function(require,module,exports){
  2463. "use strict";
  2464. var protobuf = module.exports = require(17);
  2465. protobuf.build = "full";
  2466. // Parser
  2467. protobuf.tokenize = require(34);
  2468. protobuf.parse = require(26);
  2469. protobuf.common = require(11);
  2470. // Configure parser
  2471. protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);
  2472. },{"11":11,"17":17,"26":26,"34":34}],20:[function(require,module,exports){
  2473. "use strict";
  2474. module.exports = MapField;
  2475. // extends Field
  2476. var Field = require(16);
  2477. ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
  2478. var types = require(36),
  2479. util = require(37);
  2480. /**
  2481. * Constructs a new map field instance.
  2482. * @classdesc Reflected map field.
  2483. * @extends FieldBase
  2484. * @constructor
  2485. * @param {string} name Unique name within its namespace
  2486. * @param {number} id Unique id within its namespace
  2487. * @param {string} keyType Key type
  2488. * @param {string} type Value type
  2489. * @param {Object.<string,*>} [options] Declared options
  2490. * @param {string} [comment] Comment associated with this field
  2491. */
  2492. function MapField(name, id, keyType, type, options, comment) {
  2493. Field.call(this, name, id, type, undefined, undefined, options, comment);
  2494. /* istanbul ignore if */
  2495. if (!util.isString(keyType))
  2496. throw TypeError("keyType must be a string");
  2497. /**
  2498. * Key type.
  2499. * @type {string}
  2500. */
  2501. this.keyType = keyType; // toJSON, marker
  2502. /**
  2503. * Resolved key type if not a basic type.
  2504. * @type {ReflectionObject|null}
  2505. */
  2506. this.resolvedKeyType = null;
  2507. // Overrides Field#map
  2508. this.map = true;
  2509. }
  2510. /**
  2511. * Map field descriptor.
  2512. * @interface IMapField
  2513. * @extends {IField}
  2514. * @property {string} keyType Key type
  2515. */
  2516. /**
  2517. * Extension map field descriptor.
  2518. * @interface IExtensionMapField
  2519. * @extends IMapField
  2520. * @property {string} extend Extended type
  2521. */
  2522. /**
  2523. * Constructs a map field from a map field descriptor.
  2524. * @param {string} name Field name
  2525. * @param {IMapField} json Map field descriptor
  2526. * @returns {MapField} Created map field
  2527. * @throws {TypeError} If arguments are invalid
  2528. */
  2529. MapField.fromJSON = function fromJSON(name, json) {
  2530. return new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);
  2531. };
  2532. /**
  2533. * Converts this map field to a map field descriptor.
  2534. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2535. * @returns {IMapField} Map field descriptor
  2536. */
  2537. MapField.prototype.toJSON = function toJSON(toJSONOptions) {
  2538. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  2539. return util.toObject([
  2540. "keyType" , this.keyType,
  2541. "type" , this.type,
  2542. "id" , this.id,
  2543. "extend" , this.extend,
  2544. "options" , this.options,
  2545. "comment" , keepComments ? this.comment : undefined
  2546. ]);
  2547. };
  2548. /**
  2549. * @override
  2550. */
  2551. MapField.prototype.resolve = function resolve() {
  2552. if (this.resolved)
  2553. return this;
  2554. // Besides a value type, map fields have a key type that may be "any scalar type except for floating point types and bytes"
  2555. if (types.mapKey[this.keyType] === undefined)
  2556. throw Error("invalid key type: " + this.keyType);
  2557. return Field.prototype.resolve.call(this);
  2558. };
  2559. /**
  2560. * Map field decorator (TypeScript).
  2561. * @name MapField.d
  2562. * @function
  2563. * @param {number} fieldId Field id
  2564. * @param {"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"} fieldKeyType Field key type
  2565. * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
  2566. * @returns {FieldDecorator} Decorator function
  2567. * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
  2568. */
  2569. MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
  2570. // submessage value: decorate the submessage and use its name as the type
  2571. if (typeof fieldValueType === "function")
  2572. fieldValueType = util.decorateType(fieldValueType).name;
  2573. // enum reference value: create a reflected copy of the enum and keep reuseing it
  2574. else if (fieldValueType && typeof fieldValueType === "object")
  2575. fieldValueType = util.decorateEnum(fieldValueType).name;
  2576. return function mapFieldDecorator(prototype, fieldName) {
  2577. util.decorateType(prototype.constructor)
  2578. .add(new MapField(fieldName, fieldId, fieldKeyType, fieldValueType));
  2579. };
  2580. };
  2581. },{"16":16,"36":36,"37":37}],21:[function(require,module,exports){
  2582. "use strict";
  2583. module.exports = Message;
  2584. var util = require(39);
  2585. /**
  2586. * Constructs a new message instance.
  2587. * @classdesc Abstract runtime message.
  2588. * @constructor
  2589. * @param {Properties<T>} [properties] Properties to set
  2590. * @template T extends object = object
  2591. */
  2592. function Message(properties) {
  2593. // not used internally
  2594. if (properties)
  2595. for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
  2596. this[keys[i]] = properties[keys[i]];
  2597. }
  2598. /**
  2599. * Reference to the reflected type.
  2600. * @name Message.$type
  2601. * @type {Type}
  2602. * @readonly
  2603. */
  2604. /**
  2605. * Reference to the reflected type.
  2606. * @name Message#$type
  2607. * @type {Type}
  2608. * @readonly
  2609. */
  2610. /*eslint-disable valid-jsdoc*/
  2611. /**
  2612. * Creates a new message of this type using the specified properties.
  2613. * @param {Object.<string,*>} [properties] Properties to set
  2614. * @returns {Message<T>} Message instance
  2615. * @template T extends Message<T>
  2616. * @this Constructor<T>
  2617. */
  2618. Message.create = function create(properties) {
  2619. return this.$type.create(properties);
  2620. };
  2621. /**
  2622. * Encodes a message of this type.
  2623. * @param {T|Object.<string,*>} message Message to encode
  2624. * @param {Writer} [writer] Writer to use
  2625. * @returns {Writer} Writer
  2626. * @template T extends Message<T>
  2627. * @this Constructor<T>
  2628. */
  2629. Message.encode = function encode(message, writer) {
  2630. return this.$type.encode(message, writer);
  2631. };
  2632. /**
  2633. * Encodes a message of this type preceeded by its length as a varint.
  2634. * @param {T|Object.<string,*>} message Message to encode
  2635. * @param {Writer} [writer] Writer to use
  2636. * @returns {Writer} Writer
  2637. * @template T extends Message<T>
  2638. * @this Constructor<T>
  2639. */
  2640. Message.encodeDelimited = function encodeDelimited(message, writer) {
  2641. return this.$type.encodeDelimited(message, writer);
  2642. };
  2643. /**
  2644. * Decodes a message of this type.
  2645. * @name Message.decode
  2646. * @function
  2647. * @param {Reader|Uint8Array} reader Reader or buffer to decode
  2648. * @returns {T} Decoded message
  2649. * @template T extends Message<T>
  2650. * @this Constructor<T>
  2651. */
  2652. Message.decode = function decode(reader) {
  2653. return this.$type.decode(reader);
  2654. };
  2655. /**
  2656. * Decodes a message of this type preceeded by its length as a varint.
  2657. * @name Message.decodeDelimited
  2658. * @function
  2659. * @param {Reader|Uint8Array} reader Reader or buffer to decode
  2660. * @returns {T} Decoded message
  2661. * @template T extends Message<T>
  2662. * @this Constructor<T>
  2663. */
  2664. Message.decodeDelimited = function decodeDelimited(reader) {
  2665. return this.$type.decodeDelimited(reader);
  2666. };
  2667. /**
  2668. * Verifies a message of this type.
  2669. * @name Message.verify
  2670. * @function
  2671. * @param {Object.<string,*>} message Plain object to verify
  2672. * @returns {string|null} `null` if valid, otherwise the reason why it is not
  2673. */
  2674. Message.verify = function verify(message) {
  2675. return this.$type.verify(message);
  2676. };
  2677. /**
  2678. * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
  2679. * @param {Object.<string,*>} object Plain object
  2680. * @returns {T} Message instance
  2681. * @template T extends Message<T>
  2682. * @this Constructor<T>
  2683. */
  2684. Message.fromObject = function fromObject(object) {
  2685. return this.$type.fromObject(object);
  2686. };
  2687. /**
  2688. * Creates a plain object from a message of this type. Also converts values to other types if specified.
  2689. * @param {T} message Message instance
  2690. * @param {IConversionOptions} [options] Conversion options
  2691. * @returns {Object.<string,*>} Plain object
  2692. * @template T extends Message<T>
  2693. * @this Constructor<T>
  2694. */
  2695. Message.toObject = function toObject(message, options) {
  2696. return this.$type.toObject(message, options);
  2697. };
  2698. /**
  2699. * Converts this message to JSON.
  2700. * @returns {Object.<string,*>} JSON object
  2701. */
  2702. Message.prototype.toJSON = function toJSON() {
  2703. return this.$type.toObject(this, util.toJSONOptions);
  2704. };
  2705. /*eslint-enable valid-jsdoc*/
  2706. },{"39":39}],22:[function(require,module,exports){
  2707. "use strict";
  2708. module.exports = Method;
  2709. // extends ReflectionObject
  2710. var ReflectionObject = require(24);
  2711. ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
  2712. var util = require(37);
  2713. /**
  2714. * Constructs a new service method instance.
  2715. * @classdesc Reflected service method.
  2716. * @extends ReflectionObject
  2717. * @constructor
  2718. * @param {string} name Method name
  2719. * @param {string|undefined} type Method type, usually `"rpc"`
  2720. * @param {string} requestType Request message type
  2721. * @param {string} responseType Response message type
  2722. * @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
  2723. * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
  2724. * @param {Object.<string,*>} [options] Declared options
  2725. * @param {string} [comment] The comment for this method
  2726. * @param {Object.<string,*>} [parsedOptions] Declared options, properly parsed into an object
  2727. */
  2728. function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment, parsedOptions) {
  2729. /* istanbul ignore next */
  2730. if (util.isObject(requestStream)) {
  2731. options = requestStream;
  2732. requestStream = responseStream = undefined;
  2733. } else if (util.isObject(responseStream)) {
  2734. options = responseStream;
  2735. responseStream = undefined;
  2736. }
  2737. /* istanbul ignore if */
  2738. if (!(type === undefined || util.isString(type)))
  2739. throw TypeError("type must be a string");
  2740. /* istanbul ignore if */
  2741. if (!util.isString(requestType))
  2742. throw TypeError("requestType must be a string");
  2743. /* istanbul ignore if */
  2744. if (!util.isString(responseType))
  2745. throw TypeError("responseType must be a string");
  2746. ReflectionObject.call(this, name, options);
  2747. /**
  2748. * Method type.
  2749. * @type {string}
  2750. */
  2751. this.type = type || "rpc"; // toJSON
  2752. /**
  2753. * Request type.
  2754. * @type {string}
  2755. */
  2756. this.requestType = requestType; // toJSON, marker
  2757. /**
  2758. * Whether requests are streamed or not.
  2759. * @type {boolean|undefined}
  2760. */
  2761. this.requestStream = requestStream ? true : undefined; // toJSON
  2762. /**
  2763. * Response type.
  2764. * @type {string}
  2765. */
  2766. this.responseType = responseType; // toJSON
  2767. /**
  2768. * Whether responses are streamed or not.
  2769. * @type {boolean|undefined}
  2770. */
  2771. this.responseStream = responseStream ? true : undefined; // toJSON
  2772. /**
  2773. * Resolved request type.
  2774. * @type {Type|null}
  2775. */
  2776. this.resolvedRequestType = null;
  2777. /**
  2778. * Resolved response type.
  2779. * @type {Type|null}
  2780. */
  2781. this.resolvedResponseType = null;
  2782. /**
  2783. * Comment for this method
  2784. * @type {string|null}
  2785. */
  2786. this.comment = comment;
  2787. /**
  2788. * Options properly parsed into an object
  2789. */
  2790. this.parsedOptions = parsedOptions;
  2791. }
  2792. /**
  2793. * Method descriptor.
  2794. * @interface IMethod
  2795. * @property {string} [type="rpc"] Method type
  2796. * @property {string} requestType Request type
  2797. * @property {string} responseType Response type
  2798. * @property {boolean} [requestStream=false] Whether requests are streamed
  2799. * @property {boolean} [responseStream=false] Whether responses are streamed
  2800. * @property {Object.<string,*>} [options] Method options
  2801. * @property {string} comment Method comments
  2802. * @property {Object.<string,*>} [parsedOptions] Method options properly parsed into an object
  2803. */
  2804. /**
  2805. * Constructs a method from a method descriptor.
  2806. * @param {string} name Method name
  2807. * @param {IMethod} json Method descriptor
  2808. * @returns {Method} Created method
  2809. * @throws {TypeError} If arguments are invalid
  2810. */
  2811. Method.fromJSON = function fromJSON(name, json) {
  2812. return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment, json.parsedOptions);
  2813. };
  2814. /**
  2815. * Converts this method to a method descriptor.
  2816. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2817. * @returns {IMethod} Method descriptor
  2818. */
  2819. Method.prototype.toJSON = function toJSON(toJSONOptions) {
  2820. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  2821. return util.toObject([
  2822. "type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
  2823. "requestType" , this.requestType,
  2824. "requestStream" , this.requestStream,
  2825. "responseType" , this.responseType,
  2826. "responseStream" , this.responseStream,
  2827. "options" , this.options,
  2828. "comment" , keepComments ? this.comment : undefined,
  2829. "parsedOptions" , this.parsedOptions,
  2830. ]);
  2831. };
  2832. /**
  2833. * @override
  2834. */
  2835. Method.prototype.resolve = function resolve() {
  2836. /* istanbul ignore if */
  2837. if (this.resolved)
  2838. return this;
  2839. this.resolvedRequestType = this.parent.lookupType(this.requestType);
  2840. this.resolvedResponseType = this.parent.lookupType(this.responseType);
  2841. return ReflectionObject.prototype.resolve.call(this);
  2842. };
  2843. },{"24":24,"37":37}],23:[function(require,module,exports){
  2844. "use strict";
  2845. module.exports = Namespace;
  2846. // extends ReflectionObject
  2847. var ReflectionObject = require(24);
  2848. ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
  2849. var Field = require(16),
  2850. util = require(37),
  2851. OneOf = require(25);
  2852. var Type, // cyclic
  2853. Service,
  2854. Enum;
  2855. /**
  2856. * Constructs a new namespace instance.
  2857. * @name Namespace
  2858. * @classdesc Reflected namespace.
  2859. * @extends NamespaceBase
  2860. * @constructor
  2861. * @param {string} name Namespace name
  2862. * @param {Object.<string,*>} [options] Declared options
  2863. */
  2864. /**
  2865. * Constructs a namespace from JSON.
  2866. * @memberof Namespace
  2867. * @function
  2868. * @param {string} name Namespace name
  2869. * @param {Object.<string,*>} json JSON object
  2870. * @returns {Namespace} Created namespace
  2871. * @throws {TypeError} If arguments are invalid
  2872. */
  2873. Namespace.fromJSON = function fromJSON(name, json) {
  2874. return new Namespace(name, json.options).addJSON(json.nested);
  2875. };
  2876. /**
  2877. * Converts an array of reflection objects to JSON.
  2878. * @memberof Namespace
  2879. * @param {ReflectionObject[]} array Object array
  2880. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2881. * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
  2882. */
  2883. function arrayToJSON(array, toJSONOptions) {
  2884. if (!(array && array.length))
  2885. return undefined;
  2886. var obj = {};
  2887. for (var i = 0; i < array.length; ++i)
  2888. obj[array[i].name] = array[i].toJSON(toJSONOptions);
  2889. return obj;
  2890. }
  2891. Namespace.arrayToJSON = arrayToJSON;
  2892. /**
  2893. * Tests if the specified id is reserved.
  2894. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
  2895. * @param {number} id Id to test
  2896. * @returns {boolean} `true` if reserved, otherwise `false`
  2897. */
  2898. Namespace.isReservedId = function isReservedId(reserved, id) {
  2899. if (reserved)
  2900. for (var i = 0; i < reserved.length; ++i)
  2901. if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] > id)
  2902. return true;
  2903. return false;
  2904. };
  2905. /**
  2906. * Tests if the specified name is reserved.
  2907. * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
  2908. * @param {string} name Name to test
  2909. * @returns {boolean} `true` if reserved, otherwise `false`
  2910. */
  2911. Namespace.isReservedName = function isReservedName(reserved, name) {
  2912. if (reserved)
  2913. for (var i = 0; i < reserved.length; ++i)
  2914. if (reserved[i] === name)
  2915. return true;
  2916. return false;
  2917. };
  2918. /**
  2919. * Not an actual constructor. Use {@link Namespace} instead.
  2920. * @classdesc Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions.
  2921. * @exports NamespaceBase
  2922. * @extends ReflectionObject
  2923. * @abstract
  2924. * @constructor
  2925. * @param {string} name Namespace name
  2926. * @param {Object.<string,*>} [options] Declared options
  2927. * @see {@link Namespace}
  2928. */
  2929. function Namespace(name, options) {
  2930. ReflectionObject.call(this, name, options);
  2931. /**
  2932. * Nested objects by name.
  2933. * @type {Object.<string,ReflectionObject>|undefined}
  2934. */
  2935. this.nested = undefined; // toJSON
  2936. /**
  2937. * Cached nested objects as an array.
  2938. * @type {ReflectionObject[]|null}
  2939. * @private
  2940. */
  2941. this._nestedArray = null;
  2942. }
  2943. function clearCache(namespace) {
  2944. namespace._nestedArray = null;
  2945. return namespace;
  2946. }
  2947. /**
  2948. * Nested objects of this namespace as an array for iteration.
  2949. * @name NamespaceBase#nestedArray
  2950. * @type {ReflectionObject[]}
  2951. * @readonly
  2952. */
  2953. Object.defineProperty(Namespace.prototype, "nestedArray", {
  2954. get: function() {
  2955. return this._nestedArray || (this._nestedArray = util.toArray(this.nested));
  2956. }
  2957. });
  2958. /**
  2959. * Namespace descriptor.
  2960. * @interface INamespace
  2961. * @property {Object.<string,*>} [options] Namespace options
  2962. * @property {Object.<string,AnyNestedObject>} [nested] Nested object descriptors
  2963. */
  2964. /**
  2965. * Any extension field descriptor.
  2966. * @typedef AnyExtensionField
  2967. * @type {IExtensionField|IExtensionMapField}
  2968. */
  2969. /**
  2970. * Any nested object descriptor.
  2971. * @typedef AnyNestedObject
  2972. * @type {IEnum|IType|IService|AnyExtensionField|INamespace}
  2973. */
  2974. // ^ BEWARE: VSCode hangs forever when using more than 5 types (that's why AnyExtensionField exists in the first place)
  2975. /**
  2976. * Converts this namespace to a namespace descriptor.
  2977. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  2978. * @returns {INamespace} Namespace descriptor
  2979. */
  2980. Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
  2981. return util.toObject([
  2982. "options" , this.options,
  2983. "nested" , arrayToJSON(this.nestedArray, toJSONOptions)
  2984. ]);
  2985. };
  2986. /**
  2987. * Adds nested objects to this namespace from nested object descriptors.
  2988. * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
  2989. * @returns {Namespace} `this`
  2990. */
  2991. Namespace.prototype.addJSON = function addJSON(nestedJson) {
  2992. var ns = this;
  2993. /* istanbul ignore else */
  2994. if (nestedJson) {
  2995. for (var names = Object.keys(nestedJson), i = 0, nested; i < names.length; ++i) {
  2996. nested = nestedJson[names[i]];
  2997. ns.add( // most to least likely
  2998. ( nested.fields !== undefined
  2999. ? Type.fromJSON
  3000. : nested.values !== undefined
  3001. ? Enum.fromJSON
  3002. : nested.methods !== undefined
  3003. ? Service.fromJSON
  3004. : nested.id !== undefined
  3005. ? Field.fromJSON
  3006. : Namespace.fromJSON )(names[i], nested)
  3007. );
  3008. }
  3009. }
  3010. return this;
  3011. };
  3012. /**
  3013. * Gets the nested object of the specified name.
  3014. * @param {string} name Nested object name
  3015. * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
  3016. */
  3017. Namespace.prototype.get = function get(name) {
  3018. return this.nested && this.nested[name]
  3019. || null;
  3020. };
  3021. /**
  3022. * Gets the values of the nested {@link Enum|enum} of the specified name.
  3023. * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
  3024. * @param {string} name Nested enum name
  3025. * @returns {Object.<string,number>} Enum values
  3026. * @throws {Error} If there is no such enum
  3027. */
  3028. Namespace.prototype.getEnum = function getEnum(name) {
  3029. if (this.nested && this.nested[name] instanceof Enum)
  3030. return this.nested[name].values;
  3031. throw Error("no such enum: " + name);
  3032. };
  3033. /**
  3034. * Adds a nested object to this namespace.
  3035. * @param {ReflectionObject} object Nested object to add
  3036. * @returns {Namespace} `this`
  3037. * @throws {TypeError} If arguments are invalid
  3038. * @throws {Error} If there is already a nested object with this name
  3039. */
  3040. Namespace.prototype.add = function add(object) {
  3041. if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
  3042. throw TypeError("object must be a valid nested object");
  3043. if (!this.nested)
  3044. this.nested = {};
  3045. else {
  3046. var prev = this.get(object.name);
  3047. if (prev) {
  3048. if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {
  3049. // replace plain namespace but keep existing nested elements and options
  3050. var nested = prev.nestedArray;
  3051. for (var i = 0; i < nested.length; ++i)
  3052. object.add(nested[i]);
  3053. this.remove(prev);
  3054. if (!this.nested)
  3055. this.nested = {};
  3056. object.setOptions(prev.options, true);
  3057. } else
  3058. throw Error("duplicate name '" + object.name + "' in " + this);
  3059. }
  3060. }
  3061. this.nested[object.name] = object;
  3062. object.onAdd(this);
  3063. return clearCache(this);
  3064. };
  3065. /**
  3066. * Removes a nested object from this namespace.
  3067. * @param {ReflectionObject} object Nested object to remove
  3068. * @returns {Namespace} `this`
  3069. * @throws {TypeError} If arguments are invalid
  3070. * @throws {Error} If `object` is not a member of this namespace
  3071. */
  3072. Namespace.prototype.remove = function remove(object) {
  3073. if (!(object instanceof ReflectionObject))
  3074. throw TypeError("object must be a ReflectionObject");
  3075. if (object.parent !== this)
  3076. throw Error(object + " is not a member of " + this);
  3077. delete this.nested[object.name];
  3078. if (!Object.keys(this.nested).length)
  3079. this.nested = undefined;
  3080. object.onRemove(this);
  3081. return clearCache(this);
  3082. };
  3083. /**
  3084. * Defines additial namespaces within this one if not yet existing.
  3085. * @param {string|string[]} path Path to create
  3086. * @param {*} [json] Nested types to create from JSON
  3087. * @returns {Namespace} Pointer to the last namespace created or `this` if path is empty
  3088. */
  3089. Namespace.prototype.define = function define(path, json) {
  3090. if (util.isString(path))
  3091. path = path.split(".");
  3092. else if (!Array.isArray(path))
  3093. throw TypeError("illegal path");
  3094. if (path && path.length && path[0] === "")
  3095. throw Error("path must be relative");
  3096. var ptr = this;
  3097. while (path.length > 0) {
  3098. var part = path.shift();
  3099. if (ptr.nested && ptr.nested[part]) {
  3100. ptr = ptr.nested[part];
  3101. if (!(ptr instanceof Namespace))
  3102. throw Error("path conflicts with non-namespace objects");
  3103. } else
  3104. ptr.add(ptr = new Namespace(part));
  3105. }
  3106. if (json)
  3107. ptr.addJSON(json);
  3108. return ptr;
  3109. };
  3110. /**
  3111. * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
  3112. * @returns {Namespace} `this`
  3113. */
  3114. Namespace.prototype.resolveAll = function resolveAll() {
  3115. var nested = this.nestedArray, i = 0;
  3116. while (i < nested.length)
  3117. if (nested[i] instanceof Namespace)
  3118. nested[i++].resolveAll();
  3119. else
  3120. nested[i++].resolve();
  3121. return this.resolve();
  3122. };
  3123. /**
  3124. * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
  3125. * @param {string|string[]} path Path to look up
  3126. * @param {*|Array.<*>} filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
  3127. * @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked
  3128. * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
  3129. */
  3130. Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
  3131. /* istanbul ignore next */
  3132. if (typeof filterTypes === "boolean") {
  3133. parentAlreadyChecked = filterTypes;
  3134. filterTypes = undefined;
  3135. } else if (filterTypes && !Array.isArray(filterTypes))
  3136. filterTypes = [ filterTypes ];
  3137. if (util.isString(path) && path.length) {
  3138. if (path === ".")
  3139. return this.root;
  3140. path = path.split(".");
  3141. } else if (!path.length)
  3142. return this;
  3143. // Start at root if path is absolute
  3144. if (path[0] === "")
  3145. return this.root.lookup(path.slice(1), filterTypes);
  3146. // Test if the first part matches any nested object, and if so, traverse if path contains more
  3147. var found = this.get(path[0]);
  3148. if (found) {
  3149. if (path.length === 1) {
  3150. if (!filterTypes || filterTypes.indexOf(found.constructor) > -1)
  3151. return found;
  3152. } else if (found instanceof Namespace && (found = found.lookup(path.slice(1), filterTypes, true)))
  3153. return found;
  3154. // Otherwise try each nested namespace
  3155. } else
  3156. for (var i = 0; i < this.nestedArray.length; ++i)
  3157. if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))
  3158. return found;
  3159. // If there hasn't been a match, try again at the parent
  3160. if (this.parent === null || parentAlreadyChecked)
  3161. return null;
  3162. return this.parent.lookup(path, filterTypes);
  3163. };
  3164. /**
  3165. * Looks up the reflection object at the specified path, relative to this namespace.
  3166. * @name NamespaceBase#lookup
  3167. * @function
  3168. * @param {string|string[]} path Path to look up
  3169. * @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
  3170. * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
  3171. * @variation 2
  3172. */
  3173. // lookup(path: string, [parentAlreadyChecked: boolean])
  3174. /**
  3175. * Looks up the {@link Type|type} at the specified path, relative to this namespace.
  3176. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  3177. * @param {string|string[]} path Path to look up
  3178. * @returns {Type} Looked up type
  3179. * @throws {Error} If `path` does not point to a type
  3180. */
  3181. Namespace.prototype.lookupType = function lookupType(path) {
  3182. var found = this.lookup(path, [ Type ]);
  3183. if (!found)
  3184. throw Error("no such type: " + path);
  3185. return found;
  3186. };
  3187. /**
  3188. * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
  3189. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  3190. * @param {string|string[]} path Path to look up
  3191. * @returns {Enum} Looked up enum
  3192. * @throws {Error} If `path` does not point to an enum
  3193. */
  3194. Namespace.prototype.lookupEnum = function lookupEnum(path) {
  3195. var found = this.lookup(path, [ Enum ]);
  3196. if (!found)
  3197. throw Error("no such Enum '" + path + "' in " + this);
  3198. return found;
  3199. };
  3200. /**
  3201. * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
  3202. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  3203. * @param {string|string[]} path Path to look up
  3204. * @returns {Type} Looked up type or enum
  3205. * @throws {Error} If `path` does not point to a type or enum
  3206. */
  3207. Namespace.prototype.lookupTypeOrEnum = function lookupTypeOrEnum(path) {
  3208. var found = this.lookup(path, [ Type, Enum ]);
  3209. if (!found)
  3210. throw Error("no such Type or Enum '" + path + "' in " + this);
  3211. return found;
  3212. };
  3213. /**
  3214. * Looks up the {@link Service|service} at the specified path, relative to this namespace.
  3215. * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
  3216. * @param {string|string[]} path Path to look up
  3217. * @returns {Service} Looked up service
  3218. * @throws {Error} If `path` does not point to a service
  3219. */
  3220. Namespace.prototype.lookupService = function lookupService(path) {
  3221. var found = this.lookup(path, [ Service ]);
  3222. if (!found)
  3223. throw Error("no such Service '" + path + "' in " + this);
  3224. return found;
  3225. };
  3226. // Sets up cyclic dependencies (called in index-light)
  3227. Namespace._configure = function(Type_, Service_, Enum_) {
  3228. Type = Type_;
  3229. Service = Service_;
  3230. Enum = Enum_;
  3231. };
  3232. },{"16":16,"24":24,"25":25,"37":37}],24:[function(require,module,exports){
  3233. "use strict";
  3234. module.exports = ReflectionObject;
  3235. ReflectionObject.className = "ReflectionObject";
  3236. var util = require(37);
  3237. var Root; // cyclic
  3238. /**
  3239. * Constructs a new reflection object instance.
  3240. * @classdesc Base class of all reflection objects.
  3241. * @constructor
  3242. * @param {string} name Object name
  3243. * @param {Object.<string,*>} [options] Declared options
  3244. * @abstract
  3245. */
  3246. function ReflectionObject(name, options) {
  3247. if (!util.isString(name))
  3248. throw TypeError("name must be a string");
  3249. if (options && !util.isObject(options))
  3250. throw TypeError("options must be an object");
  3251. /**
  3252. * Options.
  3253. * @type {Object.<string,*>|undefined}
  3254. */
  3255. this.options = options; // toJSON
  3256. /**
  3257. * Parsed Options.
  3258. * @type {Array.<Object.<string,*>>|undefined}
  3259. */
  3260. this.parsedOptions = null;
  3261. /**
  3262. * Unique name within its namespace.
  3263. * @type {string}
  3264. */
  3265. this.name = name;
  3266. /**
  3267. * Parent namespace.
  3268. * @type {Namespace|null}
  3269. */
  3270. this.parent = null;
  3271. /**
  3272. * Whether already resolved or not.
  3273. * @type {boolean}
  3274. */
  3275. this.resolved = false;
  3276. /**
  3277. * Comment text, if any.
  3278. * @type {string|null}
  3279. */
  3280. this.comment = null;
  3281. /**
  3282. * Defining file name.
  3283. * @type {string|null}
  3284. */
  3285. this.filename = null;
  3286. }
  3287. Object.defineProperties(ReflectionObject.prototype, {
  3288. /**
  3289. * Reference to the root namespace.
  3290. * @name ReflectionObject#root
  3291. * @type {Root}
  3292. * @readonly
  3293. */
  3294. root: {
  3295. get: function() {
  3296. var ptr = this;
  3297. while (ptr.parent !== null)
  3298. ptr = ptr.parent;
  3299. return ptr;
  3300. }
  3301. },
  3302. /**
  3303. * Full name including leading dot.
  3304. * @name ReflectionObject#fullName
  3305. * @type {string}
  3306. * @readonly
  3307. */
  3308. fullName: {
  3309. get: function() {
  3310. var path = [ this.name ],
  3311. ptr = this.parent;
  3312. while (ptr) {
  3313. path.unshift(ptr.name);
  3314. ptr = ptr.parent;
  3315. }
  3316. return path.join(".");
  3317. }
  3318. }
  3319. });
  3320. /**
  3321. * Converts this reflection object to its descriptor representation.
  3322. * @returns {Object.<string,*>} Descriptor
  3323. * @abstract
  3324. */
  3325. ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
  3326. throw Error(); // not implemented, shouldn't happen
  3327. };
  3328. /**
  3329. * Called when this object is added to a parent.
  3330. * @param {ReflectionObject} parent Parent added to
  3331. * @returns {undefined}
  3332. */
  3333. ReflectionObject.prototype.onAdd = function onAdd(parent) {
  3334. if (this.parent && this.parent !== parent)
  3335. this.parent.remove(this);
  3336. this.parent = parent;
  3337. this.resolved = false;
  3338. var root = parent.root;
  3339. if (root instanceof Root)
  3340. root._handleAdd(this);
  3341. };
  3342. /**
  3343. * Called when this object is removed from a parent.
  3344. * @param {ReflectionObject} parent Parent removed from
  3345. * @returns {undefined}
  3346. */
  3347. ReflectionObject.prototype.onRemove = function onRemove(parent) {
  3348. var root = parent.root;
  3349. if (root instanceof Root)
  3350. root._handleRemove(this);
  3351. this.parent = null;
  3352. this.resolved = false;
  3353. };
  3354. /**
  3355. * Resolves this objects type references.
  3356. * @returns {ReflectionObject} `this`
  3357. */
  3358. ReflectionObject.prototype.resolve = function resolve() {
  3359. if (this.resolved)
  3360. return this;
  3361. if (this.root instanceof Root)
  3362. this.resolved = true; // only if part of a root
  3363. return this;
  3364. };
  3365. /**
  3366. * Gets an option value.
  3367. * @param {string} name Option name
  3368. * @returns {*} Option value or `undefined` if not set
  3369. */
  3370. ReflectionObject.prototype.getOption = function getOption(name) {
  3371. if (this.options)
  3372. return this.options[name];
  3373. return undefined;
  3374. };
  3375. /**
  3376. * Sets an option.
  3377. * @param {string} name Option name
  3378. * @param {*} value Option value
  3379. * @param {boolean} [ifNotSet] Sets the option only if it isn't currently set
  3380. * @returns {ReflectionObject} `this`
  3381. */
  3382. ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
  3383. if (!ifNotSet || !this.options || this.options[name] === undefined)
  3384. (this.options || (this.options = {}))[name] = value;
  3385. return this;
  3386. };
  3387. /**
  3388. * Sets a parsed option.
  3389. * @param {string} name parsed Option name
  3390. * @param {*} value Option value
  3391. * @param {string} propName dot '.' delimited full path of property within the option to set. if undefined\empty, will add a new option with that value
  3392. * @returns {ReflectionObject} `this`
  3393. */
  3394. ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
  3395. if (!this.parsedOptions) {
  3396. this.parsedOptions = [];
  3397. }
  3398. var parsedOptions = this.parsedOptions;
  3399. if (propName) {
  3400. // If setting a sub property of an option then try to merge it
  3401. // with an existing option
  3402. var opt = parsedOptions.find(function (opt) {
  3403. return Object.prototype.hasOwnProperty.call(opt, name);
  3404. });
  3405. if (opt) {
  3406. // If we found an existing option - just merge the property value
  3407. var newValue = opt[name];
  3408. util.setProperty(newValue, propName, value);
  3409. } else {
  3410. // otherwise, create a new option, set it's property and add it to the list
  3411. opt = {};
  3412. opt[name] = util.setProperty({}, propName, value);
  3413. parsedOptions.push(opt);
  3414. }
  3415. } else {
  3416. // Always create a new option when setting the value of the option itself
  3417. var newOpt = {};
  3418. newOpt[name] = value;
  3419. parsedOptions.push(newOpt);
  3420. }
  3421. return this;
  3422. };
  3423. /**
  3424. * Sets multiple options.
  3425. * @param {Object.<string,*>} options Options to set
  3426. * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
  3427. * @returns {ReflectionObject} `this`
  3428. */
  3429. ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
  3430. if (options)
  3431. for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
  3432. this.setOption(keys[i], options[keys[i]], ifNotSet);
  3433. return this;
  3434. };
  3435. /**
  3436. * Converts this instance to its string representation.
  3437. * @returns {string} Class name[, space, full name]
  3438. */
  3439. ReflectionObject.prototype.toString = function toString() {
  3440. var className = this.constructor.className,
  3441. fullName = this.fullName;
  3442. if (fullName.length)
  3443. return className + " " + fullName;
  3444. return className;
  3445. };
  3446. // Sets up cyclic dependencies (called in index-light)
  3447. ReflectionObject._configure = function(Root_) {
  3448. Root = Root_;
  3449. };
  3450. },{"37":37}],25:[function(require,module,exports){
  3451. "use strict";
  3452. module.exports = OneOf;
  3453. // extends ReflectionObject
  3454. var ReflectionObject = require(24);
  3455. ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
  3456. var Field = require(16),
  3457. util = require(37);
  3458. /**
  3459. * Constructs a new oneof instance.
  3460. * @classdesc Reflected oneof.
  3461. * @extends ReflectionObject
  3462. * @constructor
  3463. * @param {string} name Oneof name
  3464. * @param {string[]|Object.<string,*>} [fieldNames] Field names
  3465. * @param {Object.<string,*>} [options] Declared options
  3466. * @param {string} [comment] Comment associated with this field
  3467. */
  3468. function OneOf(name, fieldNames, options, comment) {
  3469. if (!Array.isArray(fieldNames)) {
  3470. options = fieldNames;
  3471. fieldNames = undefined;
  3472. }
  3473. ReflectionObject.call(this, name, options);
  3474. /* istanbul ignore if */
  3475. if (!(fieldNames === undefined || Array.isArray(fieldNames)))
  3476. throw TypeError("fieldNames must be an Array");
  3477. /**
  3478. * Field names that belong to this oneof.
  3479. * @type {string[]}
  3480. */
  3481. this.oneof = fieldNames || []; // toJSON, marker
  3482. /**
  3483. * Fields that belong to this oneof as an array for iteration.
  3484. * @type {Field[]}
  3485. * @readonly
  3486. */
  3487. this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent
  3488. /**
  3489. * Comment for this field.
  3490. * @type {string|null}
  3491. */
  3492. this.comment = comment;
  3493. }
  3494. /**
  3495. * Oneof descriptor.
  3496. * @interface IOneOf
  3497. * @property {Array.<string>} oneof Oneof field names
  3498. * @property {Object.<string,*>} [options] Oneof options
  3499. */
  3500. /**
  3501. * Constructs a oneof from a oneof descriptor.
  3502. * @param {string} name Oneof name
  3503. * @param {IOneOf} json Oneof descriptor
  3504. * @returns {OneOf} Created oneof
  3505. * @throws {TypeError} If arguments are invalid
  3506. */
  3507. OneOf.fromJSON = function fromJSON(name, json) {
  3508. return new OneOf(name, json.oneof, json.options, json.comment);
  3509. };
  3510. /**
  3511. * Converts this oneof to a oneof descriptor.
  3512. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  3513. * @returns {IOneOf} Oneof descriptor
  3514. */
  3515. OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
  3516. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  3517. return util.toObject([
  3518. "options" , this.options,
  3519. "oneof" , this.oneof,
  3520. "comment" , keepComments ? this.comment : undefined
  3521. ]);
  3522. };
  3523. /**
  3524. * Adds the fields of the specified oneof to the parent if not already done so.
  3525. * @param {OneOf} oneof The oneof
  3526. * @returns {undefined}
  3527. * @inner
  3528. * @ignore
  3529. */
  3530. function addFieldsToParent(oneof) {
  3531. if (oneof.parent)
  3532. for (var i = 0; i < oneof.fieldsArray.length; ++i)
  3533. if (!oneof.fieldsArray[i].parent)
  3534. oneof.parent.add(oneof.fieldsArray[i]);
  3535. }
  3536. /**
  3537. * Adds a field to this oneof and removes it from its current parent, if any.
  3538. * @param {Field} field Field to add
  3539. * @returns {OneOf} `this`
  3540. */
  3541. OneOf.prototype.add = function add(field) {
  3542. /* istanbul ignore if */
  3543. if (!(field instanceof Field))
  3544. throw TypeError("field must be a Field");
  3545. if (field.parent && field.parent !== this.parent)
  3546. field.parent.remove(field);
  3547. this.oneof.push(field.name);
  3548. this.fieldsArray.push(field);
  3549. field.partOf = this; // field.parent remains null
  3550. addFieldsToParent(this);
  3551. return this;
  3552. };
  3553. /**
  3554. * Removes a field from this oneof and puts it back to the oneof's parent.
  3555. * @param {Field} field Field to remove
  3556. * @returns {OneOf} `this`
  3557. */
  3558. OneOf.prototype.remove = function remove(field) {
  3559. /* istanbul ignore if */
  3560. if (!(field instanceof Field))
  3561. throw TypeError("field must be a Field");
  3562. var index = this.fieldsArray.indexOf(field);
  3563. /* istanbul ignore if */
  3564. if (index < 0)
  3565. throw Error(field + " is not a member of " + this);
  3566. this.fieldsArray.splice(index, 1);
  3567. index = this.oneof.indexOf(field.name);
  3568. /* istanbul ignore else */
  3569. if (index > -1) // theoretical
  3570. this.oneof.splice(index, 1);
  3571. field.partOf = null;
  3572. return this;
  3573. };
  3574. /**
  3575. * @override
  3576. */
  3577. OneOf.prototype.onAdd = function onAdd(parent) {
  3578. ReflectionObject.prototype.onAdd.call(this, parent);
  3579. var self = this;
  3580. // Collect present fields
  3581. for (var i = 0; i < this.oneof.length; ++i) {
  3582. var field = parent.get(this.oneof[i]);
  3583. if (field && !field.partOf) {
  3584. field.partOf = self;
  3585. self.fieldsArray.push(field);
  3586. }
  3587. }
  3588. // Add not yet present fields
  3589. addFieldsToParent(this);
  3590. };
  3591. /**
  3592. * @override
  3593. */
  3594. OneOf.prototype.onRemove = function onRemove(parent) {
  3595. for (var i = 0, field; i < this.fieldsArray.length; ++i)
  3596. if ((field = this.fieldsArray[i]).parent)
  3597. field.parent.remove(field);
  3598. ReflectionObject.prototype.onRemove.call(this, parent);
  3599. };
  3600. /**
  3601. * Decorator function as returned by {@link OneOf.d} (TypeScript).
  3602. * @typedef OneOfDecorator
  3603. * @type {function}
  3604. * @param {Object} prototype Target prototype
  3605. * @param {string} oneofName OneOf name
  3606. * @returns {undefined}
  3607. */
  3608. /**
  3609. * OneOf decorator (TypeScript).
  3610. * @function
  3611. * @param {...string} fieldNames Field names
  3612. * @returns {OneOfDecorator} Decorator function
  3613. * @template T extends string
  3614. */
  3615. OneOf.d = function decorateOneOf() {
  3616. var fieldNames = new Array(arguments.length),
  3617. index = 0;
  3618. while (index < arguments.length)
  3619. fieldNames[index] = arguments[index++];
  3620. return function oneOfDecorator(prototype, oneofName) {
  3621. util.decorateType(prototype.constructor)
  3622. .add(new OneOf(oneofName, fieldNames));
  3623. Object.defineProperty(prototype, oneofName, {
  3624. get: util.oneOfGetter(fieldNames),
  3625. set: util.oneOfSetter(fieldNames)
  3626. });
  3627. };
  3628. };
  3629. },{"16":16,"24":24,"37":37}],26:[function(require,module,exports){
  3630. "use strict";
  3631. module.exports = parse;
  3632. parse.filename = null;
  3633. parse.defaults = { keepCase: false };
  3634. var tokenize = require(34),
  3635. Root = require(29),
  3636. Type = require(35),
  3637. Field = require(16),
  3638. MapField = require(20),
  3639. OneOf = require(25),
  3640. Enum = require(15),
  3641. Service = require(33),
  3642. Method = require(22),
  3643. types = require(36),
  3644. util = require(37);
  3645. var base10Re = /^[1-9][0-9]*$/,
  3646. base10NegRe = /^-?[1-9][0-9]*$/,
  3647. base16Re = /^0[x][0-9a-fA-F]+$/,
  3648. base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
  3649. base8Re = /^0[0-7]+$/,
  3650. base8NegRe = /^-?0[0-7]+$/,
  3651. numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,
  3652. nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
  3653. typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
  3654. fqTypeRefRe = /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;
  3655. /**
  3656. * Result object returned from {@link parse}.
  3657. * @interface IParserResult
  3658. * @property {string|undefined} package Package name, if declared
  3659. * @property {string[]|undefined} imports Imports, if any
  3660. * @property {string[]|undefined} weakImports Weak imports, if any
  3661. * @property {string|undefined} syntax Syntax, if specified (either `"proto2"` or `"proto3"`)
  3662. * @property {Root} root Populated root instance
  3663. */
  3664. /**
  3665. * Options modifying the behavior of {@link parse}.
  3666. * @interface IParseOptions
  3667. * @property {boolean} [keepCase=false] Keeps field casing instead of converting to camel case
  3668. * @property {boolean} [alternateCommentMode=false] Recognize double-slash comments in addition to doc-block comments.
  3669. * @property {boolean} [preferTrailingComment=false] Use trailing comment when both leading comment and trailing comment exist.
  3670. */
  3671. /**
  3672. * Options modifying the behavior of JSON serialization.
  3673. * @interface IToJSONOptions
  3674. * @property {boolean} [keepComments=false] Serializes comments.
  3675. */
  3676. /**
  3677. * Parses the given .proto source and returns an object with the parsed contents.
  3678. * @param {string} source Source contents
  3679. * @param {Root} root Root to populate
  3680. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  3681. * @returns {IParserResult} Parser result
  3682. * @property {string} filename=null Currently processing file name for error reporting, if known
  3683. * @property {IParseOptions} defaults Default {@link IParseOptions}
  3684. */
  3685. function parse(source, root, options) {
  3686. /* eslint-disable callback-return */
  3687. if (!(root instanceof Root)) {
  3688. options = root;
  3689. root = new Root();
  3690. }
  3691. if (!options)
  3692. options = parse.defaults;
  3693. var preferTrailingComment = options.preferTrailingComment || false;
  3694. var tn = tokenize(source, options.alternateCommentMode || false),
  3695. next = tn.next,
  3696. push = tn.push,
  3697. peek = tn.peek,
  3698. skip = tn.skip,
  3699. cmnt = tn.cmnt;
  3700. var head = true,
  3701. pkg,
  3702. imports,
  3703. weakImports,
  3704. syntax,
  3705. isProto3 = false;
  3706. var ptr = root;
  3707. var applyCase = options.keepCase ? function(name) { return name; } : util.camelCase;
  3708. /* istanbul ignore next */
  3709. function illegal(token, name, insideTryCatch) {
  3710. var filename = parse.filename;
  3711. if (!insideTryCatch)
  3712. parse.filename = null;
  3713. return Error("illegal " + (name || "token") + " '" + token + "' (" + (filename ? filename + ", " : "") + "line " + tn.line + ")");
  3714. }
  3715. function readString() {
  3716. var values = [],
  3717. token;
  3718. do {
  3719. /* istanbul ignore if */
  3720. if ((token = next()) !== "\"" && token !== "'")
  3721. throw illegal(token);
  3722. values.push(next());
  3723. skip(token);
  3724. token = peek();
  3725. } while (token === "\"" || token === "'");
  3726. return values.join("");
  3727. }
  3728. function readValue(acceptTypeRef) {
  3729. var token = next();
  3730. switch (token) {
  3731. case "'":
  3732. case "\"":
  3733. push(token);
  3734. return readString();
  3735. case "true": case "TRUE":
  3736. return true;
  3737. case "false": case "FALSE":
  3738. return false;
  3739. }
  3740. try {
  3741. return parseNumber(token, /* insideTryCatch */ true);
  3742. } catch (e) {
  3743. /* istanbul ignore else */
  3744. if (acceptTypeRef && typeRefRe.test(token))
  3745. return token;
  3746. /* istanbul ignore next */
  3747. throw illegal(token, "value");
  3748. }
  3749. }
  3750. function readRanges(target, acceptStrings) {
  3751. var token, start;
  3752. do {
  3753. if (acceptStrings && ((token = peek()) === "\"" || token === "'"))
  3754. target.push(readString());
  3755. else
  3756. target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);
  3757. } while (skip(",", true));
  3758. skip(";");
  3759. }
  3760. function parseNumber(token, insideTryCatch) {
  3761. var sign = 1;
  3762. if (token.charAt(0) === "-") {
  3763. sign = -1;
  3764. token = token.substring(1);
  3765. }
  3766. switch (token) {
  3767. case "inf": case "INF": case "Inf":
  3768. return sign * Infinity;
  3769. case "nan": case "NAN": case "Nan": case "NaN":
  3770. return NaN;
  3771. case "0":
  3772. return 0;
  3773. }
  3774. if (base10Re.test(token))
  3775. return sign * parseInt(token, 10);
  3776. if (base16Re.test(token))
  3777. return sign * parseInt(token, 16);
  3778. if (base8Re.test(token))
  3779. return sign * parseInt(token, 8);
  3780. /* istanbul ignore else */
  3781. if (numberRe.test(token))
  3782. return sign * parseFloat(token);
  3783. /* istanbul ignore next */
  3784. throw illegal(token, "number", insideTryCatch);
  3785. }
  3786. function parseId(token, acceptNegative) {
  3787. switch (token) {
  3788. case "max": case "MAX": case "Max":
  3789. return 536870911;
  3790. case "0":
  3791. return 0;
  3792. }
  3793. /* istanbul ignore if */
  3794. if (!acceptNegative && token.charAt(0) === "-")
  3795. throw illegal(token, "id");
  3796. if (base10NegRe.test(token))
  3797. return parseInt(token, 10);
  3798. if (base16NegRe.test(token))
  3799. return parseInt(token, 16);
  3800. /* istanbul ignore else */
  3801. if (base8NegRe.test(token))
  3802. return parseInt(token, 8);
  3803. /* istanbul ignore next */
  3804. throw illegal(token, "id");
  3805. }
  3806. function parsePackage() {
  3807. /* istanbul ignore if */
  3808. if (pkg !== undefined)
  3809. throw illegal("package");
  3810. pkg = next();
  3811. /* istanbul ignore if */
  3812. if (!typeRefRe.test(pkg))
  3813. throw illegal(pkg, "name");
  3814. ptr = ptr.define(pkg);
  3815. skip(";");
  3816. }
  3817. function parseImport() {
  3818. var token = peek();
  3819. var whichImports;
  3820. switch (token) {
  3821. case "weak":
  3822. whichImports = weakImports || (weakImports = []);
  3823. next();
  3824. break;
  3825. case "public":
  3826. next();
  3827. // eslint-disable-line no-fallthrough
  3828. default:
  3829. whichImports = imports || (imports = []);
  3830. break;
  3831. }
  3832. token = readString();
  3833. skip(";");
  3834. whichImports.push(token);
  3835. }
  3836. function parseSyntax() {
  3837. skip("=");
  3838. syntax = readString();
  3839. isProto3 = syntax === "proto3";
  3840. /* istanbul ignore if */
  3841. if (!isProto3 && syntax !== "proto2")
  3842. throw illegal(syntax, "syntax");
  3843. skip(";");
  3844. }
  3845. function parseCommon(parent, token) {
  3846. switch (token) {
  3847. case "option":
  3848. parseOption(parent, token);
  3849. skip(";");
  3850. return true;
  3851. case "message":
  3852. parseType(parent, token);
  3853. return true;
  3854. case "enum":
  3855. parseEnum(parent, token);
  3856. return true;
  3857. case "service":
  3858. parseService(parent, token);
  3859. return true;
  3860. case "extend":
  3861. parseExtension(parent, token);
  3862. return true;
  3863. }
  3864. return false;
  3865. }
  3866. function ifBlock(obj, fnIf, fnElse) {
  3867. var trailingLine = tn.line;
  3868. if (obj) {
  3869. if(typeof obj.comment !== "string") {
  3870. obj.comment = cmnt(); // try block-type comment
  3871. }
  3872. obj.filename = parse.filename;
  3873. }
  3874. if (skip("{", true)) {
  3875. var token;
  3876. while ((token = next()) !== "}")
  3877. fnIf(token);
  3878. skip(";", true);
  3879. } else {
  3880. if (fnElse)
  3881. fnElse();
  3882. skip(";");
  3883. if (obj && (typeof obj.comment !== "string" || preferTrailingComment))
  3884. obj.comment = cmnt(trailingLine) || obj.comment; // try line-type comment
  3885. }
  3886. }
  3887. function parseType(parent, token) {
  3888. /* istanbul ignore if */
  3889. if (!nameRe.test(token = next()))
  3890. throw illegal(token, "type name");
  3891. var type = new Type(token);
  3892. ifBlock(type, function parseType_block(token) {
  3893. if (parseCommon(type, token))
  3894. return;
  3895. switch (token) {
  3896. case "map":
  3897. parseMapField(type, token);
  3898. break;
  3899. case "required":
  3900. case "repeated":
  3901. parseField(type, token);
  3902. break;
  3903. case "optional":
  3904. /* istanbul ignore if */
  3905. if (isProto3) {
  3906. parseField(type, "proto3_optional");
  3907. } else {
  3908. parseField(type, "optional");
  3909. }
  3910. break;
  3911. case "oneof":
  3912. parseOneOf(type, token);
  3913. break;
  3914. case "extensions":
  3915. readRanges(type.extensions || (type.extensions = []));
  3916. break;
  3917. case "reserved":
  3918. readRanges(type.reserved || (type.reserved = []), true);
  3919. break;
  3920. default:
  3921. /* istanbul ignore if */
  3922. if (!isProto3 || !typeRefRe.test(token))
  3923. throw illegal(token);
  3924. push(token);
  3925. parseField(type, "optional");
  3926. break;
  3927. }
  3928. });
  3929. parent.add(type);
  3930. }
  3931. function parseField(parent, rule, extend) {
  3932. var type = next();
  3933. if (type === "group") {
  3934. parseGroup(parent, rule);
  3935. return;
  3936. }
  3937. /* istanbul ignore if */
  3938. if (!typeRefRe.test(type))
  3939. throw illegal(type, "type");
  3940. var name = next();
  3941. /* istanbul ignore if */
  3942. if (!nameRe.test(name))
  3943. throw illegal(name, "name");
  3944. name = applyCase(name);
  3945. skip("=");
  3946. var field = new Field(name, parseId(next()), type, rule, extend);
  3947. ifBlock(field, function parseField_block(token) {
  3948. /* istanbul ignore else */
  3949. if (token === "option") {
  3950. parseOption(field, token);
  3951. skip(";");
  3952. } else
  3953. throw illegal(token);
  3954. }, function parseField_line() {
  3955. parseInlineOptions(field);
  3956. });
  3957. if (rule === "proto3_optional") {
  3958. // for proto3 optional fields, we create a single-member Oneof to mimic "optional" behavior
  3959. var oneof = new OneOf("_" + name);
  3960. field.setOption("proto3_optional", true);
  3961. oneof.add(field);
  3962. parent.add(oneof);
  3963. } else {
  3964. parent.add(field);
  3965. }
  3966. // JSON defaults to packed=true if not set so we have to set packed=false explicity when
  3967. // parsing proto2 descriptors without the option, where applicable. This must be done for
  3968. // all known packable types and anything that could be an enum (= is not a basic type).
  3969. if (!isProto3 && field.repeated && (types.packed[type] !== undefined || types.basic[type] === undefined))
  3970. field.setOption("packed", false, /* ifNotSet */ true);
  3971. }
  3972. function parseGroup(parent, rule) {
  3973. var name = next();
  3974. /* istanbul ignore if */
  3975. if (!nameRe.test(name))
  3976. throw illegal(name, "name");
  3977. var fieldName = util.lcFirst(name);
  3978. if (name === fieldName)
  3979. name = util.ucFirst(name);
  3980. skip("=");
  3981. var id = parseId(next());
  3982. var type = new Type(name);
  3983. type.group = true;
  3984. var field = new Field(fieldName, id, name, rule);
  3985. field.filename = parse.filename;
  3986. ifBlock(type, function parseGroup_block(token) {
  3987. switch (token) {
  3988. case "option":
  3989. parseOption(type, token);
  3990. skip(";");
  3991. break;
  3992. case "required":
  3993. case "repeated":
  3994. parseField(type, token);
  3995. break;
  3996. case "optional":
  3997. /* istanbul ignore if */
  3998. if (isProto3) {
  3999. parseField(type, "proto3_optional");
  4000. } else {
  4001. parseField(type, "optional");
  4002. }
  4003. break;
  4004. case "message":
  4005. parseType(type, token);
  4006. break;
  4007. case "enum":
  4008. parseEnum(type, token);
  4009. break;
  4010. /* istanbul ignore next */
  4011. default:
  4012. throw illegal(token); // there are no groups with proto3 semantics
  4013. }
  4014. });
  4015. parent.add(type)
  4016. .add(field);
  4017. }
  4018. function parseMapField(parent) {
  4019. skip("<");
  4020. var keyType = next();
  4021. /* istanbul ignore if */
  4022. if (types.mapKey[keyType] === undefined)
  4023. throw illegal(keyType, "type");
  4024. skip(",");
  4025. var valueType = next();
  4026. /* istanbul ignore if */
  4027. if (!typeRefRe.test(valueType))
  4028. throw illegal(valueType, "type");
  4029. skip(">");
  4030. var name = next();
  4031. /* istanbul ignore if */
  4032. if (!nameRe.test(name))
  4033. throw illegal(name, "name");
  4034. skip("=");
  4035. var field = new MapField(applyCase(name), parseId(next()), keyType, valueType);
  4036. ifBlock(field, function parseMapField_block(token) {
  4037. /* istanbul ignore else */
  4038. if (token === "option") {
  4039. parseOption(field, token);
  4040. skip(";");
  4041. } else
  4042. throw illegal(token);
  4043. }, function parseMapField_line() {
  4044. parseInlineOptions(field);
  4045. });
  4046. parent.add(field);
  4047. }
  4048. function parseOneOf(parent, token) {
  4049. /* istanbul ignore if */
  4050. if (!nameRe.test(token = next()))
  4051. throw illegal(token, "name");
  4052. var oneof = new OneOf(applyCase(token));
  4053. ifBlock(oneof, function parseOneOf_block(token) {
  4054. if (token === "option") {
  4055. parseOption(oneof, token);
  4056. skip(";");
  4057. } else {
  4058. push(token);
  4059. parseField(oneof, "optional");
  4060. }
  4061. });
  4062. parent.add(oneof);
  4063. }
  4064. function parseEnum(parent, token) {
  4065. /* istanbul ignore if */
  4066. if (!nameRe.test(token = next()))
  4067. throw illegal(token, "name");
  4068. var enm = new Enum(token);
  4069. ifBlock(enm, function parseEnum_block(token) {
  4070. switch(token) {
  4071. case "option":
  4072. parseOption(enm, token);
  4073. skip(";");
  4074. break;
  4075. case "reserved":
  4076. readRanges(enm.reserved || (enm.reserved = []), true);
  4077. break;
  4078. default:
  4079. parseEnumValue(enm, token);
  4080. }
  4081. });
  4082. parent.add(enm);
  4083. }
  4084. function parseEnumValue(parent, token) {
  4085. /* istanbul ignore if */
  4086. if (!nameRe.test(token))
  4087. throw illegal(token, "name");
  4088. skip("=");
  4089. var value = parseId(next(), true),
  4090. dummy = {
  4091. options: undefined
  4092. };
  4093. dummy.setOption = function(name, value) {
  4094. if (this.options === undefined)
  4095. this.options = {};
  4096. this.options[name] = value;
  4097. };
  4098. ifBlock(dummy, function parseEnumValue_block(token) {
  4099. /* istanbul ignore else */
  4100. if (token === "option") {
  4101. parseOption(dummy, token); // skip
  4102. skip(";");
  4103. } else
  4104. throw illegal(token);
  4105. }, function parseEnumValue_line() {
  4106. parseInlineOptions(dummy); // skip
  4107. });
  4108. parent.add(token, value, dummy.comment, dummy.options);
  4109. }
  4110. function parseOption(parent, token) {
  4111. var isCustom = skip("(", true);
  4112. /* istanbul ignore if */
  4113. if (!typeRefRe.test(token = next()))
  4114. throw illegal(token, "name");
  4115. var name = token;
  4116. var option = name;
  4117. var propName;
  4118. if (isCustom) {
  4119. skip(")");
  4120. name = "(" + name + ")";
  4121. option = name;
  4122. token = peek();
  4123. if (fqTypeRefRe.test(token)) {
  4124. propName = token.slice(1); //remove '.' before property name
  4125. name += token;
  4126. next();
  4127. }
  4128. }
  4129. skip("=");
  4130. var optionValue = parseOptionValue(parent, name);
  4131. setParsedOption(parent, option, optionValue, propName);
  4132. }
  4133. function parseOptionValue(parent, name) {
  4134. // { a: "foo" b { c: "bar" } }
  4135. if (skip("{", true)) {
  4136. var objectResult = {};
  4137. while (!skip("}", true)) {
  4138. /* istanbul ignore if */
  4139. if (!nameRe.test(token = next())) {
  4140. throw illegal(token, "name");
  4141. }
  4142. var value;
  4143. var propName = token;
  4144. skip(":", true);
  4145. if (peek() === "{")
  4146. value = parseOptionValue(parent, name + "." + token);
  4147. else if (peek() === "[") {
  4148. // option (my_option) = {
  4149. // repeated_value: [ "foo", "bar" ]
  4150. // };
  4151. value = [];
  4152. var lastValue;
  4153. if (skip("[", true)) {
  4154. do {
  4155. lastValue = readValue(true);
  4156. value.push(lastValue);
  4157. } while (skip(",", true));
  4158. skip("]");
  4159. if (typeof lastValue !== "undefined") {
  4160. setOption(parent, name + "." + token, lastValue);
  4161. }
  4162. }
  4163. } else {
  4164. value = readValue(true);
  4165. setOption(parent, name + "." + token, value);
  4166. }
  4167. var prevValue = objectResult[propName];
  4168. if (prevValue)
  4169. value = [].concat(prevValue).concat(value);
  4170. objectResult[propName] = value;
  4171. // Semicolons and commas can be optional
  4172. skip(",", true);
  4173. skip(";", true);
  4174. }
  4175. return objectResult;
  4176. }
  4177. var simpleValue = readValue(true);
  4178. setOption(parent, name, simpleValue);
  4179. return simpleValue;
  4180. // Does not enforce a delimiter to be universal
  4181. }
  4182. function setOption(parent, name, value) {
  4183. if (parent.setOption)
  4184. parent.setOption(name, value);
  4185. }
  4186. function setParsedOption(parent, name, value, propName) {
  4187. if (parent.setParsedOption)
  4188. parent.setParsedOption(name, value, propName);
  4189. }
  4190. function parseInlineOptions(parent) {
  4191. if (skip("[", true)) {
  4192. do {
  4193. parseOption(parent, "option");
  4194. } while (skip(",", true));
  4195. skip("]");
  4196. }
  4197. return parent;
  4198. }
  4199. function parseService(parent, token) {
  4200. /* istanbul ignore if */
  4201. if (!nameRe.test(token = next()))
  4202. throw illegal(token, "service name");
  4203. var service = new Service(token);
  4204. ifBlock(service, function parseService_block(token) {
  4205. if (parseCommon(service, token))
  4206. return;
  4207. /* istanbul ignore else */
  4208. if (token === "rpc")
  4209. parseMethod(service, token);
  4210. else
  4211. throw illegal(token);
  4212. });
  4213. parent.add(service);
  4214. }
  4215. function parseMethod(parent, token) {
  4216. // Get the comment of the preceding line now (if one exists) in case the
  4217. // method is defined across multiple lines.
  4218. var commentText = cmnt();
  4219. var type = token;
  4220. /* istanbul ignore if */
  4221. if (!nameRe.test(token = next()))
  4222. throw illegal(token, "name");
  4223. var name = token,
  4224. requestType, requestStream,
  4225. responseType, responseStream;
  4226. skip("(");
  4227. if (skip("stream", true))
  4228. requestStream = true;
  4229. /* istanbul ignore if */
  4230. if (!typeRefRe.test(token = next()))
  4231. throw illegal(token);
  4232. requestType = token;
  4233. skip(")"); skip("returns"); skip("(");
  4234. if (skip("stream", true))
  4235. responseStream = true;
  4236. /* istanbul ignore if */
  4237. if (!typeRefRe.test(token = next()))
  4238. throw illegal(token);
  4239. responseType = token;
  4240. skip(")");
  4241. var method = new Method(name, type, requestType, responseType, requestStream, responseStream);
  4242. method.comment = commentText;
  4243. ifBlock(method, function parseMethod_block(token) {
  4244. /* istanbul ignore else */
  4245. if (token === "option") {
  4246. parseOption(method, token);
  4247. skip(";");
  4248. } else
  4249. throw illegal(token);
  4250. });
  4251. parent.add(method);
  4252. }
  4253. function parseExtension(parent, token) {
  4254. /* istanbul ignore if */
  4255. if (!typeRefRe.test(token = next()))
  4256. throw illegal(token, "reference");
  4257. var reference = token;
  4258. ifBlock(null, function parseExtension_block(token) {
  4259. switch (token) {
  4260. case "required":
  4261. case "repeated":
  4262. parseField(parent, token, reference);
  4263. break;
  4264. case "optional":
  4265. /* istanbul ignore if */
  4266. if (isProto3) {
  4267. parseField(parent, "proto3_optional", reference);
  4268. } else {
  4269. parseField(parent, "optional", reference);
  4270. }
  4271. break;
  4272. default:
  4273. /* istanbul ignore if */
  4274. if (!isProto3 || !typeRefRe.test(token))
  4275. throw illegal(token);
  4276. push(token);
  4277. parseField(parent, "optional", reference);
  4278. break;
  4279. }
  4280. });
  4281. }
  4282. var token;
  4283. while ((token = next()) !== null) {
  4284. switch (token) {
  4285. case "package":
  4286. /* istanbul ignore if */
  4287. if (!head)
  4288. throw illegal(token);
  4289. parsePackage();
  4290. break;
  4291. case "import":
  4292. /* istanbul ignore if */
  4293. if (!head)
  4294. throw illegal(token);
  4295. parseImport();
  4296. break;
  4297. case "syntax":
  4298. /* istanbul ignore if */
  4299. if (!head)
  4300. throw illegal(token);
  4301. parseSyntax();
  4302. break;
  4303. case "option":
  4304. parseOption(ptr, token);
  4305. skip(";");
  4306. break;
  4307. default:
  4308. /* istanbul ignore else */
  4309. if (parseCommon(ptr, token)) {
  4310. head = false;
  4311. continue;
  4312. }
  4313. /* istanbul ignore next */
  4314. throw illegal(token);
  4315. }
  4316. }
  4317. parse.filename = null;
  4318. return {
  4319. "package" : pkg,
  4320. "imports" : imports,
  4321. weakImports : weakImports,
  4322. syntax : syntax,
  4323. root : root
  4324. };
  4325. }
  4326. /**
  4327. * Parses the given .proto source and returns an object with the parsed contents.
  4328. * @name parse
  4329. * @function
  4330. * @param {string} source Source contents
  4331. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  4332. * @returns {IParserResult} Parser result
  4333. * @property {string} filename=null Currently processing file name for error reporting, if known
  4334. * @property {IParseOptions} defaults Default {@link IParseOptions}
  4335. * @variation 2
  4336. */
  4337. },{"15":15,"16":16,"20":20,"22":22,"25":25,"29":29,"33":33,"34":34,"35":35,"36":36,"37":37}],27:[function(require,module,exports){
  4338. "use strict";
  4339. module.exports = Reader;
  4340. var util = require(39);
  4341. var BufferReader; // cyclic
  4342. var LongBits = util.LongBits,
  4343. utf8 = util.utf8;
  4344. /* istanbul ignore next */
  4345. function indexOutOfRange(reader, writeLength) {
  4346. return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
  4347. }
  4348. /**
  4349. * Constructs a new reader instance using the specified buffer.
  4350. * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
  4351. * @constructor
  4352. * @param {Uint8Array} buffer Buffer to read from
  4353. */
  4354. function Reader(buffer) {
  4355. /**
  4356. * Read buffer.
  4357. * @type {Uint8Array}
  4358. */
  4359. this.buf = buffer;
  4360. /**
  4361. * Read buffer position.
  4362. * @type {number}
  4363. */
  4364. this.pos = 0;
  4365. /**
  4366. * Read buffer length.
  4367. * @type {number}
  4368. */
  4369. this.len = buffer.length;
  4370. }
  4371. var create_array = typeof Uint8Array !== "undefined"
  4372. ? function create_typed_array(buffer) {
  4373. if (buffer instanceof Uint8Array || Array.isArray(buffer))
  4374. return new Reader(buffer);
  4375. throw Error("illegal buffer");
  4376. }
  4377. /* istanbul ignore next */
  4378. : function create_array(buffer) {
  4379. if (Array.isArray(buffer))
  4380. return new Reader(buffer);
  4381. throw Error("illegal buffer");
  4382. };
  4383. var create = function create() {
  4384. return util.Buffer
  4385. ? function create_buffer_setup(buffer) {
  4386. return (Reader.create = function create_buffer(buffer) {
  4387. return util.Buffer.isBuffer(buffer)
  4388. ? new BufferReader(buffer)
  4389. /* istanbul ignore next */
  4390. : create_array(buffer);
  4391. })(buffer);
  4392. }
  4393. /* istanbul ignore next */
  4394. : create_array;
  4395. };
  4396. /**
  4397. * Creates a new reader using the specified buffer.
  4398. * @function
  4399. * @param {Uint8Array|Buffer} buffer Buffer to read from
  4400. * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
  4401. * @throws {Error} If `buffer` is not a valid buffer
  4402. */
  4403. Reader.create = create();
  4404. Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
  4405. /**
  4406. * Reads a varint as an unsigned 32 bit value.
  4407. * @function
  4408. * @returns {number} Value read
  4409. */
  4410. Reader.prototype.uint32 = (function read_uint32_setup() {
  4411. var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
  4412. return function read_uint32() {
  4413. value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
  4414. value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
  4415. value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
  4416. value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
  4417. value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
  4418. /* istanbul ignore if */
  4419. if ((this.pos += 5) > this.len) {
  4420. this.pos = this.len;
  4421. throw indexOutOfRange(this, 10);
  4422. }
  4423. return value;
  4424. };
  4425. })();
  4426. /**
  4427. * Reads a varint as a signed 32 bit value.
  4428. * @returns {number} Value read
  4429. */
  4430. Reader.prototype.int32 = function read_int32() {
  4431. return this.uint32() | 0;
  4432. };
  4433. /**
  4434. * Reads a zig-zag encoded varint as a signed 32 bit value.
  4435. * @returns {number} Value read
  4436. */
  4437. Reader.prototype.sint32 = function read_sint32() {
  4438. var value = this.uint32();
  4439. return value >>> 1 ^ -(value & 1) | 0;
  4440. };
  4441. /* eslint-disable no-invalid-this */
  4442. function readLongVarint() {
  4443. // tends to deopt with local vars for octet etc.
  4444. var bits = new LongBits(0, 0);
  4445. var i = 0;
  4446. if (this.len - this.pos > 4) { // fast route (lo)
  4447. for (; i < 4; ++i) {
  4448. // 1st..4th
  4449. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
  4450. if (this.buf[this.pos++] < 128)
  4451. return bits;
  4452. }
  4453. // 5th
  4454. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
  4455. bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
  4456. if (this.buf[this.pos++] < 128)
  4457. return bits;
  4458. i = 0;
  4459. } else {
  4460. for (; i < 3; ++i) {
  4461. /* istanbul ignore if */
  4462. if (this.pos >= this.len)
  4463. throw indexOutOfRange(this);
  4464. // 1st..3th
  4465. bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
  4466. if (this.buf[this.pos++] < 128)
  4467. return bits;
  4468. }
  4469. // 4th
  4470. bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
  4471. return bits;
  4472. }
  4473. if (this.len - this.pos > 4) { // fast route (hi)
  4474. for (; i < 5; ++i) {
  4475. // 6th..10th
  4476. bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
  4477. if (this.buf[this.pos++] < 128)
  4478. return bits;
  4479. }
  4480. } else {
  4481. for (; i < 5; ++i) {
  4482. /* istanbul ignore if */
  4483. if (this.pos >= this.len)
  4484. throw indexOutOfRange(this);
  4485. // 6th..10th
  4486. bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
  4487. if (this.buf[this.pos++] < 128)
  4488. return bits;
  4489. }
  4490. }
  4491. /* istanbul ignore next */
  4492. throw Error("invalid varint encoding");
  4493. }
  4494. /* eslint-enable no-invalid-this */
  4495. /**
  4496. * Reads a varint as a signed 64 bit value.
  4497. * @name Reader#int64
  4498. * @function
  4499. * @returns {Long} Value read
  4500. */
  4501. /**
  4502. * Reads a varint as an unsigned 64 bit value.
  4503. * @name Reader#uint64
  4504. * @function
  4505. * @returns {Long} Value read
  4506. */
  4507. /**
  4508. * Reads a zig-zag encoded varint as a signed 64 bit value.
  4509. * @name Reader#sint64
  4510. * @function
  4511. * @returns {Long} Value read
  4512. */
  4513. /**
  4514. * Reads a varint as a boolean.
  4515. * @returns {boolean} Value read
  4516. */
  4517. Reader.prototype.bool = function read_bool() {
  4518. return this.uint32() !== 0;
  4519. };
  4520. function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
  4521. return (buf[end - 4]
  4522. | buf[end - 3] << 8
  4523. | buf[end - 2] << 16
  4524. | buf[end - 1] << 24) >>> 0;
  4525. }
  4526. /**
  4527. * Reads fixed 32 bits as an unsigned 32 bit integer.
  4528. * @returns {number} Value read
  4529. */
  4530. Reader.prototype.fixed32 = function read_fixed32() {
  4531. /* istanbul ignore if */
  4532. if (this.pos + 4 > this.len)
  4533. throw indexOutOfRange(this, 4);
  4534. return readFixed32_end(this.buf, this.pos += 4);
  4535. };
  4536. /**
  4537. * Reads fixed 32 bits as a signed 32 bit integer.
  4538. * @returns {number} Value read
  4539. */
  4540. Reader.prototype.sfixed32 = function read_sfixed32() {
  4541. /* istanbul ignore if */
  4542. if (this.pos + 4 > this.len)
  4543. throw indexOutOfRange(this, 4);
  4544. return readFixed32_end(this.buf, this.pos += 4) | 0;
  4545. };
  4546. /* eslint-disable no-invalid-this */
  4547. function readFixed64(/* this: Reader */) {
  4548. /* istanbul ignore if */
  4549. if (this.pos + 8 > this.len)
  4550. throw indexOutOfRange(this, 8);
  4551. return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
  4552. }
  4553. /* eslint-enable no-invalid-this */
  4554. /**
  4555. * Reads fixed 64 bits.
  4556. * @name Reader#fixed64
  4557. * @function
  4558. * @returns {Long} Value read
  4559. */
  4560. /**
  4561. * Reads zig-zag encoded fixed 64 bits.
  4562. * @name Reader#sfixed64
  4563. * @function
  4564. * @returns {Long} Value read
  4565. */
  4566. /**
  4567. * Reads a float (32 bit) as a number.
  4568. * @function
  4569. * @returns {number} Value read
  4570. */
  4571. Reader.prototype.float = function read_float() {
  4572. /* istanbul ignore if */
  4573. if (this.pos + 4 > this.len)
  4574. throw indexOutOfRange(this, 4);
  4575. var value = util.float.readFloatLE(this.buf, this.pos);
  4576. this.pos += 4;
  4577. return value;
  4578. };
  4579. /**
  4580. * Reads a double (64 bit float) as a number.
  4581. * @function
  4582. * @returns {number} Value read
  4583. */
  4584. Reader.prototype.double = function read_double() {
  4585. /* istanbul ignore if */
  4586. if (this.pos + 8 > this.len)
  4587. throw indexOutOfRange(this, 4);
  4588. var value = util.float.readDoubleLE(this.buf, this.pos);
  4589. this.pos += 8;
  4590. return value;
  4591. };
  4592. /**
  4593. * Reads a sequence of bytes preceeded by its length as a varint.
  4594. * @returns {Uint8Array} Value read
  4595. */
  4596. Reader.prototype.bytes = function read_bytes() {
  4597. var length = this.uint32(),
  4598. start = this.pos,
  4599. end = this.pos + length;
  4600. /* istanbul ignore if */
  4601. if (end > this.len)
  4602. throw indexOutOfRange(this, length);
  4603. this.pos += length;
  4604. if (Array.isArray(this.buf)) // plain array
  4605. return this.buf.slice(start, end);
  4606. return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
  4607. ? new this.buf.constructor(0)
  4608. : this._slice.call(this.buf, start, end);
  4609. };
  4610. /**
  4611. * Reads a string preceeded by its byte length as a varint.
  4612. * @returns {string} Value read
  4613. */
  4614. Reader.prototype.string = function read_string() {
  4615. var bytes = this.bytes();
  4616. return utf8.read(bytes, 0, bytes.length);
  4617. };
  4618. /**
  4619. * Skips the specified number of bytes if specified, otherwise skips a varint.
  4620. * @param {number} [length] Length if known, otherwise a varint is assumed
  4621. * @returns {Reader} `this`
  4622. */
  4623. Reader.prototype.skip = function skip(length) {
  4624. if (typeof length === "number") {
  4625. /* istanbul ignore if */
  4626. if (this.pos + length > this.len)
  4627. throw indexOutOfRange(this, length);
  4628. this.pos += length;
  4629. } else {
  4630. do {
  4631. /* istanbul ignore if */
  4632. if (this.pos >= this.len)
  4633. throw indexOutOfRange(this);
  4634. } while (this.buf[this.pos++] & 128);
  4635. }
  4636. return this;
  4637. };
  4638. /**
  4639. * Skips the next element of the specified wire type.
  4640. * @param {number} wireType Wire type received
  4641. * @returns {Reader} `this`
  4642. */
  4643. Reader.prototype.skipType = function(wireType) {
  4644. switch (wireType) {
  4645. case 0:
  4646. this.skip();
  4647. break;
  4648. case 1:
  4649. this.skip(8);
  4650. break;
  4651. case 2:
  4652. this.skip(this.uint32());
  4653. break;
  4654. case 3:
  4655. while ((wireType = this.uint32() & 7) !== 4) {
  4656. this.skipType(wireType);
  4657. }
  4658. break;
  4659. case 5:
  4660. this.skip(4);
  4661. break;
  4662. /* istanbul ignore next */
  4663. default:
  4664. throw Error("invalid wire type " + wireType + " at offset " + this.pos);
  4665. }
  4666. return this;
  4667. };
  4668. Reader._configure = function(BufferReader_) {
  4669. BufferReader = BufferReader_;
  4670. Reader.create = create();
  4671. BufferReader._configure();
  4672. var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
  4673. util.merge(Reader.prototype, {
  4674. int64: function read_int64() {
  4675. return readLongVarint.call(this)[fn](false);
  4676. },
  4677. uint64: function read_uint64() {
  4678. return readLongVarint.call(this)[fn](true);
  4679. },
  4680. sint64: function read_sint64() {
  4681. return readLongVarint.call(this).zzDecode()[fn](false);
  4682. },
  4683. fixed64: function read_fixed64() {
  4684. return readFixed64.call(this)[fn](true);
  4685. },
  4686. sfixed64: function read_sfixed64() {
  4687. return readFixed64.call(this)[fn](false);
  4688. }
  4689. });
  4690. };
  4691. },{"39":39}],28:[function(require,module,exports){
  4692. "use strict";
  4693. module.exports = BufferReader;
  4694. // extends Reader
  4695. var Reader = require(27);
  4696. (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
  4697. var util = require(39);
  4698. /**
  4699. * Constructs a new buffer reader instance.
  4700. * @classdesc Wire format reader using node buffers.
  4701. * @extends Reader
  4702. * @constructor
  4703. * @param {Buffer} buffer Buffer to read from
  4704. */
  4705. function BufferReader(buffer) {
  4706. Reader.call(this, buffer);
  4707. /**
  4708. * Read buffer.
  4709. * @name BufferReader#buf
  4710. * @type {Buffer}
  4711. */
  4712. }
  4713. BufferReader._configure = function () {
  4714. /* istanbul ignore else */
  4715. if (util.Buffer)
  4716. BufferReader.prototype._slice = util.Buffer.prototype.slice;
  4717. };
  4718. /**
  4719. * @override
  4720. */
  4721. BufferReader.prototype.string = function read_string_buffer() {
  4722. var len = this.uint32(); // modifies pos
  4723. return this.buf.utf8Slice
  4724. ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len))
  4725. : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len));
  4726. };
  4727. /**
  4728. * Reads a sequence of bytes preceeded by its length as a varint.
  4729. * @name BufferReader#bytes
  4730. * @function
  4731. * @returns {Buffer} Value read
  4732. */
  4733. BufferReader._configure();
  4734. },{"27":27,"39":39}],29:[function(require,module,exports){
  4735. "use strict";
  4736. module.exports = Root;
  4737. // extends Namespace
  4738. var Namespace = require(23);
  4739. ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
  4740. var Field = require(16),
  4741. Enum = require(15),
  4742. OneOf = require(25),
  4743. util = require(37);
  4744. var Type, // cyclic
  4745. parse, // might be excluded
  4746. common; // "
  4747. /**
  4748. * Constructs a new root namespace instance.
  4749. * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.
  4750. * @extends NamespaceBase
  4751. * @constructor
  4752. * @param {Object.<string,*>} [options] Top level options
  4753. */
  4754. function Root(options) {
  4755. Namespace.call(this, "", options);
  4756. /**
  4757. * Deferred extension fields.
  4758. * @type {Field[]}
  4759. */
  4760. this.deferred = [];
  4761. /**
  4762. * Resolved file names of loaded files.
  4763. * @type {string[]}
  4764. */
  4765. this.files = [];
  4766. }
  4767. /**
  4768. * Loads a namespace descriptor into a root namespace.
  4769. * @param {INamespace} json Nameespace descriptor
  4770. * @param {Root} [root] Root namespace, defaults to create a new one if omitted
  4771. * @returns {Root} Root namespace
  4772. */
  4773. Root.fromJSON = function fromJSON(json, root) {
  4774. if (!root)
  4775. root = new Root();
  4776. if (json.options)
  4777. root.setOptions(json.options);
  4778. return root.addJSON(json.nested);
  4779. };
  4780. /**
  4781. * Resolves the path of an imported file, relative to the importing origin.
  4782. * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
  4783. * @function
  4784. * @param {string} origin The file name of the importing file
  4785. * @param {string} target The file name being imported
  4786. * @returns {string|null} Resolved path to `target` or `null` to skip the file
  4787. */
  4788. Root.prototype.resolvePath = util.path.resolve;
  4789. /**
  4790. * Fetch content from file path or url
  4791. * This method exists so you can override it with your own logic.
  4792. * @function
  4793. * @param {string} path File path or url
  4794. * @param {FetchCallback} callback Callback function
  4795. * @returns {undefined}
  4796. */
  4797. Root.prototype.fetch = util.fetch;
  4798. // A symbol-like function to safely signal synchronous loading
  4799. /* istanbul ignore next */
  4800. function SYNC() {} // eslint-disable-line no-empty-function
  4801. /**
  4802. * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
  4803. * @param {string|string[]} filename Names of one or multiple files to load
  4804. * @param {IParseOptions} options Parse options
  4805. * @param {LoadCallback} callback Callback function
  4806. * @returns {undefined}
  4807. */
  4808. Root.prototype.load = function load(filename, options, callback) {
  4809. if (typeof options === "function") {
  4810. callback = options;
  4811. options = undefined;
  4812. }
  4813. var self = this;
  4814. if (!callback)
  4815. return util.asPromise(load, self, filename, options);
  4816. var sync = callback === SYNC; // undocumented
  4817. // Finishes loading by calling the callback (exactly once)
  4818. function finish(err, root) {
  4819. /* istanbul ignore if */
  4820. if (!callback)
  4821. return;
  4822. var cb = callback;
  4823. callback = null;
  4824. if (sync)
  4825. throw err;
  4826. cb(err, root);
  4827. }
  4828. // Bundled definition existence checking
  4829. function getBundledFileName(filename) {
  4830. var idx = filename.lastIndexOf("google/protobuf/");
  4831. if (idx > -1) {
  4832. var altname = filename.substring(idx);
  4833. if (altname in common) return altname;
  4834. }
  4835. return null;
  4836. }
  4837. // Processes a single file
  4838. function process(filename, source) {
  4839. try {
  4840. if (util.isString(source) && source.charAt(0) === "{")
  4841. source = JSON.parse(source);
  4842. if (!util.isString(source))
  4843. self.setOptions(source.options).addJSON(source.nested);
  4844. else {
  4845. parse.filename = filename;
  4846. var parsed = parse(source, self, options),
  4847. resolved,
  4848. i = 0;
  4849. if (parsed.imports)
  4850. for (; i < parsed.imports.length; ++i)
  4851. if (resolved = getBundledFileName(parsed.imports[i]) || self.resolvePath(filename, parsed.imports[i]))
  4852. fetch(resolved);
  4853. if (parsed.weakImports)
  4854. for (i = 0; i < parsed.weakImports.length; ++i)
  4855. if (resolved = getBundledFileName(parsed.weakImports[i]) || self.resolvePath(filename, parsed.weakImports[i]))
  4856. fetch(resolved, true);
  4857. }
  4858. } catch (err) {
  4859. finish(err);
  4860. }
  4861. if (!sync && !queued)
  4862. finish(null, self); // only once anyway
  4863. }
  4864. // Fetches a single file
  4865. function fetch(filename, weak) {
  4866. // Skip if already loaded / attempted
  4867. if (self.files.indexOf(filename) > -1)
  4868. return;
  4869. self.files.push(filename);
  4870. // Shortcut bundled definitions
  4871. if (filename in common) {
  4872. if (sync)
  4873. process(filename, common[filename]);
  4874. else {
  4875. ++queued;
  4876. setTimeout(function() {
  4877. --queued;
  4878. process(filename, common[filename]);
  4879. });
  4880. }
  4881. return;
  4882. }
  4883. // Otherwise fetch from disk or network
  4884. if (sync) {
  4885. var source;
  4886. try {
  4887. source = util.fs.readFileSync(filename).toString("utf8");
  4888. } catch (err) {
  4889. if (!weak)
  4890. finish(err);
  4891. return;
  4892. }
  4893. process(filename, source);
  4894. } else {
  4895. ++queued;
  4896. self.fetch(filename, function(err, source) {
  4897. --queued;
  4898. /* istanbul ignore if */
  4899. if (!callback)
  4900. return; // terminated meanwhile
  4901. if (err) {
  4902. /* istanbul ignore else */
  4903. if (!weak)
  4904. finish(err);
  4905. else if (!queued) // can't be covered reliably
  4906. finish(null, self);
  4907. return;
  4908. }
  4909. process(filename, source);
  4910. });
  4911. }
  4912. }
  4913. var queued = 0;
  4914. // Assembling the root namespace doesn't require working type
  4915. // references anymore, so we can load everything in parallel
  4916. if (util.isString(filename))
  4917. filename = [ filename ];
  4918. for (var i = 0, resolved; i < filename.length; ++i)
  4919. if (resolved = self.resolvePath("", filename[i]))
  4920. fetch(resolved);
  4921. if (sync)
  4922. return self;
  4923. if (!queued)
  4924. finish(null, self);
  4925. return undefined;
  4926. };
  4927. // function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
  4928. /**
  4929. * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
  4930. * @function Root#load
  4931. * @param {string|string[]} filename Names of one or multiple files to load
  4932. * @param {LoadCallback} callback Callback function
  4933. * @returns {undefined}
  4934. * @variation 2
  4935. */
  4936. // function load(filename:string, callback:LoadCallback):undefined
  4937. /**
  4938. * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
  4939. * @function Root#load
  4940. * @param {string|string[]} filename Names of one or multiple files to load
  4941. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  4942. * @returns {Promise<Root>} Promise
  4943. * @variation 3
  4944. */
  4945. // function load(filename:string, [options:IParseOptions]):Promise<Root>
  4946. /**
  4947. * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
  4948. * @function Root#loadSync
  4949. * @param {string|string[]} filename Names of one or multiple files to load
  4950. * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
  4951. * @returns {Root} Root namespace
  4952. * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
  4953. */
  4954. Root.prototype.loadSync = function loadSync(filename, options) {
  4955. if (!util.isNode)
  4956. throw Error("not supported");
  4957. return this.load(filename, options, SYNC);
  4958. };
  4959. /**
  4960. * @override
  4961. */
  4962. Root.prototype.resolveAll = function resolveAll() {
  4963. if (this.deferred.length)
  4964. throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
  4965. return "'extend " + field.extend + "' in " + field.parent.fullName;
  4966. }).join(", "));
  4967. return Namespace.prototype.resolveAll.call(this);
  4968. };
  4969. // only uppercased (and thus conflict-free) children are exposed, see below
  4970. var exposeRe = /^[A-Z]/;
  4971. /**
  4972. * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
  4973. * @param {Root} root Root instance
  4974. * @param {Field} field Declaring extension field witin the declaring type
  4975. * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise
  4976. * @inner
  4977. * @ignore
  4978. */
  4979. function tryHandleExtension(root, field) {
  4980. var extendedType = field.parent.lookup(field.extend);
  4981. if (extendedType) {
  4982. var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
  4983. sisterField.declaringField = field;
  4984. field.extensionField = sisterField;
  4985. extendedType.add(sisterField);
  4986. return true;
  4987. }
  4988. return false;
  4989. }
  4990. /**
  4991. * Called when any object is added to this root or its sub-namespaces.
  4992. * @param {ReflectionObject} object Object added
  4993. * @returns {undefined}
  4994. * @private
  4995. */
  4996. Root.prototype._handleAdd = function _handleAdd(object) {
  4997. if (object instanceof Field) {
  4998. if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)
  4999. if (!tryHandleExtension(this, object))
  5000. this.deferred.push(object);
  5001. } else if (object instanceof Enum) {
  5002. if (exposeRe.test(object.name))
  5003. object.parent[object.name] = object.values; // expose enum values as property of its parent
  5004. } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {
  5005. if (object instanceof Type) // Try to handle any deferred extensions
  5006. for (var i = 0; i < this.deferred.length;)
  5007. if (tryHandleExtension(this, this.deferred[i]))
  5008. this.deferred.splice(i, 1);
  5009. else
  5010. ++i;
  5011. for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace
  5012. this._handleAdd(object._nestedArray[j]);
  5013. if (exposeRe.test(object.name))
  5014. object.parent[object.name] = object; // expose namespace as property of its parent
  5015. }
  5016. // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
  5017. // properties of namespaces just like static code does. This allows using a .d.ts generated for
  5018. // a static module with reflection-based solutions where the condition is met.
  5019. };
  5020. /**
  5021. * Called when any object is removed from this root or its sub-namespaces.
  5022. * @param {ReflectionObject} object Object removed
  5023. * @returns {undefined}
  5024. * @private
  5025. */
  5026. Root.prototype._handleRemove = function _handleRemove(object) {
  5027. if (object instanceof Field) {
  5028. if (/* an extension field */ object.extend !== undefined) {
  5029. if (/* already handled */ object.extensionField) { // remove its sister field
  5030. object.extensionField.parent.remove(object.extensionField);
  5031. object.extensionField = null;
  5032. } else { // cancel the extension
  5033. var index = this.deferred.indexOf(object);
  5034. /* istanbul ignore else */
  5035. if (index > -1)
  5036. this.deferred.splice(index, 1);
  5037. }
  5038. }
  5039. } else if (object instanceof Enum) {
  5040. if (exposeRe.test(object.name))
  5041. delete object.parent[object.name]; // unexpose enum values
  5042. } else if (object instanceof Namespace) {
  5043. for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace
  5044. this._handleRemove(object._nestedArray[i]);
  5045. if (exposeRe.test(object.name))
  5046. delete object.parent[object.name]; // unexpose namespaces
  5047. }
  5048. };
  5049. // Sets up cyclic dependencies (called in index-light)
  5050. Root._configure = function(Type_, parse_, common_) {
  5051. Type = Type_;
  5052. parse = parse_;
  5053. common = common_;
  5054. };
  5055. },{"15":15,"16":16,"23":23,"25":25,"37":37}],30:[function(require,module,exports){
  5056. "use strict";
  5057. module.exports = {};
  5058. /**
  5059. * Named roots.
  5060. * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
  5061. * Can also be used manually to make roots available across modules.
  5062. * @name roots
  5063. * @type {Object.<string,Root>}
  5064. * @example
  5065. * // pbjs -r myroot -o compiled.js ...
  5066. *
  5067. * // in another module:
  5068. * require("./compiled.js");
  5069. *
  5070. * // in any subsequent module:
  5071. * var root = protobuf.roots["myroot"];
  5072. */
  5073. },{}],31:[function(require,module,exports){
  5074. "use strict";
  5075. /**
  5076. * Streaming RPC helpers.
  5077. * @namespace
  5078. */
  5079. var rpc = exports;
  5080. /**
  5081. * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
  5082. * @typedef RPCImpl
  5083. * @type {function}
  5084. * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
  5085. * @param {Uint8Array} requestData Request data
  5086. * @param {RPCImplCallback} callback Callback function
  5087. * @returns {undefined}
  5088. * @example
  5089. * function rpcImpl(method, requestData, callback) {
  5090. * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
  5091. * throw Error("no such method");
  5092. * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
  5093. * callback(err, responseData);
  5094. * });
  5095. * }
  5096. */
  5097. /**
  5098. * Node-style callback as used by {@link RPCImpl}.
  5099. * @typedef RPCImplCallback
  5100. * @type {function}
  5101. * @param {Error|null} error Error, if any, otherwise `null`
  5102. * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
  5103. * @returns {undefined}
  5104. */
  5105. rpc.Service = require(32);
  5106. },{"32":32}],32:[function(require,module,exports){
  5107. "use strict";
  5108. module.exports = Service;
  5109. var util = require(39);
  5110. // Extends EventEmitter
  5111. (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
  5112. /**
  5113. * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
  5114. *
  5115. * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
  5116. * @typedef rpc.ServiceMethodCallback
  5117. * @template TRes extends Message<TRes>
  5118. * @type {function}
  5119. * @param {Error|null} error Error, if any
  5120. * @param {TRes} [response] Response message
  5121. * @returns {undefined}
  5122. */
  5123. /**
  5124. * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
  5125. * @typedef rpc.ServiceMethod
  5126. * @template TReq extends Message<TReq>
  5127. * @template TRes extends Message<TRes>
  5128. * @type {function}
  5129. * @param {TReq|Properties<TReq>} request Request message or plain object
  5130. * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
  5131. * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
  5132. */
  5133. /**
  5134. * Constructs a new RPC service instance.
  5135. * @classdesc An RPC service as returned by {@link Service#create}.
  5136. * @exports rpc.Service
  5137. * @extends util.EventEmitter
  5138. * @constructor
  5139. * @param {RPCImpl} rpcImpl RPC implementation
  5140. * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
  5141. * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
  5142. */
  5143. function Service(rpcImpl, requestDelimited, responseDelimited) {
  5144. if (typeof rpcImpl !== "function")
  5145. throw TypeError("rpcImpl must be a function");
  5146. util.EventEmitter.call(this);
  5147. /**
  5148. * RPC implementation. Becomes `null` once the service is ended.
  5149. * @type {RPCImpl|null}
  5150. */
  5151. this.rpcImpl = rpcImpl;
  5152. /**
  5153. * Whether requests are length-delimited.
  5154. * @type {boolean}
  5155. */
  5156. this.requestDelimited = Boolean(requestDelimited);
  5157. /**
  5158. * Whether responses are length-delimited.
  5159. * @type {boolean}
  5160. */
  5161. this.responseDelimited = Boolean(responseDelimited);
  5162. }
  5163. /**
  5164. * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
  5165. * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
  5166. * @param {Constructor<TReq>} requestCtor Request constructor
  5167. * @param {Constructor<TRes>} responseCtor Response constructor
  5168. * @param {TReq|Properties<TReq>} request Request message or plain object
  5169. * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
  5170. * @returns {undefined}
  5171. * @template TReq extends Message<TReq>
  5172. * @template TRes extends Message<TRes>
  5173. */
  5174. Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
  5175. if (!request)
  5176. throw TypeError("request must be specified");
  5177. var self = this;
  5178. if (!callback)
  5179. return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
  5180. if (!self.rpcImpl) {
  5181. setTimeout(function() { callback(Error("already ended")); }, 0);
  5182. return undefined;
  5183. }
  5184. try {
  5185. return self.rpcImpl(
  5186. method,
  5187. requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
  5188. function rpcCallback(err, response) {
  5189. if (err) {
  5190. self.emit("error", err, method);
  5191. return callback(err);
  5192. }
  5193. if (response === null) {
  5194. self.end(/* endedByRPC */ true);
  5195. return undefined;
  5196. }
  5197. if (!(response instanceof responseCtor)) {
  5198. try {
  5199. response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
  5200. } catch (err) {
  5201. self.emit("error", err, method);
  5202. return callback(err);
  5203. }
  5204. }
  5205. self.emit("data", response, method);
  5206. return callback(null, response);
  5207. }
  5208. );
  5209. } catch (err) {
  5210. self.emit("error", err, method);
  5211. setTimeout(function() { callback(err); }, 0);
  5212. return undefined;
  5213. }
  5214. };
  5215. /**
  5216. * Ends this service and emits the `end` event.
  5217. * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
  5218. * @returns {rpc.Service} `this`
  5219. */
  5220. Service.prototype.end = function end(endedByRPC) {
  5221. if (this.rpcImpl) {
  5222. if (!endedByRPC) // signal end to rpcImpl
  5223. this.rpcImpl(null, null, null);
  5224. this.rpcImpl = null;
  5225. this.emit("end").off();
  5226. }
  5227. return this;
  5228. };
  5229. },{"39":39}],33:[function(require,module,exports){
  5230. "use strict";
  5231. module.exports = Service;
  5232. // extends Namespace
  5233. var Namespace = require(23);
  5234. ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
  5235. var Method = require(22),
  5236. util = require(37),
  5237. rpc = require(31);
  5238. /**
  5239. * Constructs a new service instance.
  5240. * @classdesc Reflected service.
  5241. * @extends NamespaceBase
  5242. * @constructor
  5243. * @param {string} name Service name
  5244. * @param {Object.<string,*>} [options] Service options
  5245. * @throws {TypeError} If arguments are invalid
  5246. */
  5247. function Service(name, options) {
  5248. Namespace.call(this, name, options);
  5249. /**
  5250. * Service methods.
  5251. * @type {Object.<string,Method>}
  5252. */
  5253. this.methods = {}; // toJSON, marker
  5254. /**
  5255. * Cached methods as an array.
  5256. * @type {Method[]|null}
  5257. * @private
  5258. */
  5259. this._methodsArray = null;
  5260. }
  5261. /**
  5262. * Service descriptor.
  5263. * @interface IService
  5264. * @extends INamespace
  5265. * @property {Object.<string,IMethod>} methods Method descriptors
  5266. */
  5267. /**
  5268. * Constructs a service from a service descriptor.
  5269. * @param {string} name Service name
  5270. * @param {IService} json Service descriptor
  5271. * @returns {Service} Created service
  5272. * @throws {TypeError} If arguments are invalid
  5273. */
  5274. Service.fromJSON = function fromJSON(name, json) {
  5275. var service = new Service(name, json.options);
  5276. /* istanbul ignore else */
  5277. if (json.methods)
  5278. for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
  5279. service.add(Method.fromJSON(names[i], json.methods[names[i]]));
  5280. if (json.nested)
  5281. service.addJSON(json.nested);
  5282. service.comment = json.comment;
  5283. return service;
  5284. };
  5285. /**
  5286. * Converts this service to a service descriptor.
  5287. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  5288. * @returns {IService} Service descriptor
  5289. */
  5290. Service.prototype.toJSON = function toJSON(toJSONOptions) {
  5291. var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
  5292. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  5293. return util.toObject([
  5294. "options" , inherited && inherited.options || undefined,
  5295. "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
  5296. "nested" , inherited && inherited.nested || undefined,
  5297. "comment" , keepComments ? this.comment : undefined
  5298. ]);
  5299. };
  5300. /**
  5301. * Methods of this service as an array for iteration.
  5302. * @name Service#methodsArray
  5303. * @type {Method[]}
  5304. * @readonly
  5305. */
  5306. Object.defineProperty(Service.prototype, "methodsArray", {
  5307. get: function() {
  5308. return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
  5309. }
  5310. });
  5311. function clearCache(service) {
  5312. service._methodsArray = null;
  5313. return service;
  5314. }
  5315. /**
  5316. * @override
  5317. */
  5318. Service.prototype.get = function get(name) {
  5319. return this.methods[name]
  5320. || Namespace.prototype.get.call(this, name);
  5321. };
  5322. /**
  5323. * @override
  5324. */
  5325. Service.prototype.resolveAll = function resolveAll() {
  5326. var methods = this.methodsArray;
  5327. for (var i = 0; i < methods.length; ++i)
  5328. methods[i].resolve();
  5329. return Namespace.prototype.resolve.call(this);
  5330. };
  5331. /**
  5332. * @override
  5333. */
  5334. Service.prototype.add = function add(object) {
  5335. /* istanbul ignore if */
  5336. if (this.get(object.name))
  5337. throw Error("duplicate name '" + object.name + "' in " + this);
  5338. if (object instanceof Method) {
  5339. this.methods[object.name] = object;
  5340. object.parent = this;
  5341. return clearCache(this);
  5342. }
  5343. return Namespace.prototype.add.call(this, object);
  5344. };
  5345. /**
  5346. * @override
  5347. */
  5348. Service.prototype.remove = function remove(object) {
  5349. if (object instanceof Method) {
  5350. /* istanbul ignore if */
  5351. if (this.methods[object.name] !== object)
  5352. throw Error(object + " is not a member of " + this);
  5353. delete this.methods[object.name];
  5354. object.parent = null;
  5355. return clearCache(this);
  5356. }
  5357. return Namespace.prototype.remove.call(this, object);
  5358. };
  5359. /**
  5360. * Creates a runtime service using the specified rpc implementation.
  5361. * @param {RPCImpl} rpcImpl RPC implementation
  5362. * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
  5363. * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
  5364. * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
  5365. */
  5366. Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
  5367. var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
  5368. for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
  5369. var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
  5370. rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
  5371. m: method,
  5372. q: method.resolvedRequestType.ctor,
  5373. s: method.resolvedResponseType.ctor
  5374. });
  5375. }
  5376. return rpcService;
  5377. };
  5378. },{"22":22,"23":23,"31":31,"37":37}],34:[function(require,module,exports){
  5379. "use strict";
  5380. module.exports = tokenize;
  5381. var delimRe = /[\s{}=;:[\],'"()<>]/g,
  5382. stringDoubleRe = /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
  5383. stringSingleRe = /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g;
  5384. var setCommentRe = /^ *[*/]+ */,
  5385. setCommentAltRe = /^\s*\*?\/*/,
  5386. setCommentSplitRe = /\n/g,
  5387. whitespaceRe = /\s/,
  5388. unescapeRe = /\\(.?)/g;
  5389. var unescapeMap = {
  5390. "0": "\0",
  5391. "r": "\r",
  5392. "n": "\n",
  5393. "t": "\t"
  5394. };
  5395. /**
  5396. * Unescapes a string.
  5397. * @param {string} str String to unescape
  5398. * @returns {string} Unescaped string
  5399. * @property {Object.<string,string>} map Special characters map
  5400. * @memberof tokenize
  5401. */
  5402. function unescape(str) {
  5403. return str.replace(unescapeRe, function($0, $1) {
  5404. switch ($1) {
  5405. case "\\":
  5406. case "":
  5407. return $1;
  5408. default:
  5409. return unescapeMap[$1] || "";
  5410. }
  5411. });
  5412. }
  5413. tokenize.unescape = unescape;
  5414. /**
  5415. * Gets the next token and advances.
  5416. * @typedef TokenizerHandleNext
  5417. * @type {function}
  5418. * @returns {string|null} Next token or `null` on eof
  5419. */
  5420. /**
  5421. * Peeks for the next token.
  5422. * @typedef TokenizerHandlePeek
  5423. * @type {function}
  5424. * @returns {string|null} Next token or `null` on eof
  5425. */
  5426. /**
  5427. * Pushes a token back to the stack.
  5428. * @typedef TokenizerHandlePush
  5429. * @type {function}
  5430. * @param {string} token Token
  5431. * @returns {undefined}
  5432. */
  5433. /**
  5434. * Skips the next token.
  5435. * @typedef TokenizerHandleSkip
  5436. * @type {function}
  5437. * @param {string} expected Expected token
  5438. * @param {boolean} [optional=false] If optional
  5439. * @returns {boolean} Whether the token matched
  5440. * @throws {Error} If the token didn't match and is not optional
  5441. */
  5442. /**
  5443. * Gets the comment on the previous line or, alternatively, the line comment on the specified line.
  5444. * @typedef TokenizerHandleCmnt
  5445. * @type {function}
  5446. * @param {number} [line] Line number
  5447. * @returns {string|null} Comment text or `null` if none
  5448. */
  5449. /**
  5450. * Handle object returned from {@link tokenize}.
  5451. * @interface ITokenizerHandle
  5452. * @property {TokenizerHandleNext} next Gets the next token and advances (`null` on eof)
  5453. * @property {TokenizerHandlePeek} peek Peeks for the next token (`null` on eof)
  5454. * @property {TokenizerHandlePush} push Pushes a token back to the stack
  5455. * @property {TokenizerHandleSkip} skip Skips a token, returns its presence and advances or, if non-optional and not present, throws
  5456. * @property {TokenizerHandleCmnt} cmnt Gets the comment on the previous line or the line comment on the specified line, if any
  5457. * @property {number} line Current line number
  5458. */
  5459. /**
  5460. * Tokenizes the given .proto source and returns an object with useful utility functions.
  5461. * @param {string} source Source contents
  5462. * @param {boolean} alternateCommentMode Whether we should activate alternate comment parsing mode.
  5463. * @returns {ITokenizerHandle} Tokenizer handle
  5464. */
  5465. function tokenize(source, alternateCommentMode) {
  5466. /* eslint-disable callback-return */
  5467. source = source.toString();
  5468. var offset = 0,
  5469. length = source.length,
  5470. line = 1,
  5471. lastCommentLine = 0,
  5472. comments = {};
  5473. var stack = [];
  5474. var stringDelim = null;
  5475. /* istanbul ignore next */
  5476. /**
  5477. * Creates an error for illegal syntax.
  5478. * @param {string} subject Subject
  5479. * @returns {Error} Error created
  5480. * @inner
  5481. */
  5482. function illegal(subject) {
  5483. return Error("illegal " + subject + " (line " + line + ")");
  5484. }
  5485. /**
  5486. * Reads a string till its end.
  5487. * @returns {string} String read
  5488. * @inner
  5489. */
  5490. function readString() {
  5491. var re = stringDelim === "'" ? stringSingleRe : stringDoubleRe;
  5492. re.lastIndex = offset - 1;
  5493. var match = re.exec(source);
  5494. if (!match)
  5495. throw illegal("string");
  5496. offset = re.lastIndex;
  5497. push(stringDelim);
  5498. stringDelim = null;
  5499. return unescape(match[1]);
  5500. }
  5501. /**
  5502. * Gets the character at `pos` within the source.
  5503. * @param {number} pos Position
  5504. * @returns {string} Character
  5505. * @inner
  5506. */
  5507. function charAt(pos) {
  5508. return source.charAt(pos);
  5509. }
  5510. /**
  5511. * Sets the current comment text.
  5512. * @param {number} start Start offset
  5513. * @param {number} end End offset
  5514. * @param {boolean} isLeading set if a leading comment
  5515. * @returns {undefined}
  5516. * @inner
  5517. */
  5518. function setComment(start, end, isLeading) {
  5519. var comment = {
  5520. type: source.charAt(start++),
  5521. lineEmpty: false,
  5522. leading: isLeading,
  5523. };
  5524. var lookback;
  5525. if (alternateCommentMode) {
  5526. lookback = 2; // alternate comment parsing: "//" or "/*"
  5527. } else {
  5528. lookback = 3; // "///" or "/**"
  5529. }
  5530. var commentOffset = start - lookback,
  5531. c;
  5532. do {
  5533. if (--commentOffset < 0 ||
  5534. (c = source.charAt(commentOffset)) === "\n") {
  5535. comment.lineEmpty = true;
  5536. break;
  5537. }
  5538. } while (c === " " || c === "\t");
  5539. var lines = source
  5540. .substring(start, end)
  5541. .split(setCommentSplitRe);
  5542. for (var i = 0; i < lines.length; ++i)
  5543. lines[i] = lines[i]
  5544. .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
  5545. .trim();
  5546. comment.text = lines
  5547. .join("\n")
  5548. .trim();
  5549. comments[line] = comment;
  5550. lastCommentLine = line;
  5551. }
  5552. function isDoubleSlashCommentLine(startOffset) {
  5553. var endOffset = findEndOfLine(startOffset);
  5554. // see if remaining line matches comment pattern
  5555. var lineText = source.substring(startOffset, endOffset);
  5556. // look for 1 or 2 slashes since startOffset would already point past
  5557. // the first slash that started the comment.
  5558. var isComment = /^\s*\/{1,2}/.test(lineText);
  5559. return isComment;
  5560. }
  5561. function findEndOfLine(cursor) {
  5562. // find end of cursor's line
  5563. var endOffset = cursor;
  5564. while (endOffset < length && charAt(endOffset) !== "\n") {
  5565. endOffset++;
  5566. }
  5567. return endOffset;
  5568. }
  5569. /**
  5570. * Obtains the next token.
  5571. * @returns {string|null} Next token or `null` on eof
  5572. * @inner
  5573. */
  5574. function next() {
  5575. if (stack.length > 0)
  5576. return stack.shift();
  5577. if (stringDelim)
  5578. return readString();
  5579. var repeat,
  5580. prev,
  5581. curr,
  5582. start,
  5583. isDoc,
  5584. isLeadingComment = offset === 0;
  5585. do {
  5586. if (offset === length)
  5587. return null;
  5588. repeat = false;
  5589. while (whitespaceRe.test(curr = charAt(offset))) {
  5590. if (curr === "\n") {
  5591. isLeadingComment = true;
  5592. ++line;
  5593. }
  5594. if (++offset === length)
  5595. return null;
  5596. }
  5597. if (charAt(offset) === "/") {
  5598. if (++offset === length) {
  5599. throw illegal("comment");
  5600. }
  5601. if (charAt(offset) === "/") { // Line
  5602. if (!alternateCommentMode) {
  5603. // check for triple-slash comment
  5604. isDoc = charAt(start = offset + 1) === "/";
  5605. while (charAt(++offset) !== "\n") {
  5606. if (offset === length) {
  5607. return null;
  5608. }
  5609. }
  5610. ++offset;
  5611. if (isDoc) {
  5612. setComment(start, offset - 1, isLeadingComment);
  5613. // Trailing comment cannot not be multi-line,
  5614. // so leading comment state should be reset to handle potential next comments
  5615. isLeadingComment = true;
  5616. }
  5617. ++line;
  5618. repeat = true;
  5619. } else {
  5620. // check for double-slash comments, consolidating consecutive lines
  5621. start = offset;
  5622. isDoc = false;
  5623. if (isDoubleSlashCommentLine(offset)) {
  5624. isDoc = true;
  5625. do {
  5626. offset = findEndOfLine(offset);
  5627. if (offset === length) {
  5628. break;
  5629. }
  5630. offset++;
  5631. if (!isLeadingComment) {
  5632. // Trailing comment cannot not be multi-line
  5633. break;
  5634. }
  5635. } while (isDoubleSlashCommentLine(offset));
  5636. } else {
  5637. offset = Math.min(length, findEndOfLine(offset) + 1);
  5638. }
  5639. if (isDoc) {
  5640. setComment(start, offset, isLeadingComment);
  5641. isLeadingComment = true;
  5642. }
  5643. line++;
  5644. repeat = true;
  5645. }
  5646. } else if ((curr = charAt(offset)) === "*") { /* Block */
  5647. // check for /** (regular comment mode) or /* (alternate comment mode)
  5648. start = offset + 1;
  5649. isDoc = alternateCommentMode || charAt(start) === "*";
  5650. do {
  5651. if (curr === "\n") {
  5652. ++line;
  5653. }
  5654. if (++offset === length) {
  5655. throw illegal("comment");
  5656. }
  5657. prev = curr;
  5658. curr = charAt(offset);
  5659. } while (prev !== "*" || curr !== "/");
  5660. ++offset;
  5661. if (isDoc) {
  5662. setComment(start, offset - 2, isLeadingComment);
  5663. isLeadingComment = true;
  5664. }
  5665. repeat = true;
  5666. } else {
  5667. return "/";
  5668. }
  5669. }
  5670. } while (repeat);
  5671. // offset !== length if we got here
  5672. var end = offset;
  5673. delimRe.lastIndex = 0;
  5674. var delim = delimRe.test(charAt(end++));
  5675. if (!delim)
  5676. while (end < length && !delimRe.test(charAt(end)))
  5677. ++end;
  5678. var token = source.substring(offset, offset = end);
  5679. if (token === "\"" || token === "'")
  5680. stringDelim = token;
  5681. return token;
  5682. }
  5683. /**
  5684. * Pushes a token back to the stack.
  5685. * @param {string} token Token
  5686. * @returns {undefined}
  5687. * @inner
  5688. */
  5689. function push(token) {
  5690. stack.push(token);
  5691. }
  5692. /**
  5693. * Peeks for the next token.
  5694. * @returns {string|null} Token or `null` on eof
  5695. * @inner
  5696. */
  5697. function peek() {
  5698. if (!stack.length) {
  5699. var token = next();
  5700. if (token === null)
  5701. return null;
  5702. push(token);
  5703. }
  5704. return stack[0];
  5705. }
  5706. /**
  5707. * Skips a token.
  5708. * @param {string} expected Expected token
  5709. * @param {boolean} [optional=false] Whether the token is optional
  5710. * @returns {boolean} `true` when skipped, `false` if not
  5711. * @throws {Error} When a required token is not present
  5712. * @inner
  5713. */
  5714. function skip(expected, optional) {
  5715. var actual = peek(),
  5716. equals = actual === expected;
  5717. if (equals) {
  5718. next();
  5719. return true;
  5720. }
  5721. if (!optional)
  5722. throw illegal("token '" + actual + "', '" + expected + "' expected");
  5723. return false;
  5724. }
  5725. /**
  5726. * Gets a comment.
  5727. * @param {number} [trailingLine] Line number if looking for a trailing comment
  5728. * @returns {string|null} Comment text
  5729. * @inner
  5730. */
  5731. function cmnt(trailingLine) {
  5732. var ret = null;
  5733. var comment;
  5734. if (trailingLine === undefined) {
  5735. comment = comments[line - 1];
  5736. delete comments[line - 1];
  5737. if (comment && (alternateCommentMode || comment.type === "*" || comment.lineEmpty)) {
  5738. ret = comment.leading ? comment.text : null;
  5739. }
  5740. } else {
  5741. /* istanbul ignore else */
  5742. if (lastCommentLine < trailingLine) {
  5743. peek();
  5744. }
  5745. comment = comments[trailingLine];
  5746. delete comments[trailingLine];
  5747. if (comment && !comment.lineEmpty && (alternateCommentMode || comment.type === "/")) {
  5748. ret = comment.leading ? null : comment.text;
  5749. }
  5750. }
  5751. return ret;
  5752. }
  5753. return Object.defineProperty({
  5754. next: next,
  5755. peek: peek,
  5756. push: push,
  5757. skip: skip,
  5758. cmnt: cmnt
  5759. }, "line", {
  5760. get: function() { return line; }
  5761. });
  5762. /* eslint-enable callback-return */
  5763. }
  5764. },{}],35:[function(require,module,exports){
  5765. "use strict";
  5766. module.exports = Type;
  5767. // extends Namespace
  5768. var Namespace = require(23);
  5769. ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
  5770. var Enum = require(15),
  5771. OneOf = require(25),
  5772. Field = require(16),
  5773. MapField = require(20),
  5774. Service = require(33),
  5775. Message = require(21),
  5776. Reader = require(27),
  5777. Writer = require(42),
  5778. util = require(37),
  5779. encoder = require(14),
  5780. decoder = require(13),
  5781. verifier = require(40),
  5782. converter = require(12),
  5783. wrappers = require(41);
  5784. /**
  5785. * Constructs a new reflected message type instance.
  5786. * @classdesc Reflected message type.
  5787. * @extends NamespaceBase
  5788. * @constructor
  5789. * @param {string} name Message name
  5790. * @param {Object.<string,*>} [options] Declared options
  5791. */
  5792. function Type(name, options) {
  5793. Namespace.call(this, name, options);
  5794. /**
  5795. * Message fields.
  5796. * @type {Object.<string,Field>}
  5797. */
  5798. this.fields = {}; // toJSON, marker
  5799. /**
  5800. * Oneofs declared within this namespace, if any.
  5801. * @type {Object.<string,OneOf>}
  5802. */
  5803. this.oneofs = undefined; // toJSON
  5804. /**
  5805. * Extension ranges, if any.
  5806. * @type {number[][]}
  5807. */
  5808. this.extensions = undefined; // toJSON
  5809. /**
  5810. * Reserved ranges, if any.
  5811. * @type {Array.<number[]|string>}
  5812. */
  5813. this.reserved = undefined; // toJSON
  5814. /*?
  5815. * Whether this type is a legacy group.
  5816. * @type {boolean|undefined}
  5817. */
  5818. this.group = undefined; // toJSON
  5819. /**
  5820. * Cached fields by id.
  5821. * @type {Object.<number,Field>|null}
  5822. * @private
  5823. */
  5824. this._fieldsById = null;
  5825. /**
  5826. * Cached fields as an array.
  5827. * @type {Field[]|null}
  5828. * @private
  5829. */
  5830. this._fieldsArray = null;
  5831. /**
  5832. * Cached oneofs as an array.
  5833. * @type {OneOf[]|null}
  5834. * @private
  5835. */
  5836. this._oneofsArray = null;
  5837. /**
  5838. * Cached constructor.
  5839. * @type {Constructor<{}>}
  5840. * @private
  5841. */
  5842. this._ctor = null;
  5843. }
  5844. Object.defineProperties(Type.prototype, {
  5845. /**
  5846. * Message fields by id.
  5847. * @name Type#fieldsById
  5848. * @type {Object.<number,Field>}
  5849. * @readonly
  5850. */
  5851. fieldsById: {
  5852. get: function() {
  5853. /* istanbul ignore if */
  5854. if (this._fieldsById)
  5855. return this._fieldsById;
  5856. this._fieldsById = {};
  5857. for (var names = Object.keys(this.fields), i = 0; i < names.length; ++i) {
  5858. var field = this.fields[names[i]],
  5859. id = field.id;
  5860. /* istanbul ignore if */
  5861. if (this._fieldsById[id])
  5862. throw Error("duplicate id " + id + " in " + this);
  5863. this._fieldsById[id] = field;
  5864. }
  5865. return this._fieldsById;
  5866. }
  5867. },
  5868. /**
  5869. * Fields of this message as an array for iteration.
  5870. * @name Type#fieldsArray
  5871. * @type {Field[]}
  5872. * @readonly
  5873. */
  5874. fieldsArray: {
  5875. get: function() {
  5876. return this._fieldsArray || (this._fieldsArray = util.toArray(this.fields));
  5877. }
  5878. },
  5879. /**
  5880. * Oneofs of this message as an array for iteration.
  5881. * @name Type#oneofsArray
  5882. * @type {OneOf[]}
  5883. * @readonly
  5884. */
  5885. oneofsArray: {
  5886. get: function() {
  5887. return this._oneofsArray || (this._oneofsArray = util.toArray(this.oneofs));
  5888. }
  5889. },
  5890. /**
  5891. * The registered constructor, if any registered, otherwise a generic constructor.
  5892. * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
  5893. * @name Type#ctor
  5894. * @type {Constructor<{}>}
  5895. */
  5896. ctor: {
  5897. get: function() {
  5898. return this._ctor || (this.ctor = Type.generateConstructor(this)());
  5899. },
  5900. set: function(ctor) {
  5901. // Ensure proper prototype
  5902. var prototype = ctor.prototype;
  5903. if (!(prototype instanceof Message)) {
  5904. (ctor.prototype = new Message()).constructor = ctor;
  5905. util.merge(ctor.prototype, prototype);
  5906. }
  5907. // Classes and messages reference their reflected type
  5908. ctor.$type = ctor.prototype.$type = this;
  5909. // Mix in static methods
  5910. util.merge(ctor, Message, true);
  5911. this._ctor = ctor;
  5912. // Messages have non-enumerable default values on their prototype
  5913. var i = 0;
  5914. for (; i < /* initializes */ this.fieldsArray.length; ++i)
  5915. this._fieldsArray[i].resolve(); // ensures a proper value
  5916. // Messages have non-enumerable getters and setters for each virtual oneof field
  5917. var ctorProperties = {};
  5918. for (i = 0; i < /* initializes */ this.oneofsArray.length; ++i)
  5919. ctorProperties[this._oneofsArray[i].resolve().name] = {
  5920. get: util.oneOfGetter(this._oneofsArray[i].oneof),
  5921. set: util.oneOfSetter(this._oneofsArray[i].oneof)
  5922. };
  5923. if (i)
  5924. Object.defineProperties(ctor.prototype, ctorProperties);
  5925. }
  5926. }
  5927. });
  5928. /**
  5929. * Generates a constructor function for the specified type.
  5930. * @param {Type} mtype Message type
  5931. * @returns {Codegen} Codegen instance
  5932. */
  5933. Type.generateConstructor = function generateConstructor(mtype) {
  5934. /* eslint-disable no-unexpected-multiline */
  5935. var gen = util.codegen(["p"], mtype.name);
  5936. // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype
  5937. for (var i = 0, field; i < mtype.fieldsArray.length; ++i)
  5938. if ((field = mtype._fieldsArray[i]).map) gen
  5939. ("this%s={}", util.safeProp(field.name));
  5940. else if (field.repeated) gen
  5941. ("this%s=[]", util.safeProp(field.name));
  5942. return gen
  5943. ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null
  5944. ("this[ks[i]]=p[ks[i]]");
  5945. /* eslint-enable no-unexpected-multiline */
  5946. };
  5947. function clearCache(type) {
  5948. type._fieldsById = type._fieldsArray = type._oneofsArray = null;
  5949. delete type.encode;
  5950. delete type.decode;
  5951. delete type.verify;
  5952. return type;
  5953. }
  5954. /**
  5955. * Message type descriptor.
  5956. * @interface IType
  5957. * @extends INamespace
  5958. * @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
  5959. * @property {Object.<string,IField>} fields Field descriptors
  5960. * @property {number[][]} [extensions] Extension ranges
  5961. * @property {number[][]} [reserved] Reserved ranges
  5962. * @property {boolean} [group=false] Whether a legacy group or not
  5963. */
  5964. /**
  5965. * Creates a message type from a message type descriptor.
  5966. * @param {string} name Message name
  5967. * @param {IType} json Message type descriptor
  5968. * @returns {Type} Created message type
  5969. */
  5970. Type.fromJSON = function fromJSON(name, json) {
  5971. var type = new Type(name, json.options);
  5972. type.extensions = json.extensions;
  5973. type.reserved = json.reserved;
  5974. var names = Object.keys(json.fields),
  5975. i = 0;
  5976. for (; i < names.length; ++i)
  5977. type.add(
  5978. ( typeof json.fields[names[i]].keyType !== "undefined"
  5979. ? MapField.fromJSON
  5980. : Field.fromJSON )(names[i], json.fields[names[i]])
  5981. );
  5982. if (json.oneofs)
  5983. for (names = Object.keys(json.oneofs), i = 0; i < names.length; ++i)
  5984. type.add(OneOf.fromJSON(names[i], json.oneofs[names[i]]));
  5985. if (json.nested)
  5986. for (names = Object.keys(json.nested), i = 0; i < names.length; ++i) {
  5987. var nested = json.nested[names[i]];
  5988. type.add( // most to least likely
  5989. ( nested.id !== undefined
  5990. ? Field.fromJSON
  5991. : nested.fields !== undefined
  5992. ? Type.fromJSON
  5993. : nested.values !== undefined
  5994. ? Enum.fromJSON
  5995. : nested.methods !== undefined
  5996. ? Service.fromJSON
  5997. : Namespace.fromJSON )(names[i], nested)
  5998. );
  5999. }
  6000. if (json.extensions && json.extensions.length)
  6001. type.extensions = json.extensions;
  6002. if (json.reserved && json.reserved.length)
  6003. type.reserved = json.reserved;
  6004. if (json.group)
  6005. type.group = true;
  6006. if (json.comment)
  6007. type.comment = json.comment;
  6008. return type;
  6009. };
  6010. /**
  6011. * Converts this message type to a message type descriptor.
  6012. * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
  6013. * @returns {IType} Message type descriptor
  6014. */
  6015. Type.prototype.toJSON = function toJSON(toJSONOptions) {
  6016. var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
  6017. var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
  6018. return util.toObject([
  6019. "options" , inherited && inherited.options || undefined,
  6020. "oneofs" , Namespace.arrayToJSON(this.oneofsArray, toJSONOptions),
  6021. "fields" , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; }), toJSONOptions) || {},
  6022. "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
  6023. "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
  6024. "group" , this.group || undefined,
  6025. "nested" , inherited && inherited.nested || undefined,
  6026. "comment" , keepComments ? this.comment : undefined
  6027. ]);
  6028. };
  6029. /**
  6030. * @override
  6031. */
  6032. Type.prototype.resolveAll = function resolveAll() {
  6033. var fields = this.fieldsArray, i = 0;
  6034. while (i < fields.length)
  6035. fields[i++].resolve();
  6036. var oneofs = this.oneofsArray; i = 0;
  6037. while (i < oneofs.length)
  6038. oneofs[i++].resolve();
  6039. return Namespace.prototype.resolveAll.call(this);
  6040. };
  6041. /**
  6042. * @override
  6043. */
  6044. Type.prototype.get = function get(name) {
  6045. return this.fields[name]
  6046. || this.oneofs && this.oneofs[name]
  6047. || this.nested && this.nested[name]
  6048. || null;
  6049. };
  6050. /**
  6051. * Adds a nested object to this type.
  6052. * @param {ReflectionObject} object Nested object to add
  6053. * @returns {Type} `this`
  6054. * @throws {TypeError} If arguments are invalid
  6055. * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
  6056. */
  6057. Type.prototype.add = function add(object) {
  6058. if (this.get(object.name))
  6059. throw Error("duplicate name '" + object.name + "' in " + this);
  6060. if (object instanceof Field && object.extend === undefined) {
  6061. // NOTE: Extension fields aren't actual fields on the declaring type, but nested objects.
  6062. // The root object takes care of adding distinct sister-fields to the respective extended
  6063. // type instead.
  6064. // avoids calling the getter if not absolutely necessary because it's called quite frequently
  6065. if (this._fieldsById ? /* istanbul ignore next */ this._fieldsById[object.id] : this.fieldsById[object.id])
  6066. throw Error("duplicate id " + object.id + " in " + this);
  6067. if (this.isReservedId(object.id))
  6068. throw Error("id " + object.id + " is reserved in " + this);
  6069. if (this.isReservedName(object.name))
  6070. throw Error("name '" + object.name + "' is reserved in " + this);
  6071. if (object.parent)
  6072. object.parent.remove(object);
  6073. this.fields[object.name] = object;
  6074. object.message = this;
  6075. object.onAdd(this);
  6076. return clearCache(this);
  6077. }
  6078. if (object instanceof OneOf) {
  6079. if (!this.oneofs)
  6080. this.oneofs = {};
  6081. this.oneofs[object.name] = object;
  6082. object.onAdd(this);
  6083. return clearCache(this);
  6084. }
  6085. return Namespace.prototype.add.call(this, object);
  6086. };
  6087. /**
  6088. * Removes a nested object from this type.
  6089. * @param {ReflectionObject} object Nested object to remove
  6090. * @returns {Type} `this`
  6091. * @throws {TypeError} If arguments are invalid
  6092. * @throws {Error} If `object` is not a member of this type
  6093. */
  6094. Type.prototype.remove = function remove(object) {
  6095. if (object instanceof Field && object.extend === undefined) {
  6096. // See Type#add for the reason why extension fields are excluded here.
  6097. /* istanbul ignore if */
  6098. if (!this.fields || this.fields[object.name] !== object)
  6099. throw Error(object + " is not a member of " + this);
  6100. delete this.fields[object.name];
  6101. object.parent = null;
  6102. object.onRemove(this);
  6103. return clearCache(this);
  6104. }
  6105. if (object instanceof OneOf) {
  6106. /* istanbul ignore if */
  6107. if (!this.oneofs || this.oneofs[object.name] !== object)
  6108. throw Error(object + " is not a member of " + this);
  6109. delete this.oneofs[object.name];
  6110. object.parent = null;
  6111. object.onRemove(this);
  6112. return clearCache(this);
  6113. }
  6114. return Namespace.prototype.remove.call(this, object);
  6115. };
  6116. /**
  6117. * Tests if the specified id is reserved.
  6118. * @param {number} id Id to test
  6119. * @returns {boolean} `true` if reserved, otherwise `false`
  6120. */
  6121. Type.prototype.isReservedId = function isReservedId(id) {
  6122. return Namespace.isReservedId(this.reserved, id);
  6123. };
  6124. /**
  6125. * Tests if the specified name is reserved.
  6126. * @param {string} name Name to test
  6127. * @returns {boolean} `true` if reserved, otherwise `false`
  6128. */
  6129. Type.prototype.isReservedName = function isReservedName(name) {
  6130. return Namespace.isReservedName(this.reserved, name);
  6131. };
  6132. /**
  6133. * Creates a new message of this type using the specified properties.
  6134. * @param {Object.<string,*>} [properties] Properties to set
  6135. * @returns {Message<{}>} Message instance
  6136. */
  6137. Type.prototype.create = function create(properties) {
  6138. return new this.ctor(properties);
  6139. };
  6140. /**
  6141. * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
  6142. * @returns {Type} `this`
  6143. */
  6144. Type.prototype.setup = function setup() {
  6145. // Sets up everything at once so that the prototype chain does not have to be re-evaluated
  6146. // multiple times (V8, soft-deopt prototype-check).
  6147. var fullName = this.fullName,
  6148. types = [];
  6149. for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
  6150. types.push(this._fieldsArray[i].resolve().resolvedType);
  6151. // Replace setup methods with type-specific generated functions
  6152. this.encode = encoder(this)({
  6153. Writer : Writer,
  6154. types : types,
  6155. util : util
  6156. });
  6157. this.decode = decoder(this)({
  6158. Reader : Reader,
  6159. types : types,
  6160. util : util
  6161. });
  6162. this.verify = verifier(this)({
  6163. types : types,
  6164. util : util
  6165. });
  6166. this.fromObject = converter.fromObject(this)({
  6167. types : types,
  6168. util : util
  6169. });
  6170. this.toObject = converter.toObject(this)({
  6171. types : types,
  6172. util : util
  6173. });
  6174. // Inject custom wrappers for common types
  6175. var wrapper = wrappers[fullName];
  6176. if (wrapper) {
  6177. var originalThis = Object.create(this);
  6178. // if (wrapper.fromObject) {
  6179. originalThis.fromObject = this.fromObject;
  6180. this.fromObject = wrapper.fromObject.bind(originalThis);
  6181. // }
  6182. // if (wrapper.toObject) {
  6183. originalThis.toObject = this.toObject;
  6184. this.toObject = wrapper.toObject.bind(originalThis);
  6185. // }
  6186. }
  6187. return this;
  6188. };
  6189. /**
  6190. * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
  6191. * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
  6192. * @param {Writer} [writer] Writer to encode to
  6193. * @returns {Writer} writer
  6194. */
  6195. Type.prototype.encode = function encode_setup(message, writer) {
  6196. return this.setup().encode(message, writer); // overrides this method
  6197. };
  6198. /**
  6199. * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
  6200. * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
  6201. * @param {Writer} [writer] Writer to encode to
  6202. * @returns {Writer} writer
  6203. */
  6204. Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
  6205. return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
  6206. };
  6207. /**
  6208. * Decodes a message of this type.
  6209. * @param {Reader|Uint8Array} reader Reader or buffer to decode from
  6210. * @param {number} [length] Length of the message, if known beforehand
  6211. * @returns {Message<{}>} Decoded message
  6212. * @throws {Error} If the payload is not a reader or valid buffer
  6213. * @throws {util.ProtocolError<{}>} If required fields are missing
  6214. */
  6215. Type.prototype.decode = function decode_setup(reader, length) {
  6216. return this.setup().decode(reader, length); // overrides this method
  6217. };
  6218. /**
  6219. * Decodes a message of this type preceeded by its byte length as a varint.
  6220. * @param {Reader|Uint8Array} reader Reader or buffer to decode from
  6221. * @returns {Message<{}>} Decoded message
  6222. * @throws {Error} If the payload is not a reader or valid buffer
  6223. * @throws {util.ProtocolError} If required fields are missing
  6224. */
  6225. Type.prototype.decodeDelimited = function decodeDelimited(reader) {
  6226. if (!(reader instanceof Reader))
  6227. reader = Reader.create(reader);
  6228. return this.decode(reader, reader.uint32());
  6229. };
  6230. /**
  6231. * Verifies that field values are valid and that required fields are present.
  6232. * @param {Object.<string,*>} message Plain object to verify
  6233. * @returns {null|string} `null` if valid, otherwise the reason why it is not
  6234. */
  6235. Type.prototype.verify = function verify_setup(message) {
  6236. return this.setup().verify(message); // overrides this method
  6237. };
  6238. /**
  6239. * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
  6240. * @param {Object.<string,*>} object Plain object to convert
  6241. * @returns {Message<{}>} Message instance
  6242. */
  6243. Type.prototype.fromObject = function fromObject(object) {
  6244. return this.setup().fromObject(object);
  6245. };
  6246. /**
  6247. * Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
  6248. * @interface IConversionOptions
  6249. * @property {Function} [longs] Long conversion type.
  6250. * Valid values are `String` and `Number` (the global types).
  6251. * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
  6252. * @property {Function} [enums] Enum value conversion type.
  6253. * Only valid value is `String` (the global type).
  6254. * Defaults to copy the present value, which is the numeric id.
  6255. * @property {Function} [bytes] Bytes value conversion type.
  6256. * Valid values are `Array` and (a base64 encoded) `String` (the global types).
  6257. * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.
  6258. * @property {boolean} [defaults=false] Also sets default values on the resulting object
  6259. * @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
  6260. * @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
  6261. * @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any
  6262. * @property {boolean} [json=false] Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings
  6263. */
  6264. /**
  6265. * Creates a plain object from a message of this type. Also converts values to other types if specified.
  6266. * @param {Message<{}>} message Message instance
  6267. * @param {IConversionOptions} [options] Conversion options
  6268. * @returns {Object.<string,*>} Plain object
  6269. */
  6270. Type.prototype.toObject = function toObject(message, options) {
  6271. return this.setup().toObject(message, options);
  6272. };
  6273. /**
  6274. * Decorator function as returned by {@link Type.d} (TypeScript).
  6275. * @typedef TypeDecorator
  6276. * @type {function}
  6277. * @param {Constructor<T>} target Target constructor
  6278. * @returns {undefined}
  6279. * @template T extends Message<T>
  6280. */
  6281. /**
  6282. * Type decorator (TypeScript).
  6283. * @param {string} [typeName] Type name, defaults to the constructor's name
  6284. * @returns {TypeDecorator<T>} Decorator function
  6285. * @template T extends Message<T>
  6286. */
  6287. Type.d = function decorateType(typeName) {
  6288. return function typeDecorator(target) {
  6289. util.decorateType(target, typeName);
  6290. };
  6291. };
  6292. },{"12":12,"13":13,"14":14,"15":15,"16":16,"20":20,"21":21,"23":23,"25":25,"27":27,"33":33,"37":37,"40":40,"41":41,"42":42}],36:[function(require,module,exports){
  6293. "use strict";
  6294. /**
  6295. * Common type constants.
  6296. * @namespace
  6297. */
  6298. var types = exports;
  6299. var util = require(37);
  6300. var s = [
  6301. "double", // 0
  6302. "float", // 1
  6303. "int32", // 2
  6304. "uint32", // 3
  6305. "sint32", // 4
  6306. "fixed32", // 5
  6307. "sfixed32", // 6
  6308. "int64", // 7
  6309. "uint64", // 8
  6310. "sint64", // 9
  6311. "fixed64", // 10
  6312. "sfixed64", // 11
  6313. "bool", // 12
  6314. "string", // 13
  6315. "bytes" // 14
  6316. ];
  6317. function bake(values, offset) {
  6318. var i = 0, o = {};
  6319. offset |= 0;
  6320. while (i < values.length) o[s[i + offset]] = values[i++];
  6321. return o;
  6322. }
  6323. /**
  6324. * Basic type wire types.
  6325. * @type {Object.<string,number>}
  6326. * @const
  6327. * @property {number} double=1 Fixed64 wire type
  6328. * @property {number} float=5 Fixed32 wire type
  6329. * @property {number} int32=0 Varint wire type
  6330. * @property {number} uint32=0 Varint wire type
  6331. * @property {number} sint32=0 Varint wire type
  6332. * @property {number} fixed32=5 Fixed32 wire type
  6333. * @property {number} sfixed32=5 Fixed32 wire type
  6334. * @property {number} int64=0 Varint wire type
  6335. * @property {number} uint64=0 Varint wire type
  6336. * @property {number} sint64=0 Varint wire type
  6337. * @property {number} fixed64=1 Fixed64 wire type
  6338. * @property {number} sfixed64=1 Fixed64 wire type
  6339. * @property {number} bool=0 Varint wire type
  6340. * @property {number} string=2 Ldelim wire type
  6341. * @property {number} bytes=2 Ldelim wire type
  6342. */
  6343. types.basic = bake([
  6344. /* double */ 1,
  6345. /* float */ 5,
  6346. /* int32 */ 0,
  6347. /* uint32 */ 0,
  6348. /* sint32 */ 0,
  6349. /* fixed32 */ 5,
  6350. /* sfixed32 */ 5,
  6351. /* int64 */ 0,
  6352. /* uint64 */ 0,
  6353. /* sint64 */ 0,
  6354. /* fixed64 */ 1,
  6355. /* sfixed64 */ 1,
  6356. /* bool */ 0,
  6357. /* string */ 2,
  6358. /* bytes */ 2
  6359. ]);
  6360. /**
  6361. * Basic type defaults.
  6362. * @type {Object.<string,*>}
  6363. * @const
  6364. * @property {number} double=0 Double default
  6365. * @property {number} float=0 Float default
  6366. * @property {number} int32=0 Int32 default
  6367. * @property {number} uint32=0 Uint32 default
  6368. * @property {number} sint32=0 Sint32 default
  6369. * @property {number} fixed32=0 Fixed32 default
  6370. * @property {number} sfixed32=0 Sfixed32 default
  6371. * @property {number} int64=0 Int64 default
  6372. * @property {number} uint64=0 Uint64 default
  6373. * @property {number} sint64=0 Sint32 default
  6374. * @property {number} fixed64=0 Fixed64 default
  6375. * @property {number} sfixed64=0 Sfixed64 default
  6376. * @property {boolean} bool=false Bool default
  6377. * @property {string} string="" String default
  6378. * @property {Array.<number>} bytes=Array(0) Bytes default
  6379. * @property {null} message=null Message default
  6380. */
  6381. types.defaults = bake([
  6382. /* double */ 0,
  6383. /* float */ 0,
  6384. /* int32 */ 0,
  6385. /* uint32 */ 0,
  6386. /* sint32 */ 0,
  6387. /* fixed32 */ 0,
  6388. /* sfixed32 */ 0,
  6389. /* int64 */ 0,
  6390. /* uint64 */ 0,
  6391. /* sint64 */ 0,
  6392. /* fixed64 */ 0,
  6393. /* sfixed64 */ 0,
  6394. /* bool */ false,
  6395. /* string */ "",
  6396. /* bytes */ util.emptyArray,
  6397. /* message */ null
  6398. ]);
  6399. /**
  6400. * Basic long type wire types.
  6401. * @type {Object.<string,number>}
  6402. * @const
  6403. * @property {number} int64=0 Varint wire type
  6404. * @property {number} uint64=0 Varint wire type
  6405. * @property {number} sint64=0 Varint wire type
  6406. * @property {number} fixed64=1 Fixed64 wire type
  6407. * @property {number} sfixed64=1 Fixed64 wire type
  6408. */
  6409. types.long = bake([
  6410. /* int64 */ 0,
  6411. /* uint64 */ 0,
  6412. /* sint64 */ 0,
  6413. /* fixed64 */ 1,
  6414. /* sfixed64 */ 1
  6415. ], 7);
  6416. /**
  6417. * Allowed types for map keys with their associated wire type.
  6418. * @type {Object.<string,number>}
  6419. * @const
  6420. * @property {number} int32=0 Varint wire type
  6421. * @property {number} uint32=0 Varint wire type
  6422. * @property {number} sint32=0 Varint wire type
  6423. * @property {number} fixed32=5 Fixed32 wire type
  6424. * @property {number} sfixed32=5 Fixed32 wire type
  6425. * @property {number} int64=0 Varint wire type
  6426. * @property {number} uint64=0 Varint wire type
  6427. * @property {number} sint64=0 Varint wire type
  6428. * @property {number} fixed64=1 Fixed64 wire type
  6429. * @property {number} sfixed64=1 Fixed64 wire type
  6430. * @property {number} bool=0 Varint wire type
  6431. * @property {number} string=2 Ldelim wire type
  6432. */
  6433. types.mapKey = bake([
  6434. /* int32 */ 0,
  6435. /* uint32 */ 0,
  6436. /* sint32 */ 0,
  6437. /* fixed32 */ 5,
  6438. /* sfixed32 */ 5,
  6439. /* int64 */ 0,
  6440. /* uint64 */ 0,
  6441. /* sint64 */ 0,
  6442. /* fixed64 */ 1,
  6443. /* sfixed64 */ 1,
  6444. /* bool */ 0,
  6445. /* string */ 2
  6446. ], 2);
  6447. /**
  6448. * Allowed types for packed repeated fields with their associated wire type.
  6449. * @type {Object.<string,number>}
  6450. * @const
  6451. * @property {number} double=1 Fixed64 wire type
  6452. * @property {number} float=5 Fixed32 wire type
  6453. * @property {number} int32=0 Varint wire type
  6454. * @property {number} uint32=0 Varint wire type
  6455. * @property {number} sint32=0 Varint wire type
  6456. * @property {number} fixed32=5 Fixed32 wire type
  6457. * @property {number} sfixed32=5 Fixed32 wire type
  6458. * @property {number} int64=0 Varint wire type
  6459. * @property {number} uint64=0 Varint wire type
  6460. * @property {number} sint64=0 Varint wire type
  6461. * @property {number} fixed64=1 Fixed64 wire type
  6462. * @property {number} sfixed64=1 Fixed64 wire type
  6463. * @property {number} bool=0 Varint wire type
  6464. */
  6465. types.packed = bake([
  6466. /* double */ 1,
  6467. /* float */ 5,
  6468. /* int32 */ 0,
  6469. /* uint32 */ 0,
  6470. /* sint32 */ 0,
  6471. /* fixed32 */ 5,
  6472. /* sfixed32 */ 5,
  6473. /* int64 */ 0,
  6474. /* uint64 */ 0,
  6475. /* sint64 */ 0,
  6476. /* fixed64 */ 1,
  6477. /* sfixed64 */ 1,
  6478. /* bool */ 0
  6479. ]);
  6480. },{"37":37}],37:[function(require,module,exports){
  6481. "use strict";
  6482. /**
  6483. * Various utility functions.
  6484. * @namespace
  6485. */
  6486. var util = module.exports = require(39);
  6487. var roots = require(30);
  6488. var Type, // cyclic
  6489. Enum;
  6490. util.codegen = require(3);
  6491. util.fetch = require(5);
  6492. util.path = require(8);
  6493. /**
  6494. * Node's fs module if available.
  6495. * @type {Object.<string,*>}
  6496. */
  6497. util.fs = util.inquire("fs");
  6498. /**
  6499. * Converts an object's values to an array.
  6500. * @param {Object.<string,*>} object Object to convert
  6501. * @returns {Array.<*>} Converted array
  6502. */
  6503. util.toArray = function toArray(object) {
  6504. if (object) {
  6505. var keys = Object.keys(object),
  6506. array = new Array(keys.length),
  6507. index = 0;
  6508. while (index < keys.length)
  6509. array[index] = object[keys[index++]];
  6510. return array;
  6511. }
  6512. return [];
  6513. };
  6514. /**
  6515. * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
  6516. * @param {Array.<*>} array Array to convert
  6517. * @returns {Object.<string,*>} Converted object
  6518. */
  6519. util.toObject = function toObject(array) {
  6520. var object = {},
  6521. index = 0;
  6522. while (index < array.length) {
  6523. var key = array[index++],
  6524. val = array[index++];
  6525. if (val !== undefined)
  6526. object[key] = val;
  6527. }
  6528. return object;
  6529. };
  6530. var safePropBackslashRe = /\\/g,
  6531. safePropQuoteRe = /"/g;
  6532. /**
  6533. * Tests whether the specified name is a reserved word in JS.
  6534. * @param {string} name Name to test
  6535. * @returns {boolean} `true` if reserved, otherwise `false`
  6536. */
  6537. util.isReserved = function isReserved(name) {
  6538. return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name);
  6539. };
  6540. /**
  6541. * Returns a safe property accessor for the specified property name.
  6542. * @param {string} prop Property name
  6543. * @returns {string} Safe accessor
  6544. */
  6545. util.safeProp = function safeProp(prop) {
  6546. if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))
  6547. return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
  6548. return "." + prop;
  6549. };
  6550. /**
  6551. * Converts the first character of a string to upper case.
  6552. * @param {string} str String to convert
  6553. * @returns {string} Converted string
  6554. */
  6555. util.ucFirst = function ucFirst(str) {
  6556. return str.charAt(0).toUpperCase() + str.substring(1);
  6557. };
  6558. var camelCaseRe = /_([a-z])/g;
  6559. /**
  6560. * Converts a string to camel case.
  6561. * @param {string} str String to convert
  6562. * @returns {string} Converted string
  6563. */
  6564. util.camelCase = function camelCase(str) {
  6565. return str.substring(0, 1)
  6566. + str.substring(1)
  6567. .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
  6568. };
  6569. /**
  6570. * Compares reflected fields by id.
  6571. * @param {Field} a First field
  6572. * @param {Field} b Second field
  6573. * @returns {number} Comparison value
  6574. */
  6575. util.compareFieldsById = function compareFieldsById(a, b) {
  6576. return a.id - b.id;
  6577. };
  6578. /**
  6579. * Decorator helper for types (TypeScript).
  6580. * @param {Constructor<T>} ctor Constructor function
  6581. * @param {string} [typeName] Type name, defaults to the constructor's name
  6582. * @returns {Type} Reflected type
  6583. * @template T extends Message<T>
  6584. * @property {Root} root Decorators root
  6585. */
  6586. util.decorateType = function decorateType(ctor, typeName) {
  6587. /* istanbul ignore if */
  6588. if (ctor.$type) {
  6589. if (typeName && ctor.$type.name !== typeName) {
  6590. util.decorateRoot.remove(ctor.$type);
  6591. ctor.$type.name = typeName;
  6592. util.decorateRoot.add(ctor.$type);
  6593. }
  6594. return ctor.$type;
  6595. }
  6596. /* istanbul ignore next */
  6597. if (!Type)
  6598. Type = require(35);
  6599. var type = new Type(typeName || ctor.name);
  6600. util.decorateRoot.add(type);
  6601. type.ctor = ctor; // sets up .encode, .decode etc.
  6602. Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
  6603. Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
  6604. return type;
  6605. };
  6606. var decorateEnumIndex = 0;
  6607. /**
  6608. * Decorator helper for enums (TypeScript).
  6609. * @param {Object} object Enum object
  6610. * @returns {Enum} Reflected enum
  6611. */
  6612. util.decorateEnum = function decorateEnum(object) {
  6613. /* istanbul ignore if */
  6614. if (object.$type)
  6615. return object.$type;
  6616. /* istanbul ignore next */
  6617. if (!Enum)
  6618. Enum = require(15);
  6619. var enm = new Enum("Enum" + decorateEnumIndex++, object);
  6620. util.decorateRoot.add(enm);
  6621. Object.defineProperty(object, "$type", { value: enm, enumerable: false });
  6622. return enm;
  6623. };
  6624. /**
  6625. * Sets the value of a property by property path. If a value already exists, it is turned to an array
  6626. * @param {Object.<string,*>} dst Destination object
  6627. * @param {string} path dot '.' delimited path of the property to set
  6628. * @param {Object} value the value to set
  6629. * @returns {Object.<string,*>} Destination object
  6630. */
  6631. util.setProperty = function setProperty(dst, path, value) {
  6632. function setProp(dst, path, value) {
  6633. var part = path.shift();
  6634. if (part === "__proto__") {
  6635. return dst;
  6636. }
  6637. if (path.length > 0) {
  6638. dst[part] = setProp(dst[part] || {}, path, value);
  6639. } else {
  6640. var prevValue = dst[part];
  6641. if (prevValue)
  6642. value = [].concat(prevValue).concat(value);
  6643. dst[part] = value;
  6644. }
  6645. return dst;
  6646. }
  6647. if (typeof dst !== "object")
  6648. throw TypeError("dst must be an object");
  6649. if (!path)
  6650. throw TypeError("path must be specified");
  6651. path = path.split(".");
  6652. return setProp(dst, path, value);
  6653. };
  6654. /**
  6655. * Decorator root (TypeScript).
  6656. * @name util.decorateRoot
  6657. * @type {Root}
  6658. * @readonly
  6659. */
  6660. Object.defineProperty(util, "decorateRoot", {
  6661. get: function() {
  6662. return roots["decorated"] || (roots["decorated"] = new (require(29))());
  6663. }
  6664. });
  6665. },{"15":15,"29":29,"3":3,"30":30,"35":35,"39":39,"5":5,"8":8}],38:[function(require,module,exports){
  6666. "use strict";
  6667. module.exports = LongBits;
  6668. var util = require(39);
  6669. /**
  6670. * Constructs new long bits.
  6671. * @classdesc Helper class for working with the low and high bits of a 64 bit value.
  6672. * @memberof util
  6673. * @constructor
  6674. * @param {number} lo Low 32 bits, unsigned
  6675. * @param {number} hi High 32 bits, unsigned
  6676. */
  6677. function LongBits(lo, hi) {
  6678. // note that the casts below are theoretically unnecessary as of today, but older statically
  6679. // generated converter code might still call the ctor with signed 32bits. kept for compat.
  6680. /**
  6681. * Low bits.
  6682. * @type {number}
  6683. */
  6684. this.lo = lo >>> 0;
  6685. /**
  6686. * High bits.
  6687. * @type {number}
  6688. */
  6689. this.hi = hi >>> 0;
  6690. }
  6691. /**
  6692. * Zero bits.
  6693. * @memberof util.LongBits
  6694. * @type {util.LongBits}
  6695. */
  6696. var zero = LongBits.zero = new LongBits(0, 0);
  6697. zero.toNumber = function() { return 0; };
  6698. zero.zzEncode = zero.zzDecode = function() { return this; };
  6699. zero.length = function() { return 1; };
  6700. /**
  6701. * Zero hash.
  6702. * @memberof util.LongBits
  6703. * @type {string}
  6704. */
  6705. var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
  6706. /**
  6707. * Constructs new long bits from the specified number.
  6708. * @param {number} value Value
  6709. * @returns {util.LongBits} Instance
  6710. */
  6711. LongBits.fromNumber = function fromNumber(value) {
  6712. if (value === 0)
  6713. return zero;
  6714. var sign = value < 0;
  6715. if (sign)
  6716. value = -value;
  6717. var lo = value >>> 0,
  6718. hi = (value - lo) / 4294967296 >>> 0;
  6719. if (sign) {
  6720. hi = ~hi >>> 0;
  6721. lo = ~lo >>> 0;
  6722. if (++lo > 4294967295) {
  6723. lo = 0;
  6724. if (++hi > 4294967295)
  6725. hi = 0;
  6726. }
  6727. }
  6728. return new LongBits(lo, hi);
  6729. };
  6730. /**
  6731. * Constructs new long bits from a number, long or string.
  6732. * @param {Long|number|string} value Value
  6733. * @returns {util.LongBits} Instance
  6734. */
  6735. LongBits.from = function from(value) {
  6736. if (typeof value === "number")
  6737. return LongBits.fromNumber(value);
  6738. if (util.isString(value)) {
  6739. /* istanbul ignore else */
  6740. if (util.Long)
  6741. value = util.Long.fromString(value);
  6742. else
  6743. return LongBits.fromNumber(parseInt(value, 10));
  6744. }
  6745. return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
  6746. };
  6747. /**
  6748. * Converts this long bits to a possibly unsafe JavaScript number.
  6749. * @param {boolean} [unsigned=false] Whether unsigned or not
  6750. * @returns {number} Possibly unsafe number
  6751. */
  6752. LongBits.prototype.toNumber = function toNumber(unsigned) {
  6753. if (!unsigned && this.hi >>> 31) {
  6754. var lo = ~this.lo + 1 >>> 0,
  6755. hi = ~this.hi >>> 0;
  6756. if (!lo)
  6757. hi = hi + 1 >>> 0;
  6758. return -(lo + hi * 4294967296);
  6759. }
  6760. return this.lo + this.hi * 4294967296;
  6761. };
  6762. /**
  6763. * Converts this long bits to a long.
  6764. * @param {boolean} [unsigned=false] Whether unsigned or not
  6765. * @returns {Long} Long
  6766. */
  6767. LongBits.prototype.toLong = function toLong(unsigned) {
  6768. return util.Long
  6769. ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
  6770. /* istanbul ignore next */
  6771. : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
  6772. };
  6773. var charCodeAt = String.prototype.charCodeAt;
  6774. /**
  6775. * Constructs new long bits from the specified 8 characters long hash.
  6776. * @param {string} hash Hash
  6777. * @returns {util.LongBits} Bits
  6778. */
  6779. LongBits.fromHash = function fromHash(hash) {
  6780. if (hash === zeroHash)
  6781. return zero;
  6782. return new LongBits(
  6783. ( charCodeAt.call(hash, 0)
  6784. | charCodeAt.call(hash, 1) << 8
  6785. | charCodeAt.call(hash, 2) << 16
  6786. | charCodeAt.call(hash, 3) << 24) >>> 0
  6787. ,
  6788. ( charCodeAt.call(hash, 4)
  6789. | charCodeAt.call(hash, 5) << 8
  6790. | charCodeAt.call(hash, 6) << 16
  6791. | charCodeAt.call(hash, 7) << 24) >>> 0
  6792. );
  6793. };
  6794. /**
  6795. * Converts this long bits to a 8 characters long hash.
  6796. * @returns {string} Hash
  6797. */
  6798. LongBits.prototype.toHash = function toHash() {
  6799. return String.fromCharCode(
  6800. this.lo & 255,
  6801. this.lo >>> 8 & 255,
  6802. this.lo >>> 16 & 255,
  6803. this.lo >>> 24 ,
  6804. this.hi & 255,
  6805. this.hi >>> 8 & 255,
  6806. this.hi >>> 16 & 255,
  6807. this.hi >>> 24
  6808. );
  6809. };
  6810. /**
  6811. * Zig-zag encodes this long bits.
  6812. * @returns {util.LongBits} `this`
  6813. */
  6814. LongBits.prototype.zzEncode = function zzEncode() {
  6815. var mask = this.hi >> 31;
  6816. this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
  6817. this.lo = ( this.lo << 1 ^ mask) >>> 0;
  6818. return this;
  6819. };
  6820. /**
  6821. * Zig-zag decodes this long bits.
  6822. * @returns {util.LongBits} `this`
  6823. */
  6824. LongBits.prototype.zzDecode = function zzDecode() {
  6825. var mask = -(this.lo & 1);
  6826. this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
  6827. this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
  6828. return this;
  6829. };
  6830. /**
  6831. * Calculates the length of this longbits when encoded as a varint.
  6832. * @returns {number} Length
  6833. */
  6834. LongBits.prototype.length = function length() {
  6835. var part0 = this.lo,
  6836. part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
  6837. part2 = this.hi >>> 24;
  6838. return part2 === 0
  6839. ? part1 === 0
  6840. ? part0 < 16384
  6841. ? part0 < 128 ? 1 : 2
  6842. : part0 < 2097152 ? 3 : 4
  6843. : part1 < 16384
  6844. ? part1 < 128 ? 5 : 6
  6845. : part1 < 2097152 ? 7 : 8
  6846. : part2 < 128 ? 9 : 10;
  6847. };
  6848. },{"39":39}],39:[function(require,module,exports){
  6849. "use strict";
  6850. var util = exports;
  6851. // used to return a Promise where callback is omitted
  6852. util.asPromise = require(1);
  6853. // converts to / from base64 encoded strings
  6854. util.base64 = require(2);
  6855. // base class of rpc.Service
  6856. util.EventEmitter = require(4);
  6857. // float handling accross browsers
  6858. util.float = require(6);
  6859. // requires modules optionally and hides the call from bundlers
  6860. util.inquire = require(7);
  6861. // converts to / from utf8 encoded strings
  6862. util.utf8 = require(10);
  6863. // provides a node-like buffer pool in the browser
  6864. util.pool = require(9);
  6865. // utility to work with the low and high bits of a 64 bit value
  6866. util.LongBits = require(38);
  6867. /**
  6868. * Whether running within node or not.
  6869. * @memberof util
  6870. * @type {boolean}
  6871. */
  6872. util.isNode = Boolean(typeof global !== "undefined"
  6873. && global
  6874. && global.process
  6875. && global.process.versions
  6876. && global.process.versions.node);
  6877. /**
  6878. * Global object reference.
  6879. * @memberof util
  6880. * @type {Object}
  6881. */
  6882. util.global = util.isNode && global
  6883. || typeof window !== "undefined" && window
  6884. || typeof self !== "undefined" && self
  6885. || this; // eslint-disable-line no-invalid-this
  6886. /**
  6887. * An immuable empty array.
  6888. * @memberof util
  6889. * @type {Array.<*>}
  6890. * @const
  6891. */
  6892. util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
  6893. /**
  6894. * An immutable empty object.
  6895. * @type {Object}
  6896. * @const
  6897. */
  6898. util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
  6899. /**
  6900. * Tests if the specified value is an integer.
  6901. * @function
  6902. * @param {*} value Value to test
  6903. * @returns {boolean} `true` if the value is an integer
  6904. */
  6905. util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
  6906. return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
  6907. };
  6908. /**
  6909. * Tests if the specified value is a string.
  6910. * @param {*} value Value to test
  6911. * @returns {boolean} `true` if the value is a string
  6912. */
  6913. util.isString = function isString(value) {
  6914. return typeof value === "string" || value instanceof String;
  6915. };
  6916. /**
  6917. * Tests if the specified value is a non-null object.
  6918. * @param {*} value Value to test
  6919. * @returns {boolean} `true` if the value is a non-null object
  6920. */
  6921. util.isObject = function isObject(value) {
  6922. return value && typeof value === "object";
  6923. };
  6924. /**
  6925. * Checks if a property on a message is considered to be present.
  6926. * This is an alias of {@link util.isSet}.
  6927. * @function
  6928. * @param {Object} obj Plain object or message instance
  6929. * @param {string} prop Property name
  6930. * @returns {boolean} `true` if considered to be present, otherwise `false`
  6931. */
  6932. util.isset =
  6933. /**
  6934. * Checks if a property on a message is considered to be present.
  6935. * @param {Object} obj Plain object or message instance
  6936. * @param {string} prop Property name
  6937. * @returns {boolean} `true` if considered to be present, otherwise `false`
  6938. */
  6939. util.isSet = function isSet(obj, prop) {
  6940. var value = obj[prop];
  6941. if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
  6942. return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
  6943. return false;
  6944. };
  6945. /**
  6946. * Any compatible Buffer instance.
  6947. * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
  6948. * @interface Buffer
  6949. * @extends Uint8Array
  6950. */
  6951. /**
  6952. * Node's Buffer class if available.
  6953. * @type {Constructor<Buffer>}
  6954. */
  6955. util.Buffer = (function() {
  6956. try {
  6957. var Buffer = util.inquire("buffer").Buffer;
  6958. // refuse to use non-node buffers if not explicitly assigned (perf reasons):
  6959. return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
  6960. } catch (e) {
  6961. /* istanbul ignore next */
  6962. return null;
  6963. }
  6964. })();
  6965. // Internal alias of or polyfull for Buffer.from.
  6966. util._Buffer_from = null;
  6967. // Internal alias of or polyfill for Buffer.allocUnsafe.
  6968. util._Buffer_allocUnsafe = null;
  6969. /**
  6970. * Creates a new buffer of whatever type supported by the environment.
  6971. * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
  6972. * @returns {Uint8Array|Buffer} Buffer
  6973. */
  6974. util.newBuffer = function newBuffer(sizeOrArray) {
  6975. /* istanbul ignore next */
  6976. return typeof sizeOrArray === "number"
  6977. ? util.Buffer
  6978. ? util._Buffer_allocUnsafe(sizeOrArray)
  6979. : new util.Array(sizeOrArray)
  6980. : util.Buffer
  6981. ? util._Buffer_from(sizeOrArray)
  6982. : typeof Uint8Array === "undefined"
  6983. ? sizeOrArray
  6984. : new Uint8Array(sizeOrArray);
  6985. };
  6986. /**
  6987. * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
  6988. * @type {Constructor<Uint8Array>}
  6989. */
  6990. util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
  6991. /**
  6992. * Any compatible Long instance.
  6993. * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
  6994. * @interface Long
  6995. * @property {number} low Low bits
  6996. * @property {number} high High bits
  6997. * @property {boolean} unsigned Whether unsigned or not
  6998. */
  6999. /**
  7000. * Long.js's Long class if available.
  7001. * @type {Constructor<Long>}
  7002. */
  7003. util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
  7004. || /* istanbul ignore next */ util.global.Long
  7005. || util.inquire("long");
  7006. /**
  7007. * Regular expression used to verify 2 bit (`bool`) map keys.
  7008. * @type {RegExp}
  7009. * @const
  7010. */
  7011. util.key2Re = /^true|false|0|1$/;
  7012. /**
  7013. * Regular expression used to verify 32 bit (`int32` etc.) map keys.
  7014. * @type {RegExp}
  7015. * @const
  7016. */
  7017. util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
  7018. /**
  7019. * Regular expression used to verify 64 bit (`int64` etc.) map keys.
  7020. * @type {RegExp}
  7021. * @const
  7022. */
  7023. util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
  7024. /**
  7025. * Converts a number or long to an 8 characters long hash string.
  7026. * @param {Long|number} value Value to convert
  7027. * @returns {string} Hash
  7028. */
  7029. util.longToHash = function longToHash(value) {
  7030. return value
  7031. ? util.LongBits.from(value).toHash()
  7032. : util.LongBits.zeroHash;
  7033. };
  7034. /**
  7035. * Converts an 8 characters long hash string to a long or number.
  7036. * @param {string} hash Hash
  7037. * @param {boolean} [unsigned=false] Whether unsigned or not
  7038. * @returns {Long|number} Original value
  7039. */
  7040. util.longFromHash = function longFromHash(hash, unsigned) {
  7041. var bits = util.LongBits.fromHash(hash);
  7042. if (util.Long)
  7043. return util.Long.fromBits(bits.lo, bits.hi, unsigned);
  7044. return bits.toNumber(Boolean(unsigned));
  7045. };
  7046. /**
  7047. * Merges the properties of the source object into the destination object.
  7048. * @memberof util
  7049. * @param {Object.<string,*>} dst Destination object
  7050. * @param {Object.<string,*>} src Source object
  7051. * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
  7052. * @returns {Object.<string,*>} Destination object
  7053. */
  7054. function merge(dst, src, ifNotSet) { // used by converters
  7055. for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
  7056. if (dst[keys[i]] === undefined || !ifNotSet)
  7057. dst[keys[i]] = src[keys[i]];
  7058. return dst;
  7059. }
  7060. util.merge = merge;
  7061. /**
  7062. * Converts the first character of a string to lower case.
  7063. * @param {string} str String to convert
  7064. * @returns {string} Converted string
  7065. */
  7066. util.lcFirst = function lcFirst(str) {
  7067. return str.charAt(0).toLowerCase() + str.substring(1);
  7068. };
  7069. /**
  7070. * Creates a custom error constructor.
  7071. * @memberof util
  7072. * @param {string} name Error name
  7073. * @returns {Constructor<Error>} Custom error constructor
  7074. */
  7075. function newError(name) {
  7076. function CustomError(message, properties) {
  7077. if (!(this instanceof CustomError))
  7078. return new CustomError(message, properties);
  7079. // Error.call(this, message);
  7080. // ^ just returns a new error instance because the ctor can be called as a function
  7081. Object.defineProperty(this, "message", { get: function() { return message; } });
  7082. /* istanbul ignore next */
  7083. if (Error.captureStackTrace) // node
  7084. Error.captureStackTrace(this, CustomError);
  7085. else
  7086. Object.defineProperty(this, "stack", { value: new Error().stack || "" });
  7087. if (properties)
  7088. merge(this, properties);
  7089. }
  7090. CustomError.prototype = Object.create(Error.prototype, {
  7091. constructor: {
  7092. value: CustomError,
  7093. writable: true,
  7094. enumerable: false,
  7095. configurable: true,
  7096. },
  7097. name: {
  7098. get() { return name; },
  7099. set: undefined,
  7100. enumerable: false,
  7101. // configurable: false would accurately preserve the behavior of
  7102. // the original, but I'm guessing that was not intentional.
  7103. // For an actual error subclass, this property would
  7104. // be configurable.
  7105. configurable: true,
  7106. },
  7107. toString: {
  7108. value() { return this.name + ": " + this.message; },
  7109. writable: true,
  7110. enumerable: false,
  7111. configurable: true,
  7112. },
  7113. });
  7114. return CustomError;
  7115. }
  7116. util.newError = newError;
  7117. /**
  7118. * Constructs a new protocol error.
  7119. * @classdesc Error subclass indicating a protocol specifc error.
  7120. * @memberof util
  7121. * @extends Error
  7122. * @template T extends Message<T>
  7123. * @constructor
  7124. * @param {string} message Error message
  7125. * @param {Object.<string,*>} [properties] Additional properties
  7126. * @example
  7127. * try {
  7128. * MyMessage.decode(someBuffer); // throws if required fields are missing
  7129. * } catch (e) {
  7130. * if (e instanceof ProtocolError && e.instance)
  7131. * console.log("decoded so far: " + JSON.stringify(e.instance));
  7132. * }
  7133. */
  7134. util.ProtocolError = newError("ProtocolError");
  7135. /**
  7136. * So far decoded message instance.
  7137. * @name util.ProtocolError#instance
  7138. * @type {Message<T>}
  7139. */
  7140. /**
  7141. * A OneOf getter as returned by {@link util.oneOfGetter}.
  7142. * @typedef OneOfGetter
  7143. * @type {function}
  7144. * @returns {string|undefined} Set field name, if any
  7145. */
  7146. /**
  7147. * Builds a getter for a oneof's present field name.
  7148. * @param {string[]} fieldNames Field names
  7149. * @returns {OneOfGetter} Unbound getter
  7150. */
  7151. util.oneOfGetter = function getOneOf(fieldNames) {
  7152. var fieldMap = {};
  7153. for (var i = 0; i < fieldNames.length; ++i)
  7154. fieldMap[fieldNames[i]] = 1;
  7155. /**
  7156. * @returns {string|undefined} Set field name, if any
  7157. * @this Object
  7158. * @ignore
  7159. */
  7160. return function() { // eslint-disable-line consistent-return
  7161. for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
  7162. if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
  7163. return keys[i];
  7164. };
  7165. };
  7166. /**
  7167. * A OneOf setter as returned by {@link util.oneOfSetter}.
  7168. * @typedef OneOfSetter
  7169. * @type {function}
  7170. * @param {string|undefined} value Field name
  7171. * @returns {undefined}
  7172. */
  7173. /**
  7174. * Builds a setter for a oneof's present field name.
  7175. * @param {string[]} fieldNames Field names
  7176. * @returns {OneOfSetter} Unbound setter
  7177. */
  7178. util.oneOfSetter = function setOneOf(fieldNames) {
  7179. /**
  7180. * @param {string} name Field name
  7181. * @returns {undefined}
  7182. * @this Object
  7183. * @ignore
  7184. */
  7185. return function(name) {
  7186. for (var i = 0; i < fieldNames.length; ++i)
  7187. if (fieldNames[i] !== name)
  7188. delete this[fieldNames[i]];
  7189. };
  7190. };
  7191. /**
  7192. * Default conversion options used for {@link Message#toJSON} implementations.
  7193. *
  7194. * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
  7195. *
  7196. * - Longs become strings
  7197. * - Enums become string keys
  7198. * - Bytes become base64 encoded strings
  7199. * - (Sub-)Messages become plain objects
  7200. * - Maps become plain objects with all string keys
  7201. * - Repeated fields become arrays
  7202. * - NaN and Infinity for float and double fields become strings
  7203. *
  7204. * @type {IConversionOptions}
  7205. * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
  7206. */
  7207. util.toJSONOptions = {
  7208. longs: String,
  7209. enums: String,
  7210. bytes: String,
  7211. json: true
  7212. };
  7213. // Sets up buffer utility according to the environment (called in index-minimal)
  7214. util._configure = function() {
  7215. var Buffer = util.Buffer;
  7216. /* istanbul ignore if */
  7217. if (!Buffer) {
  7218. util._Buffer_from = util._Buffer_allocUnsafe = null;
  7219. return;
  7220. }
  7221. // because node 4.x buffers are incompatible & immutable
  7222. // see: https://github.com/dcodeIO/protobuf.js/pull/665
  7223. util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
  7224. /* istanbul ignore next */
  7225. function Buffer_from(value, encoding) {
  7226. return new Buffer(value, encoding);
  7227. };
  7228. util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
  7229. /* istanbul ignore next */
  7230. function Buffer_allocUnsafe(size) {
  7231. return new Buffer(size);
  7232. };
  7233. };
  7234. },{"1":1,"10":10,"2":2,"38":38,"4":4,"6":6,"7":7,"9":9}],40:[function(require,module,exports){
  7235. "use strict";
  7236. module.exports = verifier;
  7237. var Enum = require(15),
  7238. util = require(37);
  7239. function invalid(field, expected) {
  7240. return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
  7241. }
  7242. /**
  7243. * Generates a partial value verifier.
  7244. * @param {Codegen} gen Codegen instance
  7245. * @param {Field} field Reflected field
  7246. * @param {number} fieldIndex Field index
  7247. * @param {string} ref Variable reference
  7248. * @returns {Codegen} Codegen instance
  7249. * @ignore
  7250. */
  7251. function genVerifyValue(gen, field, fieldIndex, ref) {
  7252. /* eslint-disable no-unexpected-multiline */
  7253. if (field.resolvedType) {
  7254. if (field.resolvedType instanceof Enum) { gen
  7255. ("switch(%s){", ref)
  7256. ("default:")
  7257. ("return%j", invalid(field, "enum value"));
  7258. for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
  7259. ("case %i:", field.resolvedType.values[keys[j]]);
  7260. gen
  7261. ("break")
  7262. ("}");
  7263. } else {
  7264. gen
  7265. ("{")
  7266. ("var e=types[%i].verify(%s);", fieldIndex, ref)
  7267. ("if(e)")
  7268. ("return%j+e", field.name + ".")
  7269. ("}");
  7270. }
  7271. } else {
  7272. switch (field.type) {
  7273. case "int32":
  7274. case "uint32":
  7275. case "sint32":
  7276. case "fixed32":
  7277. case "sfixed32": gen
  7278. ("if(!util.isInteger(%s))", ref)
  7279. ("return%j", invalid(field, "integer"));
  7280. break;
  7281. case "int64":
  7282. case "uint64":
  7283. case "sint64":
  7284. case "fixed64":
  7285. case "sfixed64": gen
  7286. ("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))", ref, ref, ref, ref)
  7287. ("return%j", invalid(field, "integer|Long"));
  7288. break;
  7289. case "float":
  7290. case "double": gen
  7291. ("if(typeof %s!==\"number\")", ref)
  7292. ("return%j", invalid(field, "number"));
  7293. break;
  7294. case "bool": gen
  7295. ("if(typeof %s!==\"boolean\")", ref)
  7296. ("return%j", invalid(field, "boolean"));
  7297. break;
  7298. case "string": gen
  7299. ("if(!util.isString(%s))", ref)
  7300. ("return%j", invalid(field, "string"));
  7301. break;
  7302. case "bytes": gen
  7303. ("if(!(%s&&typeof %s.length===\"number\"||util.isString(%s)))", ref, ref, ref)
  7304. ("return%j", invalid(field, "buffer"));
  7305. break;
  7306. }
  7307. }
  7308. return gen;
  7309. /* eslint-enable no-unexpected-multiline */
  7310. }
  7311. /**
  7312. * Generates a partial key verifier.
  7313. * @param {Codegen} gen Codegen instance
  7314. * @param {Field} field Reflected field
  7315. * @param {string} ref Variable reference
  7316. * @returns {Codegen} Codegen instance
  7317. * @ignore
  7318. */
  7319. function genVerifyKey(gen, field, ref) {
  7320. /* eslint-disable no-unexpected-multiline */
  7321. switch (field.keyType) {
  7322. case "int32":
  7323. case "uint32":
  7324. case "sint32":
  7325. case "fixed32":
  7326. case "sfixed32": gen
  7327. ("if(!util.key32Re.test(%s))", ref)
  7328. ("return%j", invalid(field, "integer key"));
  7329. break;
  7330. case "int64":
  7331. case "uint64":
  7332. case "sint64":
  7333. case "fixed64":
  7334. case "sfixed64": gen
  7335. ("if(!util.key64Re.test(%s))", ref) // see comment above: x is ok, d is not
  7336. ("return%j", invalid(field, "integer|Long key"));
  7337. break;
  7338. case "bool": gen
  7339. ("if(!util.key2Re.test(%s))", ref)
  7340. ("return%j", invalid(field, "boolean key"));
  7341. break;
  7342. }
  7343. return gen;
  7344. /* eslint-enable no-unexpected-multiline */
  7345. }
  7346. /**
  7347. * Generates a verifier specific to the specified message type.
  7348. * @param {Type} mtype Message type
  7349. * @returns {Codegen} Codegen instance
  7350. */
  7351. function verifier(mtype) {
  7352. /* eslint-disable no-unexpected-multiline */
  7353. var gen = util.codegen(["m"], mtype.name + "$verify")
  7354. ("if(typeof m!==\"object\"||m===null)")
  7355. ("return%j", "object expected");
  7356. var oneofs = mtype.oneofsArray,
  7357. seenFirstField = {};
  7358. if (oneofs.length) gen
  7359. ("var p={}");
  7360. for (var i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
  7361. var field = mtype._fieldsArray[i].resolve(),
  7362. ref = "m" + util.safeProp(field.name);
  7363. if (field.optional) gen
  7364. ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
  7365. // map fields
  7366. if (field.map) { gen
  7367. ("if(!util.isObject(%s))", ref)
  7368. ("return%j", invalid(field, "object"))
  7369. ("var k=Object.keys(%s)", ref)
  7370. ("for(var i=0;i<k.length;++i){");
  7371. genVerifyKey(gen, field, "k[i]");
  7372. genVerifyValue(gen, field, i, ref + "[k[i]]")
  7373. ("}");
  7374. // repeated fields
  7375. } else if (field.repeated) { gen
  7376. ("if(!Array.isArray(%s))", ref)
  7377. ("return%j", invalid(field, "array"))
  7378. ("for(var i=0;i<%s.length;++i){", ref);
  7379. genVerifyValue(gen, field, i, ref + "[i]")
  7380. ("}");
  7381. // required or present fields
  7382. } else {
  7383. if (field.partOf) {
  7384. var oneofProp = util.safeProp(field.partOf.name);
  7385. if (seenFirstField[field.partOf.name] === 1) gen
  7386. ("if(p%s===1)", oneofProp)
  7387. ("return%j", field.partOf.name + ": multiple values");
  7388. seenFirstField[field.partOf.name] = 1;
  7389. gen
  7390. ("p%s=1", oneofProp);
  7391. }
  7392. genVerifyValue(gen, field, i, ref);
  7393. }
  7394. if (field.optional) gen
  7395. ("}");
  7396. }
  7397. return gen
  7398. ("return null");
  7399. /* eslint-enable no-unexpected-multiline */
  7400. }
  7401. },{"15":15,"37":37}],41:[function(require,module,exports){
  7402. "use strict";
  7403. /**
  7404. * Wrappers for common types.
  7405. * @type {Object.<string,IWrapper>}
  7406. * @const
  7407. */
  7408. var wrappers = exports;
  7409. var Message = require(21);
  7410. /**
  7411. * From object converter part of an {@link IWrapper}.
  7412. * @typedef WrapperFromObjectConverter
  7413. * @type {function}
  7414. * @param {Object.<string,*>} object Plain object
  7415. * @returns {Message<{}>} Message instance
  7416. * @this Type
  7417. */
  7418. /**
  7419. * To object converter part of an {@link IWrapper}.
  7420. * @typedef WrapperToObjectConverter
  7421. * @type {function}
  7422. * @param {Message<{}>} message Message instance
  7423. * @param {IConversionOptions} [options] Conversion options
  7424. * @returns {Object.<string,*>} Plain object
  7425. * @this Type
  7426. */
  7427. /**
  7428. * Common type wrapper part of {@link wrappers}.
  7429. * @interface IWrapper
  7430. * @property {WrapperFromObjectConverter} [fromObject] From object converter
  7431. * @property {WrapperToObjectConverter} [toObject] To object converter
  7432. */
  7433. // Custom wrapper for Any
  7434. wrappers[".google.protobuf.Any"] = {
  7435. fromObject: function(object) {
  7436. // unwrap value type if mapped
  7437. if (object && object["@type"]) {
  7438. // Only use fully qualified type name after the last '/'
  7439. var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
  7440. var type = this.lookup(name);
  7441. /* istanbul ignore else */
  7442. if (type) {
  7443. // type_url does not accept leading "."
  7444. var type_url = object["@type"].charAt(0) === "." ?
  7445. object["@type"].slice(1) : object["@type"];
  7446. // type_url prefix is optional, but path seperator is required
  7447. if (type_url.indexOf("/") === -1) {
  7448. type_url = "/" + type_url;
  7449. }
  7450. return this.create({
  7451. type_url: type_url,
  7452. value: type.encode(type.fromObject(object)).finish()
  7453. });
  7454. }
  7455. }
  7456. return this.fromObject(object);
  7457. },
  7458. toObject: function(message, options) {
  7459. // Default prefix
  7460. var googleApi = "type.googleapis.com/";
  7461. var prefix = "";
  7462. var name = "";
  7463. // decode value if requested and unmapped
  7464. if (options && options.json && message.type_url && message.value) {
  7465. // Only use fully qualified type name after the last '/'
  7466. name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
  7467. // Separate the prefix used
  7468. prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
  7469. var type = this.lookup(name);
  7470. /* istanbul ignore else */
  7471. if (type)
  7472. message = type.decode(message.value);
  7473. }
  7474. // wrap value if unmapped
  7475. if (!(message instanceof this.ctor) && message instanceof Message) {
  7476. var object = message.$type.toObject(message, options);
  7477. var messageName = message.$type.fullName[0] === "." ?
  7478. message.$type.fullName.slice(1) : message.$type.fullName;
  7479. // Default to type.googleapis.com prefix if no prefix is used
  7480. if (prefix === "") {
  7481. prefix = googleApi;
  7482. }
  7483. name = prefix + messageName;
  7484. object["@type"] = name;
  7485. return object;
  7486. }
  7487. return this.toObject(message, options);
  7488. }
  7489. };
  7490. },{"21":21}],42:[function(require,module,exports){
  7491. "use strict";
  7492. module.exports = Writer;
  7493. var util = require(39);
  7494. var BufferWriter; // cyclic
  7495. var LongBits = util.LongBits,
  7496. base64 = util.base64,
  7497. utf8 = util.utf8;
  7498. /**
  7499. * Constructs a new writer operation instance.
  7500. * @classdesc Scheduled writer operation.
  7501. * @constructor
  7502. * @param {function(*, Uint8Array, number)} fn Function to call
  7503. * @param {number} len Value byte length
  7504. * @param {*} val Value to write
  7505. * @ignore
  7506. */
  7507. function Op(fn, len, val) {
  7508. /**
  7509. * Function to call.
  7510. * @type {function(Uint8Array, number, *)}
  7511. */
  7512. this.fn = fn;
  7513. /**
  7514. * Value byte length.
  7515. * @type {number}
  7516. */
  7517. this.len = len;
  7518. /**
  7519. * Next operation.
  7520. * @type {Writer.Op|undefined}
  7521. */
  7522. this.next = undefined;
  7523. /**
  7524. * Value to write.
  7525. * @type {*}
  7526. */
  7527. this.val = val; // type varies
  7528. }
  7529. /* istanbul ignore next */
  7530. function noop() {} // eslint-disable-line no-empty-function
  7531. /**
  7532. * Constructs a new writer state instance.
  7533. * @classdesc Copied writer state.
  7534. * @memberof Writer
  7535. * @constructor
  7536. * @param {Writer} writer Writer to copy state from
  7537. * @ignore
  7538. */
  7539. function State(writer) {
  7540. /**
  7541. * Current head.
  7542. * @type {Writer.Op}
  7543. */
  7544. this.head = writer.head;
  7545. /**
  7546. * Current tail.
  7547. * @type {Writer.Op}
  7548. */
  7549. this.tail = writer.tail;
  7550. /**
  7551. * Current buffer length.
  7552. * @type {number}
  7553. */
  7554. this.len = writer.len;
  7555. /**
  7556. * Next state.
  7557. * @type {State|null}
  7558. */
  7559. this.next = writer.states;
  7560. }
  7561. /**
  7562. * Constructs a new writer instance.
  7563. * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
  7564. * @constructor
  7565. */
  7566. function Writer() {
  7567. /**
  7568. * Current length.
  7569. * @type {number}
  7570. */
  7571. this.len = 0;
  7572. /**
  7573. * Operations head.
  7574. * @type {Object}
  7575. */
  7576. this.head = new Op(noop, 0, 0);
  7577. /**
  7578. * Operations tail
  7579. * @type {Object}
  7580. */
  7581. this.tail = this.head;
  7582. /**
  7583. * Linked forked states.
  7584. * @type {Object|null}
  7585. */
  7586. this.states = null;
  7587. // When a value is written, the writer calculates its byte length and puts it into a linked
  7588. // list of operations to perform when finish() is called. This both allows us to allocate
  7589. // buffers of the exact required size and reduces the amount of work we have to do compared
  7590. // to first calculating over objects and then encoding over objects. In our case, the encoding
  7591. // part is just a linked list walk calling operations with already prepared values.
  7592. }
  7593. var create = function create() {
  7594. return util.Buffer
  7595. ? function create_buffer_setup() {
  7596. return (Writer.create = function create_buffer() {
  7597. return new BufferWriter();
  7598. })();
  7599. }
  7600. /* istanbul ignore next */
  7601. : function create_array() {
  7602. return new Writer();
  7603. };
  7604. };
  7605. /**
  7606. * Creates a new writer.
  7607. * @function
  7608. * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
  7609. */
  7610. Writer.create = create();
  7611. /**
  7612. * Allocates a buffer of the specified size.
  7613. * @param {number} size Buffer size
  7614. * @returns {Uint8Array} Buffer
  7615. */
  7616. Writer.alloc = function alloc(size) {
  7617. return new util.Array(size);
  7618. };
  7619. // Use Uint8Array buffer pool in the browser, just like node does with buffers
  7620. /* istanbul ignore else */
  7621. if (util.Array !== Array)
  7622. Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
  7623. /**
  7624. * Pushes a new operation to the queue.
  7625. * @param {function(Uint8Array, number, *)} fn Function to call
  7626. * @param {number} len Value byte length
  7627. * @param {number} val Value to write
  7628. * @returns {Writer} `this`
  7629. * @private
  7630. */
  7631. Writer.prototype._push = function push(fn, len, val) {
  7632. this.tail = this.tail.next = new Op(fn, len, val);
  7633. this.len += len;
  7634. return this;
  7635. };
  7636. function writeByte(val, buf, pos) {
  7637. buf[pos] = val & 255;
  7638. }
  7639. function writeVarint32(val, buf, pos) {
  7640. while (val > 127) {
  7641. buf[pos++] = val & 127 | 128;
  7642. val >>>= 7;
  7643. }
  7644. buf[pos] = val;
  7645. }
  7646. /**
  7647. * Constructs a new varint writer operation instance.
  7648. * @classdesc Scheduled varint writer operation.
  7649. * @extends Op
  7650. * @constructor
  7651. * @param {number} len Value byte length
  7652. * @param {number} val Value to write
  7653. * @ignore
  7654. */
  7655. function VarintOp(len, val) {
  7656. this.len = len;
  7657. this.next = undefined;
  7658. this.val = val;
  7659. }
  7660. VarintOp.prototype = Object.create(Op.prototype);
  7661. VarintOp.prototype.fn = writeVarint32;
  7662. /**
  7663. * Writes an unsigned 32 bit value as a varint.
  7664. * @param {number} value Value to write
  7665. * @returns {Writer} `this`
  7666. */
  7667. Writer.prototype.uint32 = function write_uint32(value) {
  7668. // here, the call to this.push has been inlined and a varint specific Op subclass is used.
  7669. // uint32 is by far the most frequently used operation and benefits significantly from this.
  7670. this.len += (this.tail = this.tail.next = new VarintOp(
  7671. (value = value >>> 0)
  7672. < 128 ? 1
  7673. : value < 16384 ? 2
  7674. : value < 2097152 ? 3
  7675. : value < 268435456 ? 4
  7676. : 5,
  7677. value)).len;
  7678. return this;
  7679. };
  7680. /**
  7681. * Writes a signed 32 bit value as a varint.
  7682. * @function
  7683. * @param {number} value Value to write
  7684. * @returns {Writer} `this`
  7685. */
  7686. Writer.prototype.int32 = function write_int32(value) {
  7687. return value < 0
  7688. ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
  7689. : this.uint32(value);
  7690. };
  7691. /**
  7692. * Writes a 32 bit value as a varint, zig-zag encoded.
  7693. * @param {number} value Value to write
  7694. * @returns {Writer} `this`
  7695. */
  7696. Writer.prototype.sint32 = function write_sint32(value) {
  7697. return this.uint32((value << 1 ^ value >> 31) >>> 0);
  7698. };
  7699. function writeVarint64(val, buf, pos) {
  7700. while (val.hi) {
  7701. buf[pos++] = val.lo & 127 | 128;
  7702. val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
  7703. val.hi >>>= 7;
  7704. }
  7705. while (val.lo > 127) {
  7706. buf[pos++] = val.lo & 127 | 128;
  7707. val.lo = val.lo >>> 7;
  7708. }
  7709. buf[pos++] = val.lo;
  7710. }
  7711. /**
  7712. * Writes an unsigned 64 bit value as a varint.
  7713. * @param {Long|number|string} value Value to write
  7714. * @returns {Writer} `this`
  7715. * @throws {TypeError} If `value` is a string and no long library is present.
  7716. */
  7717. Writer.prototype.uint64 = function write_uint64(value) {
  7718. var bits = LongBits.from(value);
  7719. return this._push(writeVarint64, bits.length(), bits);
  7720. };
  7721. /**
  7722. * Writes a signed 64 bit value as a varint.
  7723. * @function
  7724. * @param {Long|number|string} value Value to write
  7725. * @returns {Writer} `this`
  7726. * @throws {TypeError} If `value` is a string and no long library is present.
  7727. */
  7728. Writer.prototype.int64 = Writer.prototype.uint64;
  7729. /**
  7730. * Writes a signed 64 bit value as a varint, zig-zag encoded.
  7731. * @param {Long|number|string} value Value to write
  7732. * @returns {Writer} `this`
  7733. * @throws {TypeError} If `value` is a string and no long library is present.
  7734. */
  7735. Writer.prototype.sint64 = function write_sint64(value) {
  7736. var bits = LongBits.from(value).zzEncode();
  7737. return this._push(writeVarint64, bits.length(), bits);
  7738. };
  7739. /**
  7740. * Writes a boolish value as a varint.
  7741. * @param {boolean} value Value to write
  7742. * @returns {Writer} `this`
  7743. */
  7744. Writer.prototype.bool = function write_bool(value) {
  7745. return this._push(writeByte, 1, value ? 1 : 0);
  7746. };
  7747. function writeFixed32(val, buf, pos) {
  7748. buf[pos ] = val & 255;
  7749. buf[pos + 1] = val >>> 8 & 255;
  7750. buf[pos + 2] = val >>> 16 & 255;
  7751. buf[pos + 3] = val >>> 24;
  7752. }
  7753. /**
  7754. * Writes an unsigned 32 bit value as fixed 32 bits.
  7755. * @param {number} value Value to write
  7756. * @returns {Writer} `this`
  7757. */
  7758. Writer.prototype.fixed32 = function write_fixed32(value) {
  7759. return this._push(writeFixed32, 4, value >>> 0);
  7760. };
  7761. /**
  7762. * Writes a signed 32 bit value as fixed 32 bits.
  7763. * @function
  7764. * @param {number} value Value to write
  7765. * @returns {Writer} `this`
  7766. */
  7767. Writer.prototype.sfixed32 = Writer.prototype.fixed32;
  7768. /**
  7769. * Writes an unsigned 64 bit value as fixed 64 bits.
  7770. * @param {Long|number|string} value Value to write
  7771. * @returns {Writer} `this`
  7772. * @throws {TypeError} If `value` is a string and no long library is present.
  7773. */
  7774. Writer.prototype.fixed64 = function write_fixed64(value) {
  7775. var bits = LongBits.from(value);
  7776. return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
  7777. };
  7778. /**
  7779. * Writes a signed 64 bit value as fixed 64 bits.
  7780. * @function
  7781. * @param {Long|number|string} value Value to write
  7782. * @returns {Writer} `this`
  7783. * @throws {TypeError} If `value` is a string and no long library is present.
  7784. */
  7785. Writer.prototype.sfixed64 = Writer.prototype.fixed64;
  7786. /**
  7787. * Writes a float (32 bit).
  7788. * @function
  7789. * @param {number} value Value to write
  7790. * @returns {Writer} `this`
  7791. */
  7792. Writer.prototype.float = function write_float(value) {
  7793. return this._push(util.float.writeFloatLE, 4, value);
  7794. };
  7795. /**
  7796. * Writes a double (64 bit float).
  7797. * @function
  7798. * @param {number} value Value to write
  7799. * @returns {Writer} `this`
  7800. */
  7801. Writer.prototype.double = function write_double(value) {
  7802. return this._push(util.float.writeDoubleLE, 8, value);
  7803. };
  7804. var writeBytes = util.Array.prototype.set
  7805. ? function writeBytes_set(val, buf, pos) {
  7806. buf.set(val, pos); // also works for plain array values
  7807. }
  7808. /* istanbul ignore next */
  7809. : function writeBytes_for(val, buf, pos) {
  7810. for (var i = 0; i < val.length; ++i)
  7811. buf[pos + i] = val[i];
  7812. };
  7813. /**
  7814. * Writes a sequence of bytes.
  7815. * @param {Uint8Array|string} value Buffer or base64 encoded string to write
  7816. * @returns {Writer} `this`
  7817. */
  7818. Writer.prototype.bytes = function write_bytes(value) {
  7819. var len = value.length >>> 0;
  7820. if (!len)
  7821. return this._push(writeByte, 1, 0);
  7822. if (util.isString(value)) {
  7823. var buf = Writer.alloc(len = base64.length(value));
  7824. base64.decode(value, buf, 0);
  7825. value = buf;
  7826. }
  7827. return this.uint32(len)._push(writeBytes, len, value);
  7828. };
  7829. /**
  7830. * Writes a string.
  7831. * @param {string} value Value to write
  7832. * @returns {Writer} `this`
  7833. */
  7834. Writer.prototype.string = function write_string(value) {
  7835. var len = utf8.length(value);
  7836. return len
  7837. ? this.uint32(len)._push(utf8.write, len, value)
  7838. : this._push(writeByte, 1, 0);
  7839. };
  7840. /**
  7841. * Forks this writer's state by pushing it to a stack.
  7842. * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
  7843. * @returns {Writer} `this`
  7844. */
  7845. Writer.prototype.fork = function fork() {
  7846. this.states = new State(this);
  7847. this.head = this.tail = new Op(noop, 0, 0);
  7848. this.len = 0;
  7849. return this;
  7850. };
  7851. /**
  7852. * Resets this instance to the last state.
  7853. * @returns {Writer} `this`
  7854. */
  7855. Writer.prototype.reset = function reset() {
  7856. if (this.states) {
  7857. this.head = this.states.head;
  7858. this.tail = this.states.tail;
  7859. this.len = this.states.len;
  7860. this.states = this.states.next;
  7861. } else {
  7862. this.head = this.tail = new Op(noop, 0, 0);
  7863. this.len = 0;
  7864. }
  7865. return this;
  7866. };
  7867. /**
  7868. * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
  7869. * @returns {Writer} `this`
  7870. */
  7871. Writer.prototype.ldelim = function ldelim() {
  7872. var head = this.head,
  7873. tail = this.tail,
  7874. len = this.len;
  7875. this.reset().uint32(len);
  7876. if (len) {
  7877. this.tail.next = head.next; // skip noop
  7878. this.tail = tail;
  7879. this.len += len;
  7880. }
  7881. return this;
  7882. };
  7883. /**
  7884. * Finishes the write operation.
  7885. * @returns {Uint8Array} Finished buffer
  7886. */
  7887. Writer.prototype.finish = function finish() {
  7888. var head = this.head.next, // skip noop
  7889. buf = this.constructor.alloc(this.len),
  7890. pos = 0;
  7891. while (head) {
  7892. head.fn(head.val, buf, pos);
  7893. pos += head.len;
  7894. head = head.next;
  7895. }
  7896. // this.head = this.tail = null;
  7897. return buf;
  7898. };
  7899. Writer._configure = function(BufferWriter_) {
  7900. BufferWriter = BufferWriter_;
  7901. Writer.create = create();
  7902. BufferWriter._configure();
  7903. };
  7904. },{"39":39}],43:[function(require,module,exports){
  7905. "use strict";
  7906. module.exports = BufferWriter;
  7907. // extends Writer
  7908. var Writer = require(42);
  7909. (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
  7910. var util = require(39);
  7911. /**
  7912. * Constructs a new buffer writer instance.
  7913. * @classdesc Wire format writer using node buffers.
  7914. * @extends Writer
  7915. * @constructor
  7916. */
  7917. function BufferWriter() {
  7918. Writer.call(this);
  7919. }
  7920. BufferWriter._configure = function () {
  7921. /**
  7922. * Allocates a buffer of the specified size.
  7923. * @function
  7924. * @param {number} size Buffer size
  7925. * @returns {Buffer} Buffer
  7926. */
  7927. BufferWriter.alloc = util._Buffer_allocUnsafe;
  7928. BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set"
  7929. ? function writeBytesBuffer_set(val, buf, pos) {
  7930. buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
  7931. // also works for plain array values
  7932. }
  7933. /* istanbul ignore next */
  7934. : function writeBytesBuffer_copy(val, buf, pos) {
  7935. if (val.copy) // Buffer values
  7936. val.copy(buf, pos, 0, val.length);
  7937. else for (var i = 0; i < val.length;) // plain array values
  7938. buf[pos++] = val[i++];
  7939. };
  7940. };
  7941. /**
  7942. * @override
  7943. */
  7944. BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
  7945. if (util.isString(value))
  7946. value = util._Buffer_from(value, "base64");
  7947. var len = value.length >>> 0;
  7948. this.uint32(len);
  7949. if (len)
  7950. this._push(BufferWriter.writeBytesBuffer, len, value);
  7951. return this;
  7952. };
  7953. function writeStringBuffer(val, buf, pos) {
  7954. if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
  7955. util.utf8.write(val, buf, pos);
  7956. else if (buf.utf8Write)
  7957. buf.utf8Write(val, pos);
  7958. else
  7959. buf.write(val, pos);
  7960. }
  7961. /**
  7962. * @override
  7963. */
  7964. BufferWriter.prototype.string = function write_string_buffer(value) {
  7965. var len = util.Buffer.byteLength(value);
  7966. this.uint32(len);
  7967. if (len)
  7968. this._push(writeStringBuffer, len, value);
  7969. return this;
  7970. };
  7971. /**
  7972. * Finishes the write operation.
  7973. * @name BufferWriter#finish
  7974. * @function
  7975. * @returns {Buffer} Finished buffer
  7976. */
  7977. BufferWriter._configure();
  7978. },{"39":39,"42":42}]},{},[19])
  7979. })();
  7980. //# sourceMappingURL=protobuf.js.map