protobuf.js 261 KB

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