protobuf.js 274 KB

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