protobuf.js 260 KB

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