protobuf.js 262 KB

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