protobuf.js 269 KB

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