upb.h 459 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641
  1. /* Amalgamated source file */
  2. #if UINTPTR_MAX == 0xffffffff
  3. #define UPB_SIZE(size32, size64) size32
  4. #else
  5. #define UPB_SIZE(size32, size64) size64
  6. #endif
  7. #define UPB_FIELD_AT(msg, fieldtype, offset) \
  8. *(fieldtype*)((const char*)(msg) + offset)
  9. #define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
  10. UPB_FIELD_AT(msg, int, case_offset) == case_val \
  11. ? UPB_FIELD_AT(msg, fieldtype, offset) \
  12. : default
  13. #define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
  14. UPB_FIELD_AT(msg, int, case_offset) = case_val; \
  15. UPB_FIELD_AT(msg, fieldtype, offset) = value;
  16. /*
  17. ** upb::Message is a representation for protobuf messages.
  18. **
  19. ** However it differs from other common representations like
  20. ** google::protobuf::Message in one key way: it does not prescribe any
  21. ** ownership between messages and submessages, and it relies on the
  22. ** client to ensure that each submessage/array/map outlives its parent.
  23. **
  24. ** All messages, arrays, and maps live in an Arena. If the entire message
  25. ** tree is in the same arena, ensuring proper lifetimes is simple. However
  26. ** the client can mix arenas as long as they ensure that there are no
  27. ** dangling pointers.
  28. **
  29. ** A client can access a upb::Message without knowing anything about
  30. ** ownership semantics, but to create or mutate a message a user needs
  31. ** to implement the memory management themselves.
  32. **
  33. ** TODO: UTF-8 checking?
  34. **/
  35. #ifndef UPB_MSG_H_
  36. #define UPB_MSG_H_
  37. /*
  38. ** Defs are upb's internal representation of the constructs that can appear
  39. ** in a .proto file:
  40. **
  41. ** - upb::MessageDef (upb_msgdef): describes a "message" construct.
  42. ** - upb::FieldDef (upb_fielddef): describes a message field.
  43. ** - upb::FileDef (upb_filedef): describes a .proto file and its defs.
  44. ** - upb::EnumDef (upb_enumdef): describes an enum.
  45. ** - upb::OneofDef (upb_oneofdef): describes a oneof.
  46. ** - upb::Def (upb_def): base class of all the others.
  47. **
  48. ** TODO: definitions of services.
  49. **
  50. ** Like upb_refcounted objects, defs are mutable only until frozen, and are
  51. ** only thread-safe once frozen.
  52. **
  53. ** This is a mixed C/C++ interface that offers a full API to both languages.
  54. ** See the top-level README for more information.
  55. */
  56. #ifndef UPB_DEF_H_
  57. #define UPB_DEF_H_
  58. /*
  59. ** upb::RefCounted (upb_refcounted)
  60. **
  61. ** A refcounting scheme that supports circular refs. It accomplishes this by
  62. ** partitioning the set of objects into groups such that no cycle spans groups;
  63. ** we can then reference-count the group as a whole and ignore refs within the
  64. ** group. When objects are mutable, these groups are computed very
  65. ** conservatively; we group any objects that have ever had a link between them.
  66. ** When objects are frozen, we compute strongly-connected components which
  67. ** allows us to be precise and only group objects that are actually cyclic.
  68. **
  69. ** This is a mixed C/C++ interface that offers a full API to both languages.
  70. ** See the top-level README for more information.
  71. */
  72. #ifndef UPB_REFCOUNTED_H_
  73. #define UPB_REFCOUNTED_H_
  74. /*
  75. ** upb_table
  76. **
  77. ** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
  78. ** This file defines very fast int->upb_value (inttable) and string->upb_value
  79. ** (strtable) hash tables.
  80. **
  81. ** The table uses chained scatter with Brent's variation (inspired by the Lua
  82. ** implementation of hash tables). The hash function for strings is Austin
  83. ** Appleby's "MurmurHash."
  84. **
  85. ** The inttable uses uintptr_t as its key, which guarantees it can be used to
  86. ** store pointers or integers of at least 32 bits (upb isn't really useful on
  87. ** systems where sizeof(void*) < 4).
  88. **
  89. ** The table must be homogenous (all values of the same type). In debug
  90. ** mode, we check this on insert and lookup.
  91. */
  92. #ifndef UPB_TABLE_H_
  93. #define UPB_TABLE_H_
  94. #include <stdint.h>
  95. #include <string.h>
  96. /*
  97. ** This file contains shared definitions that are widely used across upb.
  98. **
  99. ** This is a mixed C/C++ interface that offers a full API to both languages.
  100. ** See the top-level README for more information.
  101. */
  102. #ifndef UPB_H_
  103. #define UPB_H_
  104. #include <assert.h>
  105. #include <stdarg.h>
  106. #include <stdbool.h>
  107. #include <stddef.h>
  108. #ifdef __cplusplus
  109. namespace upb {
  110. class Allocator;
  111. class Arena;
  112. class Environment;
  113. class ErrorSpace;
  114. class Status;
  115. template <int N> class InlinedArena;
  116. template <int N> class InlinedEnvironment;
  117. }
  118. #endif
  119. /* UPB_INLINE: inline if possible, emit standalone code if required. */
  120. #ifdef __cplusplus
  121. #define UPB_INLINE inline
  122. #elif defined (__GNUC__)
  123. #define UPB_INLINE static __inline__
  124. #else
  125. #define UPB_INLINE static
  126. #endif
  127. /* Hints to the compiler about likely/unlikely branches. */
  128. #define UPB_LIKELY(x) __builtin_expect((x),1)
  129. /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
  130. * doesn't provide these preprocessor symbols. */
  131. #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  132. #define UPB_BIG_ENDIAN
  133. #endif
  134. /* Macros for function attributes on compilers that support them. */
  135. #ifdef __GNUC__
  136. #define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
  137. #define UPB_NOINLINE __attribute__((noinline))
  138. #define UPB_NORETURN __attribute__((__noreturn__))
  139. #else /* !defined(__GNUC__) */
  140. #define UPB_FORCEINLINE
  141. #define UPB_NOINLINE
  142. #define UPB_NORETURN
  143. #endif
  144. #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
  145. /* C99/C++11 versions. */
  146. #include <stdio.h>
  147. #define _upb_snprintf snprintf
  148. #define _upb_vsnprintf vsnprintf
  149. #define _upb_va_copy(a, b) va_copy(a, b)
  150. #elif defined __GNUC__
  151. /* A few hacky workarounds for functions not in C89.
  152. * For internal use only!
  153. * TODO(haberman): fix these by including our own implementations, or finding
  154. * another workaround.
  155. */
  156. #define _upb_snprintf __builtin_snprintf
  157. #define _upb_vsnprintf __builtin_vsnprintf
  158. #define _upb_va_copy(a, b) __va_copy(a, b)
  159. #else
  160. #error Need implementations of [v]snprintf and va_copy
  161. #endif
  162. #if ((defined(__cplusplus) && __cplusplus >= 201103L) || \
  163. defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(UPB_NO_CXX11)
  164. #define UPB_CXX11
  165. #endif
  166. /* UPB_DISALLOW_COPY_AND_ASSIGN()
  167. * UPB_DISALLOW_POD_OPS()
  168. *
  169. * Declare these in the "private" section of a C++ class to forbid copy/assign
  170. * or all POD ops (construct, destruct, copy, assign) on that class. */
  171. #ifdef UPB_CXX11
  172. #include <type_traits>
  173. #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
  174. class_name(const class_name&) = delete; \
  175. void operator=(const class_name&) = delete;
  176. #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
  177. class_name() = delete; \
  178. ~class_name() = delete; \
  179. UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
  180. #define UPB_ASSERT_STDLAYOUT(type) \
  181. static_assert(std::is_standard_layout<type>::value, \
  182. #type " must be standard layout");
  183. #define UPB_FINAL final
  184. #else /* !defined(UPB_CXX11) */
  185. #define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
  186. class_name(const class_name&); \
  187. void operator=(const class_name&);
  188. #define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
  189. class_name(); \
  190. ~class_name(); \
  191. UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
  192. #define UPB_ASSERT_STDLAYOUT(type)
  193. #define UPB_FINAL
  194. #endif
  195. /* UPB_DECLARE_TYPE()
  196. * UPB_DECLARE_DERIVED_TYPE()
  197. * UPB_DECLARE_DERIVED_TYPE2()
  198. *
  199. * Macros for declaring C and C++ types both, including inheritance.
  200. * The inheritance doesn't use real C++ inheritance, to stay compatible with C.
  201. *
  202. * These macros also provide upcasts:
  203. * - in C: types-specific functions (ie. upb_foo_upcast(foo))
  204. * - in C++: upb::upcast(foo) along with implicit conversions
  205. *
  206. * Downcasts are not provided, but upb/def.h defines downcasts for upb::Def. */
  207. #define UPB_C_UPCASTS(ty, base) \
  208. UPB_INLINE base *ty ## _upcast_mutable(ty *p) { return (base*)p; } \
  209. UPB_INLINE const base *ty ## _upcast(const ty *p) { return (const base*)p; }
  210. #define UPB_C_UPCASTS2(ty, base, base2) \
  211. UPB_C_UPCASTS(ty, base) \
  212. UPB_INLINE base2 *ty ## _upcast2_mutable(ty *p) { return (base2*)p; } \
  213. UPB_INLINE const base2 *ty ## _upcast2(const ty *p) { return (const base2*)p; }
  214. #ifdef __cplusplus
  215. #define UPB_BEGIN_EXTERN_C extern "C" {
  216. #define UPB_END_EXTERN_C }
  217. #define UPB_PRIVATE_FOR_CPP private:
  218. #define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname;
  219. #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
  220. UPB_DECLARE_TYPE(cppname, cname) \
  221. UPB_C_UPCASTS(cname, cbase) \
  222. namespace upb { \
  223. template <> \
  224. class Pointer<cppname> : public PointerBase<cppname, cppbase> { \
  225. public: \
  226. explicit Pointer(cppname* ptr) \
  227. : PointerBase<cppname, cppbase>(ptr) {} \
  228. }; \
  229. template <> \
  230. class Pointer<const cppname> \
  231. : public PointerBase<const cppname, const cppbase> { \
  232. public: \
  233. explicit Pointer(const cppname* ptr) \
  234. : PointerBase<const cppname, const cppbase>(ptr) {} \
  235. }; \
  236. }
  237. #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, cname, cbase, \
  238. cbase2) \
  239. UPB_DECLARE_TYPE(cppname, cname) \
  240. UPB_C_UPCASTS2(cname, cbase, cbase2) \
  241. namespace upb { \
  242. template <> \
  243. class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \
  244. public: \
  245. explicit Pointer(cppname* ptr) \
  246. : PointerBase2<cppname, cppbase, cppbase2>(ptr) {} \
  247. }; \
  248. template <> \
  249. class Pointer<const cppname> \
  250. : public PointerBase2<const cppname, const cppbase, const cppbase2> { \
  251. public: \
  252. explicit Pointer(const cppname* ptr) \
  253. : PointerBase2<const cppname, const cppbase, const cppbase2>(ptr) {} \
  254. }; \
  255. }
  256. #else /* !defined(__cplusplus) */
  257. #define UPB_BEGIN_EXTERN_C
  258. #define UPB_END_EXTERN_C
  259. #define UPB_PRIVATE_FOR_CPP
  260. #define UPB_DECLARE_TYPE(cppname, cname) \
  261. struct cname; \
  262. typedef struct cname cname;
  263. #define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
  264. UPB_DECLARE_TYPE(cppname, cname) \
  265. UPB_C_UPCASTS(cname, cbase)
  266. #define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, \
  267. cname, cbase, cbase2) \
  268. UPB_DECLARE_TYPE(cppname, cname) \
  269. UPB_C_UPCASTS2(cname, cbase, cbase2)
  270. #endif /* defined(__cplusplus) */
  271. #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
  272. #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
  273. #define UPB_UNUSED(var) (void)var
  274. /* UPB_ASSERT(): in release mode, we use the expression without letting it be
  275. * evaluated. This prevents "unused variable" warnings. */
  276. #ifdef NDEBUG
  277. #define UPB_ASSERT(expr) do {} while (false && (expr))
  278. #else
  279. #define UPB_ASSERT(expr) assert(expr)
  280. #endif
  281. /* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
  282. * exist in debug mode. This turns into regular assert. */
  283. #define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
  284. #ifdef __GNUC__
  285. #define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
  286. #else
  287. #define UPB_UNREACHABLE() do { assert(0); } while(0)
  288. #endif
  289. /* Generic function type. */
  290. typedef void upb_func();
  291. /* C++ Casts ******************************************************************/
  292. #ifdef __cplusplus
  293. namespace upb {
  294. template <class T> class Pointer;
  295. /* Casts to a subclass. The caller must know that cast is correct; an
  296. * incorrect cast will throw an assertion failure in debug mode.
  297. *
  298. * Example:
  299. * upb::Def* def = GetDef();
  300. * // Assert-fails if this was not actually a MessageDef.
  301. * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
  302. *
  303. * Note that downcasts are only defined for some types (at the moment you can
  304. * only downcast from a upb::Def to a specific Def type). */
  305. template<class To, class From> To down_cast(From* f);
  306. /* Casts to a subclass. If the class does not actually match the given To type,
  307. * returns NULL.
  308. *
  309. * Example:
  310. * upb::Def* def = GetDef();
  311. * // md will be NULL if this was not actually a MessageDef.
  312. * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
  313. *
  314. * Note that dynamic casts are only defined for some types (at the moment you
  315. * can only downcast from a upb::Def to a specific Def type).. */
  316. template<class To, class From> To dyn_cast(From* f);
  317. /* Casts to any base class, or the type itself (ie. can be a no-op).
  318. *
  319. * Example:
  320. * upb::MessageDef* md = GetDef();
  321. * // This will fail to compile if this wasn't actually a base class.
  322. * upb::Def* def = upb::upcast(md);
  323. */
  324. template <class T> inline Pointer<T> upcast(T *f) { return Pointer<T>(f); }
  325. /* Attempt upcast to specific base class.
  326. *
  327. * Example:
  328. * upb::MessageDef* md = GetDef();
  329. * upb::upcast_to<upb::Def>(md)->MethodOnDef();
  330. */
  331. template <class T, class F> inline T* upcast_to(F *f) {
  332. return static_cast<T*>(upcast(f));
  333. }
  334. /* PointerBase<T>: implementation detail of upb::upcast().
  335. * It is implicitly convertable to pointers to the Base class(es).
  336. */
  337. template <class T, class Base>
  338. class PointerBase {
  339. public:
  340. explicit PointerBase(T* ptr) : ptr_(ptr) {}
  341. operator T*() { return ptr_; }
  342. operator Base*() { return (Base*)ptr_; }
  343. private:
  344. T* ptr_;
  345. };
  346. template <class T, class Base, class Base2>
  347. class PointerBase2 : public PointerBase<T, Base> {
  348. public:
  349. explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {}
  350. operator Base2*() { return Pointer<Base>(*this); }
  351. };
  352. }
  353. #endif
  354. /* A list of types as they are encoded on-the-wire. */
  355. typedef enum {
  356. UPB_WIRE_TYPE_VARINT = 0,
  357. UPB_WIRE_TYPE_64BIT = 1,
  358. UPB_WIRE_TYPE_DELIMITED = 2,
  359. UPB_WIRE_TYPE_START_GROUP = 3,
  360. UPB_WIRE_TYPE_END_GROUP = 4,
  361. UPB_WIRE_TYPE_32BIT = 5
  362. } upb_wiretype_t;
  363. /* upb::ErrorSpace ************************************************************/
  364. /* A upb::ErrorSpace represents some domain of possible error values. This lets
  365. * upb::Status attach specific error codes to operations, like POSIX/C errno,
  366. * Win32 error codes, etc. Clients who want to know the very specific error
  367. * code can check the error space and then know the type of the integer code.
  368. *
  369. * NOTE: upb::ErrorSpace is currently not used and should be considered
  370. * experimental. It is important primarily in cases where upb is performing
  371. * I/O, but upb doesn't currently have any components that do this. */
  372. UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace)
  373. #ifdef __cplusplus
  374. class upb::ErrorSpace {
  375. #else
  376. struct upb_errorspace {
  377. #endif
  378. const char *name;
  379. };
  380. /* upb::Status ****************************************************************/
  381. /* upb::Status represents a success or failure status and error message.
  382. * It owns no resources and allocates no memory, so it should work
  383. * even in OOM situations. */
  384. UPB_DECLARE_TYPE(upb::Status, upb_status)
  385. /* The maximum length of an error message before it will get truncated. */
  386. #define UPB_STATUS_MAX_MESSAGE 128
  387. UPB_BEGIN_EXTERN_C
  388. const char *upb_status_errmsg(const upb_status *status);
  389. bool upb_ok(const upb_status *status);
  390. upb_errorspace *upb_status_errspace(const upb_status *status);
  391. int upb_status_errcode(const upb_status *status);
  392. /* Any of the functions that write to a status object allow status to be NULL,
  393. * to support use cases where the function's caller does not care about the
  394. * status message. */
  395. void upb_status_clear(upb_status *status);
  396. void upb_status_seterrmsg(upb_status *status, const char *msg);
  397. void upb_status_seterrf(upb_status *status, const char *fmt, ...);
  398. void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
  399. void upb_status_copy(upb_status *to, const upb_status *from);
  400. UPB_END_EXTERN_C
  401. #ifdef __cplusplus
  402. class upb::Status {
  403. public:
  404. Status() { upb_status_clear(this); }
  405. /* Returns true if there is no error. */
  406. bool ok() const { return upb_ok(this); }
  407. /* Optional error space and code, useful if the caller wants to
  408. * programmatically check the specific kind of error. */
  409. ErrorSpace* error_space() { return upb_status_errspace(this); }
  410. int error_code() const { return upb_status_errcode(this); }
  411. /* The returned string is invalidated by any other call into the status. */
  412. const char *error_message() const { return upb_status_errmsg(this); }
  413. /* The error message will be truncated if it is longer than
  414. * UPB_STATUS_MAX_MESSAGE-4. */
  415. void SetErrorMessage(const char* msg) { upb_status_seterrmsg(this, msg); }
  416. void SetFormattedErrorMessage(const char* fmt, ...) {
  417. va_list args;
  418. va_start(args, fmt);
  419. upb_status_vseterrf(this, fmt, args);
  420. va_end(args);
  421. }
  422. /* Resets the status to a successful state with no message. */
  423. void Clear() { upb_status_clear(this); }
  424. void CopyFrom(const Status& other) { upb_status_copy(this, &other); }
  425. private:
  426. UPB_DISALLOW_COPY_AND_ASSIGN(Status)
  427. #else
  428. struct upb_status {
  429. #endif
  430. bool ok_;
  431. /* Specific status code defined by some error space (optional). */
  432. int code_;
  433. upb_errorspace *error_space_;
  434. /* TODO(haberman): add file/line of error? */
  435. /* Error message; NULL-terminated. */
  436. char msg[UPB_STATUS_MAX_MESSAGE];
  437. };
  438. #define UPB_STATUS_INIT {true, 0, NULL, {0}}
  439. /** Built-in error spaces. ****************************************************/
  440. /* Errors raised by upb that we want to be able to detect programmatically. */
  441. typedef enum {
  442. UPB_NOMEM /* Can't reuse ENOMEM because it is POSIX, not ISO C. */
  443. } upb_errcode_t;
  444. extern upb_errorspace upb_upberr;
  445. void upb_upberr_setoom(upb_status *s);
  446. /* Since errno is defined by standard C, we define an error space for it in
  447. * core upb. Other error spaces should be defined in other, platform-specific
  448. * modules. */
  449. extern upb_errorspace upb_errnoerr;
  450. /** upb::Allocator ************************************************************/
  451. /* A upb::Allocator is a possibly-stateful allocator object.
  452. *
  453. * It could either be an arena allocator (which doesn't require individual
  454. * free() calls) or a regular malloc() (which does). The client must therefore
  455. * free memory unless it knows that the allocator is an arena allocator. */
  456. UPB_DECLARE_TYPE(upb::Allocator, upb_alloc)
  457. /* A malloc()/free() function.
  458. * If "size" is 0 then the function acts like free(), otherwise it acts like
  459. * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */
  460. typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
  461. size_t size);
  462. #ifdef __cplusplus
  463. class upb::Allocator UPB_FINAL {
  464. public:
  465. Allocator() {}
  466. private:
  467. UPB_DISALLOW_COPY_AND_ASSIGN(Allocator)
  468. public:
  469. #else
  470. struct upb_alloc {
  471. #endif /* __cplusplus */
  472. upb_alloc_func *func;
  473. };
  474. UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
  475. UPB_ASSERT(alloc);
  476. return alloc->func(alloc, NULL, 0, size);
  477. }
  478. UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
  479. size_t size) {
  480. UPB_ASSERT(alloc);
  481. return alloc->func(alloc, ptr, oldsize, size);
  482. }
  483. UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
  484. assert(alloc);
  485. alloc->func(alloc, ptr, 0, 0);
  486. }
  487. /* The global allocator used by upb. Uses the standard malloc()/free(). */
  488. extern upb_alloc upb_alloc_global;
  489. /* Functions that hard-code the global malloc.
  490. *
  491. * We still get benefit because we can put custom logic into our global
  492. * allocator, like injecting out-of-memory faults in debug/testing builds. */
  493. UPB_INLINE void *upb_gmalloc(size_t size) {
  494. return upb_malloc(&upb_alloc_global, size);
  495. }
  496. UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
  497. return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
  498. }
  499. UPB_INLINE void upb_gfree(void *ptr) {
  500. upb_free(&upb_alloc_global, ptr);
  501. }
  502. /* upb::Arena *****************************************************************/
  503. /* upb::Arena is a specific allocator implementation that uses arena allocation.
  504. * The user provides an allocator that will be used to allocate the underlying
  505. * arena blocks. Arenas by nature do not require the individual allocations
  506. * to be freed. However the Arena does allow users to register cleanup
  507. * functions that will run when the arena is destroyed.
  508. *
  509. * A upb::Arena is *not* thread-safe.
  510. *
  511. * You could write a thread-safe arena allocator that satisfies the
  512. * upb::Allocator interface, but it would not be as efficient for the
  513. * single-threaded case. */
  514. UPB_DECLARE_TYPE(upb::Arena, upb_arena)
  515. typedef void upb_cleanup_func(void *ud);
  516. #define UPB_ARENA_BLOCK_OVERHEAD (sizeof(size_t)*4)
  517. UPB_BEGIN_EXTERN_C
  518. void upb_arena_init(upb_arena *a);
  519. void upb_arena_init2(upb_arena *a, void *mem, size_t n, upb_alloc *alloc);
  520. void upb_arena_uninit(upb_arena *a);
  521. bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud);
  522. size_t upb_arena_bytesallocated(const upb_arena *a);
  523. void upb_arena_setnextblocksize(upb_arena *a, size_t size);
  524. void upb_arena_setmaxblocksize(upb_arena *a, size_t size);
  525. UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
  526. UPB_END_EXTERN_C
  527. #ifdef __cplusplus
  528. class upb::Arena {
  529. public:
  530. /* A simple arena with no initial memory block and the default allocator. */
  531. Arena() { upb_arena_init(this); }
  532. /* Constructs an arena with the given initial block which allocates blocks
  533. * with the given allocator. The given allocator must outlive the Arena.
  534. *
  535. * If you pass NULL for the allocator it will default to the global allocator
  536. * upb_alloc_global, and NULL/0 for the initial block will cause there to be
  537. * no initial block. */
  538. Arena(void *mem, size_t len, Allocator* a) {
  539. upb_arena_init2(this, mem, len, a);
  540. }
  541. ~Arena() { upb_arena_uninit(this); }
  542. /* Sets the size of the next block the Arena will request (unless the
  543. * requested allocation is larger). Each block will double in size until the
  544. * max limit is reached. */
  545. void SetNextBlockSize(size_t size) { upb_arena_setnextblocksize(this, size); }
  546. /* Sets the maximum block size. No blocks larger than this will be requested
  547. * from the underlying allocator unless individual arena allocations are
  548. * larger. */
  549. void SetMaxBlockSize(size_t size) { upb_arena_setmaxblocksize(this, size); }
  550. /* Allows this arena to be used as a generic allocator.
  551. *
  552. * The arena does not need free() calls so when using Arena as an allocator
  553. * it is safe to skip them. However they are no-ops so there is no harm in
  554. * calling free() either. */
  555. Allocator* allocator() { return upb_arena_alloc(this); }
  556. /* Add a cleanup function to run when the arena is destroyed.
  557. * Returns false on out-of-memory. */
  558. bool AddCleanup(upb_cleanup_func* func, void* ud) {
  559. return upb_arena_addcleanup(this, func, ud);
  560. }
  561. /* Total number of bytes that have been allocated. It is undefined what
  562. * Realloc() does to this counter. */
  563. size_t BytesAllocated() const {
  564. return upb_arena_bytesallocated(this);
  565. }
  566. private:
  567. UPB_DISALLOW_COPY_AND_ASSIGN(Arena)
  568. #else
  569. struct upb_arena {
  570. #endif /* __cplusplus */
  571. /* We implement the allocator interface.
  572. * This must be the first member of upb_arena! */
  573. upb_alloc alloc;
  574. /* Allocator to allocate arena blocks. We are responsible for freeing these
  575. * when we are destroyed. */
  576. upb_alloc *block_alloc;
  577. size_t bytes_allocated;
  578. size_t next_block_size;
  579. size_t max_block_size;
  580. /* Linked list of blocks. Points to an arena_block, defined in env.c */
  581. void *block_head;
  582. /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */
  583. void *cleanup_head;
  584. /* For future expansion, since the size of this struct is exposed to users. */
  585. void *future1;
  586. void *future2;
  587. };
  588. /* upb::Environment ***********************************************************/
  589. /* A upb::Environment provides a means for injecting malloc and an
  590. * error-reporting callback into encoders/decoders. This allows them to be
  591. * independent of nearly all assumptions about their actual environment.
  592. *
  593. * It is also a container for allocating the encoders/decoders themselves that
  594. * insulates clients from knowing their actual size. This provides ABI
  595. * compatibility even if the size of the objects change. And this allows the
  596. * structure definitions to be in the .c files instead of the .h files, making
  597. * the .h files smaller and more readable.
  598. *
  599. * We might want to consider renaming this to "Pipeline" if/when the concept of
  600. * a pipeline element becomes more formalized. */
  601. UPB_DECLARE_TYPE(upb::Environment, upb_env)
  602. /* A function that receives an error report from an encoder or decoder. The
  603. * callback can return true to request that the error should be recovered, but
  604. * if the error is not recoverable this has no effect. */
  605. typedef bool upb_error_func(void *ud, const upb_status *status);
  606. UPB_BEGIN_EXTERN_C
  607. void upb_env_init(upb_env *e);
  608. void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc);
  609. void upb_env_uninit(upb_env *e);
  610. void upb_env_initonly(upb_env *e);
  611. UPB_INLINE upb_arena *upb_env_arena(upb_env *e) { return (upb_arena*)e; }
  612. bool upb_env_ok(const upb_env *e);
  613. void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud);
  614. /* Convenience wrappers around the methods of the contained arena. */
  615. void upb_env_reporterrorsto(upb_env *e, upb_status *s);
  616. bool upb_env_reporterror(upb_env *e, const upb_status *s);
  617. void *upb_env_malloc(upb_env *e, size_t size);
  618. void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size);
  619. void upb_env_free(upb_env *e, void *ptr);
  620. bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud);
  621. size_t upb_env_bytesallocated(const upb_env *e);
  622. UPB_END_EXTERN_C
  623. #ifdef __cplusplus
  624. class upb::Environment {
  625. public:
  626. /* The given Arena must outlive this environment. */
  627. Environment() { upb_env_initonly(this); }
  628. Environment(void *mem, size_t len, Allocator *a) : arena_(mem, len, a) {
  629. upb_env_initonly(this);
  630. }
  631. Arena* arena() { return upb_env_arena(this); }
  632. /* Set a custom error reporting function. */
  633. void SetErrorFunction(upb_error_func* func, void* ud) {
  634. upb_env_seterrorfunc(this, func, ud);
  635. }
  636. /* Set the error reporting function to simply copy the status to the given
  637. * status and abort. */
  638. void ReportErrorsTo(Status* status) { upb_env_reporterrorsto(this, status); }
  639. /* Returns true if all allocations and AddCleanup() calls have succeeded,
  640. * and no errors were reported with ReportError() (except ones that recovered
  641. * successfully). */
  642. bool ok() const { return upb_env_ok(this); }
  643. /* Reports an error to this environment's callback, returning true if
  644. * the caller should try to recover. */
  645. bool ReportError(const Status* status) {
  646. return upb_env_reporterror(this, status);
  647. }
  648. private:
  649. UPB_DISALLOW_COPY_AND_ASSIGN(Environment)
  650. #else
  651. struct upb_env {
  652. #endif /* __cplusplus */
  653. upb_arena arena_;
  654. upb_error_func *error_func_;
  655. void *error_ud_;
  656. bool ok_;
  657. };
  658. /* upb::InlinedArena **********************************************************/
  659. /* upb::InlinedEnvironment ****************************************************/
  660. /* upb::InlinedArena and upb::InlinedEnvironment seed their arenas with a
  661. * predefined amount of memory. No heap memory will be allocated until the
  662. * initial block is exceeded.
  663. *
  664. * These types only exist in C++ */
  665. #ifdef __cplusplus
  666. template <int N> class upb::InlinedArena : public upb::Arena {
  667. public:
  668. InlinedArena() : Arena(initial_block_, N, NULL) {}
  669. explicit InlinedArena(Allocator* a) : Arena(initial_block_, N, a) {}
  670. private:
  671. UPB_DISALLOW_COPY_AND_ASSIGN(InlinedArena)
  672. char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
  673. };
  674. template <int N> class upb::InlinedEnvironment : public upb::Environment {
  675. public:
  676. InlinedEnvironment() : Environment(initial_block_, N, NULL) {}
  677. explicit InlinedEnvironment(Allocator *a)
  678. : Environment(initial_block_, N, a) {}
  679. private:
  680. UPB_DISALLOW_COPY_AND_ASSIGN(InlinedEnvironment)
  681. char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
  682. };
  683. #endif /* __cplusplus */
  684. #endif /* UPB_H_ */
  685. #ifdef __cplusplus
  686. extern "C" {
  687. #endif
  688. /* upb_value ******************************************************************/
  689. /* A tagged union (stored untagged inside the table) so that we can check that
  690. * clients calling table accessors are correctly typed without having to have
  691. * an explosion of accessors. */
  692. typedef enum {
  693. UPB_CTYPE_INT32 = 1,
  694. UPB_CTYPE_INT64 = 2,
  695. UPB_CTYPE_UINT32 = 3,
  696. UPB_CTYPE_UINT64 = 4,
  697. UPB_CTYPE_BOOL = 5,
  698. UPB_CTYPE_CSTR = 6,
  699. UPB_CTYPE_PTR = 7,
  700. UPB_CTYPE_CONSTPTR = 8,
  701. UPB_CTYPE_FPTR = 9,
  702. UPB_CTYPE_FLOAT = 10,
  703. UPB_CTYPE_DOUBLE = 11
  704. } upb_ctype_t;
  705. typedef struct {
  706. uint64_t val;
  707. #ifndef NDEBUG
  708. /* In debug mode we carry the value type around also so we can check accesses
  709. * to be sure the right member is being read. */
  710. upb_ctype_t ctype;
  711. #endif
  712. } upb_value;
  713. #ifdef NDEBUG
  714. #define SET_TYPE(dest, val) UPB_UNUSED(val)
  715. #else
  716. #define SET_TYPE(dest, val) dest = val
  717. #endif
  718. /* Like strdup(), which isn't always available since it's not ANSI C. */
  719. char *upb_strdup(const char *s, upb_alloc *a);
  720. /* Variant that works with a length-delimited rather than NULL-delimited string,
  721. * as supported by strtable. */
  722. char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
  723. UPB_INLINE char *upb_gstrdup(const char *s) {
  724. return upb_strdup(s, &upb_alloc_global);
  725. }
  726. UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
  727. upb_ctype_t ctype) {
  728. v->val = val;
  729. SET_TYPE(v->ctype, ctype);
  730. }
  731. UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
  732. upb_value ret;
  733. _upb_value_setval(&ret, val, ctype);
  734. return ret;
  735. }
  736. /* For each value ctype, define the following set of functions:
  737. *
  738. * // Get/set an int32 from a upb_value.
  739. * int32_t upb_value_getint32(upb_value val);
  740. * void upb_value_setint32(upb_value *val, int32_t cval);
  741. *
  742. * // Construct a new upb_value from an int32.
  743. * upb_value upb_value_int32(int32_t val); */
  744. #define FUNCS(name, membername, type_t, converter, proto_type) \
  745. UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
  746. val->val = (converter)cval; \
  747. SET_TYPE(val->ctype, proto_type); \
  748. } \
  749. UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
  750. upb_value ret; \
  751. upb_value_set ## name(&ret, val); \
  752. return ret; \
  753. } \
  754. UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
  755. UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
  756. return (type_t)(converter)val.val; \
  757. }
  758. FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
  759. FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
  760. FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
  761. FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
  762. FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
  763. FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
  764. FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
  765. FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR)
  766. FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR)
  767. #undef FUNCS
  768. UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
  769. memcpy(&val->val, &cval, sizeof(cval));
  770. SET_TYPE(val->ctype, UPB_CTYPE_FLOAT);
  771. }
  772. UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
  773. memcpy(&val->val, &cval, sizeof(cval));
  774. SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE);
  775. }
  776. UPB_INLINE upb_value upb_value_float(float cval) {
  777. upb_value ret;
  778. upb_value_setfloat(&ret, cval);
  779. return ret;
  780. }
  781. UPB_INLINE upb_value upb_value_double(double cval) {
  782. upb_value ret;
  783. upb_value_setdouble(&ret, cval);
  784. return ret;
  785. }
  786. #undef SET_TYPE
  787. /* upb_tabkey *****************************************************************/
  788. /* Either:
  789. * 1. an actual integer key, or
  790. * 2. a pointer to a string prefixed by its uint32_t length, owned by us.
  791. *
  792. * ...depending on whether this is a string table or an int table. We would
  793. * make this a union of those two types, but C89 doesn't support statically
  794. * initializing a non-first union member. */
  795. typedef uintptr_t upb_tabkey;
  796. #define UPB_TABKEY_NUM(n) n
  797. #define UPB_TABKEY_NONE 0
  798. /* The preprocessor isn't quite powerful enough to turn the compile-time string
  799. * length into a byte-wise string representation, so code generation needs to
  800. * help it along.
  801. *
  802. * "len1" is the low byte and len4 is the high byte. */
  803. #ifdef UPB_BIG_ENDIAN
  804. #define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
  805. (uintptr_t)(len4 len3 len2 len1 strval)
  806. #else
  807. #define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
  808. (uintptr_t)(len1 len2 len3 len4 strval)
  809. #endif
  810. UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
  811. char* mem = (char*)key;
  812. if (len) memcpy(len, mem, sizeof(*len));
  813. return mem + sizeof(*len);
  814. }
  815. /* upb_tabval *****************************************************************/
  816. #ifdef __cplusplus
  817. /* Status initialization not supported.
  818. *
  819. * This separate definition is necessary because in C++, UINTPTR_MAX isn't
  820. * reliably available. */
  821. typedef struct {
  822. uint64_t val;
  823. } upb_tabval;
  824. #else
  825. /* C -- supports static initialization, but to support static initialization of
  826. * both integers and points for both 32 and 64 bit targets, it takes a little
  827. * bit of doing. */
  828. #if UINTPTR_MAX == 0xffffffffffffffffULL
  829. #define UPB_PTR_IS_64BITS
  830. #elif UINTPTR_MAX != 0xffffffff
  831. #error Could not determine how many bits pointers are.
  832. #endif
  833. typedef union {
  834. /* For static initialization.
  835. *
  836. * Unfortunately this ugliness is necessary -- it is the only way that we can,
  837. * with -std=c89 -pedantic, statically initialize this to either a pointer or
  838. * an integer on 32-bit platforms. */
  839. struct {
  840. #ifdef UPB_PTR_IS_64BITS
  841. uintptr_t val;
  842. #else
  843. uintptr_t val1;
  844. uintptr_t val2;
  845. #endif
  846. } staticinit;
  847. /* The normal accessor that we use for everything at runtime. */
  848. uint64_t val;
  849. } upb_tabval;
  850. #ifdef UPB_PTR_IS_64BITS
  851. #define UPB_TABVALUE_INT_INIT(v) {{v}}
  852. #define UPB_TABVALUE_EMPTY_INIT {{-1}}
  853. #else
  854. /* 32-bit pointers */
  855. #ifdef UPB_BIG_ENDIAN
  856. #define UPB_TABVALUE_INT_INIT(v) {{0, v}}
  857. #define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
  858. #else
  859. #define UPB_TABVALUE_INT_INIT(v) {{v, 0}}
  860. #define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
  861. #endif
  862. #endif
  863. #define UPB_TABVALUE_PTR_INIT(v) UPB_TABVALUE_INT_INIT((uintptr_t)v)
  864. #undef UPB_PTR_IS_64BITS
  865. #endif /* __cplusplus */
  866. /* upb_table ******************************************************************/
  867. typedef struct _upb_tabent {
  868. upb_tabkey key;
  869. upb_tabval val;
  870. /* Internal chaining. This is const so we can create static initializers for
  871. * tables. We cast away const sometimes, but *only* when the containing
  872. * upb_table is known to be non-const. This requires a bit of care, but
  873. * the subtlety is confined to table.c. */
  874. const struct _upb_tabent *next;
  875. } upb_tabent;
  876. typedef struct {
  877. size_t count; /* Number of entries in the hash part. */
  878. size_t mask; /* Mask to turn hash value -> bucket. */
  879. upb_ctype_t ctype; /* Type of all values. */
  880. uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
  881. /* Hash table entries.
  882. * Making this const isn't entirely accurate; what we really want is for it to
  883. * have the same const-ness as the table it's inside. But there's no way to
  884. * declare that in C. So we have to make it const so that we can statically
  885. * initialize const hash tables. Then we cast away const when we have to.
  886. */
  887. const upb_tabent *entries;
  888. #ifndef NDEBUG
  889. /* This table's allocator. We make the user pass it in to every relevant
  890. * function and only use this to check it in debug mode. We do this solely
  891. * to keep upb_table as small as possible. This might seem slightly paranoid
  892. * but the plan is to use upb_table for all map fields and extension sets in
  893. * a forthcoming message representation, so there could be a lot of these.
  894. * If this turns out to be too annoying later, we can change it (since this
  895. * is an internal-only header file). */
  896. upb_alloc *alloc;
  897. #endif
  898. } upb_table;
  899. #ifdef NDEBUG
  900. # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
  901. {count, mask, ctype, size_lg2, entries}
  902. #else
  903. # ifdef UPB_DEBUG_REFS
  904. /* At the moment the only mutable tables we statically initialize are debug
  905. * ref tables. */
  906. # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
  907. {count, mask, ctype, size_lg2, entries, &upb_alloc_debugrefs}
  908. # else
  909. # define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
  910. {count, mask, ctype, size_lg2, entries, NULL}
  911. # endif
  912. #endif
  913. typedef struct {
  914. upb_table t;
  915. } upb_strtable;
  916. #define UPB_STRTABLE_INIT(count, mask, ctype, size_lg2, entries) \
  917. {UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries)}
  918. #define UPB_EMPTY_STRTABLE_INIT(ctype) \
  919. UPB_STRTABLE_INIT(0, 0, ctype, 0, NULL)
  920. typedef struct {
  921. upb_table t; /* For entries that don't fit in the array part. */
  922. const upb_tabval *array; /* Array part of the table. See const note above. */
  923. size_t array_size; /* Array part size. */
  924. size_t array_count; /* Array part number of elements. */
  925. } upb_inttable;
  926. #define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
  927. {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
  928. #define UPB_EMPTY_INTTABLE_INIT(ctype) \
  929. UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
  930. #define UPB_ARRAY_EMPTYENT -1
  931. UPB_INLINE size_t upb_table_size(const upb_table *t) {
  932. if (t->size_lg2 == 0)
  933. return 0;
  934. else
  935. return 1 << t->size_lg2;
  936. }
  937. /* Internal-only functions, in .h file only out of necessity. */
  938. UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) {
  939. return e->key == 0;
  940. }
  941. /* Used by some of the unit tests for generic hashing functionality. */
  942. uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed);
  943. UPB_INLINE uintptr_t upb_intkey(uintptr_t key) {
  944. return key;
  945. }
  946. UPB_INLINE uint32_t upb_inthash(uintptr_t key) {
  947. return (uint32_t)key;
  948. }
  949. static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
  950. return t->entries + (hash & t->mask);
  951. }
  952. UPB_INLINE bool upb_arrhas(upb_tabval key) {
  953. return key.val != (uint64_t)-1;
  954. }
  955. /* Initialize and uninitialize a table, respectively. If memory allocation
  956. * failed, false is returned that the table is uninitialized. */
  957. bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
  958. bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
  959. void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
  960. void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
  961. UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
  962. return upb_inttable_init2(table, ctype, &upb_alloc_global);
  963. }
  964. UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
  965. return upb_strtable_init2(table, ctype, &upb_alloc_global);
  966. }
  967. UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
  968. upb_inttable_uninit2(table, &upb_alloc_global);
  969. }
  970. UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
  971. upb_strtable_uninit2(table, &upb_alloc_global);
  972. }
  973. /* Returns the number of values in the table. */
  974. size_t upb_inttable_count(const upb_inttable *t);
  975. UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
  976. return t->t.count;
  977. }
  978. void upb_inttable_packedsize(const upb_inttable *t, size_t *size);
  979. void upb_strtable_packedsize(const upb_strtable *t, size_t *size);
  980. upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs,
  981. size_t size);
  982. upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
  983. size_t size);
  984. /* Inserts the given key into the hashtable with the given value. The key must
  985. * not already exist in the hash table. For string tables, the key must be
  986. * NULL-terminated, and the table will make an internal copy of the key.
  987. * Inttables must not insert a value of UINTPTR_MAX.
  988. *
  989. * If a table resize was required but memory allocation failed, false is
  990. * returned and the table is unchanged. */
  991. bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
  992. upb_alloc *a);
  993. bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
  994. upb_value val, upb_alloc *a);
  995. UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
  996. upb_value val) {
  997. return upb_inttable_insert2(t, key, val, &upb_alloc_global);
  998. }
  999. UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
  1000. size_t len, upb_value val) {
  1001. return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
  1002. }
  1003. /* For NULL-terminated strings. */
  1004. UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
  1005. upb_value val) {
  1006. return upb_strtable_insert2(t, key, strlen(key), val);
  1007. }
  1008. /* Looks up key in this table, returning "true" if the key was found.
  1009. * If v is non-NULL, copies the value for this key into *v. */
  1010. bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
  1011. bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
  1012. upb_value *v);
  1013. /* For NULL-terminated strings. */
  1014. UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
  1015. upb_value *v) {
  1016. return upb_strtable_lookup2(t, key, strlen(key), v);
  1017. }
  1018. /* Removes an item from the table. Returns true if the remove was successful,
  1019. * and stores the removed item in *val if non-NULL. */
  1020. bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
  1021. bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
  1022. upb_value *val, upb_alloc *alloc);
  1023. UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
  1024. size_t len, upb_value *val) {
  1025. return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
  1026. }
  1027. /* For NULL-terminated strings. */
  1028. UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
  1029. upb_value *v) {
  1030. return upb_strtable_remove2(t, key, strlen(key), v);
  1031. }
  1032. /* Updates an existing entry in an inttable. If the entry does not exist,
  1033. * returns false and does nothing. Unlike insert/remove, this does not
  1034. * invalidate iterators. */
  1035. bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
  1036. /* Handy routines for treating an inttable like a stack. May not be mixed with
  1037. * other insert/remove calls. */
  1038. bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
  1039. upb_value upb_inttable_pop(upb_inttable *t);
  1040. UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
  1041. return upb_inttable_push2(t, val, &upb_alloc_global);
  1042. }
  1043. /* Convenience routines for inttables with pointer keys. */
  1044. bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
  1045. upb_alloc *a);
  1046. bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
  1047. bool upb_inttable_lookupptr(
  1048. const upb_inttable *t, const void *key, upb_value *val);
  1049. UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
  1050. upb_value val) {
  1051. return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
  1052. }
  1053. /* Optimizes the table for the current set of entries, for both memory use and
  1054. * lookup time. Client should call this after all entries have been inserted;
  1055. * inserting more entries is legal, but will likely require a table resize. */
  1056. void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
  1057. UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
  1058. upb_inttable_compact2(t, &upb_alloc_global);
  1059. }
  1060. /* A special-case inlinable version of the lookup routine for 32-bit
  1061. * integers. */
  1062. UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
  1063. upb_value *v) {
  1064. *v = upb_value_int32(0); /* Silence compiler warnings. */
  1065. if (key < t->array_size) {
  1066. upb_tabval arrval = t->array[key];
  1067. if (upb_arrhas(arrval)) {
  1068. _upb_value_setval(v, arrval.val, t->t.ctype);
  1069. return true;
  1070. } else {
  1071. return false;
  1072. }
  1073. } else {
  1074. const upb_tabent *e;
  1075. if (t->t.entries == NULL) return false;
  1076. for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
  1077. if ((uint32_t)e->key == key) {
  1078. _upb_value_setval(v, e->val.val, t->t.ctype);
  1079. return true;
  1080. }
  1081. if (e->next == NULL) return false;
  1082. }
  1083. }
  1084. }
  1085. /* Exposed for testing only. */
  1086. bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
  1087. /* Iterators ******************************************************************/
  1088. /* Iterators for int and string tables. We are subject to some kind of unusual
  1089. * design constraints:
  1090. *
  1091. * For high-level languages:
  1092. * - we must be able to guarantee that we don't crash or corrupt memory even if
  1093. * the program accesses an invalidated iterator.
  1094. *
  1095. * For C++11 range-based for:
  1096. * - iterators must be copyable
  1097. * - iterators must be comparable
  1098. * - it must be possible to construct an "end" value.
  1099. *
  1100. * Iteration order is undefined.
  1101. *
  1102. * Modifying the table invalidates iterators. upb_{str,int}table_done() is
  1103. * guaranteed to work even on an invalidated iterator, as long as the table it
  1104. * is iterating over has not been freed. Calling next() or accessing data from
  1105. * an invalidated iterator yields unspecified elements from the table, but it is
  1106. * guaranteed not to crash and to return real table elements (except when done()
  1107. * is true). */
  1108. /* upb_strtable_iter **********************************************************/
  1109. /* upb_strtable_iter i;
  1110. * upb_strtable_begin(&i, t);
  1111. * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
  1112. * const char *key = upb_strtable_iter_key(&i);
  1113. * const upb_value val = upb_strtable_iter_value(&i);
  1114. * // ...
  1115. * }
  1116. */
  1117. typedef struct {
  1118. const upb_strtable *t;
  1119. size_t index;
  1120. } upb_strtable_iter;
  1121. void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
  1122. void upb_strtable_next(upb_strtable_iter *i);
  1123. bool upb_strtable_done(const upb_strtable_iter *i);
  1124. const char *upb_strtable_iter_key(const upb_strtable_iter *i);
  1125. size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
  1126. upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
  1127. void upb_strtable_iter_setdone(upb_strtable_iter *i);
  1128. bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
  1129. const upb_strtable_iter *i2);
  1130. /* upb_inttable_iter **********************************************************/
  1131. /* upb_inttable_iter i;
  1132. * upb_inttable_begin(&i, t);
  1133. * for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
  1134. * uintptr_t key = upb_inttable_iter_key(&i);
  1135. * upb_value val = upb_inttable_iter_value(&i);
  1136. * // ...
  1137. * }
  1138. */
  1139. typedef struct {
  1140. const upb_inttable *t;
  1141. size_t index;
  1142. bool array_part;
  1143. } upb_inttable_iter;
  1144. void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
  1145. void upb_inttable_next(upb_inttable_iter *i);
  1146. bool upb_inttable_done(const upb_inttable_iter *i);
  1147. uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i);
  1148. upb_value upb_inttable_iter_value(const upb_inttable_iter *i);
  1149. void upb_inttable_iter_setdone(upb_inttable_iter *i);
  1150. bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
  1151. const upb_inttable_iter *i2);
  1152. #ifdef __cplusplus
  1153. } /* extern "C" */
  1154. #endif
  1155. #endif /* UPB_TABLE_H_ */
  1156. /* Reference tracking will check ref()/unref() operations to make sure the
  1157. * ref ownership is correct. Where possible it will also make tools like
  1158. * Valgrind attribute ref leaks to the code that took the leaked ref, not
  1159. * the code that originally created the object.
  1160. *
  1161. * Enabling this requires the application to define upb_lock()/upb_unlock()
  1162. * functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE).
  1163. * For this reason we don't enable it by default, even in debug builds.
  1164. */
  1165. /* #define UPB_DEBUG_REFS */
  1166. #ifdef __cplusplus
  1167. namespace upb {
  1168. class RefCounted;
  1169. template <class T> class reffed_ptr;
  1170. }
  1171. #endif
  1172. UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted)
  1173. struct upb_refcounted_vtbl;
  1174. #ifdef __cplusplus
  1175. class upb::RefCounted {
  1176. public:
  1177. /* Returns true if the given object is frozen. */
  1178. bool IsFrozen() const;
  1179. /* Increases the ref count, the new ref is owned by "owner" which must not
  1180. * already own a ref (and should not itself be a refcounted object if the ref
  1181. * could possibly be circular; see below).
  1182. * Thread-safe iff "this" is frozen. */
  1183. void Ref(const void *owner) const;
  1184. /* Release a ref that was acquired from upb_refcounted_ref() and collects any
  1185. * objects it can. */
  1186. void Unref(const void *owner) const;
  1187. /* Moves an existing ref from "from" to "to", without changing the overall
  1188. * ref count. DonateRef(foo, NULL, owner) is the same as Ref(foo, owner),
  1189. * but "to" may not be NULL. */
  1190. void DonateRef(const void *from, const void *to) const;
  1191. /* Verifies that a ref to the given object is currently held by the given
  1192. * owner. Only effective in UPB_DEBUG_REFS builds. */
  1193. void CheckRef(const void *owner) const;
  1194. private:
  1195. UPB_DISALLOW_POD_OPS(RefCounted, upb::RefCounted)
  1196. #else
  1197. struct upb_refcounted {
  1198. #endif
  1199. /* TODO(haberman): move the actual structure definition to structdefs.int.h.
  1200. * The only reason they are here is because inline functions need to see the
  1201. * definition of upb_handlers, which needs to see this definition. But we
  1202. * can change the upb_handlers inline functions to deal in raw offsets
  1203. * instead.
  1204. */
  1205. /* A single reference count shared by all objects in the group. */
  1206. uint32_t *group;
  1207. /* A singly-linked list of all objects in the group. */
  1208. upb_refcounted *next;
  1209. /* Table of function pointers for this type. */
  1210. const struct upb_refcounted_vtbl *vtbl;
  1211. /* Maintained only when mutable, this tracks the number of refs (but not
  1212. * ref2's) to this object. *group should be the sum of all individual_count
  1213. * in the group. */
  1214. uint32_t individual_count;
  1215. bool is_frozen;
  1216. #ifdef UPB_DEBUG_REFS
  1217. upb_inttable *refs; /* Maps owner -> trackedref for incoming refs. */
  1218. upb_inttable *ref2s; /* Set of targets for outgoing ref2s. */
  1219. #endif
  1220. };
  1221. #ifdef UPB_DEBUG_REFS
  1222. extern upb_alloc upb_alloc_debugrefs;
  1223. #define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
  1224. {&static_refcount, NULL, vtbl, 0, true, refs, ref2s}
  1225. #else
  1226. #define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
  1227. {&static_refcount, NULL, vtbl, 0, true}
  1228. #endif
  1229. UPB_BEGIN_EXTERN_C
  1230. /* It is better to use tracked refs when possible, for the extra debugging
  1231. * capability. But if this is not possible (because you don't have easy access
  1232. * to a stable pointer value that is associated with the ref), you can pass
  1233. * UPB_UNTRACKED_REF instead. */
  1234. extern const void *UPB_UNTRACKED_REF;
  1235. /* Native C API. */
  1236. bool upb_refcounted_isfrozen(const upb_refcounted *r);
  1237. void upb_refcounted_ref(const upb_refcounted *r, const void *owner);
  1238. void upb_refcounted_unref(const upb_refcounted *r, const void *owner);
  1239. void upb_refcounted_donateref(
  1240. const upb_refcounted *r, const void *from, const void *to);
  1241. void upb_refcounted_checkref(const upb_refcounted *r, const void *owner);
  1242. #define UPB_REFCOUNTED_CMETHODS(type, upcastfunc) \
  1243. UPB_INLINE bool type ## _isfrozen(const type *v) { \
  1244. return upb_refcounted_isfrozen(upcastfunc(v)); \
  1245. } \
  1246. UPB_INLINE void type ## _ref(const type *v, const void *owner) { \
  1247. upb_refcounted_ref(upcastfunc(v), owner); \
  1248. } \
  1249. UPB_INLINE void type ## _unref(const type *v, const void *owner) { \
  1250. upb_refcounted_unref(upcastfunc(v), owner); \
  1251. } \
  1252. UPB_INLINE void type ## _donateref(const type *v, const void *from, const void *to) { \
  1253. upb_refcounted_donateref(upcastfunc(v), from, to); \
  1254. } \
  1255. UPB_INLINE void type ## _checkref(const type *v, const void *owner) { \
  1256. upb_refcounted_checkref(upcastfunc(v), owner); \
  1257. }
  1258. #define UPB_REFCOUNTED_CPPMETHODS \
  1259. bool IsFrozen() const { \
  1260. return upb::upcast_to<const upb::RefCounted>(this)->IsFrozen(); \
  1261. } \
  1262. void Ref(const void *owner) const { \
  1263. return upb::upcast_to<const upb::RefCounted>(this)->Ref(owner); \
  1264. } \
  1265. void Unref(const void *owner) const { \
  1266. return upb::upcast_to<const upb::RefCounted>(this)->Unref(owner); \
  1267. } \
  1268. void DonateRef(const void *from, const void *to) const { \
  1269. return upb::upcast_to<const upb::RefCounted>(this)->DonateRef(from, to); \
  1270. } \
  1271. void CheckRef(const void *owner) const { \
  1272. return upb::upcast_to<const upb::RefCounted>(this)->CheckRef(owner); \
  1273. }
  1274. /* Internal-to-upb Interface **************************************************/
  1275. typedef void upb_refcounted_visit(const upb_refcounted *r,
  1276. const upb_refcounted *subobj,
  1277. void *closure);
  1278. struct upb_refcounted_vtbl {
  1279. /* Must visit all subobjects that are currently ref'd via upb_refcounted_ref2.
  1280. * Must be longjmp()-safe. */
  1281. void (*visit)(const upb_refcounted *r, upb_refcounted_visit *visit, void *c);
  1282. /* Must free the object and release all references to other objects. */
  1283. void (*free)(upb_refcounted *r);
  1284. };
  1285. /* Initializes the refcounted with a single ref for the given owner. Returns
  1286. * false if memory could not be allocated. */
  1287. bool upb_refcounted_init(upb_refcounted *r,
  1288. const struct upb_refcounted_vtbl *vtbl,
  1289. const void *owner);
  1290. /* Adds a ref from one refcounted object to another ("from" must not already
  1291. * own a ref). These refs may be circular; cycles will be collected correctly
  1292. * (if conservatively). These refs do not need to be freed in from's free()
  1293. * function. */
  1294. void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from);
  1295. /* Removes a ref that was acquired from upb_refcounted_ref2(), and collects any
  1296. * object it can. This is only necessary when "from" no longer points to "r",
  1297. * and not from from's "free" function. */
  1298. void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from);
  1299. #define upb_ref2(r, from) \
  1300. upb_refcounted_ref2((const upb_refcounted*)r, (upb_refcounted*)from)
  1301. #define upb_unref2(r, from) \
  1302. upb_refcounted_unref2((const upb_refcounted*)r, (upb_refcounted*)from)
  1303. /* Freezes all mutable object reachable by ref2() refs from the given roots.
  1304. * This will split refcounting groups into precise SCC groups, so that
  1305. * refcounting of frozen objects can be more aggressive. If memory allocation
  1306. * fails, or if more than 2**31 mutable objects are reachable from "roots", or
  1307. * if the maximum depth of the graph exceeds "maxdepth", false is returned and
  1308. * the objects are unchanged.
  1309. *
  1310. * After this operation succeeds, the objects are frozen/const, and may not be
  1311. * used through non-const pointers. In particular, they may not be passed as
  1312. * the second parameter of upb_refcounted_{ref,unref}2(). On the upside, all
  1313. * operations on frozen refcounteds are threadsafe, and objects will be freed
  1314. * at the precise moment that they become unreachable.
  1315. *
  1316. * Caller must own refs on each object in the "roots" list. */
  1317. bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
  1318. int maxdepth);
  1319. /* Shared by all compiled-in refcounted objects. */
  1320. extern uint32_t static_refcount;
  1321. UPB_END_EXTERN_C
  1322. #ifdef __cplusplus
  1323. /* C++ Wrappers. */
  1324. namespace upb {
  1325. inline bool RefCounted::IsFrozen() const {
  1326. return upb_refcounted_isfrozen(this);
  1327. }
  1328. inline void RefCounted::Ref(const void *owner) const {
  1329. upb_refcounted_ref(this, owner);
  1330. }
  1331. inline void RefCounted::Unref(const void *owner) const {
  1332. upb_refcounted_unref(this, owner);
  1333. }
  1334. inline void RefCounted::DonateRef(const void *from, const void *to) const {
  1335. upb_refcounted_donateref(this, from, to);
  1336. }
  1337. inline void RefCounted::CheckRef(const void *owner) const {
  1338. upb_refcounted_checkref(this, owner);
  1339. }
  1340. } /* namespace upb */
  1341. #endif
  1342. /* upb::reffed_ptr ************************************************************/
  1343. #ifdef __cplusplus
  1344. #include <algorithm> /* For std::swap(). */
  1345. /* Provides RAII semantics for upb refcounted objects. Each reffed_ptr owns a
  1346. * ref on whatever object it points to (if any). */
  1347. template <class T> class upb::reffed_ptr {
  1348. public:
  1349. reffed_ptr() : ptr_(NULL) {}
  1350. /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
  1351. template <class U>
  1352. reffed_ptr(U* val, const void* ref_donor = NULL)
  1353. : ptr_(upb::upcast(val)) {
  1354. if (ref_donor) {
  1355. UPB_ASSERT(ptr_);
  1356. ptr_->DonateRef(ref_donor, this);
  1357. } else if (ptr_) {
  1358. ptr_->Ref(this);
  1359. }
  1360. }
  1361. template <class U>
  1362. reffed_ptr(const reffed_ptr<U>& other)
  1363. : ptr_(upb::upcast(other.get())) {
  1364. if (ptr_) ptr_->Ref(this);
  1365. }
  1366. reffed_ptr(const reffed_ptr& other)
  1367. : ptr_(upb::upcast(other.get())) {
  1368. if (ptr_) ptr_->Ref(this);
  1369. }
  1370. ~reffed_ptr() { if (ptr_) ptr_->Unref(this); }
  1371. template <class U>
  1372. reffed_ptr& operator=(const reffed_ptr<U>& other) {
  1373. reset(other.get());
  1374. return *this;
  1375. }
  1376. reffed_ptr& operator=(const reffed_ptr& other) {
  1377. reset(other.get());
  1378. return *this;
  1379. }
  1380. /* TODO(haberman): add C++11 move construction/assignment for greater
  1381. * efficiency. */
  1382. void swap(reffed_ptr& other) {
  1383. if (ptr_ == other.ptr_) {
  1384. return;
  1385. }
  1386. if (ptr_) ptr_->DonateRef(this, &other);
  1387. if (other.ptr_) other.ptr_->DonateRef(&other, this);
  1388. std::swap(ptr_, other.ptr_);
  1389. }
  1390. T& operator*() const {
  1391. UPB_ASSERT(ptr_);
  1392. return *ptr_;
  1393. }
  1394. T* operator->() const {
  1395. UPB_ASSERT(ptr_);
  1396. return ptr_;
  1397. }
  1398. T* get() const { return ptr_; }
  1399. /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
  1400. template <class U>
  1401. void reset(U* ptr = NULL, const void* ref_donor = NULL) {
  1402. reffed_ptr(ptr, ref_donor).swap(*this);
  1403. }
  1404. template <class U>
  1405. reffed_ptr<U> down_cast() {
  1406. return reffed_ptr<U>(upb::down_cast<U*>(get()));
  1407. }
  1408. template <class U>
  1409. reffed_ptr<U> dyn_cast() {
  1410. return reffed_ptr<U>(upb::dyn_cast<U*>(get()));
  1411. }
  1412. /* Plain release() is unsafe; if we were the only owner, it would leak the
  1413. * object. Instead we provide this: */
  1414. T* ReleaseTo(const void* new_owner) {
  1415. T* ret = NULL;
  1416. ptr_->DonateRef(this, new_owner);
  1417. std::swap(ret, ptr_);
  1418. return ret;
  1419. }
  1420. private:
  1421. T* ptr_;
  1422. };
  1423. #endif /* __cplusplus */
  1424. #endif /* UPB_REFCOUNT_H_ */
  1425. #ifdef __cplusplus
  1426. #include <cstring>
  1427. #include <string>
  1428. #include <vector>
  1429. namespace upb {
  1430. class Def;
  1431. class EnumDef;
  1432. class FieldDef;
  1433. class FileDef;
  1434. class MessageDef;
  1435. class OneofDef;
  1436. class SymbolTable;
  1437. }
  1438. #endif
  1439. UPB_DECLARE_DERIVED_TYPE(upb::Def, upb::RefCounted, upb_def, upb_refcounted)
  1440. UPB_DECLARE_DERIVED_TYPE(upb::OneofDef, upb::RefCounted, upb_oneofdef,
  1441. upb_refcounted)
  1442. UPB_DECLARE_DERIVED_TYPE(upb::FileDef, upb::RefCounted, upb_filedef,
  1443. upb_refcounted)
  1444. UPB_DECLARE_TYPE(upb::SymbolTable, upb_symtab)
  1445. /* The maximum message depth that the type graph can have. This is a resource
  1446. * limit for the C stack since we sometimes need to recursively traverse the
  1447. * graph. Cycles are ok; the traversal will stop when it detects a cycle, but
  1448. * we must hit the cycle before the maximum depth is reached.
  1449. *
  1450. * If having a single static limit is too inflexible, we can add another variant
  1451. * of Def::Freeze that allows specifying this as a parameter. */
  1452. #define UPB_MAX_MESSAGE_DEPTH 64
  1453. /* upb::Def: base class for top-level defs ***********************************/
  1454. /* All the different kind of defs that can be defined at the top-level and put
  1455. * in a SymbolTable or appear in a FileDef::defs() list. This excludes some
  1456. * defs (like oneofs and files). It only includes fields because they can be
  1457. * defined as extensions. */
  1458. typedef enum {
  1459. UPB_DEF_MSG,
  1460. UPB_DEF_FIELD,
  1461. UPB_DEF_ENUM,
  1462. UPB_DEF_SERVICE, /* Not yet implemented. */
  1463. UPB_DEF_ANY = -1 /* Wildcard for upb_symtab_get*() */
  1464. } upb_deftype_t;
  1465. #ifdef __cplusplus
  1466. /* The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
  1467. * to convert). */
  1468. class upb::Def {
  1469. public:
  1470. typedef upb_deftype_t Type;
  1471. /* upb::RefCounted methods like Ref()/Unref(). */
  1472. UPB_REFCOUNTED_CPPMETHODS
  1473. Type def_type() const;
  1474. /* "fullname" is the def's fully-qualified name (eg. foo.bar.Message). */
  1475. const char *full_name() const;
  1476. /* The final part of a def's name (eg. Message). */
  1477. const char *name() const;
  1478. /* The def must be mutable. Caller retains ownership of fullname. Defs are
  1479. * not required to have a name; if a def has no name when it is frozen, it
  1480. * will remain an anonymous def. On failure, returns false and details in "s"
  1481. * if non-NULL. */
  1482. bool set_full_name(const char* fullname, upb::Status* s);
  1483. bool set_full_name(const std::string &fullname, upb::Status* s);
  1484. /* The file in which this def appears. It is not necessary to add a def to a
  1485. * file (and consequently the accessor may return NULL). Set this by calling
  1486. * file->Add(def). */
  1487. FileDef* file() const;
  1488. /* Freezes the given defs; this validates all constraints and marks the defs
  1489. * as frozen (read-only). "defs" may not contain any fielddefs, but fields
  1490. * of any msgdefs will be frozen.
  1491. *
  1492. * Symbolic references to sub-types and enum defaults must have already been
  1493. * resolved. Any mutable defs reachable from any of "defs" must also be in
  1494. * the list; more formally, "defs" must be a transitive closure of mutable
  1495. * defs.
  1496. *
  1497. * After this operation succeeds, the finalized defs must only be accessed
  1498. * through a const pointer! */
  1499. static bool Freeze(Def* const* defs, size_t n, Status* status);
  1500. static bool Freeze(const std::vector<Def*>& defs, Status* status);
  1501. private:
  1502. UPB_DISALLOW_POD_OPS(Def, upb::Def)
  1503. #else
  1504. struct upb_def {
  1505. upb_refcounted base;
  1506. const char *fullname;
  1507. const upb_filedef* file;
  1508. char type; /* A upb_deftype_t (char to save space) */
  1509. /* Used as a flag during the def's mutable stage. Must be false unless
  1510. * it is currently being used by a function on the stack. This allows
  1511. * us to easily determine which defs were passed into the function's
  1512. * current invocation. */
  1513. bool came_from_user;
  1514. #endif
  1515. };
  1516. #define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
  1517. { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
  1518. UPB_BEGIN_EXTERN_C
  1519. /* Include upb_refcounted methods like upb_def_ref()/upb_def_unref(). */
  1520. UPB_REFCOUNTED_CMETHODS(upb_def, upb_def_upcast)
  1521. upb_deftype_t upb_def_type(const upb_def *d);
  1522. const char *upb_def_fullname(const upb_def *d);
  1523. const char *upb_def_name(const upb_def *d);
  1524. const upb_filedef *upb_def_file(const upb_def *d);
  1525. bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s);
  1526. bool upb_def_freeze(upb_def *const *defs, size_t n, upb_status *s);
  1527. /* Temporary API: for internal use only. */
  1528. bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s);
  1529. UPB_END_EXTERN_C
  1530. /* upb::Def casts *************************************************************/
  1531. #ifdef __cplusplus
  1532. #define UPB_CPP_CASTS(cname, cpptype) \
  1533. namespace upb { \
  1534. template <> \
  1535. inline cpptype *down_cast<cpptype *, Def>(Def * def) { \
  1536. return upb_downcast_##cname##_mutable(def); \
  1537. } \
  1538. template <> \
  1539. inline cpptype *dyn_cast<cpptype *, Def>(Def * def) { \
  1540. return upb_dyncast_##cname##_mutable(def); \
  1541. } \
  1542. template <> \
  1543. inline const cpptype *down_cast<const cpptype *, const Def>( \
  1544. const Def *def) { \
  1545. return upb_downcast_##cname(def); \
  1546. } \
  1547. template <> \
  1548. inline const cpptype *dyn_cast<const cpptype *, const Def>(const Def *def) { \
  1549. return upb_dyncast_##cname(def); \
  1550. } \
  1551. template <> \
  1552. inline const cpptype *down_cast<const cpptype *, Def>(Def * def) { \
  1553. return upb_downcast_##cname(def); \
  1554. } \
  1555. template <> \
  1556. inline const cpptype *dyn_cast<const cpptype *, Def>(Def * def) { \
  1557. return upb_dyncast_##cname(def); \
  1558. } \
  1559. } /* namespace upb */
  1560. #else
  1561. #define UPB_CPP_CASTS(cname, cpptype)
  1562. #endif /* __cplusplus */
  1563. /* Dynamic casts, for determining if a def is of a particular type at runtime.
  1564. * Downcasts, for when some wants to assert that a def is of a particular type.
  1565. * These are only checked if we are building debug. */
  1566. #define UPB_DEF_CASTS(lower, upper, cpptype) \
  1567. UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
  1568. if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
  1569. return (upb_##lower *)def; \
  1570. } \
  1571. UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
  1572. UPB_ASSERT(upb_def_type(def) == UPB_DEF_##upper); \
  1573. return (const upb_##lower *)def; \
  1574. } \
  1575. UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
  1576. return (upb_##lower *)upb_dyncast_##lower(def); \
  1577. } \
  1578. UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
  1579. return (upb_##lower *)upb_downcast_##lower(def); \
  1580. } \
  1581. UPB_CPP_CASTS(lower, cpptype)
  1582. #define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \
  1583. UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, cppmethods, \
  1584. members) \
  1585. UPB_DEF_CASTS(lower, upper, cppname)
  1586. #define UPB_DECLARE_DEF_TYPE(cppname, lower, upper) \
  1587. UPB_DECLARE_DERIVED_TYPE2(cppname, upb::Def, upb::RefCounted, \
  1588. upb_ ## lower, upb_def, upb_refcounted) \
  1589. UPB_DEF_CASTS(lower, upper, cppname)
  1590. UPB_DECLARE_DEF_TYPE(upb::FieldDef, fielddef, FIELD)
  1591. UPB_DECLARE_DEF_TYPE(upb::MessageDef, msgdef, MSG)
  1592. UPB_DECLARE_DEF_TYPE(upb::EnumDef, enumdef, ENUM)
  1593. #undef UPB_DECLARE_DEF_TYPE
  1594. #undef UPB_DEF_CASTS
  1595. #undef UPB_CPP_CASTS
  1596. /* upb::FieldDef **************************************************************/
  1597. /* The types a field can have. Note that this list is not identical to the
  1598. * types defined in descriptor.proto, which gives INT32 and SINT32 separate
  1599. * types (we distinguish the two with the "integer encoding" enum below). */
  1600. typedef enum {
  1601. /* Types stored in 1 byte. */
  1602. UPB_TYPE_BOOL = 1,
  1603. /* Types stored in 4 bytes. */
  1604. UPB_TYPE_FLOAT = 2,
  1605. UPB_TYPE_INT32 = 3,
  1606. UPB_TYPE_UINT32 = 4,
  1607. UPB_TYPE_ENUM = 5, /* Enum values are int32. */
  1608. /* Types stored as pointers (probably 4 or 8 bytes). */
  1609. UPB_TYPE_STRING = 6,
  1610. UPB_TYPE_BYTES = 7,
  1611. UPB_TYPE_MESSAGE = 8,
  1612. /* Types stored as 8 bytes. */
  1613. UPB_TYPE_DOUBLE = 9,
  1614. UPB_TYPE_INT64 = 10,
  1615. UPB_TYPE_UINT64 = 11
  1616. } upb_fieldtype_t;
  1617. /* The repeated-ness of each field; this matches descriptor.proto. */
  1618. typedef enum {
  1619. UPB_LABEL_OPTIONAL = 1,
  1620. UPB_LABEL_REQUIRED = 2,
  1621. UPB_LABEL_REPEATED = 3
  1622. } upb_label_t;
  1623. /* How integers should be encoded in serializations that offer multiple
  1624. * integer encoding methods. */
  1625. typedef enum {
  1626. UPB_INTFMT_VARIABLE = 1,
  1627. UPB_INTFMT_FIXED = 2,
  1628. UPB_INTFMT_ZIGZAG = 3 /* Only for signed types (INT32/INT64). */
  1629. } upb_intfmt_t;
  1630. /* Descriptor types, as defined in descriptor.proto. */
  1631. typedef enum {
  1632. UPB_DESCRIPTOR_TYPE_DOUBLE = 1,
  1633. UPB_DESCRIPTOR_TYPE_FLOAT = 2,
  1634. UPB_DESCRIPTOR_TYPE_INT64 = 3,
  1635. UPB_DESCRIPTOR_TYPE_UINT64 = 4,
  1636. UPB_DESCRIPTOR_TYPE_INT32 = 5,
  1637. UPB_DESCRIPTOR_TYPE_FIXED64 = 6,
  1638. UPB_DESCRIPTOR_TYPE_FIXED32 = 7,
  1639. UPB_DESCRIPTOR_TYPE_BOOL = 8,
  1640. UPB_DESCRIPTOR_TYPE_STRING = 9,
  1641. UPB_DESCRIPTOR_TYPE_GROUP = 10,
  1642. UPB_DESCRIPTOR_TYPE_MESSAGE = 11,
  1643. UPB_DESCRIPTOR_TYPE_BYTES = 12,
  1644. UPB_DESCRIPTOR_TYPE_UINT32 = 13,
  1645. UPB_DESCRIPTOR_TYPE_ENUM = 14,
  1646. UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
  1647. UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
  1648. UPB_DESCRIPTOR_TYPE_SINT32 = 17,
  1649. UPB_DESCRIPTOR_TYPE_SINT64 = 18
  1650. } upb_descriptortype_t;
  1651. typedef enum {
  1652. UPB_SYNTAX_PROTO2 = 2,
  1653. UPB_SYNTAX_PROTO3 = 3
  1654. } upb_syntax_t;
  1655. /* All the different kind of well known type messages. For simplicity of check,
  1656. * number wrappers and string wrappers are grouped together. Make sure the
  1657. * order and merber of these groups are not changed.
  1658. */
  1659. typedef enum {
  1660. UPB_WELLKNOWN_UNSPECIFIED,
  1661. UPB_WELLKNOWN_ANY,
  1662. UPB_WELLKNOWN_FIELDMASK,
  1663. UPB_WELLKNOWN_DURATION,
  1664. UPB_WELLKNOWN_TIMESTAMP,
  1665. /* number wrappers */
  1666. UPB_WELLKNOWN_DOUBLEVALUE,
  1667. UPB_WELLKNOWN_FLOATVALUE,
  1668. UPB_WELLKNOWN_INT64VALUE,
  1669. UPB_WELLKNOWN_UINT64VALUE,
  1670. UPB_WELLKNOWN_INT32VALUE,
  1671. UPB_WELLKNOWN_UINT32VALUE,
  1672. /* string wrappers */
  1673. UPB_WELLKNOWN_STRINGVALUE,
  1674. UPB_WELLKNOWN_BYTESVALUE,
  1675. UPB_WELLKNOWN_BOOLVALUE,
  1676. UPB_WELLKNOWN_VALUE,
  1677. UPB_WELLKNOWN_LISTVALUE,
  1678. UPB_WELLKNOWN_STRUCT
  1679. } upb_wellknowntype_t;
  1680. /* Maps descriptor type -> upb field type. */
  1681. extern const uint8_t upb_desctype_to_fieldtype[];
  1682. /* Maximum field number allowed for FieldDefs. This is an inherent limit of the
  1683. * protobuf wire format. */
  1684. #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
  1685. #ifdef __cplusplus
  1686. /* A upb_fielddef describes a single field in a message. It is most often
  1687. * found as a part of a upb_msgdef, but can also stand alone to represent
  1688. * an extension.
  1689. *
  1690. * Its base class is upb::Def (use upb::upcast() to convert). */
  1691. class upb::FieldDef {
  1692. public:
  1693. typedef upb_fieldtype_t Type;
  1694. typedef upb_label_t Label;
  1695. typedef upb_intfmt_t IntegerFormat;
  1696. typedef upb_descriptortype_t DescriptorType;
  1697. /* These return true if the given value is a valid member of the enumeration. */
  1698. static bool CheckType(int32_t val);
  1699. static bool CheckLabel(int32_t val);
  1700. static bool CheckDescriptorType(int32_t val);
  1701. static bool CheckIntegerFormat(int32_t val);
  1702. /* These convert to the given enumeration; they require that the value is
  1703. * valid. */
  1704. static Type ConvertType(int32_t val);
  1705. static Label ConvertLabel(int32_t val);
  1706. static DescriptorType ConvertDescriptorType(int32_t val);
  1707. static IntegerFormat ConvertIntegerFormat(int32_t val);
  1708. /* Returns NULL if memory allocation failed. */
  1709. static reffed_ptr<FieldDef> New();
  1710. /* upb::RefCounted methods like Ref()/Unref(). */
  1711. UPB_REFCOUNTED_CPPMETHODS
  1712. /* Functionality from upb::Def. */
  1713. const char* full_name() const;
  1714. bool type_is_set() const; /* set_[descriptor_]type() has been called? */
  1715. Type type() const; /* Requires that type_is_set() == true. */
  1716. Label label() const; /* Defaults to UPB_LABEL_OPTIONAL. */
  1717. const char* name() const; /* NULL if uninitialized. */
  1718. uint32_t number() const; /* Returns 0 if uninitialized. */
  1719. bool is_extension() const;
  1720. /* Copies the JSON name for this field into the given buffer. Returns the
  1721. * actual size of the JSON name, including the NULL terminator. If the
  1722. * return value is 0, the JSON name is unset. If the return value is
  1723. * greater than len, the JSON name was truncated. The buffer is always
  1724. * NULL-terminated if len > 0.
  1725. *
  1726. * The JSON name always defaults to a camelCased version of the regular
  1727. * name. However if the regular name is unset, the JSON name will be unset
  1728. * also.
  1729. */
  1730. size_t GetJsonName(char* buf, size_t len) const;
  1731. /* Convenience version of the above function which copies the JSON name
  1732. * into the given string, returning false if the name is not set. */
  1733. template <class T>
  1734. bool GetJsonName(T* str) {
  1735. str->resize(GetJsonName(NULL, 0));
  1736. GetJsonName(&(*str)[0], str->size());
  1737. return str->size() > 0;
  1738. }
  1739. /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
  1740. * indicates whether this field should have lazy parsing handlers that yield
  1741. * the unparsed string for the submessage.
  1742. *
  1743. * TODO(haberman): I think we want to move this into a FieldOptions container
  1744. * when we add support for custom options (the FieldOptions struct will
  1745. * contain both regular FieldOptions like "lazy" *and* custom options). */
  1746. bool lazy() const;
  1747. /* For non-string, non-submessage fields, this indicates whether binary
  1748. * protobufs are encoded in packed or non-packed format.
  1749. *
  1750. * TODO(haberman): see note above about putting options like this into a
  1751. * FieldOptions container. */
  1752. bool packed() const;
  1753. /* An integer that can be used as an index into an array of fields for
  1754. * whatever message this field belongs to. Guaranteed to be less than
  1755. * f->containing_type()->field_count(). May only be accessed once the def has
  1756. * been finalized. */
  1757. uint32_t index() const;
  1758. /* The MessageDef to which this field belongs.
  1759. *
  1760. * If this field has been added to a MessageDef, that message can be retrieved
  1761. * directly (this is always the case for frozen FieldDefs).
  1762. *
  1763. * If the field has not yet been added to a MessageDef, you can set the name
  1764. * of the containing type symbolically instead. This is mostly useful for
  1765. * extensions, where the extension is declared separately from the message. */
  1766. const MessageDef* containing_type() const;
  1767. const char* containing_type_name();
  1768. /* The OneofDef to which this field belongs, or NULL if this field is not part
  1769. * of a oneof. */
  1770. const OneofDef* containing_oneof() const;
  1771. /* The field's type according to the enum in descriptor.proto. This is not
  1772. * the same as UPB_TYPE_*, because it distinguishes between (for example)
  1773. * INT32 and SINT32, whereas our "type" enum does not. This return of
  1774. * descriptor_type() is a function of type(), integer_format(), and
  1775. * is_tag_delimited(). Likewise set_descriptor_type() sets all three
  1776. * appropriately. */
  1777. DescriptorType descriptor_type() const;
  1778. /* Convenient field type tests. */
  1779. bool IsSubMessage() const;
  1780. bool IsString() const;
  1781. bool IsSequence() const;
  1782. bool IsPrimitive() const;
  1783. bool IsMap() const;
  1784. /* Returns whether this field explicitly represents presence.
  1785. *
  1786. * For proto2 messages: Returns true for any scalar (non-repeated) field.
  1787. * For proto3 messages: Returns true for scalar submessage or oneof fields. */
  1788. bool HasPresence() const;
  1789. /* How integers are encoded. Only meaningful for integer types.
  1790. * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */
  1791. IntegerFormat integer_format() const;
  1792. /* Whether a submessage field is tag-delimited or not (if false, then
  1793. * length-delimited). May only be set when type() == UPB_TYPE_MESSAGE. */
  1794. bool is_tag_delimited() const;
  1795. /* Returns the non-string default value for this fielddef, which may either
  1796. * be something the client set explicitly or the "default default" (0 for
  1797. * numbers, empty for strings). The field's type indicates the type of the
  1798. * returned value, except for enum fields that are still mutable.
  1799. *
  1800. * Requires that the given function matches the field's current type. */
  1801. int64_t default_int64() const;
  1802. int32_t default_int32() const;
  1803. uint64_t default_uint64() const;
  1804. uint32_t default_uint32() const;
  1805. bool default_bool() const;
  1806. float default_float() const;
  1807. double default_double() const;
  1808. /* The resulting string is always NULL-terminated. If non-NULL, the length
  1809. * will be stored in *len. */
  1810. const char *default_string(size_t* len) const;
  1811. /* For frozen UPB_TYPE_ENUM fields, enum defaults can always be read as either
  1812. * string or int32, and both of these methods will always return true.
  1813. *
  1814. * For mutable UPB_TYPE_ENUM fields, the story is a bit more complicated.
  1815. * Enum defaults are unusual. They can be specified either as string or int32,
  1816. * but to be valid the enum must have that value as a member. And if no
  1817. * default is specified, the "default default" comes from the EnumDef.
  1818. *
  1819. * We allow reading the default as either an int32 or a string, but only if
  1820. * we have a meaningful value to report. We have a meaningful value if it was
  1821. * set explicitly, or if we could get the "default default" from the EnumDef.
  1822. * Also if you explicitly set the name and we find the number in the EnumDef */
  1823. bool EnumHasStringDefault() const;
  1824. bool EnumHasInt32Default() const;
  1825. /* Submessage and enum fields must reference a "subdef", which is the
  1826. * upb::MessageDef or upb::EnumDef that defines their type. Note that when
  1827. * the FieldDef is mutable it may not have a subdef *yet*, but this function
  1828. * still returns true to indicate that the field's type requires a subdef. */
  1829. bool HasSubDef() const;
  1830. /* Returns the enum or submessage def for this field, if any. The field's
  1831. * type must match (ie. you may only call enum_subdef() for fields where
  1832. * type() == UPB_TYPE_ENUM). Returns NULL if the subdef has not been set or
  1833. * is currently set symbolically. */
  1834. const EnumDef* enum_subdef() const;
  1835. const MessageDef* message_subdef() const;
  1836. /* Returns the generic subdef for this field. Requires that HasSubDef() (ie.
  1837. * only works for UPB_TYPE_ENUM and UPB_TYPE_MESSAGE fields). */
  1838. const Def* subdef() const;
  1839. /* Returns the symbolic name of the subdef. If the subdef is currently set
  1840. * unresolved (ie. set symbolically) returns the symbolic name. If it has
  1841. * been resolved to a specific subdef, returns the name from that subdef. */
  1842. const char* subdef_name() const;
  1843. /* Setters (non-const methods), only valid for mutable FieldDefs! ***********/
  1844. bool set_full_name(const char* fullname, upb::Status* s);
  1845. bool set_full_name(const std::string& fullname, upb::Status* s);
  1846. /* This may only be called if containing_type() == NULL (ie. the field has not
  1847. * been added to a message yet). */
  1848. bool set_containing_type_name(const char *name, Status* status);
  1849. bool set_containing_type_name(const std::string& name, Status* status);
  1850. /* Defaults to false. When we freeze, we ensure that this can only be true
  1851. * for length-delimited message fields. Prior to freezing this can be true or
  1852. * false with no restrictions. */
  1853. void set_lazy(bool lazy);
  1854. /* Defaults to true. Sets whether this field is encoded in packed format. */
  1855. void set_packed(bool packed);
  1856. /* "type" or "descriptor_type" MUST be set explicitly before the fielddef is
  1857. * finalized. These setters require that the enum value is valid; if the
  1858. * value did not come directly from an enum constant, the caller should
  1859. * validate it first with the functions above (CheckFieldType(), etc). */
  1860. void set_type(Type type);
  1861. void set_label(Label label);
  1862. void set_descriptor_type(DescriptorType type);
  1863. void set_is_extension(bool is_extension);
  1864. /* "number" and "name" must be set before the FieldDef is added to a
  1865. * MessageDef, and may not be set after that.
  1866. *
  1867. * "name" is the same as full_name()/set_full_name(), but since fielddefs
  1868. * most often use simple, non-qualified names, we provide this accessor
  1869. * also. Generally only extensions will want to think of this name as
  1870. * fully-qualified. */
  1871. bool set_number(uint32_t number, upb::Status* s);
  1872. bool set_name(const char* name, upb::Status* s);
  1873. bool set_name(const std::string& name, upb::Status* s);
  1874. /* Sets the JSON name to the given string. */
  1875. /* TODO(haberman): implement. Right now only default json_name (camelCase)
  1876. * is supported. */
  1877. bool set_json_name(const char* json_name, upb::Status* s);
  1878. bool set_json_name(const std::string& name, upb::Status* s);
  1879. /* Clears the JSON name. This will make it revert to its default, which is
  1880. * a camelCased version of the regular field name. */
  1881. void clear_json_name();
  1882. void set_integer_format(IntegerFormat format);
  1883. bool set_tag_delimited(bool tag_delimited, upb::Status* s);
  1884. /* Sets default value for the field. The call must exactly match the type
  1885. * of the field. Enum fields may use either setint32 or setstring to set
  1886. * the default numerically or symbolically, respectively, but symbolic
  1887. * defaults must be resolved before finalizing (see ResolveEnumDefault()).
  1888. *
  1889. * Changing the type of a field will reset its default. */
  1890. void set_default_int64(int64_t val);
  1891. void set_default_int32(int32_t val);
  1892. void set_default_uint64(uint64_t val);
  1893. void set_default_uint32(uint32_t val);
  1894. void set_default_bool(bool val);
  1895. void set_default_float(float val);
  1896. void set_default_double(double val);
  1897. bool set_default_string(const void *str, size_t len, Status *s);
  1898. bool set_default_string(const std::string &str, Status *s);
  1899. void set_default_cstr(const char *str, Status *s);
  1900. /* Before a fielddef is frozen, its subdef may be set either directly (with a
  1901. * upb::Def*) or symbolically. Symbolic refs must be resolved before the
  1902. * containing msgdef can be frozen (see upb_resolve() above). upb always
  1903. * guarantees that any def reachable from a live def will also be kept alive.
  1904. *
  1905. * Both methods require that upb_hassubdef(f) (so the type must be set prior
  1906. * to calling these methods). Returns false if this is not the case, or if
  1907. * the given subdef is not of the correct type. The subdef is reset if the
  1908. * field's type is changed. The subdef can be set to NULL to clear it. */
  1909. bool set_subdef(const Def* subdef, Status* s);
  1910. bool set_enum_subdef(const EnumDef* subdef, Status* s);
  1911. bool set_message_subdef(const MessageDef* subdef, Status* s);
  1912. bool set_subdef_name(const char* name, Status* s);
  1913. bool set_subdef_name(const std::string &name, Status* s);
  1914. private:
  1915. UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef)
  1916. #else
  1917. struct upb_fielddef {
  1918. upb_def base;
  1919. union {
  1920. int64_t sint;
  1921. uint64_t uint;
  1922. double dbl;
  1923. float flt;
  1924. void *bytes;
  1925. } defaultval;
  1926. union {
  1927. const upb_msgdef *def; /* If !msg_is_symbolic. */
  1928. char *name; /* If msg_is_symbolic. */
  1929. } msg;
  1930. union {
  1931. const upb_def *def; /* If !subdef_is_symbolic. */
  1932. char *name; /* If subdef_is_symbolic. */
  1933. } sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
  1934. bool subdef_is_symbolic;
  1935. bool msg_is_symbolic;
  1936. const upb_oneofdef *oneof;
  1937. bool default_is_string;
  1938. bool type_is_set_; /* False until type is explicitly set. */
  1939. bool is_extension_;
  1940. bool lazy_;
  1941. bool packed_;
  1942. upb_intfmt_t intfmt;
  1943. bool tagdelim;
  1944. upb_fieldtype_t type_;
  1945. upb_label_t label_;
  1946. uint32_t number_;
  1947. uint32_t selector_base; /* Used to index into a upb::Handlers table. */
  1948. uint32_t index_;
  1949. # endif /* defined(__cplusplus) */
  1950. };
  1951. UPB_BEGIN_EXTERN_C
  1952. extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
  1953. #define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
  1954. packed, name, num, msgdef, subdef, selector_base, \
  1955. index, defaultval, refs, ref2s) \
  1956. { \
  1957. UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
  1958. defaultval, {msgdef}, {subdef}, NULL, false, false, \
  1959. type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
  1960. lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
  1961. }
  1962. /* Native C API. */
  1963. upb_fielddef *upb_fielddef_new(const void *owner);
  1964. /* Include upb_refcounted methods like upb_fielddef_ref(). */
  1965. UPB_REFCOUNTED_CMETHODS(upb_fielddef, upb_fielddef_upcast2)
  1966. /* Methods from upb_def. */
  1967. const char *upb_fielddef_fullname(const upb_fielddef *f);
  1968. bool upb_fielddef_setfullname(upb_fielddef *f, const char *fullname,
  1969. upb_status *s);
  1970. bool upb_fielddef_typeisset(const upb_fielddef *f);
  1971. upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
  1972. upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
  1973. upb_label_t upb_fielddef_label(const upb_fielddef *f);
  1974. uint32_t upb_fielddef_number(const upb_fielddef *f);
  1975. const char *upb_fielddef_name(const upb_fielddef *f);
  1976. bool upb_fielddef_isextension(const upb_fielddef *f);
  1977. bool upb_fielddef_lazy(const upb_fielddef *f);
  1978. bool upb_fielddef_packed(const upb_fielddef *f);
  1979. size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
  1980. const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
  1981. const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
  1982. upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f);
  1983. const char *upb_fielddef_containingtypename(upb_fielddef *f);
  1984. upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f);
  1985. uint32_t upb_fielddef_index(const upb_fielddef *f);
  1986. bool upb_fielddef_istagdelim(const upb_fielddef *f);
  1987. bool upb_fielddef_issubmsg(const upb_fielddef *f);
  1988. bool upb_fielddef_isstring(const upb_fielddef *f);
  1989. bool upb_fielddef_isseq(const upb_fielddef *f);
  1990. bool upb_fielddef_isprimitive(const upb_fielddef *f);
  1991. bool upb_fielddef_ismap(const upb_fielddef *f);
  1992. bool upb_fielddef_haspresence(const upb_fielddef *f);
  1993. int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
  1994. int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
  1995. uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
  1996. uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
  1997. bool upb_fielddef_defaultbool(const upb_fielddef *f);
  1998. float upb_fielddef_defaultfloat(const upb_fielddef *f);
  1999. double upb_fielddef_defaultdouble(const upb_fielddef *f);
  2000. const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
  2001. bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f);
  2002. bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f);
  2003. bool upb_fielddef_hassubdef(const upb_fielddef *f);
  2004. const upb_def *upb_fielddef_subdef(const upb_fielddef *f);
  2005. const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
  2006. const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
  2007. const char *upb_fielddef_subdefname(const upb_fielddef *f);
  2008. void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type);
  2009. void upb_fielddef_setdescriptortype(upb_fielddef *f, int type);
  2010. void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label);
  2011. bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s);
  2012. bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s);
  2013. bool upb_fielddef_setjsonname(upb_fielddef *f, const char *name, upb_status *s);
  2014. bool upb_fielddef_clearjsonname(upb_fielddef *f);
  2015. bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
  2016. upb_status *s);
  2017. void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension);
  2018. void upb_fielddef_setlazy(upb_fielddef *f, bool lazy);
  2019. void upb_fielddef_setpacked(upb_fielddef *f, bool packed);
  2020. void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt);
  2021. void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim);
  2022. void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t val);
  2023. void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t val);
  2024. void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t val);
  2025. void upb_fielddef_setdefaultuint32(upb_fielddef *f, uint32_t val);
  2026. void upb_fielddef_setdefaultbool(upb_fielddef *f, bool val);
  2027. void upb_fielddef_setdefaultfloat(upb_fielddef *f, float val);
  2028. void upb_fielddef_setdefaultdouble(upb_fielddef *f, double val);
  2029. bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len,
  2030. upb_status *s);
  2031. void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str,
  2032. upb_status *s);
  2033. bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
  2034. upb_status *s);
  2035. bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
  2036. upb_status *s);
  2037. bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
  2038. upb_status *s);
  2039. bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
  2040. upb_status *s);
  2041. bool upb_fielddef_checklabel(int32_t label);
  2042. bool upb_fielddef_checktype(int32_t type);
  2043. bool upb_fielddef_checkdescriptortype(int32_t type);
  2044. bool upb_fielddef_checkintfmt(int32_t fmt);
  2045. UPB_END_EXTERN_C
  2046. /* upb::MessageDef ************************************************************/
  2047. typedef upb_inttable_iter upb_msg_field_iter;
  2048. typedef upb_strtable_iter upb_msg_oneof_iter;
  2049. /* Well-known field tag numbers for map-entry messages. */
  2050. #define UPB_MAPENTRY_KEY 1
  2051. #define UPB_MAPENTRY_VALUE 2
  2052. /* Well-known field tag numbers for Any messages. */
  2053. #define UPB_ANY_TYPE 1
  2054. #define UPB_ANY_VALUE 2
  2055. /* Well-known field tag numbers for timestamp messages. */
  2056. #define UPB_DURATION_SECONDS 1
  2057. #define UPB_DURATION_NANOS 2
  2058. /* Well-known field tag numbers for duration messages. */
  2059. #define UPB_TIMESTAMP_SECONDS 1
  2060. #define UPB_TIMESTAMP_NANOS 2
  2061. #ifdef __cplusplus
  2062. /* Structure that describes a single .proto message type.
  2063. *
  2064. * Its base class is upb::Def (use upb::upcast() to convert). */
  2065. class upb::MessageDef {
  2066. public:
  2067. /* Returns NULL if memory allocation failed. */
  2068. static reffed_ptr<MessageDef> New();
  2069. /* upb::RefCounted methods like Ref()/Unref(). */
  2070. UPB_REFCOUNTED_CPPMETHODS
  2071. /* Functionality from upb::Def. */
  2072. const char* full_name() const;
  2073. const char* name() const;
  2074. bool set_full_name(const char* fullname, Status* s);
  2075. bool set_full_name(const std::string& fullname, Status* s);
  2076. /* Call to freeze this MessageDef.
  2077. * WARNING: this will fail if this message has any unfrozen submessages!
  2078. * Messages with cycles must be frozen as a batch using upb::Def::Freeze(). */
  2079. bool Freeze(Status* s);
  2080. /* The number of fields that belong to the MessageDef. */
  2081. int field_count() const;
  2082. /* The number of oneofs that belong to the MessageDef. */
  2083. int oneof_count() const;
  2084. /* Adds a field (upb_fielddef object) to a msgdef. Requires that the msgdef
  2085. * and the fielddefs are mutable. The fielddef's name and number must be
  2086. * set, and the message may not already contain any field with this name or
  2087. * number, and this fielddef may not be part of another message. In error
  2088. * cases false is returned and the msgdef is unchanged.
  2089. *
  2090. * If the given field is part of a oneof, this call succeeds if and only if
  2091. * that oneof is already part of this msgdef. (Note that adding a oneof to a
  2092. * msgdef automatically adds all of its fields to the msgdef at the time that
  2093. * the oneof is added, so it is usually more idiomatic to add the oneof's
  2094. * fields first then add the oneof to the msgdef. This case is supported for
  2095. * convenience.)
  2096. *
  2097. * If |f| is already part of this MessageDef, this method performs no action
  2098. * and returns true (success). Thus, this method is idempotent. */
  2099. bool AddField(FieldDef* f, Status* s);
  2100. bool AddField(const reffed_ptr<FieldDef>& f, Status* s);
  2101. /* Adds a oneof (upb_oneofdef object) to a msgdef. Requires that the msgdef,
  2102. * oneof, and any fielddefs are mutable, that the fielddefs contained in the
  2103. * oneof do not have any name or number conflicts with existing fields in the
  2104. * msgdef, and that the oneof's name is unique among all oneofs in the msgdef.
  2105. * If the oneof is added successfully, all of its fields will be added
  2106. * directly to the msgdef as well. In error cases, false is returned and the
  2107. * msgdef is unchanged. */
  2108. bool AddOneof(OneofDef* o, Status* s);
  2109. bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
  2110. upb_syntax_t syntax() const;
  2111. /* Returns false if we don't support this syntax value. */
  2112. bool set_syntax(upb_syntax_t syntax);
  2113. /* Set this to false to indicate that primitive fields should not have
  2114. * explicit presence information associated with them. This will affect all
  2115. * fields added to this message. Defaults to true. */
  2116. void SetPrimitivesHavePresence(bool have_presence);
  2117. /* These return NULL if the field is not found. */
  2118. FieldDef* FindFieldByNumber(uint32_t number);
  2119. FieldDef* FindFieldByName(const char *name, size_t len);
  2120. const FieldDef* FindFieldByNumber(uint32_t number) const;
  2121. const FieldDef* FindFieldByName(const char* name, size_t len) const;
  2122. FieldDef* FindFieldByName(const char *name) {
  2123. return FindFieldByName(name, strlen(name));
  2124. }
  2125. const FieldDef* FindFieldByName(const char *name) const {
  2126. return FindFieldByName(name, strlen(name));
  2127. }
  2128. template <class T>
  2129. FieldDef* FindFieldByName(const T& str) {
  2130. return FindFieldByName(str.c_str(), str.size());
  2131. }
  2132. template <class T>
  2133. const FieldDef* FindFieldByName(const T& str) const {
  2134. return FindFieldByName(str.c_str(), str.size());
  2135. }
  2136. OneofDef* FindOneofByName(const char* name, size_t len);
  2137. const OneofDef* FindOneofByName(const char* name, size_t len) const;
  2138. OneofDef* FindOneofByName(const char* name) {
  2139. return FindOneofByName(name, strlen(name));
  2140. }
  2141. const OneofDef* FindOneofByName(const char* name) const {
  2142. return FindOneofByName(name, strlen(name));
  2143. }
  2144. template<class T>
  2145. OneofDef* FindOneofByName(const T& str) {
  2146. return FindOneofByName(str.c_str(), str.size());
  2147. }
  2148. template<class T>
  2149. const OneofDef* FindOneofByName(const T& str) const {
  2150. return FindOneofByName(str.c_str(), str.size());
  2151. }
  2152. /* Is this message a map entry? */
  2153. void setmapentry(bool map_entry);
  2154. bool mapentry() const;
  2155. /* Return the type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
  2156. * non-well-known message. */
  2157. upb_wellknowntype_t wellknowntype() const;
  2158. /* Whether is a number wrapper. */
  2159. bool isnumberwrapper() const;
  2160. /* Iteration over fields. The order is undefined. */
  2161. class field_iterator
  2162. : public std::iterator<std::forward_iterator_tag, FieldDef*> {
  2163. public:
  2164. explicit field_iterator(MessageDef* md);
  2165. static field_iterator end(MessageDef* md);
  2166. void operator++();
  2167. FieldDef* operator*() const;
  2168. bool operator!=(const field_iterator& other) const;
  2169. bool operator==(const field_iterator& other) const;
  2170. private:
  2171. upb_msg_field_iter iter_;
  2172. };
  2173. class const_field_iterator
  2174. : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
  2175. public:
  2176. explicit const_field_iterator(const MessageDef* md);
  2177. static const_field_iterator end(const MessageDef* md);
  2178. void operator++();
  2179. const FieldDef* operator*() const;
  2180. bool operator!=(const const_field_iterator& other) const;
  2181. bool operator==(const const_field_iterator& other) const;
  2182. private:
  2183. upb_msg_field_iter iter_;
  2184. };
  2185. /* Iteration over oneofs. The order is undefined. */
  2186. class oneof_iterator
  2187. : public std::iterator<std::forward_iterator_tag, FieldDef*> {
  2188. public:
  2189. explicit oneof_iterator(MessageDef* md);
  2190. static oneof_iterator end(MessageDef* md);
  2191. void operator++();
  2192. OneofDef* operator*() const;
  2193. bool operator!=(const oneof_iterator& other) const;
  2194. bool operator==(const oneof_iterator& other) const;
  2195. private:
  2196. upb_msg_oneof_iter iter_;
  2197. };
  2198. class const_oneof_iterator
  2199. : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
  2200. public:
  2201. explicit const_oneof_iterator(const MessageDef* md);
  2202. static const_oneof_iterator end(const MessageDef* md);
  2203. void operator++();
  2204. const OneofDef* operator*() const;
  2205. bool operator!=(const const_oneof_iterator& other) const;
  2206. bool operator==(const const_oneof_iterator& other) const;
  2207. private:
  2208. upb_msg_oneof_iter iter_;
  2209. };
  2210. class FieldAccessor {
  2211. public:
  2212. explicit FieldAccessor(MessageDef* msg) : msg_(msg) {}
  2213. field_iterator begin() { return msg_->field_begin(); }
  2214. field_iterator end() { return msg_->field_end(); }
  2215. private:
  2216. MessageDef* msg_;
  2217. };
  2218. class ConstFieldAccessor {
  2219. public:
  2220. explicit ConstFieldAccessor(const MessageDef* msg) : msg_(msg) {}
  2221. const_field_iterator begin() { return msg_->field_begin(); }
  2222. const_field_iterator end() { return msg_->field_end(); }
  2223. private:
  2224. const MessageDef* msg_;
  2225. };
  2226. class OneofAccessor {
  2227. public:
  2228. explicit OneofAccessor(MessageDef* msg) : msg_(msg) {}
  2229. oneof_iterator begin() { return msg_->oneof_begin(); }
  2230. oneof_iterator end() { return msg_->oneof_end(); }
  2231. private:
  2232. MessageDef* msg_;
  2233. };
  2234. class ConstOneofAccessor {
  2235. public:
  2236. explicit ConstOneofAccessor(const MessageDef* msg) : msg_(msg) {}
  2237. const_oneof_iterator begin() { return msg_->oneof_begin(); }
  2238. const_oneof_iterator end() { return msg_->oneof_end(); }
  2239. private:
  2240. const MessageDef* msg_;
  2241. };
  2242. field_iterator field_begin();
  2243. field_iterator field_end();
  2244. const_field_iterator field_begin() const;
  2245. const_field_iterator field_end() const;
  2246. oneof_iterator oneof_begin();
  2247. oneof_iterator oneof_end();
  2248. const_oneof_iterator oneof_begin() const;
  2249. const_oneof_iterator oneof_end() const;
  2250. FieldAccessor fields() { return FieldAccessor(this); }
  2251. ConstFieldAccessor fields() const { return ConstFieldAccessor(this); }
  2252. OneofAccessor oneofs() { return OneofAccessor(this); }
  2253. ConstOneofAccessor oneofs() const { return ConstOneofAccessor(this); }
  2254. private:
  2255. UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef)
  2256. #else
  2257. struct upb_msgdef {
  2258. upb_def base;
  2259. size_t selector_count;
  2260. uint32_t submsg_field_count;
  2261. /* Tables for looking up fields by number and name. */
  2262. upb_inttable itof; /* int to field */
  2263. upb_strtable ntof; /* name to field/oneof */
  2264. /* Is this a map-entry message? */
  2265. bool map_entry;
  2266. /* Whether this message has proto2 or proto3 semantics. */
  2267. upb_syntax_t syntax;
  2268. /* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
  2269. * non-well-known message. */
  2270. upb_wellknowntype_t well_known_type;
  2271. /* TODO(haberman): proper extension ranges (there can be multiple). */
  2272. #endif /* __cplusplus */
  2273. };
  2274. UPB_BEGIN_EXTERN_C
  2275. extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
  2276. /* TODO: also support static initialization of the oneofs table. This will be
  2277. * needed if we compile in descriptors that contain oneofs. */
  2278. #define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
  2279. map_entry, syntax, well_known_type, refs, ref2s) \
  2280. { \
  2281. UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
  2282. selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \
  2283. well_known_type \
  2284. }
  2285. /* Returns NULL if memory allocation failed. */
  2286. upb_msgdef *upb_msgdef_new(const void *owner);
  2287. /* Include upb_refcounted methods like upb_msgdef_ref(). */
  2288. UPB_REFCOUNTED_CMETHODS(upb_msgdef, upb_msgdef_upcast2)
  2289. bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status);
  2290. const char *upb_msgdef_fullname(const upb_msgdef *m);
  2291. const char *upb_msgdef_name(const upb_msgdef *m);
  2292. int upb_msgdef_numoneofs(const upb_msgdef *m);
  2293. upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
  2294. bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
  2295. upb_status *s);
  2296. bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
  2297. upb_status *s);
  2298. bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
  2299. void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
  2300. bool upb_msgdef_mapentry(const upb_msgdef *m);
  2301. upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m);
  2302. bool upb_msgdef_isnumberwrapper(const upb_msgdef *m);
  2303. bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
  2304. /* Field lookup in a couple of different variations:
  2305. * - itof = int to field
  2306. * - ntof = name to field
  2307. * - ntofz = name to field, null-terminated string. */
  2308. const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
  2309. const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
  2310. size_t len);
  2311. int upb_msgdef_numfields(const upb_msgdef *m);
  2312. UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m,
  2313. const char *name) {
  2314. return upb_msgdef_ntof(m, name, strlen(name));
  2315. }
  2316. UPB_INLINE upb_fielddef *upb_msgdef_itof_mutable(upb_msgdef *m, uint32_t i) {
  2317. return (upb_fielddef*)upb_msgdef_itof(m, i);
  2318. }
  2319. UPB_INLINE upb_fielddef *upb_msgdef_ntof_mutable(upb_msgdef *m,
  2320. const char *name, size_t len) {
  2321. return (upb_fielddef *)upb_msgdef_ntof(m, name, len);
  2322. }
  2323. /* Oneof lookup:
  2324. * - ntoo = name to oneof
  2325. * - ntooz = name to oneof, null-terminated string. */
  2326. const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
  2327. size_t len);
  2328. int upb_msgdef_numoneofs(const upb_msgdef *m);
  2329. UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
  2330. const char *name) {
  2331. return upb_msgdef_ntoo(m, name, strlen(name));
  2332. }
  2333. UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m,
  2334. const char *name, size_t len) {
  2335. return (upb_oneofdef *)upb_msgdef_ntoo(m, name, len);
  2336. }
  2337. /* Lookup of either field or oneof by name. Returns whether either was found.
  2338. * If the return is true, then the found def will be set, and the non-found
  2339. * one set to NULL. */
  2340. bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
  2341. const upb_fielddef **f, const upb_oneofdef **o);
  2342. UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
  2343. const upb_fielddef **f,
  2344. const upb_oneofdef **o) {
  2345. return upb_msgdef_lookupname(m, name, strlen(name), f, o);
  2346. }
  2347. /* Iteration over fields and oneofs. For example:
  2348. *
  2349. * upb_msg_field_iter i;
  2350. * for(upb_msg_field_begin(&i, m);
  2351. * !upb_msg_field_done(&i);
  2352. * upb_msg_field_next(&i)) {
  2353. * upb_fielddef *f = upb_msg_iter_field(&i);
  2354. * // ...
  2355. * }
  2356. *
  2357. * For C we don't have separate iterators for const and non-const.
  2358. * It is the caller's responsibility to cast the upb_fielddef* to
  2359. * const if the upb_msgdef* is const. */
  2360. void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
  2361. void upb_msg_field_next(upb_msg_field_iter *iter);
  2362. bool upb_msg_field_done(const upb_msg_field_iter *iter);
  2363. upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
  2364. void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
  2365. /* Similar to above, we also support iterating through the oneofs in a
  2366. * msgdef. */
  2367. void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m);
  2368. void upb_msg_oneof_next(upb_msg_oneof_iter *iter);
  2369. bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
  2370. upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
  2371. void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter);
  2372. UPB_END_EXTERN_C
  2373. /* upb::EnumDef ***************************************************************/
  2374. typedef upb_strtable_iter upb_enum_iter;
  2375. #ifdef __cplusplus
  2376. /* Class that represents an enum. Its base class is upb::Def (convert with
  2377. * upb::upcast()). */
  2378. class upb::EnumDef {
  2379. public:
  2380. /* Returns NULL if memory allocation failed. */
  2381. static reffed_ptr<EnumDef> New();
  2382. /* upb::RefCounted methods like Ref()/Unref(). */
  2383. UPB_REFCOUNTED_CPPMETHODS
  2384. /* Functionality from upb::Def. */
  2385. const char* full_name() const;
  2386. const char* name() const;
  2387. bool set_full_name(const char* fullname, Status* s);
  2388. bool set_full_name(const std::string& fullname, Status* s);
  2389. /* Call to freeze this EnumDef. */
  2390. bool Freeze(Status* s);
  2391. /* The value that is used as the default when no field default is specified.
  2392. * If not set explicitly, the first value that was added will be used.
  2393. * The default value must be a member of the enum.
  2394. * Requires that value_count() > 0. */
  2395. int32_t default_value() const;
  2396. /* Sets the default value. If this value is not valid, returns false and an
  2397. * error message in status. */
  2398. bool set_default_value(int32_t val, Status* status);
  2399. /* Returns the number of values currently defined in the enum. Note that
  2400. * multiple names can refer to the same number, so this may be greater than
  2401. * the total number of unique numbers. */
  2402. int value_count() const;
  2403. /* Adds a single name/number pair to the enum. Fails if this name has
  2404. * already been used by another value. */
  2405. bool AddValue(const char* name, int32_t num, Status* status);
  2406. bool AddValue(const std::string& name, int32_t num, Status* status);
  2407. /* Lookups from name to integer, returning true if found. */
  2408. bool FindValueByName(const char* name, int32_t* num) const;
  2409. /* Finds the name corresponding to the given number, or NULL if none was
  2410. * found. If more than one name corresponds to this number, returns the
  2411. * first one that was added. */
  2412. const char* FindValueByNumber(int32_t num) const;
  2413. /* Iteration over name/value pairs. The order is undefined.
  2414. * Adding an enum val invalidates any iterators.
  2415. *
  2416. * TODO: make compatible with range-for, with elements as pairs? */
  2417. class Iterator {
  2418. public:
  2419. explicit Iterator(const EnumDef*);
  2420. int32_t number();
  2421. const char *name();
  2422. bool Done();
  2423. void Next();
  2424. private:
  2425. upb_enum_iter iter_;
  2426. };
  2427. private:
  2428. UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef)
  2429. #else
  2430. struct upb_enumdef {
  2431. upb_def base;
  2432. upb_strtable ntoi;
  2433. upb_inttable iton;
  2434. int32_t defaultval;
  2435. #endif /* __cplusplus */
  2436. };
  2437. UPB_BEGIN_EXTERN_C
  2438. extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
  2439. #define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
  2440. { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
  2441. iton, defaultval }
  2442. /* Native C API. */
  2443. upb_enumdef *upb_enumdef_new(const void *owner);
  2444. /* Include upb_refcounted methods like upb_enumdef_ref(). */
  2445. UPB_REFCOUNTED_CMETHODS(upb_enumdef, upb_enumdef_upcast2)
  2446. bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status);
  2447. /* From upb_def. */
  2448. const char *upb_enumdef_fullname(const upb_enumdef *e);
  2449. const char *upb_enumdef_name(const upb_enumdef *e);
  2450. bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
  2451. upb_status *s);
  2452. int32_t upb_enumdef_default(const upb_enumdef *e);
  2453. bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s);
  2454. int upb_enumdef_numvals(const upb_enumdef *e);
  2455. bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
  2456. upb_status *status);
  2457. /* Enum lookups:
  2458. * - ntoi: look up a name with specified length.
  2459. * - ntoiz: look up a name provided as a null-terminated string.
  2460. * - iton: look up an integer, returning the name as a null-terminated
  2461. * string. */
  2462. bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
  2463. int32_t *num);
  2464. UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
  2465. const char *name, int32_t *num) {
  2466. return upb_enumdef_ntoi(e, name, strlen(name), num);
  2467. }
  2468. const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
  2469. /* upb_enum_iter i;
  2470. * for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
  2471. * // ...
  2472. * }
  2473. */
  2474. void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
  2475. void upb_enum_next(upb_enum_iter *iter);
  2476. bool upb_enum_done(upb_enum_iter *iter);
  2477. const char *upb_enum_iter_name(upb_enum_iter *iter);
  2478. int32_t upb_enum_iter_number(upb_enum_iter *iter);
  2479. UPB_END_EXTERN_C
  2480. /* upb::OneofDef **************************************************************/
  2481. typedef upb_inttable_iter upb_oneof_iter;
  2482. #ifdef __cplusplus
  2483. /* Class that represents a oneof. */
  2484. class upb::OneofDef {
  2485. public:
  2486. /* Returns NULL if memory allocation failed. */
  2487. static reffed_ptr<OneofDef> New();
  2488. /* upb::RefCounted methods like Ref()/Unref(). */
  2489. UPB_REFCOUNTED_CPPMETHODS
  2490. /* Returns the MessageDef that owns this OneofDef. */
  2491. const MessageDef* containing_type() const;
  2492. /* Returns the name of this oneof. This is the name used to look up the oneof
  2493. * by name once added to a message def. */
  2494. const char* name() const;
  2495. bool set_name(const char* name, Status* s);
  2496. bool set_name(const std::string& name, Status* s);
  2497. /* Returns the number of fields currently defined in the oneof. */
  2498. int field_count() const;
  2499. /* Adds a field to the oneof. The field must not have been added to any other
  2500. * oneof or msgdef. If the oneof is not yet part of a msgdef, then when the
  2501. * oneof is eventually added to a msgdef, all fields added to the oneof will
  2502. * also be added to the msgdef at that time. If the oneof is already part of a
  2503. * msgdef, the field must either be a part of that msgdef already, or must not
  2504. * be a part of any msgdef; in the latter case, the field is added to the
  2505. * msgdef as a part of this operation.
  2506. *
  2507. * The field may only have an OPTIONAL label, never REQUIRED or REPEATED.
  2508. *
  2509. * If |f| is already part of this MessageDef, this method performs no action
  2510. * and returns true (success). Thus, this method is idempotent. */
  2511. bool AddField(FieldDef* field, Status* s);
  2512. bool AddField(const reffed_ptr<FieldDef>& field, Status* s);
  2513. /* Looks up by name. */
  2514. const FieldDef* FindFieldByName(const char* name, size_t len) const;
  2515. FieldDef* FindFieldByName(const char* name, size_t len);
  2516. const FieldDef* FindFieldByName(const char* name) const {
  2517. return FindFieldByName(name, strlen(name));
  2518. }
  2519. FieldDef* FindFieldByName(const char* name) {
  2520. return FindFieldByName(name, strlen(name));
  2521. }
  2522. template <class T>
  2523. FieldDef* FindFieldByName(const T& str) {
  2524. return FindFieldByName(str.c_str(), str.size());
  2525. }
  2526. template <class T>
  2527. const FieldDef* FindFieldByName(const T& str) const {
  2528. return FindFieldByName(str.c_str(), str.size());
  2529. }
  2530. /* Looks up by tag number. */
  2531. const FieldDef* FindFieldByNumber(uint32_t num) const;
  2532. /* Iteration over fields. The order is undefined. */
  2533. class iterator : public std::iterator<std::forward_iterator_tag, FieldDef*> {
  2534. public:
  2535. explicit iterator(OneofDef* md);
  2536. static iterator end(OneofDef* md);
  2537. void operator++();
  2538. FieldDef* operator*() const;
  2539. bool operator!=(const iterator& other) const;
  2540. bool operator==(const iterator& other) const;
  2541. private:
  2542. upb_oneof_iter iter_;
  2543. };
  2544. class const_iterator
  2545. : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
  2546. public:
  2547. explicit const_iterator(const OneofDef* md);
  2548. static const_iterator end(const OneofDef* md);
  2549. void operator++();
  2550. const FieldDef* operator*() const;
  2551. bool operator!=(const const_iterator& other) const;
  2552. bool operator==(const const_iterator& other) const;
  2553. private:
  2554. upb_oneof_iter iter_;
  2555. };
  2556. iterator begin();
  2557. iterator end();
  2558. const_iterator begin() const;
  2559. const_iterator end() const;
  2560. private:
  2561. UPB_DISALLOW_POD_OPS(OneofDef, upb::OneofDef)
  2562. #else
  2563. struct upb_oneofdef {
  2564. upb_refcounted base;
  2565. uint32_t index; /* Index within oneofs. */
  2566. const char *name;
  2567. upb_strtable ntof;
  2568. upb_inttable itof;
  2569. const upb_msgdef *parent;
  2570. #endif /* __cplusplus */
  2571. };
  2572. UPB_BEGIN_EXTERN_C
  2573. extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
  2574. #define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
  2575. { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
  2576. /* Native C API. */
  2577. upb_oneofdef *upb_oneofdef_new(const void *owner);
  2578. /* Include upb_refcounted methods like upb_oneofdef_ref(). */
  2579. UPB_REFCOUNTED_CMETHODS(upb_oneofdef, upb_oneofdef_upcast)
  2580. const char *upb_oneofdef_name(const upb_oneofdef *o);
  2581. const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
  2582. int upb_oneofdef_numfields(const upb_oneofdef *o);
  2583. uint32_t upb_oneofdef_index(const upb_oneofdef *o);
  2584. bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s);
  2585. bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
  2586. const void *ref_donor,
  2587. upb_status *s);
  2588. /* Oneof lookups:
  2589. * - ntof: look up a field by name.
  2590. * - ntofz: look up a field by name (as a null-terminated string).
  2591. * - itof: look up a field by number. */
  2592. const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
  2593. const char *name, size_t length);
  2594. UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
  2595. const char *name) {
  2596. return upb_oneofdef_ntof(o, name, strlen(name));
  2597. }
  2598. const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
  2599. /* upb_oneof_iter i;
  2600. * for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
  2601. * // ...
  2602. * }
  2603. */
  2604. void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
  2605. void upb_oneof_next(upb_oneof_iter *iter);
  2606. bool upb_oneof_done(upb_oneof_iter *iter);
  2607. upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
  2608. void upb_oneof_iter_setdone(upb_oneof_iter *iter);
  2609. UPB_END_EXTERN_C
  2610. /* upb::FileDef ***************************************************************/
  2611. #ifdef __cplusplus
  2612. /* Class that represents a .proto file with some things defined in it.
  2613. *
  2614. * Many users won't care about FileDefs, but they are necessary if you want to
  2615. * read the values of file-level options. */
  2616. class upb::FileDef {
  2617. public:
  2618. /* Returns NULL if memory allocation failed. */
  2619. static reffed_ptr<FileDef> New();
  2620. /* upb::RefCounted methods like Ref()/Unref(). */
  2621. UPB_REFCOUNTED_CPPMETHODS
  2622. /* Get/set name of the file (eg. "foo/bar.proto"). */
  2623. const char* name() const;
  2624. bool set_name(const char* name, Status* s);
  2625. bool set_name(const std::string& name, Status* s);
  2626. /* Package name for definitions inside the file (eg. "foo.bar"). */
  2627. const char* package() const;
  2628. bool set_package(const char* package, Status* s);
  2629. /* Sets the php class prefix which is prepended to all php generated classes
  2630. * from this .proto. Default is empty. */
  2631. const char* phpprefix() const;
  2632. bool set_phpprefix(const char* phpprefix, Status* s);
  2633. /* Use this option to change the namespace of php generated classes. Default
  2634. * is empty. When this option is empty, the package name will be used for
  2635. * determining the namespace. */
  2636. const char* phpnamespace() const;
  2637. bool set_phpnamespace(const char* phpnamespace, Status* s);
  2638. /* Syntax for the file. Defaults to proto2. */
  2639. upb_syntax_t syntax() const;
  2640. void set_syntax(upb_syntax_t syntax);
  2641. /* Get the list of defs from the file. These are returned in the order that
  2642. * they were added to the FileDef. */
  2643. int def_count() const;
  2644. const Def* def(int index) const;
  2645. Def* def(int index);
  2646. /* Get the list of dependencies from the file. These are returned in the
  2647. * order that they were added to the FileDef. */
  2648. int dependency_count() const;
  2649. const FileDef* dependency(int index) const;
  2650. /* Adds defs to this file. The def must not already belong to another
  2651. * file.
  2652. *
  2653. * Note: this does *not* ensure that this def's name is unique in this file!
  2654. * Use a SymbolTable if you want to check this property. Especially since
  2655. * properly checking uniqueness would require a check across *all* files
  2656. * (including dependencies). */
  2657. bool AddDef(Def* def, Status* s);
  2658. bool AddMessage(MessageDef* m, Status* s);
  2659. bool AddEnum(EnumDef* e, Status* s);
  2660. bool AddExtension(FieldDef* f, Status* s);
  2661. /* Adds a dependency of this file. */
  2662. bool AddDependency(const FileDef* file);
  2663. /* Freezes this FileDef and all messages/enums under it. All subdefs must be
  2664. * resolved and all messages/enums must validate. Returns true if this
  2665. * succeeded.
  2666. *
  2667. * TODO(haberman): should we care whether the file's dependencies are frozen
  2668. * already? */
  2669. bool Freeze(Status* s);
  2670. private:
  2671. UPB_DISALLOW_POD_OPS(FileDef, upb::FileDef)
  2672. #else
  2673. struct upb_filedef {
  2674. upb_refcounted base;
  2675. const char *name;
  2676. const char *package;
  2677. const char *phpprefix;
  2678. const char *phpnamespace;
  2679. upb_syntax_t syntax;
  2680. upb_inttable defs;
  2681. upb_inttable deps;
  2682. #endif
  2683. };
  2684. UPB_BEGIN_EXTERN_C
  2685. extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
  2686. upb_filedef *upb_filedef_new(const void *owner);
  2687. /* Include upb_refcounted methods like upb_msgdef_ref(). */
  2688. UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast)
  2689. const char *upb_filedef_name(const upb_filedef *f);
  2690. const char *upb_filedef_package(const upb_filedef *f);
  2691. const char *upb_filedef_phpprefix(const upb_filedef *f);
  2692. const char *upb_filedef_phpnamespace(const upb_filedef *f);
  2693. upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
  2694. size_t upb_filedef_defcount(const upb_filedef *f);
  2695. size_t upb_filedef_depcount(const upb_filedef *f);
  2696. const upb_def *upb_filedef_def(const upb_filedef *f, size_t i);
  2697. const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i);
  2698. bool upb_filedef_freeze(upb_filedef *f, upb_status *s);
  2699. bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s);
  2700. bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s);
  2701. bool upb_filedef_setphpprefix(upb_filedef *f, const char *phpprefix,
  2702. upb_status *s);
  2703. bool upb_filedef_setphpnamespace(upb_filedef *f, const char *phpnamespace,
  2704. upb_status *s);
  2705. bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s);
  2706. bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
  2707. upb_status *s);
  2708. bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep);
  2709. UPB_INLINE bool upb_filedef_addmsg(upb_filedef *f, upb_msgdef *m,
  2710. const void *ref_donor, upb_status *s) {
  2711. return upb_filedef_adddef(f, upb_msgdef_upcast_mutable(m), ref_donor, s);
  2712. }
  2713. UPB_INLINE bool upb_filedef_addenum(upb_filedef *f, upb_enumdef *e,
  2714. const void *ref_donor, upb_status *s) {
  2715. return upb_filedef_adddef(f, upb_enumdef_upcast_mutable(e), ref_donor, s);
  2716. }
  2717. UPB_INLINE bool upb_filedef_addext(upb_filedef *file, upb_fielddef *f,
  2718. const void *ref_donor, upb_status *s) {
  2719. return upb_filedef_adddef(file, upb_fielddef_upcast_mutable(f), ref_donor, s);
  2720. }
  2721. UPB_INLINE upb_def *upb_filedef_mutabledef(upb_filedef *f, int i) {
  2722. return (upb_def*)upb_filedef_def(f, i);
  2723. }
  2724. UPB_END_EXTERN_C
  2725. typedef struct {
  2726. UPB_PRIVATE_FOR_CPP
  2727. upb_strtable_iter iter;
  2728. upb_deftype_t type;
  2729. } upb_symtab_iter;
  2730. #ifdef __cplusplus
  2731. /* Non-const methods in upb::SymbolTable are NOT thread-safe. */
  2732. class upb::SymbolTable {
  2733. public:
  2734. /* Returns a new symbol table with a single ref owned by "owner."
  2735. * Returns NULL if memory allocation failed. */
  2736. static SymbolTable* New();
  2737. static void Free(upb::SymbolTable* table);
  2738. /* For all lookup functions, the returned pointer is not owned by the
  2739. * caller; it may be invalidated by any non-const call or unref of the
  2740. * SymbolTable! To protect against this, take a ref if desired. */
  2741. /* Freezes the symbol table: prevents further modification of it.
  2742. * After the Freeze() operation is successful, the SymbolTable must only be
  2743. * accessed via a const pointer.
  2744. *
  2745. * Unlike with upb::MessageDef/upb::EnumDef/etc, freezing a SymbolTable is not
  2746. * a necessary step in using a SymbolTable. If you have no need for it to be
  2747. * immutable, there is no need to freeze it ever. However sometimes it is
  2748. * useful, and SymbolTables that are statically compiled into the binary are
  2749. * always frozen by nature. */
  2750. void Freeze();
  2751. /* Resolves the given symbol using the rules described in descriptor.proto,
  2752. * namely:
  2753. *
  2754. * If the name starts with a '.', it is fully-qualified. Otherwise,
  2755. * C++-like scoping rules are used to find the type (i.e. first the nested
  2756. * types within this message are searched, then within the parent, on up
  2757. * to the root namespace).
  2758. *
  2759. * If not found, returns NULL. */
  2760. const Def* Resolve(const char* base, const char* sym) const;
  2761. /* Finds an entry in the symbol table with this exact name. If not found,
  2762. * returns NULL. */
  2763. const Def* Lookup(const char *sym) const;
  2764. const MessageDef* LookupMessage(const char *sym) const;
  2765. const EnumDef* LookupEnum(const char *sym) const;
  2766. /* TODO: introduce a C++ iterator, but make it nice and templated so that if
  2767. * you ask for an iterator of MessageDef the iterated elements are strongly
  2768. * typed as MessageDef*. */
  2769. /* Adds the given mutable defs to the symtab, resolving all symbols (including
  2770. * enum default values) and finalizing the defs. Only one def per name may be
  2771. * in the list, and the defs may not duplicate any name already in the symtab.
  2772. * All defs must have a name -- anonymous defs are not allowed. Anonymous
  2773. * defs can still be frozen by calling upb_def_freeze() directly.
  2774. *
  2775. * The entire operation either succeeds or fails. If the operation fails,
  2776. * the symtab is unchanged, false is returned, and status indicates the
  2777. * error. The caller passes a ref on all defs to the symtab (even if the
  2778. * operation fails).
  2779. *
  2780. * TODO(haberman): currently failure will leave the symtab unchanged, but may
  2781. * leave the defs themselves partially resolved. Does this matter? If so we
  2782. * could do a prepass that ensures that all symbols are resolvable and bail
  2783. * if not, so we don't mutate anything until we know the operation will
  2784. * succeed. */
  2785. bool Add(Def*const* defs, size_t n, void* ref_donor, Status* status);
  2786. bool Add(const std::vector<Def*>& defs, void *owner, Status* status) {
  2787. return Add((Def*const*)&defs[0], defs.size(), owner, status);
  2788. }
  2789. /* Resolves all subdefs for messages in this file and attempts to freeze the
  2790. * file. If this succeeds, adds all the symbols to this SymbolTable
  2791. * (replacing any existing ones with the same names). */
  2792. bool AddFile(FileDef* file, Status* s);
  2793. private:
  2794. UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable)
  2795. #else
  2796. struct upb_symtab {
  2797. upb_refcounted base;
  2798. upb_strtable symtab;
  2799. #endif /* __cplusplus */
  2800. };
  2801. UPB_BEGIN_EXTERN_C
  2802. /* Native C API. */
  2803. upb_symtab *upb_symtab_new();
  2804. void upb_symtab_free(upb_symtab* s);
  2805. const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
  2806. const char *sym);
  2807. const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym);
  2808. const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
  2809. const upb_msgdef *upb_symtab_lookupmsg2(
  2810. const upb_symtab *s, const char *sym, size_t len);
  2811. const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
  2812. bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
  2813. void *ref_donor, upb_status *status);
  2814. bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status* status);
  2815. /* upb_symtab_iter i;
  2816. * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i);
  2817. * upb_symtab_next(&i)) {
  2818. * const upb_def *def = upb_symtab_iter_def(&i);
  2819. * // ...
  2820. * }
  2821. *
  2822. * For C we don't have separate iterators for const and non-const.
  2823. * It is the caller's responsibility to cast the upb_fielddef* to
  2824. * const if the upb_msgdef* is const. */
  2825. void upb_symtab_begin(upb_symtab_iter *iter, const upb_symtab *s,
  2826. upb_deftype_t type);
  2827. void upb_symtab_next(upb_symtab_iter *iter);
  2828. bool upb_symtab_done(const upb_symtab_iter *iter);
  2829. const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter);
  2830. UPB_END_EXTERN_C
  2831. #ifdef __cplusplus
  2832. /* C++ inline wrappers. */
  2833. namespace upb {
  2834. inline SymbolTable* SymbolTable::New() {
  2835. return upb_symtab_new();
  2836. }
  2837. inline void SymbolTable::Free(SymbolTable* s) {
  2838. upb_symtab_free(s);
  2839. }
  2840. inline const Def *SymbolTable::Resolve(const char *base,
  2841. const char *sym) const {
  2842. return upb_symtab_resolve(this, base, sym);
  2843. }
  2844. inline const Def* SymbolTable::Lookup(const char *sym) const {
  2845. return upb_symtab_lookup(this, sym);
  2846. }
  2847. inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const {
  2848. return upb_symtab_lookupmsg(this, sym);
  2849. }
  2850. inline bool SymbolTable::Add(
  2851. Def*const* defs, size_t n, void* ref_donor, Status* status) {
  2852. return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status);
  2853. }
  2854. inline bool SymbolTable::AddFile(FileDef* file, Status* s) {
  2855. return upb_symtab_addfile(this, file, s);
  2856. }
  2857. } /* namespace upb */
  2858. #endif
  2859. #ifdef __cplusplus
  2860. UPB_INLINE const char* upb_safecstr(const std::string& str) {
  2861. UPB_ASSERT(str.size() == std::strlen(str.c_str()));
  2862. return str.c_str();
  2863. }
  2864. /* Inline C++ wrappers. */
  2865. namespace upb {
  2866. inline Def::Type Def::def_type() const { return upb_def_type(this); }
  2867. inline const char* Def::full_name() const { return upb_def_fullname(this); }
  2868. inline const char* Def::name() const { return upb_def_name(this); }
  2869. inline bool Def::set_full_name(const char* fullname, Status* s) {
  2870. return upb_def_setfullname(this, fullname, s);
  2871. }
  2872. inline bool Def::set_full_name(const std::string& fullname, Status* s) {
  2873. return upb_def_setfullname(this, upb_safecstr(fullname), s);
  2874. }
  2875. inline bool Def::Freeze(Def* const* defs, size_t n, Status* status) {
  2876. return upb_def_freeze(defs, n, status);
  2877. }
  2878. inline bool Def::Freeze(const std::vector<Def*>& defs, Status* status) {
  2879. return upb_def_freeze((Def* const*)&defs[0], defs.size(), status);
  2880. }
  2881. inline bool FieldDef::CheckType(int32_t val) {
  2882. return upb_fielddef_checktype(val);
  2883. }
  2884. inline bool FieldDef::CheckLabel(int32_t val) {
  2885. return upb_fielddef_checklabel(val);
  2886. }
  2887. inline bool FieldDef::CheckDescriptorType(int32_t val) {
  2888. return upb_fielddef_checkdescriptortype(val);
  2889. }
  2890. inline bool FieldDef::CheckIntegerFormat(int32_t val) {
  2891. return upb_fielddef_checkintfmt(val);
  2892. }
  2893. inline FieldDef::Type FieldDef::ConvertType(int32_t val) {
  2894. UPB_ASSERT(CheckType(val));
  2895. return static_cast<FieldDef::Type>(val);
  2896. }
  2897. inline FieldDef::Label FieldDef::ConvertLabel(int32_t val) {
  2898. UPB_ASSERT(CheckLabel(val));
  2899. return static_cast<FieldDef::Label>(val);
  2900. }
  2901. inline FieldDef::DescriptorType FieldDef::ConvertDescriptorType(int32_t val) {
  2902. UPB_ASSERT(CheckDescriptorType(val));
  2903. return static_cast<FieldDef::DescriptorType>(val);
  2904. }
  2905. inline FieldDef::IntegerFormat FieldDef::ConvertIntegerFormat(int32_t val) {
  2906. UPB_ASSERT(CheckIntegerFormat(val));
  2907. return static_cast<FieldDef::IntegerFormat>(val);
  2908. }
  2909. inline reffed_ptr<FieldDef> FieldDef::New() {
  2910. upb_fielddef *f = upb_fielddef_new(&f);
  2911. return reffed_ptr<FieldDef>(f, &f);
  2912. }
  2913. inline const char* FieldDef::full_name() const {
  2914. return upb_fielddef_fullname(this);
  2915. }
  2916. inline bool FieldDef::set_full_name(const char* fullname, Status* s) {
  2917. return upb_fielddef_setfullname(this, fullname, s);
  2918. }
  2919. inline bool FieldDef::set_full_name(const std::string& fullname, Status* s) {
  2920. return upb_fielddef_setfullname(this, upb_safecstr(fullname), s);
  2921. }
  2922. inline bool FieldDef::type_is_set() const {
  2923. return upb_fielddef_typeisset(this);
  2924. }
  2925. inline FieldDef::Type FieldDef::type() const { return upb_fielddef_type(this); }
  2926. inline FieldDef::DescriptorType FieldDef::descriptor_type() const {
  2927. return upb_fielddef_descriptortype(this);
  2928. }
  2929. inline FieldDef::Label FieldDef::label() const {
  2930. return upb_fielddef_label(this);
  2931. }
  2932. inline uint32_t FieldDef::number() const { return upb_fielddef_number(this); }
  2933. inline const char* FieldDef::name() const { return upb_fielddef_name(this); }
  2934. inline bool FieldDef::is_extension() const {
  2935. return upb_fielddef_isextension(this);
  2936. }
  2937. inline size_t FieldDef::GetJsonName(char* buf, size_t len) const {
  2938. return upb_fielddef_getjsonname(this, buf, len);
  2939. }
  2940. inline bool FieldDef::lazy() const {
  2941. return upb_fielddef_lazy(this);
  2942. }
  2943. inline void FieldDef::set_lazy(bool lazy) {
  2944. upb_fielddef_setlazy(this, lazy);
  2945. }
  2946. inline bool FieldDef::packed() const {
  2947. return upb_fielddef_packed(this);
  2948. }
  2949. inline uint32_t FieldDef::index() const {
  2950. return upb_fielddef_index(this);
  2951. }
  2952. inline void FieldDef::set_packed(bool packed) {
  2953. upb_fielddef_setpacked(this, packed);
  2954. }
  2955. inline const MessageDef* FieldDef::containing_type() const {
  2956. return upb_fielddef_containingtype(this);
  2957. }
  2958. inline const OneofDef* FieldDef::containing_oneof() const {
  2959. return upb_fielddef_containingoneof(this);
  2960. }
  2961. inline const char* FieldDef::containing_type_name() {
  2962. return upb_fielddef_containingtypename(this);
  2963. }
  2964. inline bool FieldDef::set_number(uint32_t number, Status* s) {
  2965. return upb_fielddef_setnumber(this, number, s);
  2966. }
  2967. inline bool FieldDef::set_name(const char *name, Status* s) {
  2968. return upb_fielddef_setname(this, name, s);
  2969. }
  2970. inline bool FieldDef::set_name(const std::string& name, Status* s) {
  2971. return upb_fielddef_setname(this, upb_safecstr(name), s);
  2972. }
  2973. inline bool FieldDef::set_json_name(const char *name, Status* s) {
  2974. return upb_fielddef_setjsonname(this, name, s);
  2975. }
  2976. inline bool FieldDef::set_json_name(const std::string& name, Status* s) {
  2977. return upb_fielddef_setjsonname(this, upb_safecstr(name), s);
  2978. }
  2979. inline void FieldDef::clear_json_name() {
  2980. upb_fielddef_clearjsonname(this);
  2981. }
  2982. inline bool FieldDef::set_containing_type_name(const char *name, Status* s) {
  2983. return upb_fielddef_setcontainingtypename(this, name, s);
  2984. }
  2985. inline bool FieldDef::set_containing_type_name(const std::string &name,
  2986. Status *s) {
  2987. return upb_fielddef_setcontainingtypename(this, upb_safecstr(name), s);
  2988. }
  2989. inline void FieldDef::set_type(upb_fieldtype_t type) {
  2990. upb_fielddef_settype(this, type);
  2991. }
  2992. inline void FieldDef::set_is_extension(bool is_extension) {
  2993. upb_fielddef_setisextension(this, is_extension);
  2994. }
  2995. inline void FieldDef::set_descriptor_type(FieldDef::DescriptorType type) {
  2996. upb_fielddef_setdescriptortype(this, type);
  2997. }
  2998. inline void FieldDef::set_label(upb_label_t label) {
  2999. upb_fielddef_setlabel(this, label);
  3000. }
  3001. inline bool FieldDef::IsSubMessage() const {
  3002. return upb_fielddef_issubmsg(this);
  3003. }
  3004. inline bool FieldDef::IsString() const { return upb_fielddef_isstring(this); }
  3005. inline bool FieldDef::IsSequence() const { return upb_fielddef_isseq(this); }
  3006. inline bool FieldDef::IsMap() const { return upb_fielddef_ismap(this); }
  3007. inline int64_t FieldDef::default_int64() const {
  3008. return upb_fielddef_defaultint64(this);
  3009. }
  3010. inline int32_t FieldDef::default_int32() const {
  3011. return upb_fielddef_defaultint32(this);
  3012. }
  3013. inline uint64_t FieldDef::default_uint64() const {
  3014. return upb_fielddef_defaultuint64(this);
  3015. }
  3016. inline uint32_t FieldDef::default_uint32() const {
  3017. return upb_fielddef_defaultuint32(this);
  3018. }
  3019. inline bool FieldDef::default_bool() const {
  3020. return upb_fielddef_defaultbool(this);
  3021. }
  3022. inline float FieldDef::default_float() const {
  3023. return upb_fielddef_defaultfloat(this);
  3024. }
  3025. inline double FieldDef::default_double() const {
  3026. return upb_fielddef_defaultdouble(this);
  3027. }
  3028. inline const char* FieldDef::default_string(size_t* len) const {
  3029. return upb_fielddef_defaultstr(this, len);
  3030. }
  3031. inline void FieldDef::set_default_int64(int64_t value) {
  3032. upb_fielddef_setdefaultint64(this, value);
  3033. }
  3034. inline void FieldDef::set_default_int32(int32_t value) {
  3035. upb_fielddef_setdefaultint32(this, value);
  3036. }
  3037. inline void FieldDef::set_default_uint64(uint64_t value) {
  3038. upb_fielddef_setdefaultuint64(this, value);
  3039. }
  3040. inline void FieldDef::set_default_uint32(uint32_t value) {
  3041. upb_fielddef_setdefaultuint32(this, value);
  3042. }
  3043. inline void FieldDef::set_default_bool(bool value) {
  3044. upb_fielddef_setdefaultbool(this, value);
  3045. }
  3046. inline void FieldDef::set_default_float(float value) {
  3047. upb_fielddef_setdefaultfloat(this, value);
  3048. }
  3049. inline void FieldDef::set_default_double(double value) {
  3050. upb_fielddef_setdefaultdouble(this, value);
  3051. }
  3052. inline bool FieldDef::set_default_string(const void *str, size_t len,
  3053. Status *s) {
  3054. return upb_fielddef_setdefaultstr(this, str, len, s);
  3055. }
  3056. inline bool FieldDef::set_default_string(const std::string& str, Status* s) {
  3057. return upb_fielddef_setdefaultstr(this, str.c_str(), str.size(), s);
  3058. }
  3059. inline void FieldDef::set_default_cstr(const char* str, Status* s) {
  3060. return upb_fielddef_setdefaultcstr(this, str, s);
  3061. }
  3062. inline bool FieldDef::HasSubDef() const { return upb_fielddef_hassubdef(this); }
  3063. inline const Def* FieldDef::subdef() const { return upb_fielddef_subdef(this); }
  3064. inline const MessageDef *FieldDef::message_subdef() const {
  3065. return upb_fielddef_msgsubdef(this);
  3066. }
  3067. inline const EnumDef *FieldDef::enum_subdef() const {
  3068. return upb_fielddef_enumsubdef(this);
  3069. }
  3070. inline const char* FieldDef::subdef_name() const {
  3071. return upb_fielddef_subdefname(this);
  3072. }
  3073. inline bool FieldDef::set_subdef(const Def* subdef, Status* s) {
  3074. return upb_fielddef_setsubdef(this, subdef, s);
  3075. }
  3076. inline bool FieldDef::set_enum_subdef(const EnumDef* subdef, Status* s) {
  3077. return upb_fielddef_setenumsubdef(this, subdef, s);
  3078. }
  3079. inline bool FieldDef::set_message_subdef(const MessageDef* subdef, Status* s) {
  3080. return upb_fielddef_setmsgsubdef(this, subdef, s);
  3081. }
  3082. inline bool FieldDef::set_subdef_name(const char* name, Status* s) {
  3083. return upb_fielddef_setsubdefname(this, name, s);
  3084. }
  3085. inline bool FieldDef::set_subdef_name(const std::string& name, Status* s) {
  3086. return upb_fielddef_setsubdefname(this, upb_safecstr(name), s);
  3087. }
  3088. inline reffed_ptr<MessageDef> MessageDef::New() {
  3089. upb_msgdef *m = upb_msgdef_new(&m);
  3090. return reffed_ptr<MessageDef>(m, &m);
  3091. }
  3092. inline const char *MessageDef::full_name() const {
  3093. return upb_msgdef_fullname(this);
  3094. }
  3095. inline const char *MessageDef::name() const {
  3096. return upb_msgdef_name(this);
  3097. }
  3098. inline upb_syntax_t MessageDef::syntax() const {
  3099. return upb_msgdef_syntax(this);
  3100. }
  3101. inline bool MessageDef::set_full_name(const char* fullname, Status* s) {
  3102. return upb_msgdef_setfullname(this, fullname, s);
  3103. }
  3104. inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) {
  3105. return upb_msgdef_setfullname(this, upb_safecstr(fullname), s);
  3106. }
  3107. inline bool MessageDef::set_syntax(upb_syntax_t syntax) {
  3108. return upb_msgdef_setsyntax(this, syntax);
  3109. }
  3110. inline bool MessageDef::Freeze(Status* status) {
  3111. return upb_msgdef_freeze(this, status);
  3112. }
  3113. inline int MessageDef::field_count() const {
  3114. return upb_msgdef_numfields(this);
  3115. }
  3116. inline int MessageDef::oneof_count() const {
  3117. return upb_msgdef_numoneofs(this);
  3118. }
  3119. inline bool MessageDef::AddField(upb_fielddef* f, Status* s) {
  3120. return upb_msgdef_addfield(this, f, NULL, s);
  3121. }
  3122. inline bool MessageDef::AddField(const reffed_ptr<FieldDef>& f, Status* s) {
  3123. return upb_msgdef_addfield(this, f.get(), NULL, s);
  3124. }
  3125. inline bool MessageDef::AddOneof(upb_oneofdef* o, Status* s) {
  3126. return upb_msgdef_addoneof(this, o, NULL, s);
  3127. }
  3128. inline bool MessageDef::AddOneof(const reffed_ptr<OneofDef>& o, Status* s) {
  3129. return upb_msgdef_addoneof(this, o.get(), NULL, s);
  3130. }
  3131. inline FieldDef* MessageDef::FindFieldByNumber(uint32_t number) {
  3132. return upb_msgdef_itof_mutable(this, number);
  3133. }
  3134. inline FieldDef* MessageDef::FindFieldByName(const char* name, size_t len) {
  3135. return upb_msgdef_ntof_mutable(this, name, len);
  3136. }
  3137. inline const FieldDef* MessageDef::FindFieldByNumber(uint32_t number) const {
  3138. return upb_msgdef_itof(this, number);
  3139. }
  3140. inline const FieldDef *MessageDef::FindFieldByName(const char *name,
  3141. size_t len) const {
  3142. return upb_msgdef_ntof(this, name, len);
  3143. }
  3144. inline OneofDef* MessageDef::FindOneofByName(const char* name, size_t len) {
  3145. return upb_msgdef_ntoo_mutable(this, name, len);
  3146. }
  3147. inline const OneofDef* MessageDef::FindOneofByName(const char* name,
  3148. size_t len) const {
  3149. return upb_msgdef_ntoo(this, name, len);
  3150. }
  3151. inline void MessageDef::setmapentry(bool map_entry) {
  3152. upb_msgdef_setmapentry(this, map_entry);
  3153. }
  3154. inline bool MessageDef::mapentry() const {
  3155. return upb_msgdef_mapentry(this);
  3156. }
  3157. inline upb_wellknowntype_t MessageDef::wellknowntype() const {
  3158. return upb_msgdef_wellknowntype(this);
  3159. }
  3160. inline bool MessageDef::isnumberwrapper() const {
  3161. return upb_msgdef_isnumberwrapper(this);
  3162. }
  3163. inline MessageDef::field_iterator MessageDef::field_begin() {
  3164. return field_iterator(this);
  3165. }
  3166. inline MessageDef::field_iterator MessageDef::field_end() {
  3167. return field_iterator::end(this);
  3168. }
  3169. inline MessageDef::const_field_iterator MessageDef::field_begin() const {
  3170. return const_field_iterator(this);
  3171. }
  3172. inline MessageDef::const_field_iterator MessageDef::field_end() const {
  3173. return const_field_iterator::end(this);
  3174. }
  3175. inline MessageDef::oneof_iterator MessageDef::oneof_begin() {
  3176. return oneof_iterator(this);
  3177. }
  3178. inline MessageDef::oneof_iterator MessageDef::oneof_end() {
  3179. return oneof_iterator::end(this);
  3180. }
  3181. inline MessageDef::const_oneof_iterator MessageDef::oneof_begin() const {
  3182. return const_oneof_iterator(this);
  3183. }
  3184. inline MessageDef::const_oneof_iterator MessageDef::oneof_end() const {
  3185. return const_oneof_iterator::end(this);
  3186. }
  3187. inline MessageDef::field_iterator::field_iterator(MessageDef* md) {
  3188. upb_msg_field_begin(&iter_, md);
  3189. }
  3190. inline MessageDef::field_iterator MessageDef::field_iterator::end(
  3191. MessageDef* md) {
  3192. MessageDef::field_iterator iter(md);
  3193. upb_msg_field_iter_setdone(&iter.iter_);
  3194. return iter;
  3195. }
  3196. inline FieldDef* MessageDef::field_iterator::operator*() const {
  3197. return upb_msg_iter_field(&iter_);
  3198. }
  3199. inline void MessageDef::field_iterator::operator++() {
  3200. return upb_msg_field_next(&iter_);
  3201. }
  3202. inline bool MessageDef::field_iterator::operator==(
  3203. const field_iterator &other) const {
  3204. return upb_inttable_iter_isequal(&iter_, &other.iter_);
  3205. }
  3206. inline bool MessageDef::field_iterator::operator!=(
  3207. const field_iterator &other) const {
  3208. return !(*this == other);
  3209. }
  3210. inline MessageDef::const_field_iterator::const_field_iterator(
  3211. const MessageDef* md) {
  3212. upb_msg_field_begin(&iter_, md);
  3213. }
  3214. inline MessageDef::const_field_iterator MessageDef::const_field_iterator::end(
  3215. const MessageDef *md) {
  3216. MessageDef::const_field_iterator iter(md);
  3217. upb_msg_field_iter_setdone(&iter.iter_);
  3218. return iter;
  3219. }
  3220. inline const FieldDef* MessageDef::const_field_iterator::operator*() const {
  3221. return upb_msg_iter_field(&iter_);
  3222. }
  3223. inline void MessageDef::const_field_iterator::operator++() {
  3224. return upb_msg_field_next(&iter_);
  3225. }
  3226. inline bool MessageDef::const_field_iterator::operator==(
  3227. const const_field_iterator &other) const {
  3228. return upb_inttable_iter_isequal(&iter_, &other.iter_);
  3229. }
  3230. inline bool MessageDef::const_field_iterator::operator!=(
  3231. const const_field_iterator &other) const {
  3232. return !(*this == other);
  3233. }
  3234. inline MessageDef::oneof_iterator::oneof_iterator(MessageDef* md) {
  3235. upb_msg_oneof_begin(&iter_, md);
  3236. }
  3237. inline MessageDef::oneof_iterator MessageDef::oneof_iterator::end(
  3238. MessageDef* md) {
  3239. MessageDef::oneof_iterator iter(md);
  3240. upb_msg_oneof_iter_setdone(&iter.iter_);
  3241. return iter;
  3242. }
  3243. inline OneofDef* MessageDef::oneof_iterator::operator*() const {
  3244. return upb_msg_iter_oneof(&iter_);
  3245. }
  3246. inline void MessageDef::oneof_iterator::operator++() {
  3247. return upb_msg_oneof_next(&iter_);
  3248. }
  3249. inline bool MessageDef::oneof_iterator::operator==(
  3250. const oneof_iterator &other) const {
  3251. return upb_strtable_iter_isequal(&iter_, &other.iter_);
  3252. }
  3253. inline bool MessageDef::oneof_iterator::operator!=(
  3254. const oneof_iterator &other) const {
  3255. return !(*this == other);
  3256. }
  3257. inline MessageDef::const_oneof_iterator::const_oneof_iterator(
  3258. const MessageDef* md) {
  3259. upb_msg_oneof_begin(&iter_, md);
  3260. }
  3261. inline MessageDef::const_oneof_iterator MessageDef::const_oneof_iterator::end(
  3262. const MessageDef *md) {
  3263. MessageDef::const_oneof_iterator iter(md);
  3264. upb_msg_oneof_iter_setdone(&iter.iter_);
  3265. return iter;
  3266. }
  3267. inline const OneofDef* MessageDef::const_oneof_iterator::operator*() const {
  3268. return upb_msg_iter_oneof(&iter_);
  3269. }
  3270. inline void MessageDef::const_oneof_iterator::operator++() {
  3271. return upb_msg_oneof_next(&iter_);
  3272. }
  3273. inline bool MessageDef::const_oneof_iterator::operator==(
  3274. const const_oneof_iterator &other) const {
  3275. return upb_strtable_iter_isequal(&iter_, &other.iter_);
  3276. }
  3277. inline bool MessageDef::const_oneof_iterator::operator!=(
  3278. const const_oneof_iterator &other) const {
  3279. return !(*this == other);
  3280. }
  3281. inline reffed_ptr<EnumDef> EnumDef::New() {
  3282. upb_enumdef *e = upb_enumdef_new(&e);
  3283. return reffed_ptr<EnumDef>(e, &e);
  3284. }
  3285. inline const char* EnumDef::full_name() const {
  3286. return upb_enumdef_fullname(this);
  3287. }
  3288. inline const char* EnumDef::name() const {
  3289. return upb_enumdef_name(this);
  3290. }
  3291. inline bool EnumDef::set_full_name(const char* fullname, Status* s) {
  3292. return upb_enumdef_setfullname(this, fullname, s);
  3293. }
  3294. inline bool EnumDef::set_full_name(const std::string& fullname, Status* s) {
  3295. return upb_enumdef_setfullname(this, upb_safecstr(fullname), s);
  3296. }
  3297. inline bool EnumDef::Freeze(Status* status) {
  3298. return upb_enumdef_freeze(this, status);
  3299. }
  3300. inline int32_t EnumDef::default_value() const {
  3301. return upb_enumdef_default(this);
  3302. }
  3303. inline bool EnumDef::set_default_value(int32_t val, Status* status) {
  3304. return upb_enumdef_setdefault(this, val, status);
  3305. }
  3306. inline int EnumDef::value_count() const { return upb_enumdef_numvals(this); }
  3307. inline bool EnumDef::AddValue(const char* name, int32_t num, Status* status) {
  3308. return upb_enumdef_addval(this, name, num, status);
  3309. }
  3310. inline bool EnumDef::AddValue(const std::string& name, int32_t num,
  3311. Status* status) {
  3312. return upb_enumdef_addval(this, upb_safecstr(name), num, status);
  3313. }
  3314. inline bool EnumDef::FindValueByName(const char* name, int32_t *num) const {
  3315. return upb_enumdef_ntoiz(this, name, num);
  3316. }
  3317. inline const char* EnumDef::FindValueByNumber(int32_t num) const {
  3318. return upb_enumdef_iton(this, num);
  3319. }
  3320. inline EnumDef::Iterator::Iterator(const EnumDef* e) {
  3321. upb_enum_begin(&iter_, e);
  3322. }
  3323. inline int32_t EnumDef::Iterator::number() {
  3324. return upb_enum_iter_number(&iter_);
  3325. }
  3326. inline const char* EnumDef::Iterator::name() {
  3327. return upb_enum_iter_name(&iter_);
  3328. }
  3329. inline bool EnumDef::Iterator::Done() { return upb_enum_done(&iter_); }
  3330. inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); }
  3331. inline reffed_ptr<OneofDef> OneofDef::New() {
  3332. upb_oneofdef *o = upb_oneofdef_new(&o);
  3333. return reffed_ptr<OneofDef>(o, &o);
  3334. }
  3335. inline const MessageDef* OneofDef::containing_type() const {
  3336. return upb_oneofdef_containingtype(this);
  3337. }
  3338. inline const char* OneofDef::name() const {
  3339. return upb_oneofdef_name(this);
  3340. }
  3341. inline bool OneofDef::set_name(const char* name, Status* s) {
  3342. return upb_oneofdef_setname(this, name, s);
  3343. }
  3344. inline bool OneofDef::set_name(const std::string& name, Status* s) {
  3345. return upb_oneofdef_setname(this, upb_safecstr(name), s);
  3346. }
  3347. inline int OneofDef::field_count() const {
  3348. return upb_oneofdef_numfields(this);
  3349. }
  3350. inline bool OneofDef::AddField(FieldDef* field, Status* s) {
  3351. return upb_oneofdef_addfield(this, field, NULL, s);
  3352. }
  3353. inline bool OneofDef::AddField(const reffed_ptr<FieldDef>& field, Status* s) {
  3354. return upb_oneofdef_addfield(this, field.get(), NULL, s);
  3355. }
  3356. inline const FieldDef* OneofDef::FindFieldByName(const char* name,
  3357. size_t len) const {
  3358. return upb_oneofdef_ntof(this, name, len);
  3359. }
  3360. inline const FieldDef* OneofDef::FindFieldByNumber(uint32_t num) const {
  3361. return upb_oneofdef_itof(this, num);
  3362. }
  3363. inline OneofDef::iterator OneofDef::begin() { return iterator(this); }
  3364. inline OneofDef::iterator OneofDef::end() { return iterator::end(this); }
  3365. inline OneofDef::const_iterator OneofDef::begin() const {
  3366. return const_iterator(this);
  3367. }
  3368. inline OneofDef::const_iterator OneofDef::end() const {
  3369. return const_iterator::end(this);
  3370. }
  3371. inline OneofDef::iterator::iterator(OneofDef* o) {
  3372. upb_oneof_begin(&iter_, o);
  3373. }
  3374. inline OneofDef::iterator OneofDef::iterator::end(OneofDef* o) {
  3375. OneofDef::iterator iter(o);
  3376. upb_oneof_iter_setdone(&iter.iter_);
  3377. return iter;
  3378. }
  3379. inline FieldDef* OneofDef::iterator::operator*() const {
  3380. return upb_oneof_iter_field(&iter_);
  3381. }
  3382. inline void OneofDef::iterator::operator++() { return upb_oneof_next(&iter_); }
  3383. inline bool OneofDef::iterator::operator==(const iterator &other) const {
  3384. return upb_inttable_iter_isequal(&iter_, &other.iter_);
  3385. }
  3386. inline bool OneofDef::iterator::operator!=(const iterator &other) const {
  3387. return !(*this == other);
  3388. }
  3389. inline OneofDef::const_iterator::const_iterator(const OneofDef* md) {
  3390. upb_oneof_begin(&iter_, md);
  3391. }
  3392. inline OneofDef::const_iterator OneofDef::const_iterator::end(
  3393. const OneofDef *md) {
  3394. OneofDef::const_iterator iter(md);
  3395. upb_oneof_iter_setdone(&iter.iter_);
  3396. return iter;
  3397. }
  3398. inline const FieldDef* OneofDef::const_iterator::operator*() const {
  3399. return upb_msg_iter_field(&iter_);
  3400. }
  3401. inline void OneofDef::const_iterator::operator++() {
  3402. return upb_oneof_next(&iter_);
  3403. }
  3404. inline bool OneofDef::const_iterator::operator==(
  3405. const const_iterator &other) const {
  3406. return upb_inttable_iter_isequal(&iter_, &other.iter_);
  3407. }
  3408. inline bool OneofDef::const_iterator::operator!=(
  3409. const const_iterator &other) const {
  3410. return !(*this == other);
  3411. }
  3412. inline reffed_ptr<FileDef> FileDef::New() {
  3413. upb_filedef *f = upb_filedef_new(&f);
  3414. return reffed_ptr<FileDef>(f, &f);
  3415. }
  3416. inline const char* FileDef::name() const {
  3417. return upb_filedef_name(this);
  3418. }
  3419. inline bool FileDef::set_name(const char* name, Status* s) {
  3420. return upb_filedef_setname(this, name, s);
  3421. }
  3422. inline bool FileDef::set_name(const std::string& name, Status* s) {
  3423. return upb_filedef_setname(this, upb_safecstr(name), s);
  3424. }
  3425. inline const char* FileDef::package() const {
  3426. return upb_filedef_package(this);
  3427. }
  3428. inline bool FileDef::set_package(const char* package, Status* s) {
  3429. return upb_filedef_setpackage(this, package, s);
  3430. }
  3431. inline const char* FileDef::phpprefix() const {
  3432. return upb_filedef_phpprefix(this);
  3433. }
  3434. inline bool FileDef::set_phpprefix(const char* phpprefix, Status* s) {
  3435. return upb_filedef_setphpprefix(this, phpprefix, s);
  3436. }
  3437. inline const char* FileDef::phpnamespace() const {
  3438. return upb_filedef_phpnamespace(this);
  3439. }
  3440. inline bool FileDef::set_phpnamespace(const char* phpnamespace, Status* s) {
  3441. return upb_filedef_setphpnamespace(this, phpnamespace, s);
  3442. }
  3443. inline int FileDef::def_count() const {
  3444. return upb_filedef_defcount(this);
  3445. }
  3446. inline const Def* FileDef::def(int index) const {
  3447. return upb_filedef_def(this, index);
  3448. }
  3449. inline Def* FileDef::def(int index) {
  3450. return const_cast<Def*>(upb_filedef_def(this, index));
  3451. }
  3452. inline int FileDef::dependency_count() const {
  3453. return upb_filedef_depcount(this);
  3454. }
  3455. inline const FileDef* FileDef::dependency(int index) const {
  3456. return upb_filedef_dep(this, index);
  3457. }
  3458. inline bool FileDef::AddDef(Def* def, Status* s) {
  3459. return upb_filedef_adddef(this, def, NULL, s);
  3460. }
  3461. inline bool FileDef::AddMessage(MessageDef* m, Status* s) {
  3462. return upb_filedef_addmsg(this, m, NULL, s);
  3463. }
  3464. inline bool FileDef::AddEnum(EnumDef* e, Status* s) {
  3465. return upb_filedef_addenum(this, e, NULL, s);
  3466. }
  3467. inline bool FileDef::AddExtension(FieldDef* f, Status* s) {
  3468. return upb_filedef_addext(this, f, NULL, s);
  3469. }
  3470. inline bool FileDef::AddDependency(const FileDef* file) {
  3471. return upb_filedef_adddep(this, file);
  3472. }
  3473. } /* namespace upb */
  3474. #endif
  3475. #endif /* UPB_DEF_H_ */
  3476. /*
  3477. ** upb::Handlers (upb_handlers)
  3478. **
  3479. ** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the
  3480. ** message can have associated functions that will be called when we are
  3481. ** parsing or visiting a stream of data. This is similar to how handlers work
  3482. ** in SAX (the Simple API for XML).
  3483. **
  3484. ** The handlers have no idea where the data is coming from, so a single set of
  3485. ** handlers could be used with two completely different data sources (for
  3486. ** example, a parser and a visitor over in-memory objects). This decoupling is
  3487. ** the most important feature of upb, because it allows parsers and serializers
  3488. ** to be highly reusable.
  3489. **
  3490. ** This is a mixed C/C++ interface that offers a full API to both languages.
  3491. ** See the top-level README for more information.
  3492. */
  3493. #ifndef UPB_HANDLERS_H
  3494. #define UPB_HANDLERS_H
  3495. #ifdef __cplusplus
  3496. namespace upb {
  3497. class BufferHandle;
  3498. class BytesHandler;
  3499. class HandlerAttributes;
  3500. class Handlers;
  3501. template <class T> class Handler;
  3502. template <class T> struct CanonicalType;
  3503. } /* namespace upb */
  3504. #endif
  3505. UPB_DECLARE_TYPE(upb::BufferHandle, upb_bufhandle)
  3506. UPB_DECLARE_TYPE(upb::BytesHandler, upb_byteshandler)
  3507. UPB_DECLARE_TYPE(upb::HandlerAttributes, upb_handlerattr)
  3508. UPB_DECLARE_DERIVED_TYPE(upb::Handlers, upb::RefCounted,
  3509. upb_handlers, upb_refcounted)
  3510. /* The maximum depth that the handler graph can have. This is a resource limit
  3511. * for the C stack since we sometimes need to recursively traverse the graph.
  3512. * Cycles are ok; the traversal will stop when it detects a cycle, but we must
  3513. * hit the cycle before the maximum depth is reached.
  3514. *
  3515. * If having a single static limit is too inflexible, we can add another variant
  3516. * of Handlers::Freeze that allows specifying this as a parameter. */
  3517. #define UPB_MAX_HANDLER_DEPTH 64
  3518. /* All the different types of handlers that can be registered.
  3519. * Only needed for the advanced functions in upb::Handlers. */
  3520. typedef enum {
  3521. UPB_HANDLER_INT32,
  3522. UPB_HANDLER_INT64,
  3523. UPB_HANDLER_UINT32,
  3524. UPB_HANDLER_UINT64,
  3525. UPB_HANDLER_FLOAT,
  3526. UPB_HANDLER_DOUBLE,
  3527. UPB_HANDLER_BOOL,
  3528. UPB_HANDLER_STARTSTR,
  3529. UPB_HANDLER_STRING,
  3530. UPB_HANDLER_ENDSTR,
  3531. UPB_HANDLER_STARTSUBMSG,
  3532. UPB_HANDLER_ENDSUBMSG,
  3533. UPB_HANDLER_STARTSEQ,
  3534. UPB_HANDLER_ENDSEQ
  3535. } upb_handlertype_t;
  3536. #define UPB_HANDLER_MAX (UPB_HANDLER_ENDSEQ+1)
  3537. #define UPB_BREAK NULL
  3538. /* A convenient definition for when no closure is needed. */
  3539. extern char _upb_noclosure;
  3540. #define UPB_NO_CLOSURE &_upb_noclosure
  3541. /* A selector refers to a specific field handler in the Handlers object
  3542. * (for example: the STARTSUBMSG handler for field "field15"). */
  3543. typedef int32_t upb_selector_t;
  3544. UPB_BEGIN_EXTERN_C
  3545. /* Forward-declares for C inline accessors. We need to declare these here
  3546. * so we can "friend" them in the class declarations in C++. */
  3547. UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
  3548. upb_selector_t s);
  3549. UPB_INLINE const void *upb_handlerattr_handlerdata(const upb_handlerattr *attr);
  3550. UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
  3551. upb_selector_t s);
  3552. UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h);
  3553. UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
  3554. const void *type);
  3555. UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
  3556. size_t ofs);
  3557. UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h);
  3558. UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h);
  3559. UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h);
  3560. UPB_END_EXTERN_C
  3561. /* Static selectors for upb::Handlers. */
  3562. #define UPB_STARTMSG_SELECTOR 0
  3563. #define UPB_ENDMSG_SELECTOR 1
  3564. #define UPB_UNKNOWN_SELECTOR 2
  3565. #define UPB_STATIC_SELECTOR_COUNT 3
  3566. /* Static selectors for upb::BytesHandler. */
  3567. #define UPB_STARTSTR_SELECTOR 0
  3568. #define UPB_STRING_SELECTOR 1
  3569. #define UPB_ENDSTR_SELECTOR 2
  3570. typedef void upb_handlerfree(void *d);
  3571. #ifdef __cplusplus
  3572. /* A set of attributes that accompanies a handler's function pointer. */
  3573. class upb::HandlerAttributes {
  3574. public:
  3575. HandlerAttributes();
  3576. ~HandlerAttributes();
  3577. /* Sets the handler data that will be passed as the second parameter of the
  3578. * handler. To free this pointer when the handlers are freed, call
  3579. * Handlers::AddCleanup(). */
  3580. bool SetHandlerData(const void *handler_data);
  3581. const void* handler_data() const;
  3582. /* Use this to specify the type of the closure. This will be checked against
  3583. * all other closure types for handler that use the same closure.
  3584. * Registration will fail if this does not match all other non-NULL closure
  3585. * types. */
  3586. bool SetClosureType(const void *closure_type);
  3587. const void* closure_type() const;
  3588. /* Use this to specify the type of the returned closure. Only used for
  3589. * Start*{String,SubMessage,Sequence} handlers. This must match the closure
  3590. * type of any handlers that use it (for example, the StringBuf handler must
  3591. * match the closure returned from StartString). */
  3592. bool SetReturnClosureType(const void *return_closure_type);
  3593. const void* return_closure_type() const;
  3594. /* Set to indicate that the handler always returns "ok" (either "true" or a
  3595. * non-NULL closure). This is a hint that can allow code generators to
  3596. * generate more efficient code. */
  3597. bool SetAlwaysOk(bool always_ok);
  3598. bool always_ok() const;
  3599. private:
  3600. friend UPB_INLINE const void * ::upb_handlerattr_handlerdata(
  3601. const upb_handlerattr *attr);
  3602. #else
  3603. struct upb_handlerattr {
  3604. #endif
  3605. const void *handler_data_;
  3606. const void *closure_type_;
  3607. const void *return_closure_type_;
  3608. bool alwaysok_;
  3609. };
  3610. #define UPB_HANDLERATTR_INITIALIZER {NULL, NULL, NULL, false}
  3611. typedef struct {
  3612. upb_func *func;
  3613. /* It is wasteful to include the entire attributes here:
  3614. *
  3615. * * Some of the information is redundant (like storing the closure type
  3616. * separately for each handler that must match).
  3617. * * Some of the info is only needed prior to freeze() (like closure types).
  3618. * * alignment padding wastes a lot of space for alwaysok_.
  3619. *
  3620. * If/when the size and locality of handlers is an issue, we can optimize this
  3621. * not to store the entire attr like this. We do not expose the table's
  3622. * layout to allow this optimization in the future. */
  3623. upb_handlerattr attr;
  3624. } upb_handlers_tabent;
  3625. #ifdef __cplusplus
  3626. /* Extra information about a buffer that is passed to a StringBuf handler.
  3627. * TODO(haberman): allow the handle to be pinned so that it will outlive
  3628. * the handler invocation. */
  3629. class upb::BufferHandle {
  3630. public:
  3631. BufferHandle();
  3632. ~BufferHandle();
  3633. /* The beginning of the buffer. This may be different than the pointer
  3634. * passed to a StringBuf handler because the handler may receive data
  3635. * that is from the middle or end of a larger buffer. */
  3636. const char* buffer() const;
  3637. /* The offset within the attached object where this buffer begins. Only
  3638. * meaningful if there is an attached object. */
  3639. size_t object_offset() const;
  3640. /* Note that object_offset is the offset of "buf" within the attached
  3641. * object. */
  3642. void SetBuffer(const char* buf, size_t object_offset);
  3643. /* The BufferHandle can have an "attached object", which can be used to
  3644. * tunnel through a pointer to the buffer's underlying representation. */
  3645. template <class T>
  3646. void SetAttachedObject(const T* obj);
  3647. /* Returns NULL if the attached object is not of this type. */
  3648. template <class T>
  3649. const T* GetAttachedObject() const;
  3650. private:
  3651. friend UPB_INLINE void ::upb_bufhandle_init(upb_bufhandle *h);
  3652. friend UPB_INLINE void ::upb_bufhandle_setobj(upb_bufhandle *h,
  3653. const void *obj,
  3654. const void *type);
  3655. friend UPB_INLINE void ::upb_bufhandle_setbuf(upb_bufhandle *h,
  3656. const char *buf, size_t ofs);
  3657. friend UPB_INLINE const void* ::upb_bufhandle_obj(const upb_bufhandle *h);
  3658. friend UPB_INLINE const void* ::upb_bufhandle_objtype(
  3659. const upb_bufhandle *h);
  3660. friend UPB_INLINE const char* ::upb_bufhandle_buf(const upb_bufhandle *h);
  3661. #else
  3662. struct upb_bufhandle {
  3663. #endif
  3664. const char *buf_;
  3665. const void *obj_;
  3666. const void *objtype_;
  3667. size_t objofs_;
  3668. };
  3669. #ifdef __cplusplus
  3670. /* A upb::Handlers object represents the set of handlers associated with a
  3671. * message in the graph of messages. You can think of it as a big virtual
  3672. * table with functions corresponding to all the events that can fire while
  3673. * parsing or visiting a message of a specific type.
  3674. *
  3675. * Any handlers that are not set behave as if they had successfully consumed
  3676. * the value. Any unset Start* handlers will propagate their closure to the
  3677. * inner frame.
  3678. *
  3679. * The easiest way to create the *Handler objects needed by the Set* methods is
  3680. * with the UpbBind() and UpbMakeHandler() macros; see below. */
  3681. class upb::Handlers {
  3682. public:
  3683. typedef upb_selector_t Selector;
  3684. typedef upb_handlertype_t Type;
  3685. typedef Handler<void *(*)(void *, const void *)> StartFieldHandler;
  3686. typedef Handler<bool (*)(void *, const void *)> EndFieldHandler;
  3687. typedef Handler<bool (*)(void *, const void *)> StartMessageHandler;
  3688. typedef Handler<bool (*)(void *, const void *, Status*)> EndMessageHandler;
  3689. typedef Handler<void *(*)(void *, const void *, size_t)> StartStringHandler;
  3690. typedef Handler<size_t (*)(void *, const void *, const char *, size_t,
  3691. const BufferHandle *)> StringHandler;
  3692. template <class T> struct ValueHandler {
  3693. typedef Handler<bool(*)(void *, const void *, T)> H;
  3694. };
  3695. typedef ValueHandler<int32_t>::H Int32Handler;
  3696. typedef ValueHandler<int64_t>::H Int64Handler;
  3697. typedef ValueHandler<uint32_t>::H UInt32Handler;
  3698. typedef ValueHandler<uint64_t>::H UInt64Handler;
  3699. typedef ValueHandler<float>::H FloatHandler;
  3700. typedef ValueHandler<double>::H DoubleHandler;
  3701. typedef ValueHandler<bool>::H BoolHandler;
  3702. /* Any function pointer can be converted to this and converted back to its
  3703. * correct type. */
  3704. typedef void GenericFunction();
  3705. typedef void HandlersCallback(const void *closure, upb_handlers *h);
  3706. /* Returns a new handlers object for the given frozen msgdef.
  3707. * Returns NULL if memory allocation failed. */
  3708. static reffed_ptr<Handlers> New(const MessageDef *m);
  3709. /* Convenience function for registering a graph of handlers that mirrors the
  3710. * graph of msgdefs for some message. For "m" and all its children a new set
  3711. * of handlers will be created and the given callback will be invoked,
  3712. * allowing the client to register handlers for this message. Note that any
  3713. * subhandlers set by the callback will be overwritten. */
  3714. static reffed_ptr<const Handlers> NewFrozen(const MessageDef *m,
  3715. HandlersCallback *callback,
  3716. const void *closure);
  3717. /* Functionality from upb::RefCounted. */
  3718. UPB_REFCOUNTED_CPPMETHODS
  3719. /* All handler registration functions return bool to indicate success or
  3720. * failure; details about failures are stored in this status object. If a
  3721. * failure does occur, it must be cleared before the Handlers are frozen,
  3722. * otherwise the freeze() operation will fail. The functions may *only* be
  3723. * used while the Handlers are mutable. */
  3724. const Status* status();
  3725. void ClearError();
  3726. /* Call to freeze these Handlers. Requires that any SubHandlers are already
  3727. * frozen. For cycles, you must use the static version below and freeze the
  3728. * whole graph at once. */
  3729. bool Freeze(Status* s);
  3730. /* Freezes the given set of handlers. You may not freeze a handler without
  3731. * also freezing any handlers they point to. */
  3732. static bool Freeze(Handlers*const* handlers, int n, Status* s);
  3733. static bool Freeze(const std::vector<Handlers*>& handlers, Status* s);
  3734. /* Returns the msgdef associated with this handlers object. */
  3735. const MessageDef* message_def() const;
  3736. /* Adds the given pointer and function to the list of cleanup functions that
  3737. * will be run when these handlers are freed. If this pointer has previously
  3738. * been registered, the function returns false and does nothing. */
  3739. bool AddCleanup(void *ptr, upb_handlerfree *cleanup);
  3740. /* Sets the startmsg handler for the message, which is defined as follows:
  3741. *
  3742. * bool startmsg(MyType* closure) {
  3743. * // Called when the message begins. Returns true if processing should
  3744. * // continue.
  3745. * return true;
  3746. * }
  3747. */
  3748. bool SetStartMessageHandler(const StartMessageHandler& handler);
  3749. /* Sets the endmsg handler for the message, which is defined as follows:
  3750. *
  3751. * bool endmsg(MyType* closure, upb_status *status) {
  3752. * // Called when processing of this message ends, whether in success or
  3753. * // failure. "status" indicates the final status of processing, and
  3754. * // can also be modified in-place to update the final status.
  3755. * }
  3756. */
  3757. bool SetEndMessageHandler(const EndMessageHandler& handler);
  3758. /* Sets the value handler for the given field, which is defined as follows
  3759. * (this is for an int32 field; other field types will pass their native
  3760. * C/C++ type for "val"):
  3761. *
  3762. * bool OnValue(MyClosure* c, const MyHandlerData* d, int32_t val) {
  3763. * // Called when the field's value is encountered. "d" contains
  3764. * // whatever data was bound to this field when it was registered.
  3765. * // Returns true if processing should continue.
  3766. * return true;
  3767. * }
  3768. *
  3769. * handers->SetInt32Handler(f, UpbBind(OnValue, new MyHandlerData(...)));
  3770. *
  3771. * The value type must exactly match f->type().
  3772. * For example, a handler that takes an int32_t parameter may only be used for
  3773. * fields of type UPB_TYPE_INT32 and UPB_TYPE_ENUM.
  3774. *
  3775. * Returns false if the handler failed to register; in this case the cleanup
  3776. * handler (if any) will be called immediately.
  3777. */
  3778. bool SetInt32Handler (const FieldDef* f, const Int32Handler& h);
  3779. bool SetInt64Handler (const FieldDef* f, const Int64Handler& h);
  3780. bool SetUInt32Handler(const FieldDef* f, const UInt32Handler& h);
  3781. bool SetUInt64Handler(const FieldDef* f, const UInt64Handler& h);
  3782. bool SetFloatHandler (const FieldDef* f, const FloatHandler& h);
  3783. bool SetDoubleHandler(const FieldDef* f, const DoubleHandler& h);
  3784. bool SetBoolHandler (const FieldDef* f, const BoolHandler& h);
  3785. /* Like the previous, but templated on the type on the value (ie. int32).
  3786. * This is mostly useful to call from other templates. To call this you must
  3787. * specify the template parameter explicitly, ie:
  3788. * h->SetValueHandler<T>(f, UpbBind(MyHandler<T>, MyData)); */
  3789. template <class T>
  3790. bool SetValueHandler(
  3791. const FieldDef *f,
  3792. const typename ValueHandler<typename CanonicalType<T>::Type>::H& handler);
  3793. /* Sets handlers for a string field, which are defined as follows:
  3794. *
  3795. * MySubClosure* startstr(MyClosure* c, const MyHandlerData* d,
  3796. * size_t size_hint) {
  3797. * // Called when a string value begins. The return value indicates the
  3798. * // closure for the string. "size_hint" indicates the size of the
  3799. * // string if it is known, however if the string is length-delimited
  3800. * // and the end-of-string is not available size_hint will be zero.
  3801. * // This case is indistinguishable from the case where the size is
  3802. * // known to be zero.
  3803. * //
  3804. * // TODO(haberman): is it important to distinguish these cases?
  3805. * // If we had ssize_t as a type we could make -1 "unknown", but
  3806. * // ssize_t is POSIX (not ANSI) and therefore less portable.
  3807. * // In practice I suspect it won't be important to distinguish.
  3808. * return closure;
  3809. * }
  3810. *
  3811. * size_t str(MyClosure* closure, const MyHandlerData* d,
  3812. * const char *str, size_t len) {
  3813. * // Called for each buffer of string data; the multiple physical buffers
  3814. * // are all part of the same logical string. The return value indicates
  3815. * // how many bytes were consumed. If this number is less than "len",
  3816. * // this will also indicate that processing should be halted for now,
  3817. * // like returning false or UPB_BREAK from any other callback. If
  3818. * // number is greater than "len", the excess bytes will be skipped over
  3819. * // and not passed to the callback.
  3820. * return len;
  3821. * }
  3822. *
  3823. * bool endstr(MyClosure* c, const MyHandlerData* d) {
  3824. * // Called when a string value ends. Return value indicates whether
  3825. * // processing should continue.
  3826. * return true;
  3827. * }
  3828. */
  3829. bool SetStartStringHandler(const FieldDef* f, const StartStringHandler& h);
  3830. bool SetStringHandler(const FieldDef* f, const StringHandler& h);
  3831. bool SetEndStringHandler(const FieldDef* f, const EndFieldHandler& h);
  3832. /* Sets the startseq handler, which is defined as follows:
  3833. *
  3834. * MySubClosure *startseq(MyClosure* c, const MyHandlerData* d) {
  3835. * // Called when a sequence (repeated field) begins. The returned
  3836. * // pointer indicates the closure for the sequence (or UPB_BREAK
  3837. * // to interrupt processing).
  3838. * return closure;
  3839. * }
  3840. *
  3841. * h->SetStartSequenceHandler(f, UpbBind(startseq, new MyHandlerData(...)));
  3842. *
  3843. * Returns "false" if "f" does not belong to this message or is not a
  3844. * repeated field.
  3845. */
  3846. bool SetStartSequenceHandler(const FieldDef* f, const StartFieldHandler& h);
  3847. /* Sets the startsubmsg handler for the given field, which is defined as
  3848. * follows:
  3849. *
  3850. * MySubClosure* startsubmsg(MyClosure* c, const MyHandlerData* d) {
  3851. * // Called when a submessage begins. The returned pointer indicates the
  3852. * // closure for the sequence (or UPB_BREAK to interrupt processing).
  3853. * return closure;
  3854. * }
  3855. *
  3856. * h->SetStartSubMessageHandler(f, UpbBind(startsubmsg,
  3857. * new MyHandlerData(...)));
  3858. *
  3859. * Returns "false" if "f" does not belong to this message or is not a
  3860. * submessage/group field.
  3861. */
  3862. bool SetStartSubMessageHandler(const FieldDef* f, const StartFieldHandler& h);
  3863. /* Sets the endsubmsg handler for the given field, which is defined as
  3864. * follows:
  3865. *
  3866. * bool endsubmsg(MyClosure* c, const MyHandlerData* d) {
  3867. * // Called when a submessage ends. Returns true to continue processing.
  3868. * return true;
  3869. * }
  3870. *
  3871. * Returns "false" if "f" does not belong to this message or is not a
  3872. * submessage/group field.
  3873. */
  3874. bool SetEndSubMessageHandler(const FieldDef *f, const EndFieldHandler &h);
  3875. /* Starts the endsubseq handler for the given field, which is defined as
  3876. * follows:
  3877. *
  3878. * bool endseq(MyClosure* c, const MyHandlerData* d) {
  3879. * // Called when a sequence ends. Returns true continue processing.
  3880. * return true;
  3881. * }
  3882. *
  3883. * Returns "false" if "f" does not belong to this message or is not a
  3884. * repeated field.
  3885. */
  3886. bool SetEndSequenceHandler(const FieldDef* f, const EndFieldHandler& h);
  3887. /* Sets or gets the object that specifies handlers for the given field, which
  3888. * must be a submessage or group. Returns NULL if no handlers are set. */
  3889. bool SetSubHandlers(const FieldDef* f, const Handlers* sub);
  3890. const Handlers* GetSubHandlers(const FieldDef* f) const;
  3891. /* Equivalent to GetSubHandlers, but takes the STARTSUBMSG selector for the
  3892. * field. */
  3893. const Handlers* GetSubHandlers(Selector startsubmsg) const;
  3894. /* A selector refers to a specific field handler in the Handlers object
  3895. * (for example: the STARTSUBMSG handler for field "field15").
  3896. * On success, returns true and stores the selector in "s".
  3897. * If the FieldDef or Type are invalid, returns false.
  3898. * The returned selector is ONLY valid for Handlers whose MessageDef
  3899. * contains this FieldDef. */
  3900. static bool GetSelector(const FieldDef* f, Type type, Selector* s);
  3901. /* Given a START selector of any kind, returns the corresponding END selector. */
  3902. static Selector GetEndSelector(Selector start_selector);
  3903. /* Returns the function pointer for this handler. It is the client's
  3904. * responsibility to cast to the correct function type before calling it. */
  3905. GenericFunction* GetHandler(Selector selector);
  3906. /* Sets the given attributes to the attributes for this selector. */
  3907. bool GetAttributes(Selector selector, HandlerAttributes* attr);
  3908. /* Returns the handler data that was registered with this handler. */
  3909. const void* GetHandlerData(Selector selector);
  3910. /* Could add any of the following functions as-needed, with some minor
  3911. * implementation changes:
  3912. *
  3913. * const FieldDef* GetFieldDef(Selector selector);
  3914. * static bool IsSequence(Selector selector); */
  3915. private:
  3916. UPB_DISALLOW_POD_OPS(Handlers, upb::Handlers)
  3917. friend UPB_INLINE GenericFunction *::upb_handlers_gethandler(
  3918. const upb_handlers *h, upb_selector_t s);
  3919. friend UPB_INLINE const void *::upb_handlers_gethandlerdata(
  3920. const upb_handlers *h, upb_selector_t s);
  3921. #else
  3922. struct upb_handlers {
  3923. #endif
  3924. upb_refcounted base;
  3925. const upb_msgdef *msg;
  3926. const upb_handlers **sub;
  3927. const void *top_closure_type;
  3928. upb_inttable cleanup_;
  3929. upb_status status_; /* Used only when mutable. */
  3930. upb_handlers_tabent table[1]; /* Dynamically-sized field handler array. */
  3931. };
  3932. #ifdef __cplusplus
  3933. namespace upb {
  3934. /* Convenience macros for creating a Handler object that is wrapped with a
  3935. * type-safe wrapper function that converts the "void*" parameters/returns
  3936. * of the underlying C API into nice C++ function.
  3937. *
  3938. * Sample usage:
  3939. * void OnValue1(MyClosure* c, const MyHandlerData* d, int32_t val) {
  3940. * // do stuff ...
  3941. * }
  3942. *
  3943. * // Handler that doesn't need any data bound to it.
  3944. * void OnValue2(MyClosure* c, int32_t val) {
  3945. * // do stuff ...
  3946. * }
  3947. *
  3948. * // Handler that returns bool so it can return failure if necessary.
  3949. * bool OnValue3(MyClosure* c, int32_t val) {
  3950. * // do stuff ...
  3951. * return ok;
  3952. * }
  3953. *
  3954. * // Member function handler.
  3955. * class MyClosure {
  3956. * public:
  3957. * void OnValue(int32_t val) {
  3958. * // do stuff ...
  3959. * }
  3960. * };
  3961. *
  3962. * // Takes ownership of the MyHandlerData.
  3963. * handlers->SetInt32Handler(f1, UpbBind(OnValue1, new MyHandlerData(...)));
  3964. * handlers->SetInt32Handler(f2, UpbMakeHandler(OnValue2));
  3965. * handlers->SetInt32Handler(f1, UpbMakeHandler(OnValue3));
  3966. * handlers->SetInt32Handler(f2, UpbMakeHandler(&MyClosure::OnValue));
  3967. */
  3968. #ifdef UPB_CXX11
  3969. /* In C++11, the "template" disambiguator can appear even outside templates,
  3970. * so all calls can safely use this pair of macros. */
  3971. #define UpbMakeHandler(f) upb::MatchFunc(f).template GetFunc<f>()
  3972. /* We have to be careful to only evaluate "d" once. */
  3973. #define UpbBind(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
  3974. #else
  3975. /* Prior to C++11, the "template" disambiguator may only appear inside a
  3976. * template, so the regular macro must not use "template" */
  3977. #define UpbMakeHandler(f) upb::MatchFunc(f).GetFunc<f>()
  3978. #define UpbBind(f, d) upb::MatchFunc(f).GetFunc<f>((d))
  3979. #endif /* UPB_CXX11 */
  3980. /* This macro must be used in C++98 for calls from inside a template. But we
  3981. * define this variant in all cases; code that wants to be compatible with both
  3982. * C++98 and C++11 should always use this macro when calling from a template. */
  3983. #define UpbMakeHandlerT(f) upb::MatchFunc(f).template GetFunc<f>()
  3984. /* We have to be careful to only evaluate "d" once. */
  3985. #define UpbBindT(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
  3986. /* Handler: a struct that contains the (handler, data, deleter) tuple that is
  3987. * used to register all handlers. Users can Make() these directly but it's
  3988. * more convenient to use the UpbMakeHandler/UpbBind macros above. */
  3989. template <class T> class Handler {
  3990. public:
  3991. /* The underlying, handler function signature that upb uses internally. */
  3992. typedef T FuncPtr;
  3993. /* Intentionally implicit. */
  3994. template <class F> Handler(F func);
  3995. ~Handler();
  3996. private:
  3997. void AddCleanup(Handlers* h) const {
  3998. if (cleanup_func_) {
  3999. bool ok = h->AddCleanup(cleanup_data_, cleanup_func_);
  4000. UPB_ASSERT(ok);
  4001. }
  4002. }
  4003. UPB_DISALLOW_COPY_AND_ASSIGN(Handler)
  4004. friend class Handlers;
  4005. FuncPtr handler_;
  4006. mutable HandlerAttributes attr_;
  4007. mutable bool registered_;
  4008. void *cleanup_data_;
  4009. upb_handlerfree *cleanup_func_;
  4010. };
  4011. } /* namespace upb */
  4012. #endif /* __cplusplus */
  4013. UPB_BEGIN_EXTERN_C
  4014. /* Native C API. */
  4015. /* Handler function typedefs. */
  4016. typedef bool upb_unknown_handlerfunc(void *c, const void *hd, const char *buf,
  4017. size_t n);
  4018. typedef bool upb_startmsg_handlerfunc(void *c, const void*);
  4019. typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status);
  4020. typedef void* upb_startfield_handlerfunc(void *c, const void *hd);
  4021. typedef bool upb_endfield_handlerfunc(void *c, const void *hd);
  4022. typedef bool upb_int32_handlerfunc(void *c, const void *hd, int32_t val);
  4023. typedef bool upb_int64_handlerfunc(void *c, const void *hd, int64_t val);
  4024. typedef bool upb_uint32_handlerfunc(void *c, const void *hd, uint32_t val);
  4025. typedef bool upb_uint64_handlerfunc(void *c, const void *hd, uint64_t val);
  4026. typedef bool upb_float_handlerfunc(void *c, const void *hd, float val);
  4027. typedef bool upb_double_handlerfunc(void *c, const void *hd, double val);
  4028. typedef bool upb_bool_handlerfunc(void *c, const void *hd, bool val);
  4029. typedef void *upb_startstr_handlerfunc(void *c, const void *hd,
  4030. size_t size_hint);
  4031. typedef size_t upb_string_handlerfunc(void *c, const void *hd, const char *buf,
  4032. size_t n, const upb_bufhandle* handle);
  4033. /* upb_bufhandle */
  4034. size_t upb_bufhandle_objofs(const upb_bufhandle *h);
  4035. /* upb_handlerattr */
  4036. void upb_handlerattr_init(upb_handlerattr *attr);
  4037. void upb_handlerattr_uninit(upb_handlerattr *attr);
  4038. bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd);
  4039. bool upb_handlerattr_setclosuretype(upb_handlerattr *attr, const void *type);
  4040. const void *upb_handlerattr_closuretype(const upb_handlerattr *attr);
  4041. bool upb_handlerattr_setreturnclosuretype(upb_handlerattr *attr,
  4042. const void *type);
  4043. const void *upb_handlerattr_returnclosuretype(const upb_handlerattr *attr);
  4044. bool upb_handlerattr_setalwaysok(upb_handlerattr *attr, bool alwaysok);
  4045. bool upb_handlerattr_alwaysok(const upb_handlerattr *attr);
  4046. UPB_INLINE const void *upb_handlerattr_handlerdata(
  4047. const upb_handlerattr *attr) {
  4048. return attr->handler_data_;
  4049. }
  4050. /* upb_handlers */
  4051. typedef void upb_handlers_callback(const void *closure, upb_handlers *h);
  4052. upb_handlers *upb_handlers_new(const upb_msgdef *m,
  4053. const void *owner);
  4054. const upb_handlers *upb_handlers_newfrozen(const upb_msgdef *m,
  4055. const void *owner,
  4056. upb_handlers_callback *callback,
  4057. const void *closure);
  4058. /* Include refcounted methods like upb_handlers_ref(). */
  4059. UPB_REFCOUNTED_CMETHODS(upb_handlers, upb_handlers_upcast)
  4060. const upb_status *upb_handlers_status(upb_handlers *h);
  4061. void upb_handlers_clearerr(upb_handlers *h);
  4062. const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h);
  4063. bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree);
  4064. bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func,
  4065. upb_handlerattr *attr);
  4066. bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
  4067. upb_handlerattr *attr);
  4068. bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
  4069. upb_handlerattr *attr);
  4070. bool upb_handlers_setint32(upb_handlers *h, const upb_fielddef *f,
  4071. upb_int32_handlerfunc *func, upb_handlerattr *attr);
  4072. bool upb_handlers_setint64(upb_handlers *h, const upb_fielddef *f,
  4073. upb_int64_handlerfunc *func, upb_handlerattr *attr);
  4074. bool upb_handlers_setuint32(upb_handlers *h, const upb_fielddef *f,
  4075. upb_uint32_handlerfunc *func,
  4076. upb_handlerattr *attr);
  4077. bool upb_handlers_setuint64(upb_handlers *h, const upb_fielddef *f,
  4078. upb_uint64_handlerfunc *func,
  4079. upb_handlerattr *attr);
  4080. bool upb_handlers_setfloat(upb_handlers *h, const upb_fielddef *f,
  4081. upb_float_handlerfunc *func, upb_handlerattr *attr);
  4082. bool upb_handlers_setdouble(upb_handlers *h, const upb_fielddef *f,
  4083. upb_double_handlerfunc *func,
  4084. upb_handlerattr *attr);
  4085. bool upb_handlers_setbool(upb_handlers *h, const upb_fielddef *f,
  4086. upb_bool_handlerfunc *func,
  4087. upb_handlerattr *attr);
  4088. bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f,
  4089. upb_startstr_handlerfunc *func,
  4090. upb_handlerattr *attr);
  4091. bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f,
  4092. upb_string_handlerfunc *func,
  4093. upb_handlerattr *attr);
  4094. bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f,
  4095. upb_endfield_handlerfunc *func,
  4096. upb_handlerattr *attr);
  4097. bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f,
  4098. upb_startfield_handlerfunc *func,
  4099. upb_handlerattr *attr);
  4100. bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f,
  4101. upb_startfield_handlerfunc *func,
  4102. upb_handlerattr *attr);
  4103. bool upb_handlers_setendsubmsg(upb_handlers *h, const upb_fielddef *f,
  4104. upb_endfield_handlerfunc *func,
  4105. upb_handlerattr *attr);
  4106. bool upb_handlers_setendseq(upb_handlers *h, const upb_fielddef *f,
  4107. upb_endfield_handlerfunc *func,
  4108. upb_handlerattr *attr);
  4109. bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
  4110. const upb_handlers *sub);
  4111. const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
  4112. const upb_fielddef *f);
  4113. const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
  4114. upb_selector_t sel);
  4115. UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
  4116. upb_selector_t s) {
  4117. return (upb_func *)h->table[s].func;
  4118. }
  4119. bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t s,
  4120. upb_handlerattr *attr);
  4121. UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
  4122. upb_selector_t s) {
  4123. return upb_handlerattr_handlerdata(&h->table[s].attr);
  4124. }
  4125. #ifdef __cplusplus
  4126. /* Handler types for single fields.
  4127. * Right now we only have one for TYPE_BYTES but ones for other types
  4128. * should follow.
  4129. *
  4130. * These follow the same handlers protocol for fields of a message. */
  4131. class upb::BytesHandler {
  4132. public:
  4133. BytesHandler();
  4134. ~BytesHandler();
  4135. #else
  4136. struct upb_byteshandler {
  4137. #endif
  4138. upb_handlers_tabent table[3];
  4139. };
  4140. void upb_byteshandler_init(upb_byteshandler *h);
  4141. /* Caller must ensure that "d" outlives the handlers.
  4142. * TODO(haberman): should this have a "freeze" operation? It's not necessary
  4143. * for memory management, but could be useful to force immutability and provide
  4144. * a convenient moment to verify that all registration succeeded. */
  4145. bool upb_byteshandler_setstartstr(upb_byteshandler *h,
  4146. upb_startstr_handlerfunc *func, void *d);
  4147. bool upb_byteshandler_setstring(upb_byteshandler *h,
  4148. upb_string_handlerfunc *func, void *d);
  4149. bool upb_byteshandler_setendstr(upb_byteshandler *h,
  4150. upb_endfield_handlerfunc *func, void *d);
  4151. /* "Static" methods */
  4152. bool upb_handlers_freeze(upb_handlers *const *handlers, int n, upb_status *s);
  4153. upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f);
  4154. bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
  4155. upb_selector_t *s);
  4156. UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) {
  4157. return start + 1;
  4158. }
  4159. /* Internal-only. */
  4160. uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f);
  4161. uint32_t upb_handlers_selectorcount(const upb_fielddef *f);
  4162. /** Message handlers ******************************************************************/
  4163. /* These are the handlers used internally by upb_msgfactory_getmergehandlers().
  4164. * They write scalar data to a known offset from the message pointer.
  4165. *
  4166. * These would be trivial for anyone to implement themselves, but it's better
  4167. * to use these because some JITs will recognize and specialize these instead
  4168. * of actually calling the function. */
  4169. /* Sets a handler for the given primitive field that will write the data at the
  4170. * given offset. If hasbit > 0, also sets a hasbit at the given bit offset
  4171. * (addressing each byte low to high). */
  4172. bool upb_msg_setscalarhandler(upb_handlers *h,
  4173. const upb_fielddef *f,
  4174. size_t offset,
  4175. int32_t hasbit);
  4176. /* If the given handler is a msghandlers_primitive field, returns true and sets
  4177. * *type, *offset and *hasbit. Otherwise returns false. */
  4178. bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
  4179. upb_selector_t s,
  4180. upb_fieldtype_t *type,
  4181. size_t *offset,
  4182. int32_t *hasbit);
  4183. UPB_END_EXTERN_C
  4184. /*
  4185. ** Inline definitions for handlers.h, which are particularly long and a bit
  4186. ** tricky.
  4187. */
  4188. #ifndef UPB_HANDLERS_INL_H_
  4189. #define UPB_HANDLERS_INL_H_
  4190. #include <limits.h>
  4191. /* C inline methods. */
  4192. /* upb_bufhandle */
  4193. UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h) {
  4194. h->obj_ = NULL;
  4195. h->objtype_ = NULL;
  4196. h->buf_ = NULL;
  4197. h->objofs_ = 0;
  4198. }
  4199. UPB_INLINE void upb_bufhandle_uninit(upb_bufhandle *h) {
  4200. UPB_UNUSED(h);
  4201. }
  4202. UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
  4203. const void *type) {
  4204. h->obj_ = obj;
  4205. h->objtype_ = type;
  4206. }
  4207. UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
  4208. size_t ofs) {
  4209. h->buf_ = buf;
  4210. h->objofs_ = ofs;
  4211. }
  4212. UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h) {
  4213. return h->obj_;
  4214. }
  4215. UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h) {
  4216. return h->objtype_;
  4217. }
  4218. UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) {
  4219. return h->buf_;
  4220. }
  4221. #ifdef __cplusplus
  4222. /* Type detection and typedefs for integer types.
  4223. * For platforms where there are multiple 32-bit or 64-bit types, we need to be
  4224. * able to enumerate them so we can properly create overloads for all variants.
  4225. *
  4226. * If any platform existed where there were three integer types with the same
  4227. * size, this would have to become more complicated. For example, short, int,
  4228. * and long could all be 32-bits. Even more diabolically, short, int, long,
  4229. * and long long could all be 64 bits and still be standard-compliant.
  4230. * However, few platforms are this strange, and it's unlikely that upb will be
  4231. * used on the strangest ones. */
  4232. /* Can't count on stdint.h limits like INT32_MAX, because in C++ these are
  4233. * only defined when __STDC_LIMIT_MACROS are defined before the *first* include
  4234. * of stdint.h. We can't guarantee that someone else didn't include these first
  4235. * without defining __STDC_LIMIT_MACROS. */
  4236. #define UPB_INT32_MAX 0x7fffffffLL
  4237. #define UPB_INT32_MIN (-UPB_INT32_MAX - 1)
  4238. #define UPB_INT64_MAX 0x7fffffffffffffffLL
  4239. #define UPB_INT64_MIN (-UPB_INT64_MAX - 1)
  4240. #if INT_MAX == UPB_INT32_MAX && INT_MIN == UPB_INT32_MIN
  4241. #define UPB_INT_IS_32BITS 1
  4242. #endif
  4243. #if LONG_MAX == UPB_INT32_MAX && LONG_MIN == UPB_INT32_MIN
  4244. #define UPB_LONG_IS_32BITS 1
  4245. #endif
  4246. #if LONG_MAX == UPB_INT64_MAX && LONG_MIN == UPB_INT64_MIN
  4247. #define UPB_LONG_IS_64BITS 1
  4248. #endif
  4249. #if LLONG_MAX == UPB_INT64_MAX && LLONG_MIN == UPB_INT64_MIN
  4250. #define UPB_LLONG_IS_64BITS 1
  4251. #endif
  4252. /* We use macros instead of typedefs so we can undefine them later and avoid
  4253. * leaking them outside this header file. */
  4254. #if UPB_INT_IS_32BITS
  4255. #define UPB_INT32_T int
  4256. #define UPB_UINT32_T unsigned int
  4257. #if UPB_LONG_IS_32BITS
  4258. #define UPB_TWO_32BIT_TYPES 1
  4259. #define UPB_INT32ALT_T long
  4260. #define UPB_UINT32ALT_T unsigned long
  4261. #endif /* UPB_LONG_IS_32BITS */
  4262. #elif UPB_LONG_IS_32BITS /* && !UPB_INT_IS_32BITS */
  4263. #define UPB_INT32_T long
  4264. #define UPB_UINT32_T unsigned long
  4265. #endif /* UPB_INT_IS_32BITS */
  4266. #if UPB_LONG_IS_64BITS
  4267. #define UPB_INT64_T long
  4268. #define UPB_UINT64_T unsigned long
  4269. #if UPB_LLONG_IS_64BITS
  4270. #define UPB_TWO_64BIT_TYPES 1
  4271. #define UPB_INT64ALT_T long long
  4272. #define UPB_UINT64ALT_T unsigned long long
  4273. #endif /* UPB_LLONG_IS_64BITS */
  4274. #elif UPB_LLONG_IS_64BITS /* && !UPB_LONG_IS_64BITS */
  4275. #define UPB_INT64_T long long
  4276. #define UPB_UINT64_T unsigned long long
  4277. #endif /* UPB_LONG_IS_64BITS */
  4278. #undef UPB_INT32_MAX
  4279. #undef UPB_INT32_MIN
  4280. #undef UPB_INT64_MAX
  4281. #undef UPB_INT64_MIN
  4282. #undef UPB_INT_IS_32BITS
  4283. #undef UPB_LONG_IS_32BITS
  4284. #undef UPB_LONG_IS_64BITS
  4285. #undef UPB_LLONG_IS_64BITS
  4286. namespace upb {
  4287. typedef void CleanupFunc(void *ptr);
  4288. /* Template to remove "const" from "const T*" and just return "T*".
  4289. *
  4290. * We define a nonsense default because otherwise it will fail to instantiate as
  4291. * a function parameter type even in cases where we don't expect any caller to
  4292. * actually match the overload. */
  4293. class CouldntRemoveConst {};
  4294. template <class T> struct remove_constptr { typedef CouldntRemoveConst type; };
  4295. template <class T> struct remove_constptr<const T *> { typedef T *type; };
  4296. /* Template that we use below to remove a template specialization from
  4297. * consideration if it matches a specific type. */
  4298. template <class T, class U> struct disable_if_same { typedef void Type; };
  4299. template <class T> struct disable_if_same<T, T> {};
  4300. template <class T> void DeletePointer(void *p) { delete static_cast<T>(p); }
  4301. template <class T1, class T2>
  4302. struct FirstUnlessVoidOrBool {
  4303. typedef T1 value;
  4304. };
  4305. template <class T2>
  4306. struct FirstUnlessVoidOrBool<void, T2> {
  4307. typedef T2 value;
  4308. };
  4309. template <class T2>
  4310. struct FirstUnlessVoidOrBool<bool, T2> {
  4311. typedef T2 value;
  4312. };
  4313. template<class T, class U>
  4314. struct is_same {
  4315. static bool value;
  4316. };
  4317. template<class T>
  4318. struct is_same<T, T> {
  4319. static bool value;
  4320. };
  4321. template<class T, class U>
  4322. bool is_same<T, U>::value = false;
  4323. template<class T>
  4324. bool is_same<T, T>::value = true;
  4325. /* FuncInfo *******************************************************************/
  4326. /* Info about the user's original, pre-wrapped function. */
  4327. template <class C, class R = void>
  4328. struct FuncInfo {
  4329. /* The type of the closure that the function takes (its first param). */
  4330. typedef C Closure;
  4331. /* The return type. */
  4332. typedef R Return;
  4333. };
  4334. /* Func ***********************************************************************/
  4335. /* Func1, Func2, Func3: Template classes representing a function and its
  4336. * signature.
  4337. *
  4338. * Since the function is a template parameter, calling the function can be
  4339. * inlined at compile-time and does not require a function pointer at runtime.
  4340. * These functions are not bound to a handler data so have no data or cleanup
  4341. * handler. */
  4342. struct UnboundFunc {
  4343. CleanupFunc *GetCleanup() { return NULL; }
  4344. void *GetData() { return NULL; }
  4345. };
  4346. template <class R, class P1, R F(P1), class I>
  4347. struct Func1 : public UnboundFunc {
  4348. typedef R Return;
  4349. typedef I FuncInfo;
  4350. static R Call(P1 p1) { return F(p1); }
  4351. };
  4352. template <class R, class P1, class P2, R F(P1, P2), class I>
  4353. struct Func2 : public UnboundFunc {
  4354. typedef R Return;
  4355. typedef I FuncInfo;
  4356. static R Call(P1 p1, P2 p2) { return F(p1, p2); }
  4357. };
  4358. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
  4359. struct Func3 : public UnboundFunc {
  4360. typedef R Return;
  4361. typedef I FuncInfo;
  4362. static R Call(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); }
  4363. };
  4364. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  4365. class I>
  4366. struct Func4 : public UnboundFunc {
  4367. typedef R Return;
  4368. typedef I FuncInfo;
  4369. static R Call(P1 p1, P2 p2, P3 p3, P4 p4) { return F(p1, p2, p3, p4); }
  4370. };
  4371. template <class R, class P1, class P2, class P3, class P4, class P5,
  4372. R F(P1, P2, P3, P4, P5), class I>
  4373. struct Func5 : public UnboundFunc {
  4374. typedef R Return;
  4375. typedef I FuncInfo;
  4376. static R Call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
  4377. return F(p1, p2, p3, p4, p5);
  4378. }
  4379. };
  4380. /* BoundFunc ******************************************************************/
  4381. /* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that
  4382. * shall be bound to the function's second parameter.
  4383. *
  4384. * Note that the second parameter is a const pointer, but our stored bound value
  4385. * is non-const so we can free it when the handlers are destroyed. */
  4386. template <class T>
  4387. struct BoundFunc {
  4388. typedef typename remove_constptr<T>::type MutableP2;
  4389. explicit BoundFunc(MutableP2 data_) : data(data_) {}
  4390. CleanupFunc *GetCleanup() { return &DeletePointer<MutableP2>; }
  4391. MutableP2 GetData() { return data; }
  4392. MutableP2 data;
  4393. };
  4394. template <class R, class P1, class P2, R F(P1, P2), class I>
  4395. struct BoundFunc2 : public BoundFunc<P2> {
  4396. typedef BoundFunc<P2> Base;
  4397. typedef I FuncInfo;
  4398. explicit BoundFunc2(typename Base::MutableP2 arg) : Base(arg) {}
  4399. };
  4400. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
  4401. struct BoundFunc3 : public BoundFunc<P2> {
  4402. typedef BoundFunc<P2> Base;
  4403. typedef I FuncInfo;
  4404. explicit BoundFunc3(typename Base::MutableP2 arg) : Base(arg) {}
  4405. };
  4406. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  4407. class I>
  4408. struct BoundFunc4 : public BoundFunc<P2> {
  4409. typedef BoundFunc<P2> Base;
  4410. typedef I FuncInfo;
  4411. explicit BoundFunc4(typename Base::MutableP2 arg) : Base(arg) {}
  4412. };
  4413. template <class R, class P1, class P2, class P3, class P4, class P5,
  4414. R F(P1, P2, P3, P4, P5), class I>
  4415. struct BoundFunc5 : public BoundFunc<P2> {
  4416. typedef BoundFunc<P2> Base;
  4417. typedef I FuncInfo;
  4418. explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {}
  4419. };
  4420. /* FuncSig ********************************************************************/
  4421. /* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function
  4422. * *signature*, but without a specific function attached.
  4423. *
  4424. * These classes contain member functions that can be invoked with a
  4425. * specific function to return a Func/BoundFunc class. */
  4426. template <class R, class P1>
  4427. struct FuncSig1 {
  4428. template <R F(P1)>
  4429. Func1<R, P1, F, FuncInfo<P1, R> > GetFunc() {
  4430. return Func1<R, P1, F, FuncInfo<P1, R> >();
  4431. }
  4432. };
  4433. template <class R, class P1, class P2>
  4434. struct FuncSig2 {
  4435. template <R F(P1, P2)>
  4436. Func2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc() {
  4437. return Func2<R, P1, P2, F, FuncInfo<P1, R> >();
  4438. }
  4439. template <R F(P1, P2)>
  4440. BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc(
  4441. typename remove_constptr<P2>::type param2) {
  4442. return BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> >(param2);
  4443. }
  4444. };
  4445. template <class R, class P1, class P2, class P3>
  4446. struct FuncSig3 {
  4447. template <R F(P1, P2, P3)>
  4448. Func3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc() {
  4449. return Func3<R, P1, P2, P3, F, FuncInfo<P1, R> >();
  4450. }
  4451. template <R F(P1, P2, P3)>
  4452. BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc(
  4453. typename remove_constptr<P2>::type param2) {
  4454. return BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> >(param2);
  4455. }
  4456. };
  4457. template <class R, class P1, class P2, class P3, class P4>
  4458. struct FuncSig4 {
  4459. template <R F(P1, P2, P3, P4)>
  4460. Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc() {
  4461. return Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >();
  4462. }
  4463. template <R F(P1, P2, P3, P4)>
  4464. BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc(
  4465. typename remove_constptr<P2>::type param2) {
  4466. return BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >(param2);
  4467. }
  4468. };
  4469. template <class R, class P1, class P2, class P3, class P4, class P5>
  4470. struct FuncSig5 {
  4471. template <R F(P1, P2, P3, P4, P5)>
  4472. Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc() {
  4473. return Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >();
  4474. }
  4475. template <R F(P1, P2, P3, P4, P5)>
  4476. BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc(
  4477. typename remove_constptr<P2>::type param2) {
  4478. return BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >(param2);
  4479. }
  4480. };
  4481. /* Overloaded template function that can construct the appropriate FuncSig*
  4482. * class given a function pointer by deducing the template parameters. */
  4483. template <class R, class P1>
  4484. inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) {
  4485. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4486. return FuncSig1<R, P1>();
  4487. }
  4488. template <class R, class P1, class P2>
  4489. inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) {
  4490. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4491. return FuncSig2<R, P1, P2>();
  4492. }
  4493. template <class R, class P1, class P2, class P3>
  4494. inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) {
  4495. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4496. return FuncSig3<R, P1, P2, P3>();
  4497. }
  4498. template <class R, class P1, class P2, class P3, class P4>
  4499. inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) {
  4500. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4501. return FuncSig4<R, P1, P2, P3, P4>();
  4502. }
  4503. template <class R, class P1, class P2, class P3, class P4, class P5>
  4504. inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) {
  4505. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4506. return FuncSig5<R, P1, P2, P3, P4, P5>();
  4507. }
  4508. /* MethodSig ******************************************************************/
  4509. /* CallMethod*: a function template that calls a given method. */
  4510. template <class R, class C, R (C::*F)()>
  4511. R CallMethod0(C *obj) {
  4512. return ((*obj).*F)();
  4513. }
  4514. template <class R, class C, class P1, R (C::*F)(P1)>
  4515. R CallMethod1(C *obj, P1 arg1) {
  4516. return ((*obj).*F)(arg1);
  4517. }
  4518. template <class R, class C, class P1, class P2, R (C::*F)(P1, P2)>
  4519. R CallMethod2(C *obj, P1 arg1, P2 arg2) {
  4520. return ((*obj).*F)(arg1, arg2);
  4521. }
  4522. template <class R, class C, class P1, class P2, class P3, R (C::*F)(P1, P2, P3)>
  4523. R CallMethod3(C *obj, P1 arg1, P2 arg2, P3 arg3) {
  4524. return ((*obj).*F)(arg1, arg2, arg3);
  4525. }
  4526. template <class R, class C, class P1, class P2, class P3, class P4,
  4527. R (C::*F)(P1, P2, P3, P4)>
  4528. R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) {
  4529. return ((*obj).*F)(arg1, arg2, arg3, arg4);
  4530. }
  4531. /* MethodSig: like FuncSig, but for member functions.
  4532. *
  4533. * GetFunc() returns a normal FuncN object, so after calling GetFunc() no
  4534. * more logic is required to special-case methods. */
  4535. template <class R, class C>
  4536. struct MethodSig0 {
  4537. template <R (C::*F)()>
  4538. Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> > GetFunc() {
  4539. return Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> >();
  4540. }
  4541. };
  4542. template <class R, class C, class P1>
  4543. struct MethodSig1 {
  4544. template <R (C::*F)(P1)>
  4545. Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc() {
  4546. return Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >();
  4547. }
  4548. template <R (C::*F)(P1)>
  4549. BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc(
  4550. typename remove_constptr<P1>::type param1) {
  4551. return BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >(
  4552. param1);
  4553. }
  4554. };
  4555. template <class R, class C, class P1, class P2>
  4556. struct MethodSig2 {
  4557. template <R (C::*F)(P1, P2)>
  4558. Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
  4559. GetFunc() {
  4560. return Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
  4561. FuncInfo<C *, R> >();
  4562. }
  4563. template <R (C::*F)(P1, P2)>
  4564. BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
  4565. GetFunc(typename remove_constptr<P1>::type param1) {
  4566. return BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
  4567. FuncInfo<C *, R> >(param1);
  4568. }
  4569. };
  4570. template <class R, class C, class P1, class P2, class P3>
  4571. struct MethodSig3 {
  4572. template <R (C::*F)(P1, P2, P3)>
  4573. Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>, FuncInfo<C *, R> >
  4574. GetFunc() {
  4575. return Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4576. FuncInfo<C *, R> >();
  4577. }
  4578. template <R (C::*F)(P1, P2, P3)>
  4579. BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4580. FuncInfo<C *, R> >
  4581. GetFunc(typename remove_constptr<P1>::type param1) {
  4582. return BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4583. FuncInfo<C *, R> >(param1);
  4584. }
  4585. };
  4586. template <class R, class C, class P1, class P2, class P3, class P4>
  4587. struct MethodSig4 {
  4588. template <R (C::*F)(P1, P2, P3, P4)>
  4589. Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4590. FuncInfo<C *, R> >
  4591. GetFunc() {
  4592. return Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4593. FuncInfo<C *, R> >();
  4594. }
  4595. template <R (C::*F)(P1, P2, P3, P4)>
  4596. BoundFunc5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4597. FuncInfo<C *, R> >
  4598. GetFunc(typename remove_constptr<P1>::type param1) {
  4599. return BoundFunc5<R, C *, P1, P2, P3, P4,
  4600. CallMethod4<R, C, P1, P2, P3, P4, F>, FuncInfo<C *, R> >(
  4601. param1);
  4602. }
  4603. };
  4604. template <class R, class C>
  4605. inline MethodSig0<R, C> MatchFunc(R (C::*f)()) {
  4606. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4607. return MethodSig0<R, C>();
  4608. }
  4609. template <class R, class C, class P1>
  4610. inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) {
  4611. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4612. return MethodSig1<R, C, P1>();
  4613. }
  4614. template <class R, class C, class P1, class P2>
  4615. inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) {
  4616. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4617. return MethodSig2<R, C, P1, P2>();
  4618. }
  4619. template <class R, class C, class P1, class P2, class P3>
  4620. inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) {
  4621. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4622. return MethodSig3<R, C, P1, P2, P3>();
  4623. }
  4624. template <class R, class C, class P1, class P2, class P3, class P4>
  4625. inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) {
  4626. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4627. return MethodSig4<R, C, P1, P2, P3, P4>();
  4628. }
  4629. /* MaybeWrapReturn ************************************************************/
  4630. /* Template class that attempts to wrap the return value of the function so it
  4631. * matches the expected type. There are two main adjustments it may make:
  4632. *
  4633. * 1. If the function returns void, make it return the expected type and with
  4634. * a value that always indicates success.
  4635. * 2. If the function returns bool, make it return the expected type with a
  4636. * value that indicates success or failure.
  4637. *
  4638. * The "expected type" for return is:
  4639. * 1. void* for start handlers. If the closure parameter has a different type
  4640. * we will cast it to void* for the return in the success case.
  4641. * 2. size_t for string buffer handlers.
  4642. * 3. bool for everything else. */
  4643. /* Template parameters are FuncN type and desired return type. */
  4644. template <class F, class R, class Enable = void>
  4645. struct MaybeWrapReturn;
  4646. /* If the return type matches, return the given function unwrapped. */
  4647. template <class F>
  4648. struct MaybeWrapReturn<F, typename F::Return> {
  4649. typedef F Func;
  4650. };
  4651. /* Function wrapper that munges the return value from void to (bool)true. */
  4652. template <class P1, class P2, void F(P1, P2)>
  4653. bool ReturnTrue2(P1 p1, P2 p2) {
  4654. F(p1, p2);
  4655. return true;
  4656. }
  4657. template <class P1, class P2, class P3, void F(P1, P2, P3)>
  4658. bool ReturnTrue3(P1 p1, P2 p2, P3 p3) {
  4659. F(p1, p2, p3);
  4660. return true;
  4661. }
  4662. /* Function wrapper that munges the return value from void to (void*)arg1 */
  4663. template <class P1, class P2, void F(P1, P2)>
  4664. void *ReturnClosure2(P1 p1, P2 p2) {
  4665. F(p1, p2);
  4666. return p1;
  4667. }
  4668. template <class P1, class P2, class P3, void F(P1, P2, P3)>
  4669. void *ReturnClosure3(P1 p1, P2 p2, P3 p3) {
  4670. F(p1, p2, p3);
  4671. return p1;
  4672. }
  4673. /* Function wrapper that munges the return value from R to void*. */
  4674. template <class R, class P1, class P2, R F(P1, P2)>
  4675. void *CastReturnToVoidPtr2(P1 p1, P2 p2) {
  4676. return F(p1, p2);
  4677. }
  4678. template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
  4679. void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) {
  4680. return F(p1, p2, p3);
  4681. }
  4682. /* Function wrapper that munges the return value from bool to void*. */
  4683. template <class P1, class P2, bool F(P1, P2)>
  4684. void *ReturnClosureOrBreak2(P1 p1, P2 p2) {
  4685. return F(p1, p2) ? p1 : UPB_BREAK;
  4686. }
  4687. template <class P1, class P2, class P3, bool F(P1, P2, P3)>
  4688. void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) {
  4689. return F(p1, p2, p3) ? p1 : UPB_BREAK;
  4690. }
  4691. /* For the string callback, which takes five params, returns the size param. */
  4692. template <class P1, class P2,
  4693. void F(P1, P2, const char *, size_t, const BufferHandle *)>
  4694. size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4,
  4695. const BufferHandle *p5) {
  4696. F(p1, p2, p3, p4, p5);
  4697. return p4;
  4698. }
  4699. /* For the string callback, which takes five params, returns the size param or
  4700. * zero. */
  4701. template <class P1, class P2,
  4702. bool F(P1, P2, const char *, size_t, const BufferHandle *)>
  4703. size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4,
  4704. const BufferHandle *p5) {
  4705. return F(p1, p2, p3, p4, p5) ? p4 : 0;
  4706. }
  4707. /* If we have a function returning void but want a function returning bool, wrap
  4708. * it in a function that returns true. */
  4709. template <class P1, class P2, void F(P1, P2), class I>
  4710. struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> {
  4711. typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func;
  4712. };
  4713. template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
  4714. struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> {
  4715. typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func;
  4716. };
  4717. /* If our function returns void but we want one returning void*, wrap it in a
  4718. * function that returns the first argument. */
  4719. template <class P1, class P2, void F(P1, P2), class I>
  4720. struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> {
  4721. typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func;
  4722. };
  4723. template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
  4724. struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> {
  4725. typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func;
  4726. };
  4727. /* If our function returns R* but we want one returning void*, wrap it in a
  4728. * function that casts to void*. */
  4729. template <class R, class P1, class P2, R *F(P1, P2), class I>
  4730. struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *,
  4731. typename disable_if_same<R *, void *>::Type> {
  4732. typedef Func2<void *, P1, P2, CastReturnToVoidPtr2<R *, P1, P2, F>, I> Func;
  4733. };
  4734. template <class R, class P1, class P2, class P3, R *F(P1, P2, P3), class I>
  4735. struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *,
  4736. typename disable_if_same<R *, void *>::Type> {
  4737. typedef Func3<void *, P1, P2, P3, CastReturnToVoidPtr3<R *, P1, P2, P3, F>, I>
  4738. Func;
  4739. };
  4740. /* If our function returns bool but we want one returning void*, wrap it in a
  4741. * function that returns either the first param or UPB_BREAK. */
  4742. template <class P1, class P2, bool F(P1, P2), class I>
  4743. struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> {
  4744. typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func;
  4745. };
  4746. template <class P1, class P2, class P3, bool F(P1, P2, P3), class I>
  4747. struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> {
  4748. typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I>
  4749. Func;
  4750. };
  4751. /* If our function returns void but we want one returning size_t, wrap it in a
  4752. * function that returns the size argument. */
  4753. template <class P1, class P2,
  4754. void F(P1, P2, const char *, size_t, const BufferHandle *), class I>
  4755. struct MaybeWrapReturn<
  4756. Func5<void, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
  4757. size_t> {
  4758. typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
  4759. ReturnStringLen<P1, P2, F>, I> Func;
  4760. };
  4761. /* If our function returns bool but we want one returning size_t, wrap it in a
  4762. * function that returns either 0 or the buf size. */
  4763. template <class P1, class P2,
  4764. bool F(P1, P2, const char *, size_t, const BufferHandle *), class I>
  4765. struct MaybeWrapReturn<
  4766. Func5<bool, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
  4767. size_t> {
  4768. typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
  4769. ReturnNOr0<P1, P2, F>, I> Func;
  4770. };
  4771. /* ConvertParams **************************************************************/
  4772. /* Template class that converts the function parameters if necessary, and
  4773. * ignores the HandlerData parameter if appropriate.
  4774. *
  4775. * Template parameter is the are FuncN function type. */
  4776. template <class F, class T>
  4777. struct ConvertParams;
  4778. /* Function that discards the handler data parameter. */
  4779. template <class R, class P1, R F(P1)>
  4780. R IgnoreHandlerData2(void *p1, const void *hd) {
  4781. UPB_UNUSED(hd);
  4782. return F(static_cast<P1>(p1));
  4783. }
  4784. template <class R, class P1, class P2Wrapper, class P2Wrapped,
  4785. R F(P1, P2Wrapped)>
  4786. R IgnoreHandlerData3(void *p1, const void *hd, P2Wrapper p2) {
  4787. UPB_UNUSED(hd);
  4788. return F(static_cast<P1>(p1), p2);
  4789. }
  4790. template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
  4791. R IgnoreHandlerData4(void *p1, const void *hd, P2 p2, P3 p3) {
  4792. UPB_UNUSED(hd);
  4793. return F(static_cast<P1>(p1), p2, p3);
  4794. }
  4795. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4)>
  4796. R IgnoreHandlerData5(void *p1, const void *hd, P2 p2, P3 p3, P4 p4) {
  4797. UPB_UNUSED(hd);
  4798. return F(static_cast<P1>(p1), p2, p3, p4);
  4799. }
  4800. template <class R, class P1, R F(P1, const char*, size_t)>
  4801. R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2,
  4802. size_t p3, const BufferHandle *handle) {
  4803. UPB_UNUSED(hd);
  4804. UPB_UNUSED(handle);
  4805. return F(static_cast<P1>(p1), p2, p3);
  4806. }
  4807. /* Function that casts the handler data parameter. */
  4808. template <class R, class P1, class P2, R F(P1, P2)>
  4809. R CastHandlerData2(void *c, const void *hd) {
  4810. return F(static_cast<P1>(c), static_cast<P2>(hd));
  4811. }
  4812. template <class R, class P1, class P2, class P3Wrapper, class P3Wrapped,
  4813. R F(P1, P2, P3Wrapped)>
  4814. R CastHandlerData3(void *c, const void *hd, P3Wrapper p3) {
  4815. return F(static_cast<P1>(c), static_cast<P2>(hd), p3);
  4816. }
  4817. template <class R, class P1, class P2, class P3, class P4, class P5,
  4818. R F(P1, P2, P3, P4, P5)>
  4819. R CastHandlerData5(void *c, const void *hd, P3 p3, P4 p4, P5 p5) {
  4820. return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4, p5);
  4821. }
  4822. template <class R, class P1, class P2, R F(P1, P2, const char *, size_t)>
  4823. R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
  4824. size_t p4, const BufferHandle *handle) {
  4825. UPB_UNUSED(handle);
  4826. return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4);
  4827. }
  4828. /* For unbound functions, ignore the handler data. */
  4829. template <class R, class P1, R F(P1), class I, class T>
  4830. struct ConvertParams<Func1<R, P1, F, I>, T> {
  4831. typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
  4832. };
  4833. template <class R, class P1, class P2, R F(P1, P2), class I,
  4834. class R2, class P1_2, class P2_2, class P3_2>
  4835. struct ConvertParams<Func2<R, P1, P2, F, I>,
  4836. R2 (*)(P1_2, P2_2, P3_2)> {
  4837. typedef Func3<R, void *, const void *, P3_2,
  4838. IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
  4839. };
  4840. /* For StringBuffer only; this ignores both the handler data and the
  4841. * BufferHandle. */
  4842. template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
  4843. struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
  4844. typedef Func5<R, void *, const void *, const char *, size_t,
  4845. const BufferHandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
  4846. I> Func;
  4847. };
  4848. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  4849. class I, class T>
  4850. struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
  4851. typedef Func5<R, void *, const void *, P2, P3, P4,
  4852. IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
  4853. };
  4854. /* For bound functions, cast the handler data. */
  4855. template <class R, class P1, class P2, R F(P1, P2), class I, class T>
  4856. struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
  4857. typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
  4858. Func;
  4859. };
  4860. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
  4861. class R2, class P1_2, class P2_2, class P3_2>
  4862. struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
  4863. R2 (*)(P1_2, P2_2, P3_2)> {
  4864. typedef Func3<R, void *, const void *, P3_2,
  4865. CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
  4866. };
  4867. /* For StringBuffer only; this ignores the BufferHandle. */
  4868. template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
  4869. class I, class T>
  4870. struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
  4871. typedef Func5<R, void *, const void *, const char *, size_t,
  4872. const BufferHandle *, CastHandlerDataIgnoreHandle<R, P1, P2, F>,
  4873. I> Func;
  4874. };
  4875. template <class R, class P1, class P2, class P3, class P4, class P5,
  4876. R F(P1, P2, P3, P4, P5), class I, class T>
  4877. struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
  4878. typedef Func5<R, void *, const void *, P3, P4, P5,
  4879. CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
  4880. };
  4881. /* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
  4882. * variant C type. */
  4883. #define TYPE_METHODS(utype, ltype, ctype, vtype) \
  4884. template <> struct CanonicalType<vtype> { \
  4885. typedef ctype Type; \
  4886. }; \
  4887. template <> \
  4888. inline bool Handlers::SetValueHandler<vtype>( \
  4889. const FieldDef *f, \
  4890. const Handlers::utype ## Handler& handler) { \
  4891. UPB_ASSERT(!handler.registered_); \
  4892. handler.AddCleanup(this); \
  4893. handler.registered_ = true; \
  4894. return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \
  4895. } \
  4896. TYPE_METHODS(Double, double, double, double)
  4897. TYPE_METHODS(Float, float, float, float)
  4898. TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
  4899. TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
  4900. TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T)
  4901. TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T)
  4902. TYPE_METHODS(Bool, bool, bool, bool)
  4903. #ifdef UPB_TWO_32BIT_TYPES
  4904. TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T)
  4905. TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T)
  4906. #endif
  4907. #ifdef UPB_TWO_64BIT_TYPES
  4908. TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T)
  4909. TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T)
  4910. #endif
  4911. #undef TYPE_METHODS
  4912. template <> struct CanonicalType<Status*> {
  4913. typedef Status* Type;
  4914. };
  4915. /* Type methods that are only one-per-canonical-type and not
  4916. * one-per-cvariant. */
  4917. #define TYPE_METHODS(utype, ctype) \
  4918. inline bool Handlers::Set##utype##Handler(const FieldDef *f, \
  4919. const utype##Handler &h) { \
  4920. return SetValueHandler<ctype>(f, h); \
  4921. } \
  4922. TYPE_METHODS(Double, double)
  4923. TYPE_METHODS(Float, float)
  4924. TYPE_METHODS(UInt64, uint64_t)
  4925. TYPE_METHODS(UInt32, uint32_t)
  4926. TYPE_METHODS(Int64, int64_t)
  4927. TYPE_METHODS(Int32, int32_t)
  4928. TYPE_METHODS(Bool, bool)
  4929. #undef TYPE_METHODS
  4930. template <class F> struct ReturnOf;
  4931. template <class R, class P1, class P2>
  4932. struct ReturnOf<R (*)(P1, P2)> {
  4933. typedef R Return;
  4934. };
  4935. template <class R, class P1, class P2, class P3>
  4936. struct ReturnOf<R (*)(P1, P2, P3)> {
  4937. typedef R Return;
  4938. };
  4939. template <class R, class P1, class P2, class P3, class P4>
  4940. struct ReturnOf<R (*)(P1, P2, P3, P4)> {
  4941. typedef R Return;
  4942. };
  4943. template <class R, class P1, class P2, class P3, class P4, class P5>
  4944. struct ReturnOf<R (*)(P1, P2, P3, P4, P5)> {
  4945. typedef R Return;
  4946. };
  4947. template<class T> const void *UniquePtrForType() {
  4948. static const char ch = 0;
  4949. return &ch;
  4950. }
  4951. template <class T>
  4952. template <class F>
  4953. inline Handler<T>::Handler(F func)
  4954. : registered_(false),
  4955. cleanup_data_(func.GetData()),
  4956. cleanup_func_(func.GetCleanup()) {
  4957. upb_handlerattr_sethandlerdata(&attr_, func.GetData());
  4958. typedef typename ReturnOf<T>::Return Return;
  4959. typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
  4960. typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
  4961. ReturnWrappedFunc;
  4962. handler_ = ReturnWrappedFunc().Call;
  4963. /* Set attributes based on what templates can statically tell us about the
  4964. * user's function. */
  4965. /* If the original function returns void, then we know that we wrapped it to
  4966. * always return ok. */
  4967. bool always_ok = is_same<typename F::FuncInfo::Return, void>::value;
  4968. attr_.SetAlwaysOk(always_ok);
  4969. /* Closure parameter and return type. */
  4970. attr_.SetClosureType(UniquePtrForType<typename F::FuncInfo::Closure>());
  4971. /* We use the closure type (from the first parameter) if the return type is
  4972. * void or bool, since these are the two cases we wrap to return the closure's
  4973. * type anyway.
  4974. *
  4975. * This is all nonsense for non START* handlers, but it doesn't matter because
  4976. * in that case the value will be ignored. */
  4977. typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
  4978. typename F::FuncInfo::Closure>::value
  4979. EffectiveReturn;
  4980. attr_.SetReturnClosureType(UniquePtrForType<EffectiveReturn>());
  4981. }
  4982. template <class T>
  4983. inline Handler<T>::~Handler() {
  4984. UPB_ASSERT(registered_);
  4985. }
  4986. inline HandlerAttributes::HandlerAttributes() { upb_handlerattr_init(this); }
  4987. inline HandlerAttributes::~HandlerAttributes() { upb_handlerattr_uninit(this); }
  4988. inline bool HandlerAttributes::SetHandlerData(const void *hd) {
  4989. return upb_handlerattr_sethandlerdata(this, hd);
  4990. }
  4991. inline const void* HandlerAttributes::handler_data() const {
  4992. return upb_handlerattr_handlerdata(this);
  4993. }
  4994. inline bool HandlerAttributes::SetClosureType(const void *type) {
  4995. return upb_handlerattr_setclosuretype(this, type);
  4996. }
  4997. inline const void* HandlerAttributes::closure_type() const {
  4998. return upb_handlerattr_closuretype(this);
  4999. }
  5000. inline bool HandlerAttributes::SetReturnClosureType(const void *type) {
  5001. return upb_handlerattr_setreturnclosuretype(this, type);
  5002. }
  5003. inline const void* HandlerAttributes::return_closure_type() const {
  5004. return upb_handlerattr_returnclosuretype(this);
  5005. }
  5006. inline bool HandlerAttributes::SetAlwaysOk(bool always_ok) {
  5007. return upb_handlerattr_setalwaysok(this, always_ok);
  5008. }
  5009. inline bool HandlerAttributes::always_ok() const {
  5010. return upb_handlerattr_alwaysok(this);
  5011. }
  5012. inline BufferHandle::BufferHandle() { upb_bufhandle_init(this); }
  5013. inline BufferHandle::~BufferHandle() { upb_bufhandle_uninit(this); }
  5014. inline const char* BufferHandle::buffer() const {
  5015. return upb_bufhandle_buf(this);
  5016. }
  5017. inline size_t BufferHandle::object_offset() const {
  5018. return upb_bufhandle_objofs(this);
  5019. }
  5020. inline void BufferHandle::SetBuffer(const char* buf, size_t ofs) {
  5021. upb_bufhandle_setbuf(this, buf, ofs);
  5022. }
  5023. template <class T>
  5024. void BufferHandle::SetAttachedObject(const T* obj) {
  5025. upb_bufhandle_setobj(this, obj, UniquePtrForType<T>());
  5026. }
  5027. template <class T>
  5028. const T* BufferHandle::GetAttachedObject() const {
  5029. return upb_bufhandle_objtype(this) == UniquePtrForType<T>()
  5030. ? static_cast<const T *>(upb_bufhandle_obj(this))
  5031. : NULL;
  5032. }
  5033. inline reffed_ptr<Handlers> Handlers::New(const MessageDef *m) {
  5034. upb_handlers *h = upb_handlers_new(m, &h);
  5035. return reffed_ptr<Handlers>(h, &h);
  5036. }
  5037. inline reffed_ptr<const Handlers> Handlers::NewFrozen(
  5038. const MessageDef *m, upb_handlers_callback *callback,
  5039. const void *closure) {
  5040. const upb_handlers *h = upb_handlers_newfrozen(m, &h, callback, closure);
  5041. return reffed_ptr<const Handlers>(h, &h);
  5042. }
  5043. inline const Status* Handlers::status() {
  5044. return upb_handlers_status(this);
  5045. }
  5046. inline void Handlers::ClearError() {
  5047. return upb_handlers_clearerr(this);
  5048. }
  5049. inline bool Handlers::Freeze(Status *s) {
  5050. upb::Handlers* h = this;
  5051. return upb_handlers_freeze(&h, 1, s);
  5052. }
  5053. inline bool Handlers::Freeze(Handlers *const *handlers, int n, Status *s) {
  5054. return upb_handlers_freeze(handlers, n, s);
  5055. }
  5056. inline bool Handlers::Freeze(const std::vector<Handlers*>& h, Status* status) {
  5057. return upb_handlers_freeze((Handlers* const*)&h[0], h.size(), status);
  5058. }
  5059. inline const MessageDef *Handlers::message_def() const {
  5060. return upb_handlers_msgdef(this);
  5061. }
  5062. inline bool Handlers::AddCleanup(void *p, upb_handlerfree *func) {
  5063. return upb_handlers_addcleanup(this, p, func);
  5064. }
  5065. inline bool Handlers::SetStartMessageHandler(
  5066. const Handlers::StartMessageHandler &handler) {
  5067. UPB_ASSERT(!handler.registered_);
  5068. handler.registered_ = true;
  5069. handler.AddCleanup(this);
  5070. return upb_handlers_setstartmsg(this, handler.handler_, &handler.attr_);
  5071. }
  5072. inline bool Handlers::SetEndMessageHandler(
  5073. const Handlers::EndMessageHandler &handler) {
  5074. UPB_ASSERT(!handler.registered_);
  5075. handler.registered_ = true;
  5076. handler.AddCleanup(this);
  5077. return upb_handlers_setendmsg(this, handler.handler_, &handler.attr_);
  5078. }
  5079. inline bool Handlers::SetStartStringHandler(const FieldDef *f,
  5080. const StartStringHandler &handler) {
  5081. UPB_ASSERT(!handler.registered_);
  5082. handler.registered_ = true;
  5083. handler.AddCleanup(this);
  5084. return upb_handlers_setstartstr(this, f, handler.handler_, &handler.attr_);
  5085. }
  5086. inline bool Handlers::SetEndStringHandler(const FieldDef *f,
  5087. const EndFieldHandler &handler) {
  5088. UPB_ASSERT(!handler.registered_);
  5089. handler.registered_ = true;
  5090. handler.AddCleanup(this);
  5091. return upb_handlers_setendstr(this, f, handler.handler_, &handler.attr_);
  5092. }
  5093. inline bool Handlers::SetStringHandler(const FieldDef *f,
  5094. const StringHandler& handler) {
  5095. UPB_ASSERT(!handler.registered_);
  5096. handler.registered_ = true;
  5097. handler.AddCleanup(this);
  5098. return upb_handlers_setstring(this, f, handler.handler_, &handler.attr_);
  5099. }
  5100. inline bool Handlers::SetStartSequenceHandler(
  5101. const FieldDef *f, const StartFieldHandler &handler) {
  5102. UPB_ASSERT(!handler.registered_);
  5103. handler.registered_ = true;
  5104. handler.AddCleanup(this);
  5105. return upb_handlers_setstartseq(this, f, handler.handler_, &handler.attr_);
  5106. }
  5107. inline bool Handlers::SetStartSubMessageHandler(
  5108. const FieldDef *f, const StartFieldHandler &handler) {
  5109. UPB_ASSERT(!handler.registered_);
  5110. handler.registered_ = true;
  5111. handler.AddCleanup(this);
  5112. return upb_handlers_setstartsubmsg(this, f, handler.handler_, &handler.attr_);
  5113. }
  5114. inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f,
  5115. const EndFieldHandler &handler) {
  5116. UPB_ASSERT(!handler.registered_);
  5117. handler.registered_ = true;
  5118. handler.AddCleanup(this);
  5119. return upb_handlers_setendsubmsg(this, f, handler.handler_, &handler.attr_);
  5120. }
  5121. inline bool Handlers::SetEndSequenceHandler(const FieldDef *f,
  5122. const EndFieldHandler &handler) {
  5123. UPB_ASSERT(!handler.registered_);
  5124. handler.registered_ = true;
  5125. handler.AddCleanup(this);
  5126. return upb_handlers_setendseq(this, f, handler.handler_, &handler.attr_);
  5127. }
  5128. inline bool Handlers::SetSubHandlers(const FieldDef *f, const Handlers *sub) {
  5129. return upb_handlers_setsubhandlers(this, f, sub);
  5130. }
  5131. inline const Handlers *Handlers::GetSubHandlers(const FieldDef *f) const {
  5132. return upb_handlers_getsubhandlers(this, f);
  5133. }
  5134. inline const Handlers *Handlers::GetSubHandlers(Handlers::Selector sel) const {
  5135. return upb_handlers_getsubhandlers_sel(this, sel);
  5136. }
  5137. inline bool Handlers::GetSelector(const FieldDef *f, Handlers::Type type,
  5138. Handlers::Selector *s) {
  5139. return upb_handlers_getselector(f, type, s);
  5140. }
  5141. inline Handlers::Selector Handlers::GetEndSelector(Handlers::Selector start) {
  5142. return upb_handlers_getendselector(start);
  5143. }
  5144. inline Handlers::GenericFunction *Handlers::GetHandler(
  5145. Handlers::Selector selector) {
  5146. return upb_handlers_gethandler(this, selector);
  5147. }
  5148. inline const void *Handlers::GetHandlerData(Handlers::Selector selector) {
  5149. return upb_handlers_gethandlerdata(this, selector);
  5150. }
  5151. inline BytesHandler::BytesHandler() {
  5152. upb_byteshandler_init(this);
  5153. }
  5154. inline BytesHandler::~BytesHandler() {}
  5155. } /* namespace upb */
  5156. #endif /* __cplusplus */
  5157. #undef UPB_TWO_32BIT_TYPES
  5158. #undef UPB_TWO_64BIT_TYPES
  5159. #undef UPB_INT32_T
  5160. #undef UPB_UINT32_T
  5161. #undef UPB_INT32ALT_T
  5162. #undef UPB_UINT32ALT_T
  5163. #undef UPB_INT64_T
  5164. #undef UPB_UINT64_T
  5165. #undef UPB_INT64ALT_T
  5166. #undef UPB_UINT64ALT_T
  5167. #endif /* UPB_HANDLERS_INL_H_ */
  5168. #endif /* UPB_HANDLERS_H */
  5169. /*
  5170. ** upb::Sink (upb_sink)
  5171. ** upb::BytesSink (upb_bytessink)
  5172. **
  5173. ** A upb_sink is an object that binds a upb_handlers object to some runtime
  5174. ** state. It is the object that can actually receive data via the upb_handlers
  5175. ** interface.
  5176. **
  5177. ** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
  5178. ** thread-safe. You can create as many of them as you want, but each one may
  5179. ** only be used in a single thread at a time.
  5180. **
  5181. ** If we compare with class-based OOP, a you can think of a upb_def as an
  5182. ** abstract base class, a upb_handlers as a concrete derived class, and a
  5183. ** upb_sink as an object (class instance).
  5184. */
  5185. #ifndef UPB_SINK_H
  5186. #define UPB_SINK_H
  5187. #ifdef __cplusplus
  5188. namespace upb {
  5189. class BufferSink;
  5190. class BufferSource;
  5191. class BytesSink;
  5192. class Sink;
  5193. }
  5194. #endif
  5195. UPB_DECLARE_TYPE(upb::BufferSink, upb_bufsink)
  5196. UPB_DECLARE_TYPE(upb::BufferSource, upb_bufsrc)
  5197. UPB_DECLARE_TYPE(upb::BytesSink, upb_bytessink)
  5198. UPB_DECLARE_TYPE(upb::Sink, upb_sink)
  5199. #ifdef __cplusplus
  5200. /* A upb::Sink is an object that binds a upb::Handlers object to some runtime
  5201. * state. It represents an endpoint to which data can be sent.
  5202. *
  5203. * TODO(haberman): right now all of these functions take selectors. Should they
  5204. * take selectorbase instead?
  5205. *
  5206. * ie. instead of calling:
  5207. * sink->StartString(FOO_FIELD_START_STRING, ...)
  5208. * a selector base would let you say:
  5209. * sink->StartString(FOO_FIELD, ...)
  5210. *
  5211. * This would make call sites a little nicer and require emitting fewer selector
  5212. * definitions in .h files.
  5213. *
  5214. * But the current scheme has the benefit that you can retrieve a function
  5215. * pointer for any handler with handlers->GetHandler(selector), without having
  5216. * to have a separate GetHandler() function for each handler type. The JIT
  5217. * compiler uses this. To accommodate we'd have to expose a separate
  5218. * GetHandler() for every handler type.
  5219. *
  5220. * Also to ponder: selectors right now are independent of a specific Handlers
  5221. * instance. In other words, they allocate a number to every possible handler
  5222. * that *could* be registered, without knowing anything about what handlers
  5223. * *are* registered. That means that using selectors as table offsets prohibits
  5224. * us from compacting the handler table at Freeze() time. If the table is very
  5225. * sparse, this could be wasteful.
  5226. *
  5227. * Having another selector-like thing that is specific to a Handlers instance
  5228. * would allow this compacting, but then it would be impossible to write code
  5229. * ahead-of-time that can be bound to any Handlers instance at runtime. For
  5230. * example, a .proto file parser written as straight C will not know what
  5231. * Handlers it will be bound to, so when it calls sink->StartString() what
  5232. * selector will it pass? It needs a selector like we have today, that is
  5233. * independent of any particular upb::Handlers.
  5234. *
  5235. * Is there a way then to allow Handlers table compaction? */
  5236. class upb::Sink {
  5237. public:
  5238. /* Constructor with no initialization; must be Reset() before use. */
  5239. Sink() {}
  5240. /* Constructs a new sink for the given frozen handlers and closure.
  5241. *
  5242. * TODO: once the Handlers know the expected closure type, verify that T
  5243. * matches it. */
  5244. template <class T> Sink(const Handlers* handlers, T* closure);
  5245. /* Resets the value of the sink. */
  5246. template <class T> void Reset(const Handlers* handlers, T* closure);
  5247. /* Returns the top-level object that is bound to this sink.
  5248. *
  5249. * TODO: once the Handlers know the expected closure type, verify that T
  5250. * matches it. */
  5251. template <class T> T* GetObject() const;
  5252. /* Functions for pushing data into the sink.
  5253. *
  5254. * These return false if processing should stop (either due to error or just
  5255. * to suspend).
  5256. *
  5257. * These may not be called from within one of the same sink's handlers (in
  5258. * other words, handlers are not re-entrant). */
  5259. /* Should be called at the start and end of every message; both the top-level
  5260. * message and submessages. This means that submessages should use the
  5261. * following sequence:
  5262. * sink->StartSubMessage(startsubmsg_selector);
  5263. * sink->StartMessage();
  5264. * // ...
  5265. * sink->EndMessage(&status);
  5266. * sink->EndSubMessage(endsubmsg_selector); */
  5267. bool StartMessage();
  5268. bool EndMessage(Status* status);
  5269. /* Putting of individual values. These work for both repeated and
  5270. * non-repeated fields, but for repeated fields you must wrap them in
  5271. * calls to StartSequence()/EndSequence(). */
  5272. bool PutInt32(Handlers::Selector s, int32_t val);
  5273. bool PutInt64(Handlers::Selector s, int64_t val);
  5274. bool PutUInt32(Handlers::Selector s, uint32_t val);
  5275. bool PutUInt64(Handlers::Selector s, uint64_t val);
  5276. bool PutFloat(Handlers::Selector s, float val);
  5277. bool PutDouble(Handlers::Selector s, double val);
  5278. bool PutBool(Handlers::Selector s, bool val);
  5279. /* Putting of string/bytes values. Each string can consist of zero or more
  5280. * non-contiguous buffers of data.
  5281. *
  5282. * For StartString(), the function will write a sink for the string to "sub."
  5283. * The sub-sink must be used for any/all PutStringBuffer() calls. */
  5284. bool StartString(Handlers::Selector s, size_t size_hint, Sink* sub);
  5285. size_t PutStringBuffer(Handlers::Selector s, const char *buf, size_t len,
  5286. const BufferHandle *handle);
  5287. bool EndString(Handlers::Selector s);
  5288. /* For submessage fields.
  5289. *
  5290. * For StartSubMessage(), the function will write a sink for the string to
  5291. * "sub." The sub-sink must be used for any/all handlers called within the
  5292. * submessage. */
  5293. bool StartSubMessage(Handlers::Selector s, Sink* sub);
  5294. bool EndSubMessage(Handlers::Selector s);
  5295. /* For repeated fields of any type, the sequence of values must be wrapped in
  5296. * these calls.
  5297. *
  5298. * For StartSequence(), the function will write a sink for the string to
  5299. * "sub." The sub-sink must be used for any/all handlers called within the
  5300. * sequence. */
  5301. bool StartSequence(Handlers::Selector s, Sink* sub);
  5302. bool EndSequence(Handlers::Selector s);
  5303. /* Copy and assign specifically allowed.
  5304. * We don't even bother making these members private because so many
  5305. * functions need them and this is mainly just a dumb data container anyway.
  5306. */
  5307. #else
  5308. struct upb_sink {
  5309. #endif
  5310. const upb_handlers *handlers;
  5311. void *closure;
  5312. };
  5313. #ifdef __cplusplus
  5314. class upb::BytesSink {
  5315. public:
  5316. BytesSink() {}
  5317. /* Constructs a new sink for the given frozen handlers and closure.
  5318. *
  5319. * TODO(haberman): once the Handlers know the expected closure type, verify
  5320. * that T matches it. */
  5321. template <class T> BytesSink(const BytesHandler* handler, T* closure);
  5322. /* Resets the value of the sink. */
  5323. template <class T> void Reset(const BytesHandler* handler, T* closure);
  5324. bool Start(size_t size_hint, void **subc);
  5325. size_t PutBuffer(void *subc, const char *buf, size_t len,
  5326. const BufferHandle *handle);
  5327. bool End();
  5328. #else
  5329. struct upb_bytessink {
  5330. #endif
  5331. const upb_byteshandler *handler;
  5332. void *closure;
  5333. };
  5334. #ifdef __cplusplus
  5335. /* A class for pushing a flat buffer of data to a BytesSink.
  5336. * You can construct an instance of this to get a resumable source,
  5337. * or just call the static PutBuffer() to do a non-resumable push all in one
  5338. * go. */
  5339. class upb::BufferSource {
  5340. public:
  5341. BufferSource();
  5342. BufferSource(const char* buf, size_t len, BytesSink* sink);
  5343. /* Returns true if the entire buffer was pushed successfully. Otherwise the
  5344. * next call to PutNext() will resume where the previous one left off.
  5345. * TODO(haberman): implement this. */
  5346. bool PutNext();
  5347. /* A static version; with this version is it not possible to resume in the
  5348. * case of failure or a partially-consumed buffer. */
  5349. static bool PutBuffer(const char* buf, size_t len, BytesSink* sink);
  5350. template <class T> static bool PutBuffer(const T& str, BytesSink* sink) {
  5351. return PutBuffer(str.c_str(), str.size(), sink);
  5352. }
  5353. #else
  5354. struct upb_bufsrc {
  5355. char dummy;
  5356. #endif
  5357. };
  5358. UPB_BEGIN_EXTERN_C
  5359. /* A class for accumulating output string data in a flat buffer. */
  5360. upb_bufsink *upb_bufsink_new(upb_env *env);
  5361. void upb_bufsink_free(upb_bufsink *sink);
  5362. upb_bytessink *upb_bufsink_sink(upb_bufsink *sink);
  5363. const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len);
  5364. /* Inline definitions. */
  5365. UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h,
  5366. void *closure) {
  5367. s->handler = h;
  5368. s->closure = closure;
  5369. }
  5370. UPB_INLINE bool upb_bytessink_start(upb_bytessink *s, size_t size_hint,
  5371. void **subc) {
  5372. typedef upb_startstr_handlerfunc func;
  5373. func *start;
  5374. *subc = s->closure;
  5375. if (!s->handler) return true;
  5376. start = (func *)s->handler->table[UPB_STARTSTR_SELECTOR].func;
  5377. if (!start) return true;
  5378. *subc = start(s->closure, upb_handlerattr_handlerdata(
  5379. &s->handler->table[UPB_STARTSTR_SELECTOR].attr),
  5380. size_hint);
  5381. return *subc != NULL;
  5382. }
  5383. UPB_INLINE size_t upb_bytessink_putbuf(upb_bytessink *s, void *subc,
  5384. const char *buf, size_t size,
  5385. const upb_bufhandle* handle) {
  5386. typedef upb_string_handlerfunc func;
  5387. func *putbuf;
  5388. if (!s->handler) return true;
  5389. putbuf = (func *)s->handler->table[UPB_STRING_SELECTOR].func;
  5390. if (!putbuf) return true;
  5391. return putbuf(subc, upb_handlerattr_handlerdata(
  5392. &s->handler->table[UPB_STRING_SELECTOR].attr),
  5393. buf, size, handle);
  5394. }
  5395. UPB_INLINE bool upb_bytessink_end(upb_bytessink *s) {
  5396. typedef upb_endfield_handlerfunc func;
  5397. func *end;
  5398. if (!s->handler) return true;
  5399. end = (func *)s->handler->table[UPB_ENDSTR_SELECTOR].func;
  5400. if (!end) return true;
  5401. return end(s->closure,
  5402. upb_handlerattr_handlerdata(
  5403. &s->handler->table[UPB_ENDSTR_SELECTOR].attr));
  5404. }
  5405. bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink);
  5406. #define PUTVAL(type, ctype) \
  5407. UPB_INLINE bool upb_sink_put##type(upb_sink *s, upb_selector_t sel, \
  5408. ctype val) { \
  5409. typedef upb_##type##_handlerfunc functype; \
  5410. functype *func; \
  5411. const void *hd; \
  5412. if (!s->handlers) return true; \
  5413. func = (functype *)upb_handlers_gethandler(s->handlers, sel); \
  5414. if (!func) return true; \
  5415. hd = upb_handlers_gethandlerdata(s->handlers, sel); \
  5416. return func(s->closure, hd, val); \
  5417. }
  5418. PUTVAL(int32, int32_t)
  5419. PUTVAL(int64, int64_t)
  5420. PUTVAL(uint32, uint32_t)
  5421. PUTVAL(uint64, uint64_t)
  5422. PUTVAL(float, float)
  5423. PUTVAL(double, double)
  5424. PUTVAL(bool, bool)
  5425. #undef PUTVAL
  5426. UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c) {
  5427. s->handlers = h;
  5428. s->closure = c;
  5429. }
  5430. UPB_INLINE size_t upb_sink_putstring(upb_sink *s, upb_selector_t sel,
  5431. const char *buf, size_t n,
  5432. const upb_bufhandle *handle) {
  5433. typedef upb_string_handlerfunc func;
  5434. func *handler;
  5435. const void *hd;
  5436. if (!s->handlers) return n;
  5437. handler = (func *)upb_handlers_gethandler(s->handlers, sel);
  5438. if (!handler) return n;
  5439. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5440. return handler(s->closure, hd, buf, n, handle);
  5441. }
  5442. UPB_INLINE bool upb_sink_putunknown(upb_sink *s, const char *buf, size_t n) {
  5443. typedef upb_unknown_handlerfunc func;
  5444. func *handler;
  5445. const void *hd;
  5446. if (!s->handlers) return true;
  5447. handler = (func *)upb_handlers_gethandler(s->handlers, UPB_UNKNOWN_SELECTOR);
  5448. if (!handler) return n;
  5449. hd = upb_handlers_gethandlerdata(s->handlers, UPB_UNKNOWN_SELECTOR);
  5450. return handler(s->closure, hd, buf, n);
  5451. }
  5452. UPB_INLINE bool upb_sink_startmsg(upb_sink *s) {
  5453. typedef upb_startmsg_handlerfunc func;
  5454. func *startmsg;
  5455. const void *hd;
  5456. if (!s->handlers) return true;
  5457. startmsg = (func*)upb_handlers_gethandler(s->handlers, UPB_STARTMSG_SELECTOR);
  5458. if (!startmsg) return true;
  5459. hd = upb_handlers_gethandlerdata(s->handlers, UPB_STARTMSG_SELECTOR);
  5460. return startmsg(s->closure, hd);
  5461. }
  5462. UPB_INLINE bool upb_sink_endmsg(upb_sink *s, upb_status *status) {
  5463. typedef upb_endmsg_handlerfunc func;
  5464. func *endmsg;
  5465. const void *hd;
  5466. if (!s->handlers) return true;
  5467. endmsg = (func *)upb_handlers_gethandler(s->handlers, UPB_ENDMSG_SELECTOR);
  5468. if (!endmsg) return true;
  5469. hd = upb_handlers_gethandlerdata(s->handlers, UPB_ENDMSG_SELECTOR);
  5470. return endmsg(s->closure, hd, status);
  5471. }
  5472. UPB_INLINE bool upb_sink_startseq(upb_sink *s, upb_selector_t sel,
  5473. upb_sink *sub) {
  5474. typedef upb_startfield_handlerfunc func;
  5475. func *startseq;
  5476. const void *hd;
  5477. sub->closure = s->closure;
  5478. sub->handlers = s->handlers;
  5479. if (!s->handlers) return true;
  5480. startseq = (func*)upb_handlers_gethandler(s->handlers, sel);
  5481. if (!startseq) return true;
  5482. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5483. sub->closure = startseq(s->closure, hd);
  5484. return sub->closure ? true : false;
  5485. }
  5486. UPB_INLINE bool upb_sink_endseq(upb_sink *s, upb_selector_t sel) {
  5487. typedef upb_endfield_handlerfunc func;
  5488. func *endseq;
  5489. const void *hd;
  5490. if (!s->handlers) return true;
  5491. endseq = (func*)upb_handlers_gethandler(s->handlers, sel);
  5492. if (!endseq) return true;
  5493. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5494. return endseq(s->closure, hd);
  5495. }
  5496. UPB_INLINE bool upb_sink_startstr(upb_sink *s, upb_selector_t sel,
  5497. size_t size_hint, upb_sink *sub) {
  5498. typedef upb_startstr_handlerfunc func;
  5499. func *startstr;
  5500. const void *hd;
  5501. sub->closure = s->closure;
  5502. sub->handlers = s->handlers;
  5503. if (!s->handlers) return true;
  5504. startstr = (func*)upb_handlers_gethandler(s->handlers, sel);
  5505. if (!startstr) return true;
  5506. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5507. sub->closure = startstr(s->closure, hd, size_hint);
  5508. return sub->closure ? true : false;
  5509. }
  5510. UPB_INLINE bool upb_sink_endstr(upb_sink *s, upb_selector_t sel) {
  5511. typedef upb_endfield_handlerfunc func;
  5512. func *endstr;
  5513. const void *hd;
  5514. if (!s->handlers) return true;
  5515. endstr = (func*)upb_handlers_gethandler(s->handlers, sel);
  5516. if (!endstr) return true;
  5517. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5518. return endstr(s->closure, hd);
  5519. }
  5520. UPB_INLINE bool upb_sink_startsubmsg(upb_sink *s, upb_selector_t sel,
  5521. upb_sink *sub) {
  5522. typedef upb_startfield_handlerfunc func;
  5523. func *startsubmsg;
  5524. const void *hd;
  5525. sub->closure = s->closure;
  5526. if (!s->handlers) {
  5527. sub->handlers = NULL;
  5528. return true;
  5529. }
  5530. sub->handlers = upb_handlers_getsubhandlers_sel(s->handlers, sel);
  5531. startsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
  5532. if (!startsubmsg) return true;
  5533. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5534. sub->closure = startsubmsg(s->closure, hd);
  5535. return sub->closure ? true : false;
  5536. }
  5537. UPB_INLINE bool upb_sink_endsubmsg(upb_sink *s, upb_selector_t sel) {
  5538. typedef upb_endfield_handlerfunc func;
  5539. func *endsubmsg;
  5540. const void *hd;
  5541. if (!s->handlers) return true;
  5542. endsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
  5543. if (!endsubmsg) return s->closure;
  5544. hd = upb_handlers_gethandlerdata(s->handlers, sel);
  5545. return endsubmsg(s->closure, hd);
  5546. }
  5547. UPB_END_EXTERN_C
  5548. #ifdef __cplusplus
  5549. namespace upb {
  5550. template <class T> Sink::Sink(const Handlers* handlers, T* closure) {
  5551. upb_sink_reset(this, handlers, closure);
  5552. }
  5553. template <class T>
  5554. inline void Sink::Reset(const Handlers* handlers, T* closure) {
  5555. upb_sink_reset(this, handlers, closure);
  5556. }
  5557. inline bool Sink::StartMessage() {
  5558. return upb_sink_startmsg(this);
  5559. }
  5560. inline bool Sink::EndMessage(Status* status) {
  5561. return upb_sink_endmsg(this, status);
  5562. }
  5563. inline bool Sink::PutInt32(Handlers::Selector sel, int32_t val) {
  5564. return upb_sink_putint32(this, sel, val);
  5565. }
  5566. inline bool Sink::PutInt64(Handlers::Selector sel, int64_t val) {
  5567. return upb_sink_putint64(this, sel, val);
  5568. }
  5569. inline bool Sink::PutUInt32(Handlers::Selector sel, uint32_t val) {
  5570. return upb_sink_putuint32(this, sel, val);
  5571. }
  5572. inline bool Sink::PutUInt64(Handlers::Selector sel, uint64_t val) {
  5573. return upb_sink_putuint64(this, sel, val);
  5574. }
  5575. inline bool Sink::PutFloat(Handlers::Selector sel, float val) {
  5576. return upb_sink_putfloat(this, sel, val);
  5577. }
  5578. inline bool Sink::PutDouble(Handlers::Selector sel, double val) {
  5579. return upb_sink_putdouble(this, sel, val);
  5580. }
  5581. inline bool Sink::PutBool(Handlers::Selector sel, bool val) {
  5582. return upb_sink_putbool(this, sel, val);
  5583. }
  5584. inline bool Sink::StartString(Handlers::Selector sel, size_t size_hint,
  5585. Sink *sub) {
  5586. return upb_sink_startstr(this, sel, size_hint, sub);
  5587. }
  5588. inline size_t Sink::PutStringBuffer(Handlers::Selector sel, const char *buf,
  5589. size_t len, const BufferHandle* handle) {
  5590. return upb_sink_putstring(this, sel, buf, len, handle);
  5591. }
  5592. inline bool Sink::EndString(Handlers::Selector sel) {
  5593. return upb_sink_endstr(this, sel);
  5594. }
  5595. inline bool Sink::StartSubMessage(Handlers::Selector sel, Sink* sub) {
  5596. return upb_sink_startsubmsg(this, sel, sub);
  5597. }
  5598. inline bool Sink::EndSubMessage(Handlers::Selector sel) {
  5599. return upb_sink_endsubmsg(this, sel);
  5600. }
  5601. inline bool Sink::StartSequence(Handlers::Selector sel, Sink* sub) {
  5602. return upb_sink_startseq(this, sel, sub);
  5603. }
  5604. inline bool Sink::EndSequence(Handlers::Selector sel) {
  5605. return upb_sink_endseq(this, sel);
  5606. }
  5607. template <class T>
  5608. BytesSink::BytesSink(const BytesHandler* handler, T* closure) {
  5609. Reset(handler, closure);
  5610. }
  5611. template <class T>
  5612. void BytesSink::Reset(const BytesHandler *handler, T *closure) {
  5613. upb_bytessink_reset(this, handler, closure);
  5614. }
  5615. inline bool BytesSink::Start(size_t size_hint, void **subc) {
  5616. return upb_bytessink_start(this, size_hint, subc);
  5617. }
  5618. inline size_t BytesSink::PutBuffer(void *subc, const char *buf, size_t len,
  5619. const BufferHandle *handle) {
  5620. return upb_bytessink_putbuf(this, subc, buf, len, handle);
  5621. }
  5622. inline bool BytesSink::End() {
  5623. return upb_bytessink_end(this);
  5624. }
  5625. inline bool BufferSource::PutBuffer(const char *buf, size_t len,
  5626. BytesSink *sink) {
  5627. return upb_bufsrc_putbuf(buf, len, sink);
  5628. }
  5629. } /* namespace upb */
  5630. #endif
  5631. #endif
  5632. #ifdef __cplusplus
  5633. namespace upb {
  5634. class Array;
  5635. class Map;
  5636. class MapIterator;
  5637. class MessageLayout;
  5638. }
  5639. #endif
  5640. UPB_DECLARE_TYPE(upb::Map, upb_map)
  5641. UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter)
  5642. struct upb_array;
  5643. typedef struct upb_array upb_array;
  5644. /* TODO(haberman): C++ accessors */
  5645. UPB_BEGIN_EXTERN_C
  5646. typedef void upb_msg;
  5647. /** upb_msglayout *************************************************************/
  5648. /* upb_msglayout represents the memory layout of a given upb_msgdef. The
  5649. * members are public so generated code can initialize them, but users MUST NOT
  5650. * read or write any of its members. */
  5651. typedef struct {
  5652. uint32_t number;
  5653. uint16_t offset;
  5654. int16_t presence; /* If >0, hasbit_index+1. If <0, oneof_index+1. */
  5655. uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
  5656. uint8_t descriptortype;
  5657. uint8_t label;
  5658. } upb_msglayout_field;
  5659. typedef struct upb_msglayout {
  5660. const struct upb_msglayout *const* submsgs;
  5661. const upb_msglayout_field *fields;
  5662. /* Must be aligned to sizeof(void*). Doesn't include internal members like
  5663. * unknown fields, extension dict, pointer to msglayout, etc. */
  5664. uint16_t size;
  5665. uint16_t field_count;
  5666. bool extendable;
  5667. } upb_msglayout;
  5668. /** upb_strview ************************************************************/
  5669. typedef struct {
  5670. const char *data;
  5671. size_t size;
  5672. } upb_strview;
  5673. UPB_INLINE upb_strview upb_strview_make(const char *data, size_t size) {
  5674. upb_strview ret;
  5675. ret.data = data;
  5676. ret.size = size;
  5677. return ret;
  5678. }
  5679. #define UPB_STRVIEW_INIT(ptr, len) {ptr, len}
  5680. /** upb_msgval ****************************************************************/
  5681. /* A union representing all possible protobuf values. Used for generic get/set
  5682. * operations. */
  5683. typedef union {
  5684. bool b;
  5685. float flt;
  5686. double dbl;
  5687. int32_t i32;
  5688. int64_t i64;
  5689. uint32_t u32;
  5690. uint64_t u64;
  5691. const upb_map* map;
  5692. const upb_msg* msg;
  5693. const upb_array* arr;
  5694. const void* ptr;
  5695. upb_strview str;
  5696. } upb_msgval;
  5697. #define ACCESSORS(name, membername, ctype) \
  5698. UPB_INLINE ctype upb_msgval_get ## name(upb_msgval v) { \
  5699. return v.membername; \
  5700. } \
  5701. UPB_INLINE void upb_msgval_set ## name(upb_msgval *v, ctype cval) { \
  5702. v->membername = cval; \
  5703. } \
  5704. UPB_INLINE upb_msgval upb_msgval_ ## name(ctype v) { \
  5705. upb_msgval ret; \
  5706. ret.membername = v; \
  5707. return ret; \
  5708. }
  5709. ACCESSORS(bool, b, bool)
  5710. ACCESSORS(float, flt, float)
  5711. ACCESSORS(double, dbl, double)
  5712. ACCESSORS(int32, i32, int32_t)
  5713. ACCESSORS(int64, i64, int64_t)
  5714. ACCESSORS(uint32, u32, uint32_t)
  5715. ACCESSORS(uint64, u64, uint64_t)
  5716. ACCESSORS(map, map, const upb_map*)
  5717. ACCESSORS(msg, msg, const upb_msg*)
  5718. ACCESSORS(ptr, ptr, const void*)
  5719. ACCESSORS(arr, arr, const upb_array*)
  5720. ACCESSORS(str, str, upb_strview)
  5721. #undef ACCESSORS
  5722. UPB_INLINE upb_msgval upb_msgval_makestr(const char *data, size_t size) {
  5723. return upb_msgval_str(upb_strview_make(data, size));
  5724. }
  5725. /** upb_msg *******************************************************************/
  5726. /* A upb_msg represents a protobuf message. It always corresponds to a specific
  5727. * upb_msglayout, which describes how it is laid out in memory. */
  5728. /* Creates a new message of the given type/layout in this arena. */
  5729. upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
  5730. /* Returns the arena for the given message. */
  5731. upb_arena *upb_msg_arena(const upb_msg *msg);
  5732. void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len);
  5733. const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
  5734. /* Read-only message API. Can be safely called by anyone. */
  5735. /* Returns the value associated with this field:
  5736. * - for scalar fields (including strings), the value directly.
  5737. * - return upb_msg*, or upb_map* for msg/map.
  5738. * If the field is unset for these field types, returns NULL.
  5739. *
  5740. * TODO(haberman): should we let users store cached array/map/msg
  5741. * pointers here for fields that are unset? Could be useful for the
  5742. * strongly-owned submessage model (ie. generated C API that doesn't use
  5743. * arenas).
  5744. */
  5745. upb_msgval upb_msg_get(const upb_msg *msg,
  5746. int field_index,
  5747. const upb_msglayout *l);
  5748. /* May only be called for fields where upb_fielddef_haspresence(f) == true. */
  5749. bool upb_msg_has(const upb_msg *msg,
  5750. int field_index,
  5751. const upb_msglayout *l);
  5752. /* Mutable message API. May only be called by the owner of the message who
  5753. * knows its ownership scheme and how to keep it consistent. */
  5754. /* Sets the given field to the given value. Does not perform any memory
  5755. * management: if you overwrite a pointer to a msg/array/map/string without
  5756. * cleaning it up (or using an arena) it will leak.
  5757. */
  5758. void upb_msg_set(upb_msg *msg,
  5759. int field_index,
  5760. upb_msgval val,
  5761. const upb_msglayout *l);
  5762. /* For a primitive field, set it back to its default. For repeated, string, and
  5763. * submessage fields set it back to NULL. This could involve releasing some
  5764. * internal memory (for example, from an extension dictionary), but it is not
  5765. * recursive in any way and will not recover any memory that may be used by
  5766. * arrays/maps/strings/msgs that this field may have pointed to.
  5767. */
  5768. bool upb_msg_clearfield(upb_msg *msg,
  5769. int field_index,
  5770. const upb_msglayout *l);
  5771. /* TODO(haberman): copyfrom()/mergefrom()? */
  5772. /** upb_array *****************************************************************/
  5773. /* A upb_array stores data for a repeated field. The memory management
  5774. * semantics are the same as upb_msg. A upb_array allocates dynamic
  5775. * memory internally for the array elements. */
  5776. upb_array *upb_array_new(upb_fieldtype_t type, upb_arena *a);
  5777. upb_fieldtype_t upb_array_type(const upb_array *arr);
  5778. /* Read-only interface. Safe for anyone to call. */
  5779. size_t upb_array_size(const upb_array *arr);
  5780. upb_msgval upb_array_get(const upb_array *arr, size_t i);
  5781. /* Write interface. May only be called by the message's owner who can enforce
  5782. * its memory management invariants. */
  5783. bool upb_array_set(upb_array *arr, size_t i, upb_msgval val);
  5784. /** upb_map *******************************************************************/
  5785. /* A upb_map stores data for a map field. The memory management semantics are
  5786. * the same as upb_msg, with one notable exception. upb_map will internally
  5787. * store a copy of all string keys, but *not* any string values or submessages.
  5788. * So you must ensure that any string or message values outlive the map, and you
  5789. * must delete them manually when they are no longer required. */
  5790. upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype,
  5791. upb_arena *a);
  5792. /* Read-only interface. Safe for anyone to call. */
  5793. size_t upb_map_size(const upb_map *map);
  5794. upb_fieldtype_t upb_map_keytype(const upb_map *map);
  5795. upb_fieldtype_t upb_map_valuetype(const upb_map *map);
  5796. bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
  5797. /* Write interface. May only be called by the message's owner who can enforce
  5798. * its memory management invariants. */
  5799. /* Sets or overwrites an entry in the map. Return value indicates whether
  5800. * the operation succeeded or failed with OOM, and also whether an existing
  5801. * key was replaced or not. */
  5802. bool upb_map_set(upb_map *map,
  5803. upb_msgval key, upb_msgval val,
  5804. upb_msgval *valremoved);
  5805. /* Deletes an entry in the map. Returns true if the key was present. */
  5806. bool upb_map_del(upb_map *map, upb_msgval key);
  5807. /** upb_mapiter ***************************************************************/
  5808. /* For iterating over a map. Map iterators are invalidated by mutations to the
  5809. * map, but an invalidated iterator will never return junk or crash the process.
  5810. * An invalidated iterator may return entries that were already returned though,
  5811. * and if you keep invalidating the iterator during iteration, the program may
  5812. * enter an infinite loop. */
  5813. size_t upb_mapiter_sizeof();
  5814. void upb_mapiter_begin(upb_mapiter *i, const upb_map *t);
  5815. upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a);
  5816. void upb_mapiter_free(upb_mapiter *i, upb_alloc *a);
  5817. void upb_mapiter_next(upb_mapiter *i);
  5818. bool upb_mapiter_done(const upb_mapiter *i);
  5819. upb_msgval upb_mapiter_key(const upb_mapiter *i);
  5820. upb_msgval upb_mapiter_value(const upb_mapiter *i);
  5821. void upb_mapiter_setdone(upb_mapiter *i);
  5822. bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2);
  5823. UPB_END_EXTERN_C
  5824. #endif /* UPB_MSG_H_ */
  5825. /* This file was generated by upbc (the upb compiler) from the input
  5826. * file:
  5827. *
  5828. * google/protobuf/descriptor.proto
  5829. *
  5830. * Do not edit -- your changes will be discarded when the file is
  5831. * regenerated. */
  5832. #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
  5833. #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
  5834. /*
  5835. ** Functions for use by generated code. These are not public and users must
  5836. ** not call them directly.
  5837. */
  5838. #ifndef UPB_GENERATED_UTIL_H_
  5839. #define UPB_GENERATED_UTIL_H_
  5840. #include <stdint.h>
  5841. /*
  5842. ** structs.int.h: structures definitions that are internal to upb.
  5843. */
  5844. #ifndef UPB_STRUCTS_H_
  5845. #define UPB_STRUCTS_H_
  5846. struct upb_array {
  5847. upb_fieldtype_t type;
  5848. uint8_t element_size;
  5849. void *data; /* Each element is element_size. */
  5850. size_t len; /* Measured in elements. */
  5851. size_t size; /* Measured in elements. */
  5852. upb_arena *arena;
  5853. };
  5854. #endif /* UPB_STRUCTS_H_ */
  5855. #define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
  5856. UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
  5857. size_t *size) {
  5858. const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
  5859. if (arr) {
  5860. if (size) *size = arr->size;
  5861. return arr->data;
  5862. } else {
  5863. if (size) *size = 0;
  5864. return NULL;
  5865. }
  5866. }
  5867. UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
  5868. size_t *size) {
  5869. upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
  5870. if (arr) {
  5871. if (size) *size = arr->size;
  5872. return arr->data;
  5873. } else {
  5874. if (size) *size = 0;
  5875. return NULL;
  5876. }
  5877. }
  5878. /* TODO(haberman): this is a mess. It will improve when upb_array no longer
  5879. * carries reflective state (type, elem_size). */
  5880. UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
  5881. size_t elem_size,
  5882. upb_fieldtype_t type,
  5883. upb_arena *arena) {
  5884. upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
  5885. if (!arr) {
  5886. arr = upb_array_new(type, arena);
  5887. if (!arr) return NULL;
  5888. *PTR_AT(msg, ofs, upb_array*) = arr;
  5889. }
  5890. if (size > arr->size) {
  5891. size_t new_size = UPB_MAX(arr->size, 4);
  5892. size_t old_bytes = arr->size * elem_size;
  5893. size_t new_bytes;
  5894. upb_alloc *alloc = upb_arena_alloc(arr->arena);
  5895. while (new_size < size) new_size *= 2;
  5896. new_bytes = new_size * elem_size;
  5897. arr->data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
  5898. if (!arr->data) {
  5899. return NULL;
  5900. }
  5901. arr->size = new_size;
  5902. }
  5903. arr->len = size;
  5904. return arr->data;
  5905. }
  5906. UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
  5907. size_t elem_size,
  5908. upb_fieldtype_t type,
  5909. const void *value,
  5910. upb_arena *arena) {
  5911. upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
  5912. size_t i = arr ? arr->len : 0;
  5913. void *data =
  5914. _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena);
  5915. if (!data) return false;
  5916. memcpy(PTR_AT(data, i * elem_size, char), value, elem_size);
  5917. return true;
  5918. }
  5919. UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
  5920. return (*PTR_AT(msg, idx / 8, const char) & (idx % 8)) != 0;
  5921. }
  5922. UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) {
  5923. return (*PTR_AT(msg, idx / 8, char)) |= (1 << (idx % 8));
  5924. }
  5925. UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) {
  5926. return (*PTR_AT(msg, idx / 8, char)) &= ~(1 << (idx % 8));
  5927. }
  5928. UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) {
  5929. return *PTR_AT(msg, case_ofs, int32_t) == num;
  5930. }
  5931. #undef PTR_AT
  5932. #endif /* UPB_GENERATED_UTIL_H_ */
  5933. /*
  5934. ** upb_decode: parsing into a upb_msg using a upb_msglayout.
  5935. */
  5936. #ifndef UPB_DECODE_H_
  5937. #define UPB_DECODE_H_
  5938. UPB_BEGIN_EXTERN_C
  5939. bool upb_decode(upb_strview buf, upb_msg *msg, const upb_msglayout *l);
  5940. UPB_END_EXTERN_C
  5941. #endif /* UPB_DECODE_H_ */
  5942. /*
  5943. ** upb_encode: parsing into a upb_msg using a upb_msglayout.
  5944. */
  5945. #ifndef UPB_ENCODE_H_
  5946. #define UPB_ENCODE_H_
  5947. UPB_BEGIN_EXTERN_C
  5948. char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
  5949. size_t *size);
  5950. UPB_END_EXTERN_C
  5951. #endif /* UPB_ENCODE_H_ */
  5952. UPB_BEGIN_EXTERN_C
  5953. struct google_protobuf_FileDescriptorSet;
  5954. struct google_protobuf_FileDescriptorProto;
  5955. struct google_protobuf_DescriptorProto;
  5956. struct google_protobuf_DescriptorProto_ExtensionRange;
  5957. struct google_protobuf_DescriptorProto_ReservedRange;
  5958. struct google_protobuf_ExtensionRangeOptions;
  5959. struct google_protobuf_FieldDescriptorProto;
  5960. struct google_protobuf_OneofDescriptorProto;
  5961. struct google_protobuf_EnumDescriptorProto;
  5962. struct google_protobuf_EnumDescriptorProto_EnumReservedRange;
  5963. struct google_protobuf_EnumValueDescriptorProto;
  5964. struct google_protobuf_ServiceDescriptorProto;
  5965. struct google_protobuf_MethodDescriptorProto;
  5966. struct google_protobuf_FileOptions;
  5967. struct google_protobuf_MessageOptions;
  5968. struct google_protobuf_FieldOptions;
  5969. struct google_protobuf_OneofOptions;
  5970. struct google_protobuf_EnumOptions;
  5971. struct google_protobuf_EnumValueOptions;
  5972. struct google_protobuf_ServiceOptions;
  5973. struct google_protobuf_MethodOptions;
  5974. struct google_protobuf_UninterpretedOption;
  5975. struct google_protobuf_UninterpretedOption_NamePart;
  5976. struct google_protobuf_SourceCodeInfo;
  5977. struct google_protobuf_SourceCodeInfo_Location;
  5978. struct google_protobuf_GeneratedCodeInfo;
  5979. struct google_protobuf_GeneratedCodeInfo_Annotation;
  5980. typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet;
  5981. typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto;
  5982. typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto;
  5983. typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange;
  5984. typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange;
  5985. typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions;
  5986. typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto;
  5987. typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto;
  5988. typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto;
  5989. typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange;
  5990. typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto;
  5991. typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto;
  5992. typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto;
  5993. typedef struct google_protobuf_FileOptions google_protobuf_FileOptions;
  5994. typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions;
  5995. typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions;
  5996. typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions;
  5997. typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions;
  5998. typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions;
  5999. typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions;
  6000. typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions;
  6001. typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption;
  6002. typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart;
  6003. typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo;
  6004. typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location;
  6005. typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo;
  6006. typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation;
  6007. extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit;
  6008. extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit;
  6009. extern const upb_msglayout google_protobuf_DescriptorProto_msginit;
  6010. extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit;
  6011. extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit;
  6012. extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit;
  6013. extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit;
  6014. extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit;
  6015. extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit;
  6016. extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit;
  6017. extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit;
  6018. extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit;
  6019. extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit;
  6020. extern const upb_msglayout google_protobuf_FileOptions_msginit;
  6021. extern const upb_msglayout google_protobuf_MessageOptions_msginit;
  6022. extern const upb_msglayout google_protobuf_FieldOptions_msginit;
  6023. extern const upb_msglayout google_protobuf_OneofOptions_msginit;
  6024. extern const upb_msglayout google_protobuf_EnumOptions_msginit;
  6025. extern const upb_msglayout google_protobuf_EnumValueOptions_msginit;
  6026. extern const upb_msglayout google_protobuf_ServiceOptions_msginit;
  6027. extern const upb_msglayout google_protobuf_MethodOptions_msginit;
  6028. extern const upb_msglayout google_protobuf_UninterpretedOption_msginit;
  6029. extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit;
  6030. extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit;
  6031. extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit;
  6032. extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit;
  6033. extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit;
  6034. /* Enums */
  6035. typedef enum {
  6036. google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
  6037. google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
  6038. google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
  6039. } google_protobuf_FieldDescriptorProto_Label;
  6040. typedef enum {
  6041. google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
  6042. google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
  6043. google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
  6044. google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
  6045. google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
  6046. google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
  6047. google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
  6048. google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
  6049. google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
  6050. google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
  6051. google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
  6052. google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
  6053. google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
  6054. google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
  6055. google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
  6056. google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
  6057. google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
  6058. google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
  6059. } google_protobuf_FieldDescriptorProto_Type;
  6060. typedef enum {
  6061. google_protobuf_FieldOptions_STRING = 0,
  6062. google_protobuf_FieldOptions_CORD = 1,
  6063. google_protobuf_FieldOptions_STRING_PIECE = 2
  6064. } google_protobuf_FieldOptions_CType;
  6065. typedef enum {
  6066. google_protobuf_FieldOptions_JS_NORMAL = 0,
  6067. google_protobuf_FieldOptions_JS_STRING = 1,
  6068. google_protobuf_FieldOptions_JS_NUMBER = 2
  6069. } google_protobuf_FieldOptions_JSType;
  6070. typedef enum {
  6071. google_protobuf_FileOptions_SPEED = 1,
  6072. google_protobuf_FileOptions_CODE_SIZE = 2,
  6073. google_protobuf_FileOptions_LITE_RUNTIME = 3
  6074. } google_protobuf_FileOptions_OptimizeMode;
  6075. typedef enum {
  6076. google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
  6077. google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
  6078. google_protobuf_MethodOptions_IDEMPOTENT = 2
  6079. } google_protobuf_MethodOptions_IdempotencyLevel;
  6080. /* google.protobuf.FileDescriptorSet */
  6081. UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) {
  6082. return (google_protobuf_FileDescriptorSet *)upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena);
  6083. }
  6084. UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parsenew(upb_strview buf, upb_arena *arena) {
  6085. google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena);
  6086. return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorSet_msginit)) ? ret : NULL;
  6087. }
  6088. UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) {
  6089. return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len);
  6090. }
  6091. UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len) { return (const google_protobuf_FileDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
  6092. UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) {
  6093. return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  6094. }
  6095. UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) {
  6096. return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6097. }
  6098. UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) {
  6099. struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
  6100. bool ok = _upb_array_append_accessor(
  6101. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6102. if (!ok) return NULL;
  6103. return sub;
  6104. }
  6105. /* google.protobuf.FileDescriptorProto */
  6106. UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) {
  6107. return (google_protobuf_FileDescriptorProto *)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
  6108. }
  6109. UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6110. google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena);
  6111. return (ret && upb_decode(buf, ret, &google_protobuf_FileDescriptorProto_msginit)) ? ret : NULL;
  6112. }
  6113. UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6114. return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len);
  6115. }
  6116. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6117. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6118. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6119. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
  6120. UPB_INLINE upb_strview const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
  6121. UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
  6122. UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
  6123. UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); }
  6124. UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); }
  6125. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  6126. UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FileOptions*, UPB_SIZE(28, 56)); }
  6127. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  6128. UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)); }
  6129. UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); }
  6130. UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); }
  6131. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  6132. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
  6133. UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  6134. _upb_sethas(msg, 0);
  6135. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6136. }
  6137. UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  6138. _upb_sethas(msg, 1);
  6139. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
  6140. }
  6141. UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6142. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
  6143. }
  6144. UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6145. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
  6146. }
  6147. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) {
  6148. return _upb_array_append_accessor(
  6149. msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
  6150. }
  6151. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6152. return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
  6153. }
  6154. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6155. return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6156. }
  6157. UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6158. struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  6159. bool ok = _upb_array_append_accessor(
  6160. msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6161. if (!ok) return NULL;
  6162. return sub;
  6163. }
  6164. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6165. return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
  6166. }
  6167. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6168. return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6169. }
  6170. UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6171. struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  6172. bool ok = _upb_array_append_accessor(
  6173. msg, UPB_SIZE(44, 88), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6174. if (!ok) return NULL;
  6175. return sub;
  6176. }
  6177. UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6178. return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len);
  6179. }
  6180. UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6181. return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6182. }
  6183. UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6184. struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
  6185. bool ok = _upb_array_append_accessor(
  6186. msg, UPB_SIZE(48, 96), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6187. if (!ok) return NULL;
  6188. return sub;
  6189. }
  6190. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6191. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len);
  6192. }
  6193. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6194. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6195. }
  6196. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6197. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  6198. bool ok = _upb_array_append_accessor(
  6199. msg, UPB_SIZE(52, 104), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6200. if (!ok) return NULL;
  6201. return sub;
  6202. }
  6203. UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
  6204. _upb_sethas(msg, 3);
  6205. UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(28, 56)) = value;
  6206. }
  6207. UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6208. struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg);
  6209. if (sub == NULL) {
  6210. sub = (struct google_protobuf_FileOptions*)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
  6211. if (!sub) return NULL;
  6212. google_protobuf_FileDescriptorProto_set_options(msg, sub);
  6213. }
  6214. return sub;
  6215. }
  6216. UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
  6217. _upb_sethas(msg, 4);
  6218. UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)) = value;
  6219. }
  6220. UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  6221. struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg);
  6222. if (sub == NULL) {
  6223. sub = (struct google_protobuf_SourceCodeInfo*)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
  6224. if (!sub) return NULL;
  6225. google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub);
  6226. }
  6227. return sub;
  6228. }
  6229. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6230. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len);
  6231. }
  6232. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6233. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
  6234. }
  6235. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
  6236. return _upb_array_append_accessor(
  6237. msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
  6238. }
  6239. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  6240. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len);
  6241. }
  6242. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  6243. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
  6244. }
  6245. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
  6246. return _upb_array_append_accessor(
  6247. msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
  6248. }
  6249. UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  6250. _upb_sethas(msg, 2);
  6251. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
  6252. }
  6253. /* google.protobuf.DescriptorProto */
  6254. UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) {
  6255. return (google_protobuf_DescriptorProto *)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  6256. }
  6257. UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6258. google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena);
  6259. return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_msginit)) ? ret : NULL;
  6260. }
  6261. UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) {
  6262. return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len);
  6263. }
  6264. UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6265. UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6266. UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
  6267. UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
  6268. UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
  6269. UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
  6270. UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); }
  6271. UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6272. UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MessageOptions*, UPB_SIZE(12, 24)); }
  6273. UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
  6274. UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
  6275. UPB_INLINE upb_strview const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
  6276. UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) {
  6277. _upb_sethas(msg, 0);
  6278. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6279. }
  6280. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) {
  6281. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  6282. }
  6283. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6284. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6285. }
  6286. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6287. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  6288. bool ok = _upb_array_append_accessor(
  6289. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6290. if (!ok) return NULL;
  6291. return sub;
  6292. }
  6293. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto *msg, size_t *len) {
  6294. return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  6295. }
  6296. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6297. return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6298. }
  6299. UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6300. struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  6301. bool ok = _upb_array_append_accessor(
  6302. msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6303. if (!ok) return NULL;
  6304. return sub;
  6305. }
  6306. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto *msg, size_t *len) {
  6307. return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  6308. }
  6309. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6310. return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6311. }
  6312. UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6313. struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  6314. bool ok = _upb_array_append_accessor(
  6315. msg, UPB_SIZE(24, 48), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6316. if (!ok) return NULL;
  6317. return sub;
  6318. }
  6319. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto *msg, size_t *len) {
  6320. return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
  6321. }
  6322. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6323. return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6324. }
  6325. UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6326. struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
  6327. bool ok = _upb_array_append_accessor(
  6328. msg, UPB_SIZE(28, 56), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6329. if (!ok) return NULL;
  6330. return sub;
  6331. }
  6332. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto *msg, size_t *len) {
  6333. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len);
  6334. }
  6335. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6336. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6337. }
  6338. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6339. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  6340. bool ok = _upb_array_append_accessor(
  6341. msg, UPB_SIZE(32, 64), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6342. if (!ok) return NULL;
  6343. return sub;
  6344. }
  6345. UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) {
  6346. _upb_sethas(msg, 1);
  6347. UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(12, 24)) = value;
  6348. }
  6349. UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6350. struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg);
  6351. if (sub == NULL) {
  6352. sub = (struct google_protobuf_MessageOptions*)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
  6353. if (!sub) return NULL;
  6354. google_protobuf_DescriptorProto_set_options(msg, sub);
  6355. }
  6356. return sub;
  6357. }
  6358. UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto *msg, size_t *len) {
  6359. return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
  6360. }
  6361. UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6362. return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6363. }
  6364. UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6365. struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
  6366. bool ok = _upb_array_append_accessor(
  6367. msg, UPB_SIZE(36, 72), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6368. if (!ok) return NULL;
  6369. return sub;
  6370. }
  6371. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto *msg, size_t *len) {
  6372. return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
  6373. }
  6374. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6375. return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6376. }
  6377. UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  6378. struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
  6379. bool ok = _upb_array_append_accessor(
  6380. msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6381. if (!ok) return NULL;
  6382. return sub;
  6383. }
  6384. UPB_INLINE upb_strview* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto *msg, size_t *len) {
  6385. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
  6386. }
  6387. UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  6388. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
  6389. }
  6390. UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) {
  6391. return _upb_array_append_accessor(
  6392. msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
  6393. }
  6394. /* google.protobuf.DescriptorProto.ExtensionRange */
  6395. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) {
  6396. return (google_protobuf_DescriptorProto_ExtensionRange *)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
  6397. }
  6398. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parsenew(upb_strview buf, upb_arena *arena) {
  6399. google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena);
  6400. return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit)) ? ret : NULL;
  6401. }
  6402. UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) {
  6403. return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len);
  6404. }
  6405. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 0); }
  6406. UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
  6407. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 1); }
  6408. UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
  6409. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 2); }
  6410. UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)); }
  6411. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
  6412. _upb_sethas(msg, 0);
  6413. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
  6414. }
  6415. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
  6416. _upb_sethas(msg, 1);
  6417. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
  6418. }
  6419. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) {
  6420. _upb_sethas(msg, 2);
  6421. UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value;
  6422. }
  6423. UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena) {
  6424. struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg);
  6425. if (sub == NULL) {
  6426. sub = (struct google_protobuf_ExtensionRangeOptions*)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
  6427. if (!sub) return NULL;
  6428. google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub);
  6429. }
  6430. return sub;
  6431. }
  6432. /* google.protobuf.DescriptorProto.ReservedRange */
  6433. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) {
  6434. return (google_protobuf_DescriptorProto_ReservedRange *)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
  6435. }
  6436. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parsenew(upb_strview buf, upb_arena *arena) {
  6437. google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena);
  6438. return (ret && upb_decode(buf, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit)) ? ret : NULL;
  6439. }
  6440. UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) {
  6441. return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len);
  6442. }
  6443. UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 0); }
  6444. UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
  6445. UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 1); }
  6446. UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
  6447. UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
  6448. _upb_sethas(msg, 0);
  6449. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
  6450. }
  6451. UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
  6452. _upb_sethas(msg, 1);
  6453. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
  6454. }
  6455. /* google.protobuf.ExtensionRangeOptions */
  6456. UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) {
  6457. return (google_protobuf_ExtensionRangeOptions *)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
  6458. }
  6459. UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parsenew(upb_strview buf, upb_arena *arena) {
  6460. google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena);
  6461. return (ret && upb_decode(buf, ret, &google_protobuf_ExtensionRangeOptions_msginit)) ? ret : NULL;
  6462. }
  6463. UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) {
  6464. return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len);
  6465. }
  6466. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
  6467. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) {
  6468. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  6469. }
  6470. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) {
  6471. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6472. }
  6473. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) {
  6474. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  6475. bool ok = _upb_array_append_accessor(
  6476. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6477. if (!ok) return NULL;
  6478. return sub;
  6479. }
  6480. /* google.protobuf.FieldDescriptorProto */
  6481. UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) {
  6482. return (google_protobuf_FieldDescriptorProto *)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  6483. }
  6484. UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6485. google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena);
  6486. return (ret && upb_decode(buf, ret, &google_protobuf_FieldDescriptorProto_msginit)) ? ret : NULL;
  6487. }
  6488. UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6489. return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len);
  6490. }
  6491. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  6492. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
  6493. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); }
  6494. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
  6495. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  6496. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)); }
  6497. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6498. UPB_INLINE google_protobuf_FieldDescriptorProto_Label google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)); }
  6499. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6500. UPB_INLINE google_protobuf_FieldDescriptorProto_Type google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)); }
  6501. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); }
  6502. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
  6503. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); }
  6504. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)); }
  6505. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); }
  6506. UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FieldOptions*, UPB_SIZE(72, 112)); }
  6507. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  6508. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); }
  6509. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); }
  6510. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)); }
  6511. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  6512. _upb_sethas(msg, 4);
  6513. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
  6514. }
  6515. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  6516. _upb_sethas(msg, 5);
  6517. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
  6518. }
  6519. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  6520. _upb_sethas(msg, 2);
  6521. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value;
  6522. }
  6523. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Label value) {
  6524. _upb_sethas(msg, 0);
  6525. UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Label, UPB_SIZE(8, 8)) = value;
  6526. }
  6527. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldDescriptorProto_Type value) {
  6528. _upb_sethas(msg, 1);
  6529. UPB_FIELD_AT(msg, google_protobuf_FieldDescriptorProto_Type, UPB_SIZE(16, 16)) = value;
  6530. }
  6531. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  6532. _upb_sethas(msg, 6);
  6533. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
  6534. }
  6535. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  6536. _upb_sethas(msg, 7);
  6537. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)) = value;
  6538. }
  6539. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
  6540. _upb_sethas(msg, 9);
  6541. UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value;
  6542. }
  6543. UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) {
  6544. struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg);
  6545. if (sub == NULL) {
  6546. sub = (struct google_protobuf_FieldOptions*)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
  6547. if (!sub) return NULL;
  6548. google_protobuf_FieldDescriptorProto_set_options(msg, sub);
  6549. }
  6550. return sub;
  6551. }
  6552. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  6553. _upb_sethas(msg, 3);
  6554. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value;
  6555. }
  6556. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  6557. _upb_sethas(msg, 8);
  6558. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value;
  6559. }
  6560. /* google.protobuf.OneofDescriptorProto */
  6561. UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) {
  6562. return (google_protobuf_OneofDescriptorProto *)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
  6563. }
  6564. UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6565. google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena);
  6566. return (ret && upb_decode(buf, ret, &google_protobuf_OneofDescriptorProto_msginit)) ? ret : NULL;
  6567. }
  6568. UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6569. return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len);
  6570. }
  6571. UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6572. UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6573. UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6574. UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_OneofOptions*, UPB_SIZE(12, 24)); }
  6575. UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) {
  6576. _upb_sethas(msg, 0);
  6577. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6578. }
  6579. UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) {
  6580. _upb_sethas(msg, 1);
  6581. UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(12, 24)) = value;
  6582. }
  6583. UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_arena *arena) {
  6584. struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg);
  6585. if (sub == NULL) {
  6586. sub = (struct google_protobuf_OneofOptions*)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
  6587. if (!sub) return NULL;
  6588. google_protobuf_OneofDescriptorProto_set_options(msg, sub);
  6589. }
  6590. return sub;
  6591. }
  6592. /* google.protobuf.EnumDescriptorProto */
  6593. UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) {
  6594. return (google_protobuf_EnumDescriptorProto *)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  6595. }
  6596. UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6597. google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena);
  6598. return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_msginit)) ? ret : NULL;
  6599. }
  6600. UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6601. return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len);
  6602. }
  6603. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6604. UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6605. UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
  6606. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6607. UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumOptions*, UPB_SIZE(12, 24)); }
  6608. UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
  6609. UPB_INLINE upb_strview const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
  6610. UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) {
  6611. _upb_sethas(msg, 0);
  6612. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6613. }
  6614. UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  6615. return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  6616. }
  6617. UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  6618. return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6619. }
  6620. UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  6621. struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
  6622. bool ok = _upb_array_append_accessor(
  6623. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6624. if (!ok) return NULL;
  6625. return sub;
  6626. }
  6627. UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) {
  6628. _upb_sethas(msg, 1);
  6629. UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(12, 24)) = value;
  6630. }
  6631. UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  6632. struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg);
  6633. if (sub == NULL) {
  6634. sub = (struct google_protobuf_EnumOptions*)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
  6635. if (!sub) return NULL;
  6636. google_protobuf_EnumDescriptorProto_set_options(msg, sub);
  6637. }
  6638. return sub;
  6639. }
  6640. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  6641. return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  6642. }
  6643. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  6644. return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6645. }
  6646. UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  6647. struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
  6648. bool ok = _upb_array_append_accessor(
  6649. msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6650. if (!ok) return NULL;
  6651. return sub;
  6652. }
  6653. UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  6654. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  6655. }
  6656. UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  6657. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
  6658. }
  6659. UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) {
  6660. return _upb_array_append_accessor(
  6661. msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
  6662. }
  6663. /* google.protobuf.EnumDescriptorProto.EnumReservedRange */
  6664. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) {
  6665. return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
  6666. }
  6667. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parsenew(upb_strview buf, upb_arena *arena) {
  6668. google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena);
  6669. return (ret && upb_decode(buf, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit)) ? ret : NULL;
  6670. }
  6671. UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) {
  6672. return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len);
  6673. }
  6674. UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 0); }
  6675. UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
  6676. UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 1); }
  6677. UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
  6678. UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
  6679. _upb_sethas(msg, 0);
  6680. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
  6681. }
  6682. UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
  6683. _upb_sethas(msg, 1);
  6684. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
  6685. }
  6686. /* google.protobuf.EnumValueDescriptorProto */
  6687. UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) {
  6688. return (google_protobuf_EnumValueDescriptorProto *)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
  6689. }
  6690. UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6691. google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena);
  6692. return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueDescriptorProto_msginit)) ? ret : NULL;
  6693. }
  6694. UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6695. return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len);
  6696. }
  6697. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6698. UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)); }
  6699. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6700. UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
  6701. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  6702. UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)); }
  6703. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) {
  6704. _upb_sethas(msg, 1);
  6705. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)) = value;
  6706. }
  6707. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
  6708. _upb_sethas(msg, 0);
  6709. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
  6710. }
  6711. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
  6712. _upb_sethas(msg, 2);
  6713. UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)) = value;
  6714. }
  6715. UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena) {
  6716. struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg);
  6717. if (sub == NULL) {
  6718. sub = (struct google_protobuf_EnumValueOptions*)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
  6719. if (!sub) return NULL;
  6720. google_protobuf_EnumValueDescriptorProto_set_options(msg, sub);
  6721. }
  6722. return sub;
  6723. }
  6724. /* google.protobuf.ServiceDescriptorProto */
  6725. UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) {
  6726. return (google_protobuf_ServiceDescriptorProto *)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
  6727. }
  6728. UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6729. google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena);
  6730. return (ret && upb_decode(buf, ret, &google_protobuf_ServiceDescriptorProto_msginit)) ? ret : NULL;
  6731. }
  6732. UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6733. return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len);
  6734. }
  6735. UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6736. UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6737. UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
  6738. UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6739. UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)); }
  6740. UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) {
  6741. _upb_sethas(msg, 0);
  6742. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6743. }
  6744. UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) {
  6745. return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  6746. }
  6747. UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) {
  6748. return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6749. }
  6750. UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
  6751. struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
  6752. bool ok = _upb_array_append_accessor(
  6753. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6754. if (!ok) return NULL;
  6755. return sub;
  6756. }
  6757. UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) {
  6758. _upb_sethas(msg, 1);
  6759. UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)) = value;
  6760. }
  6761. UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
  6762. struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg);
  6763. if (sub == NULL) {
  6764. sub = (struct google_protobuf_ServiceOptions*)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
  6765. if (!sub) return NULL;
  6766. google_protobuf_ServiceDescriptorProto_set_options(msg, sub);
  6767. }
  6768. return sub;
  6769. }
  6770. /* google.protobuf.MethodDescriptorProto */
  6771. UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) {
  6772. return (google_protobuf_MethodDescriptorProto *)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
  6773. }
  6774. UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parsenew(upb_strview buf, upb_arena *arena) {
  6775. google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena);
  6776. return (ret && upb_decode(buf, ret, &google_protobuf_MethodDescriptorProto_msginit)) ? ret : NULL;
  6777. }
  6778. UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) {
  6779. return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len);
  6780. }
  6781. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  6782. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  6783. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  6784. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
  6785. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  6786. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
  6787. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 5); }
  6788. UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MethodOptions*, UPB_SIZE(28, 56)); }
  6789. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 0); }
  6790. UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  6791. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  6792. UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
  6793. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  6794. _upb_sethas(msg, 2);
  6795. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  6796. }
  6797. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  6798. _upb_sethas(msg, 3);
  6799. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
  6800. }
  6801. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  6802. _upb_sethas(msg, 4);
  6803. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
  6804. }
  6805. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
  6806. _upb_sethas(msg, 5);
  6807. UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(28, 56)) = value;
  6808. }
  6809. UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) {
  6810. struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg);
  6811. if (sub == NULL) {
  6812. sub = (struct google_protobuf_MethodOptions*)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
  6813. if (!sub) return NULL;
  6814. google_protobuf_MethodDescriptorProto_set_options(msg, sub);
  6815. }
  6816. return sub;
  6817. }
  6818. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
  6819. _upb_sethas(msg, 0);
  6820. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  6821. }
  6822. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
  6823. _upb_sethas(msg, 1);
  6824. UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
  6825. }
  6826. /* google.protobuf.FileOptions */
  6827. UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) {
  6828. return (google_protobuf_FileOptions *)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
  6829. }
  6830. UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parsenew(upb_strview buf, upb_arena *arena) {
  6831. google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena);
  6832. return (ret && upb_decode(buf, ret, &google_protobuf_FileOptions_msginit)) ? ret : NULL;
  6833. }
  6834. UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) {
  6835. return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len);
  6836. }
  6837. UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 10); }
  6838. UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)); }
  6839. UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 11); }
  6840. UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)); }
  6841. UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 0); }
  6842. UPB_INLINE google_protobuf_FileOptions_OptimizeMode google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)); }
  6843. UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 1); }
  6844. UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
  6845. UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 12); }
  6846. UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)); }
  6847. UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 2); }
  6848. UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)); }
  6849. UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 3); }
  6850. UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); }
  6851. UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 4); }
  6852. UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)); }
  6853. UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 5); }
  6854. UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)); }
  6855. UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 6); }
  6856. UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); }
  6857. UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 7); }
  6858. UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)); }
  6859. UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 8); }
  6860. UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); }
  6861. UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 13); }
  6862. UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)); }
  6863. UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 14); }
  6864. UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)); }
  6865. UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 15); }
  6866. UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)); }
  6867. UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 16); }
  6868. UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)); }
  6869. UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 17); }
  6870. UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)); }
  6871. UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 9); }
  6872. UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
  6873. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(92, 160), len); }
  6874. UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) {
  6875. _upb_sethas(msg, 10);
  6876. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)) = value;
  6877. }
  6878. UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) {
  6879. _upb_sethas(msg, 11);
  6880. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)) = value;
  6881. }
  6882. UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, google_protobuf_FileOptions_OptimizeMode value) {
  6883. _upb_sethas(msg, 0);
  6884. UPB_FIELD_AT(msg, google_protobuf_FileOptions_OptimizeMode, UPB_SIZE(8, 8)) = value;
  6885. }
  6886. UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
  6887. _upb_sethas(msg, 1);
  6888. UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
  6889. }
  6890. UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) {
  6891. _upb_sethas(msg, 12);
  6892. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)) = value;
  6893. }
  6894. UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
  6895. _upb_sethas(msg, 2);
  6896. UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value;
  6897. }
  6898. UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
  6899. _upb_sethas(msg, 3);
  6900. UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value;
  6901. }
  6902. UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
  6903. _upb_sethas(msg, 4);
  6904. UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value;
  6905. }
  6906. UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
  6907. _upb_sethas(msg, 5);
  6908. UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value;
  6909. }
  6910. UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
  6911. _upb_sethas(msg, 6);
  6912. UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value;
  6913. }
  6914. UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
  6915. _upb_sethas(msg, 7);
  6916. UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value;
  6917. }
  6918. UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
  6919. _upb_sethas(msg, 8);
  6920. UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value;
  6921. }
  6922. UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  6923. _upb_sethas(msg, 13);
  6924. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)) = value;
  6925. }
  6926. UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
  6927. _upb_sethas(msg, 14);
  6928. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)) = value;
  6929. }
  6930. UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  6931. _upb_sethas(msg, 15);
  6932. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)) = value;
  6933. }
  6934. UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  6935. _upb_sethas(msg, 16);
  6936. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)) = value;
  6937. }
  6938. UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
  6939. _upb_sethas(msg, 17);
  6940. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)) = value;
  6941. }
  6942. UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
  6943. _upb_sethas(msg, 9);
  6944. UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
  6945. }
  6946. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) {
  6947. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(92, 160), len);
  6948. }
  6949. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) {
  6950. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(92, 160), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  6951. }
  6952. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) {
  6953. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  6954. bool ok = _upb_array_append_accessor(
  6955. msg, UPB_SIZE(92, 160), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  6956. if (!ok) return NULL;
  6957. return sub;
  6958. }
  6959. /* google.protobuf.MessageOptions */
  6960. UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) {
  6961. return (google_protobuf_MessageOptions *)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
  6962. }
  6963. UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parsenew(upb_strview buf, upb_arena *arena) {
  6964. google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena);
  6965. return (ret && upb_decode(buf, ret, &google_protobuf_MessageOptions_msginit)) ? ret : NULL;
  6966. }
  6967. UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) {
  6968. return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len);
  6969. }
  6970. UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 0); }
  6971. UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  6972. UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 1); }
  6973. UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
  6974. UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 2); }
  6975. UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); }
  6976. UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 3); }
  6977. UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)); }
  6978. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(8, 8), len); }
  6979. UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) {
  6980. _upb_sethas(msg, 0);
  6981. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  6982. }
  6983. UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) {
  6984. _upb_sethas(msg, 1);
  6985. UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
  6986. }
  6987. UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) {
  6988. _upb_sethas(msg, 2);
  6989. UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value;
  6990. }
  6991. UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) {
  6992. _upb_sethas(msg, 3);
  6993. UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value;
  6994. }
  6995. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) {
  6996. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len);
  6997. }
  6998. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) {
  6999. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7000. }
  7001. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) {
  7002. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7003. bool ok = _upb_array_append_accessor(
  7004. msg, UPB_SIZE(8, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7005. if (!ok) return NULL;
  7006. return sub;
  7007. }
  7008. /* google.protobuf.FieldOptions */
  7009. UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) {
  7010. return (google_protobuf_FieldOptions *)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
  7011. }
  7012. UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7013. google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena);
  7014. return (ret && upb_decode(buf, ret, &google_protobuf_FieldOptions_msginit)) ? ret : NULL;
  7015. }
  7016. UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) {
  7017. return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len);
  7018. }
  7019. UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 0); }
  7020. UPB_INLINE google_protobuf_FieldOptions_CType google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)); }
  7021. UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 2); }
  7022. UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
  7023. UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 3); }
  7024. UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); }
  7025. UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 4); }
  7026. UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); }
  7027. UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 1); }
  7028. UPB_INLINE google_protobuf_FieldOptions_JSType google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)); }
  7029. UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 5); }
  7030. UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); }
  7031. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(28, 32), len); }
  7032. UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_CType value) {
  7033. _upb_sethas(msg, 0);
  7034. UPB_FIELD_AT(msg, google_protobuf_FieldOptions_CType, UPB_SIZE(8, 8)) = value;
  7035. }
  7036. UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
  7037. _upb_sethas(msg, 2);
  7038. UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
  7039. }
  7040. UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
  7041. _upb_sethas(msg, 3);
  7042. UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value;
  7043. }
  7044. UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
  7045. _upb_sethas(msg, 4);
  7046. UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value;
  7047. }
  7048. UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, google_protobuf_FieldOptions_JSType value) {
  7049. _upb_sethas(msg, 1);
  7050. UPB_FIELD_AT(msg, google_protobuf_FieldOptions_JSType, UPB_SIZE(16, 16)) = value;
  7051. }
  7052. UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
  7053. _upb_sethas(msg, 5);
  7054. UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value;
  7055. }
  7056. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) {
  7057. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 32), len);
  7058. }
  7059. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) {
  7060. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7061. }
  7062. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) {
  7063. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7064. bool ok = _upb_array_append_accessor(
  7065. msg, UPB_SIZE(28, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7066. if (!ok) return NULL;
  7067. return sub;
  7068. }
  7069. /* google.protobuf.OneofOptions */
  7070. UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) {
  7071. return (google_protobuf_OneofOptions *)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
  7072. }
  7073. UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7074. google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena);
  7075. return (ret && upb_decode(buf, ret, &google_protobuf_OneofOptions_msginit)) ? ret : NULL;
  7076. }
  7077. UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) {
  7078. return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len);
  7079. }
  7080. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
  7081. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) {
  7082. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  7083. }
  7084. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) {
  7085. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7086. }
  7087. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) {
  7088. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7089. bool ok = _upb_array_append_accessor(
  7090. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7091. if (!ok) return NULL;
  7092. return sub;
  7093. }
  7094. /* google.protobuf.EnumOptions */
  7095. UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) {
  7096. return (google_protobuf_EnumOptions *)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
  7097. }
  7098. UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7099. google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena);
  7100. return (ret && upb_decode(buf, ret, &google_protobuf_EnumOptions_msginit)) ? ret : NULL;
  7101. }
  7102. UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) {
  7103. return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len);
  7104. }
  7105. UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 0); }
  7106. UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  7107. UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 1); }
  7108. UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
  7109. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
  7110. UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) {
  7111. _upb_sethas(msg, 0);
  7112. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  7113. }
  7114. UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) {
  7115. _upb_sethas(msg, 1);
  7116. UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
  7117. }
  7118. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) {
  7119. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  7120. }
  7121. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) {
  7122. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7123. }
  7124. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) {
  7125. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7126. bool ok = _upb_array_append_accessor(
  7127. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7128. if (!ok) return NULL;
  7129. return sub;
  7130. }
  7131. /* google.protobuf.EnumValueOptions */
  7132. UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) {
  7133. return (google_protobuf_EnumValueOptions *)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
  7134. }
  7135. UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7136. google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena);
  7137. return (ret && upb_decode(buf, ret, &google_protobuf_EnumValueOptions_msginit)) ? ret : NULL;
  7138. }
  7139. UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) {
  7140. return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len);
  7141. }
  7142. UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_has_field(msg, 0); }
  7143. UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  7144. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
  7145. UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) {
  7146. _upb_sethas(msg, 0);
  7147. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  7148. }
  7149. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) {
  7150. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  7151. }
  7152. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) {
  7153. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7154. }
  7155. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) {
  7156. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7157. bool ok = _upb_array_append_accessor(
  7158. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7159. if (!ok) return NULL;
  7160. return sub;
  7161. }
  7162. /* google.protobuf.ServiceOptions */
  7163. UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) {
  7164. return (google_protobuf_ServiceOptions *)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
  7165. }
  7166. UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7167. google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena);
  7168. return (ret && upb_decode(buf, ret, &google_protobuf_ServiceOptions_msginit)) ? ret : NULL;
  7169. }
  7170. UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) {
  7171. return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len);
  7172. }
  7173. UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_has_field(msg, 0); }
  7174. UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  7175. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
  7176. UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) {
  7177. _upb_sethas(msg, 0);
  7178. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  7179. }
  7180. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) {
  7181. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  7182. }
  7183. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) {
  7184. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7185. }
  7186. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) {
  7187. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7188. bool ok = _upb_array_append_accessor(
  7189. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7190. if (!ok) return NULL;
  7191. return sub;
  7192. }
  7193. /* google.protobuf.MethodOptions */
  7194. UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) {
  7195. return (google_protobuf_MethodOptions *)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
  7196. }
  7197. UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parsenew(upb_strview buf, upb_arena *arena) {
  7198. google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena);
  7199. return (ret && upb_decode(buf, ret, &google_protobuf_MethodOptions_msginit)) ? ret : NULL;
  7200. }
  7201. UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) {
  7202. return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len);
  7203. }
  7204. UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 1); }
  7205. UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
  7206. UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 0); }
  7207. UPB_INLINE google_protobuf_MethodOptions_IdempotencyLevel google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)); }
  7208. UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 24), len); }
  7209. UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
  7210. _upb_sethas(msg, 1);
  7211. UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
  7212. }
  7213. UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, google_protobuf_MethodOptions_IdempotencyLevel value) {
  7214. _upb_sethas(msg, 0);
  7215. UPB_FIELD_AT(msg, google_protobuf_MethodOptions_IdempotencyLevel, UPB_SIZE(8, 8)) = value;
  7216. }
  7217. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) {
  7218. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 24), len);
  7219. }
  7220. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) {
  7221. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7222. }
  7223. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) {
  7224. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7225. bool ok = _upb_array_append_accessor(
  7226. msg, UPB_SIZE(20, 24), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7227. if (!ok) return NULL;
  7228. return sub;
  7229. }
  7230. /* google.protobuf.UninterpretedOption */
  7231. UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) {
  7232. return (google_protobuf_UninterpretedOption *)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  7233. }
  7234. UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parsenew(upb_strview buf, upb_arena *arena) {
  7235. google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena);
  7236. return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_msginit)) ? ret : NULL;
  7237. }
  7238. UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) {
  7239. return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len);
  7240. }
  7241. UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); }
  7242. UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 3); }
  7243. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
  7244. UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 0); }
  7245. UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)); }
  7246. UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 1); }
  7247. UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)); }
  7248. UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 2); }
  7249. UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); }
  7250. UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 4); }
  7251. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
  7252. UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 5); }
  7253. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
  7254. UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) {
  7255. return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len);
  7256. }
  7257. UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) {
  7258. return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7259. }
  7260. UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) {
  7261. struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
  7262. bool ok = _upb_array_append_accessor(
  7263. msg, UPB_SIZE(56, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7264. if (!ok) return NULL;
  7265. return sub;
  7266. }
  7267. UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  7268. _upb_sethas(msg, 3);
  7269. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
  7270. }
  7271. UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
  7272. _upb_sethas(msg, 0);
  7273. UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value;
  7274. }
  7275. UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
  7276. _upb_sethas(msg, 1);
  7277. UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value;
  7278. }
  7279. UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
  7280. _upb_sethas(msg, 2);
  7281. UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value;
  7282. }
  7283. UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  7284. _upb_sethas(msg, 4);
  7285. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
  7286. }
  7287. UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  7288. _upb_sethas(msg, 5);
  7289. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
  7290. }
  7291. /* google.protobuf.UninterpretedOption.NamePart */
  7292. UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) {
  7293. return (google_protobuf_UninterpretedOption_NamePart *)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
  7294. }
  7295. UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parsenew(upb_strview buf, upb_arena *arena) {
  7296. google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena);
  7297. return (ret && upb_decode(buf, ret, &google_protobuf_UninterpretedOption_NamePart_msginit)) ? ret : NULL;
  7298. }
  7299. UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) {
  7300. return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len);
  7301. }
  7302. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 1); }
  7303. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  7304. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 0); }
  7305. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
  7306. UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) {
  7307. _upb_sethas(msg, 1);
  7308. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  7309. }
  7310. UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
  7311. _upb_sethas(msg, 0);
  7312. UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
  7313. }
  7314. /* google.protobuf.SourceCodeInfo */
  7315. UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) {
  7316. return (google_protobuf_SourceCodeInfo *)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
  7317. }
  7318. UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parsenew(upb_strview buf, upb_arena *arena) {
  7319. google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena);
  7320. return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_msginit)) ? ret : NULL;
  7321. }
  7322. UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) {
  7323. return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len);
  7324. }
  7325. UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg, size_t *len) { return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
  7326. UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) {
  7327. return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  7328. }
  7329. UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) {
  7330. return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7331. }
  7332. UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) {
  7333. struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
  7334. bool ok = _upb_array_append_accessor(
  7335. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7336. if (!ok) return NULL;
  7337. return sub;
  7338. }
  7339. /* google.protobuf.SourceCodeInfo.Location */
  7340. UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) {
  7341. return (google_protobuf_SourceCodeInfo_Location *)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
  7342. }
  7343. UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parsenew(upb_strview buf, upb_arena *arena) {
  7344. google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena);
  7345. return (ret && upb_decode(buf, ret, &google_protobuf_SourceCodeInfo_Location_msginit)) ? ret : NULL;
  7346. }
  7347. UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) {
  7348. return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len);
  7349. }
  7350. UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
  7351. UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
  7352. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 0); }
  7353. UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
  7354. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 1); }
  7355. UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
  7356. UPB_INLINE upb_strview const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
  7357. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  7358. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  7359. }
  7360. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  7361. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
  7362. }
  7363. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
  7364. return _upb_array_append_accessor(
  7365. msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
  7366. }
  7367. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  7368. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  7369. }
  7370. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  7371. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
  7372. }
  7373. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
  7374. return _upb_array_append_accessor(
  7375. msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
  7376. }
  7377. UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
  7378. _upb_sethas(msg, 0);
  7379. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
  7380. }
  7381. UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
  7382. _upb_sethas(msg, 1);
  7383. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
  7384. }
  7385. UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  7386. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
  7387. }
  7388. UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  7389. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
  7390. }
  7391. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) {
  7392. return _upb_array_append_accessor(
  7393. msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
  7394. }
  7395. /* google.protobuf.GeneratedCodeInfo */
  7396. UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) {
  7397. return (google_protobuf_GeneratedCodeInfo *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena);
  7398. }
  7399. UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parsenew(upb_strview buf, upb_arena *arena) {
  7400. google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena);
  7401. return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_msginit)) ? ret : NULL;
  7402. }
  7403. UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) {
  7404. return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len);
  7405. }
  7406. UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
  7407. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) {
  7408. return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  7409. }
  7410. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) {
  7411. return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
  7412. }
  7413. UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) {
  7414. struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
  7415. bool ok = _upb_array_append_accessor(
  7416. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  7417. if (!ok) return NULL;
  7418. return sub;
  7419. }
  7420. /* google.protobuf.GeneratedCodeInfo.Annotation */
  7421. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) {
  7422. return (google_protobuf_GeneratedCodeInfo_Annotation *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
  7423. }
  7424. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parsenew(upb_strview buf, upb_arena *arena) {
  7425. google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena);
  7426. return (ret && upb_decode(buf, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit)) ? ret : NULL;
  7427. }
  7428. UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) {
  7429. return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len);
  7430. }
  7431. UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); }
  7432. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 2); }
  7433. UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)); }
  7434. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 0); }
  7435. UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
  7436. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 1); }
  7437. UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
  7438. UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) {
  7439. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len);
  7440. }
  7441. UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) {
  7442. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
  7443. }
  7444. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) {
  7445. return _upb_array_append_accessor(
  7446. msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
  7447. }
  7448. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) {
  7449. _upb_sethas(msg, 2);
  7450. UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)) = value;
  7451. }
  7452. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
  7453. _upb_sethas(msg, 0);
  7454. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
  7455. }
  7456. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
  7457. _upb_sethas(msg, 1);
  7458. UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
  7459. }
  7460. UPB_END_EXTERN_C
  7461. #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */
  7462. #ifndef UPB_MSGFACTORY_H_
  7463. #define UPB_MSGFACTORY_H_
  7464. #ifdef __cplusplus
  7465. namespace upb {
  7466. class MessageFactory;
  7467. }
  7468. #endif
  7469. UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory)
  7470. /** upb_msgfactory ************************************************************/
  7471. /* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and
  7472. * upb_visitorplan objects. These are the objects necessary to represent,
  7473. * populate, and and visit upb_msg objects.
  7474. *
  7475. * These caches are all populated by upb_msgdef, and lazily created on demand.
  7476. */
  7477. /* Creates and destroys a msgfactory, respectively. The messages for this
  7478. * msgfactory must come from |symtab| (which should outlive the msgfactory). */
  7479. upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab);
  7480. void upb_msgfactory_free(upb_msgfactory *f);
  7481. const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f);
  7482. /* The functions to get cached objects, lazily creating them on demand. These
  7483. * all require:
  7484. *
  7485. * - m is in upb_msgfactory_symtab(f)
  7486. * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts).
  7487. *
  7488. * The returned objects will live for as long as the msgfactory does.
  7489. *
  7490. * TODO(haberman): consider making this thread-safe and take a const
  7491. * upb_msgfactory. */
  7492. const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
  7493. const upb_msgdef *m);
  7494. #endif /* UPB_MSGFACTORY_H_ */
  7495. /*
  7496. ** upb::descriptor::Reader (upb_descreader)
  7497. **
  7498. ** Provides a way of building upb::Defs from data in descriptor.proto format.
  7499. */
  7500. #ifndef UPB_DESCRIPTOR_H
  7501. #define UPB_DESCRIPTOR_H
  7502. #ifdef __cplusplus
  7503. namespace upb {
  7504. namespace descriptor {
  7505. class Reader;
  7506. } /* namespace descriptor */
  7507. } /* namespace upb */
  7508. #endif
  7509. UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader)
  7510. #ifdef __cplusplus
  7511. /* Class that receives descriptor data according to the descriptor.proto schema
  7512. * and use it to build upb::Defs corresponding to that schema. */
  7513. class upb::descriptor::Reader {
  7514. public:
  7515. /* These handlers must have come from NewHandlers() and must outlive the
  7516. * Reader.
  7517. *
  7518. * TODO: generate the handlers statically (like we do with the
  7519. * descriptor.proto defs) so that there is no need to pass this parameter (or
  7520. * to build/memory-manage the handlers at runtime at all). Unfortunately this
  7521. * is a bit tricky to implement for Handlers, but necessary to simplify this
  7522. * interface. */
  7523. static Reader* Create(Environment* env, const Handlers* handlers);
  7524. /* The reader's input; this is where descriptor.proto data should be sent. */
  7525. Sink* input();
  7526. /* Use to get the FileDefs that have been parsed. */
  7527. size_t file_count() const;
  7528. FileDef* file(size_t i) const;
  7529. /* Builds and returns handlers for the reader, owned by "owner." */
  7530. static Handlers* NewHandlers(const void* owner);
  7531. private:
  7532. UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader)
  7533. };
  7534. #endif
  7535. UPB_BEGIN_EXTERN_C
  7536. /* C API. */
  7537. upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h);
  7538. upb_sink *upb_descreader_input(upb_descreader *r);
  7539. size_t upb_descreader_filecount(const upb_descreader *r);
  7540. upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i);
  7541. const upb_handlers *upb_descreader_newhandlers(const void *owner);
  7542. UPB_END_EXTERN_C
  7543. #ifdef __cplusplus
  7544. /* C++ implementation details. ************************************************/
  7545. namespace upb {
  7546. namespace descriptor {
  7547. inline Reader* Reader::Create(Environment* e, const Handlers *h) {
  7548. return upb_descreader_create(e, h);
  7549. }
  7550. inline Sink* Reader::input() { return upb_descreader_input(this); }
  7551. inline size_t Reader::file_count() const {
  7552. return upb_descreader_filecount(this);
  7553. }
  7554. inline FileDef* Reader::file(size_t i) const {
  7555. return upb_descreader_file(this, i);
  7556. }
  7557. } /* namespace descriptor */
  7558. } /* namespace upb */
  7559. #endif
  7560. #endif /* UPB_DESCRIPTOR_H */
  7561. /* This file contains accessors for a set of compiled-in defs.
  7562. * Note that unlike Google's protobuf, it does *not* define
  7563. * generated classes or any other kind of data structure for
  7564. * actually storing protobufs. It only contains *defs* which
  7565. * let you reflect over a protobuf *schema*.
  7566. */
  7567. /* This file was generated by upbc (the upb compiler) from the input
  7568. * file:
  7569. *
  7570. * upb/descriptor/descriptor.proto
  7571. *
  7572. * Do not edit -- your changes will be discarded when the file is
  7573. * regenerated. */
  7574. #ifndef UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
  7575. #define UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
  7576. UPB_BEGIN_EXTERN_C
  7577. /* MessageDefs: call these functions to get a ref to a msgdef. */
  7578. const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner);
  7579. const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner);
  7580. const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(const void *owner);
  7581. const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *owner);
  7582. const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner);
  7583. const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const void *owner);
  7584. const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner);
  7585. const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *owner);
  7586. const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner);
  7587. const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *owner);
  7588. const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owner);
  7589. const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner);
  7590. const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner);
  7591. const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *owner);
  7592. const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner);
  7593. const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *owner);
  7594. const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner);
  7595. const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner);
  7596. const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner);
  7597. const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner);
  7598. const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *owner);
  7599. const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner);
  7600. /* EnumDefs: call these functions to get a ref to an enumdef. */
  7601. const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner);
  7602. const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const void *owner);
  7603. const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *owner);
  7604. const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *owner);
  7605. const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const void *owner);
  7606. /* Functions to test whether this message is of a certain type. */
  7607. UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_is(const upb_msgdef *m) {
  7608. return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto") == 0;
  7609. }
  7610. UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(const upb_msgdef *m) {
  7611. return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ExtensionRange") == 0;
  7612. }
  7613. UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(const upb_msgdef *m) {
  7614. return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ReservedRange") == 0;
  7615. }
  7616. UPB_INLINE bool upbdefs_google_protobuf_EnumDescriptorProto_is(const upb_msgdef *m) {
  7617. return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumDescriptorProto") == 0;
  7618. }
  7619. UPB_INLINE bool upbdefs_google_protobuf_EnumOptions_is(const upb_msgdef *m) {
  7620. return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumOptions") == 0;
  7621. }
  7622. UPB_INLINE bool upbdefs_google_protobuf_EnumValueDescriptorProto_is(const upb_msgdef *m) {
  7623. return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueDescriptorProto") == 0;
  7624. }
  7625. UPB_INLINE bool upbdefs_google_protobuf_EnumValueOptions_is(const upb_msgdef *m) {
  7626. return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueOptions") == 0;
  7627. }
  7628. UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_is(const upb_msgdef *m) {
  7629. return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldDescriptorProto") == 0;
  7630. }
  7631. UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_is(const upb_msgdef *m) {
  7632. return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldOptions") == 0;
  7633. }
  7634. UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorProto_is(const upb_msgdef *m) {
  7635. return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorProto") == 0;
  7636. }
  7637. UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorSet_is(const upb_msgdef *m) {
  7638. return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorSet") == 0;
  7639. }
  7640. UPB_INLINE bool upbdefs_google_protobuf_FileOptions_is(const upb_msgdef *m) {
  7641. return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileOptions") == 0;
  7642. }
  7643. UPB_INLINE bool upbdefs_google_protobuf_MessageOptions_is(const upb_msgdef *m) {
  7644. return strcmp(upb_msgdef_fullname(m), "google.protobuf.MessageOptions") == 0;
  7645. }
  7646. UPB_INLINE bool upbdefs_google_protobuf_MethodDescriptorProto_is(const upb_msgdef *m) {
  7647. return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodDescriptorProto") == 0;
  7648. }
  7649. UPB_INLINE bool upbdefs_google_protobuf_MethodOptions_is(const upb_msgdef *m) {
  7650. return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodOptions") == 0;
  7651. }
  7652. UPB_INLINE bool upbdefs_google_protobuf_OneofDescriptorProto_is(const upb_msgdef *m) {
  7653. return strcmp(upb_msgdef_fullname(m), "google.protobuf.OneofDescriptorProto") == 0;
  7654. }
  7655. UPB_INLINE bool upbdefs_google_protobuf_ServiceDescriptorProto_is(const upb_msgdef *m) {
  7656. return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceDescriptorProto") == 0;
  7657. }
  7658. UPB_INLINE bool upbdefs_google_protobuf_ServiceOptions_is(const upb_msgdef *m) {
  7659. return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceOptions") == 0;
  7660. }
  7661. UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_is(const upb_msgdef *m) {
  7662. return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo") == 0;
  7663. }
  7664. UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_Location_is(const upb_msgdef *m) {
  7665. return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo.Location") == 0;
  7666. }
  7667. UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_is(const upb_msgdef *m) {
  7668. return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption") == 0;
  7669. }
  7670. UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_NamePart_is(const upb_msgdef *m) {
  7671. return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption.NamePart") == 0;
  7672. }
  7673. /* Functions to test whether this enum is of a certain type. */
  7674. UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Label_is(const upb_enumdef *e) {
  7675. return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Label") == 0;
  7676. }
  7677. UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Type_is(const upb_enumdef *e) {
  7678. return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Type") == 0;
  7679. }
  7680. UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_CType_is(const upb_enumdef *e) {
  7681. return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.CType") == 0;
  7682. }
  7683. UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_JSType_is(const upb_enumdef *e) {
  7684. return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.JSType") == 0;
  7685. }
  7686. UPB_INLINE bool upbdefs_google_protobuf_FileOptions_OptimizeMode_is(const upb_enumdef *e) {
  7687. return strcmp(upb_enumdef_fullname(e), "google.protobuf.FileOptions.OptimizeMode") == 0;
  7688. }
  7689. /* Functions to get a fielddef from a msgdef reference. */
  7690. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 2); }
  7691. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 1); }
  7692. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 2); }
  7693. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 1); }
  7694. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
  7695. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
  7696. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
  7697. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_field(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7698. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7699. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_nested_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7700. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_oneof_decl(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
  7701. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
  7702. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
  7703. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
  7704. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7705. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7706. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7707. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_allow_alias(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 2); }
  7708. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 3); }
  7709. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7710. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7711. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7712. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7713. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 1); }
  7714. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7715. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_default_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
  7716. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_extendee(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7717. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_json_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
  7718. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_label(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
  7719. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7720. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7721. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_oneof_index(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
  7722. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
  7723. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
  7724. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
  7725. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_ctype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 1); }
  7726. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 3); }
  7727. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_jstype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 6); }
  7728. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_lazy(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 5); }
  7729. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_packed(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 2); }
  7730. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7731. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_weak(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 10); }
  7732. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7733. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
  7734. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
  7735. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_message_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
  7736. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7737. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
  7738. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7739. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_public_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
  7740. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_service(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
  7741. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_source_code_info(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
  7742. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_syntax(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 12); }
  7743. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_weak_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 11); }
  7744. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_f_file(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m)); return upb_msgdef_itof(m, 1); }
  7745. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_enable_arenas(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 31); }
  7746. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 16); }
  7747. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_csharp_namespace(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 37); }
  7748. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 23); }
  7749. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_go_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 11); }
  7750. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generate_equals_and_hash(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 20); }
  7751. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 17); }
  7752. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_multiple_files(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 10); }
  7753. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_outer_classname(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 8); }
  7754. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 1); }
  7755. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string_check_utf8(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 27); }
  7756. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_use_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 38); }
  7757. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 36); }
  7758. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_for(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); }
  7759. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_php_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 40); }
  7760. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_php_namespace(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 41); }
  7761. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 18); }
  7762. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7763. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 3); }
  7764. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_map_entry(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 7); }
  7765. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_message_set_wire_format(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 1); }
  7766. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_no_standard_descriptor_accessor(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 2); }
  7767. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7768. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_client_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
  7769. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_input_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7770. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7771. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
  7772. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_output_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7773. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_server_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
  7774. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 33); }
  7775. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7776. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_OneofDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7777. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_method(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
  7778. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
  7779. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
  7780. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 33); }
  7781. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 999); }
  7782. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 3); }
  7783. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_detached_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 6); }
  7784. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_path(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 1); }
  7785. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_span(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 2); }
  7786. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_trailing_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 4); }
  7787. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_f_location(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m)); return upb_msgdef_itof(m, 1); }
  7788. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_is_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 2); }
  7789. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_name_part(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 1); }
  7790. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_aggregate_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 8); }
  7791. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_double_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 6); }
  7792. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_identifier_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 3); }
  7793. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 2); }
  7794. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_negative_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 5); }
  7795. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_positive_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 4); }
  7796. UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_string_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 7); }
  7797. UPB_END_EXTERN_C
  7798. #ifdef __cplusplus
  7799. namespace upbdefs {
  7800. namespace google {
  7801. namespace protobuf {
  7802. class DescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7803. public:
  7804. DescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7805. : reffed_ptr(m, ref_donor) {
  7806. UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m));
  7807. }
  7808. static DescriptorProto get() {
  7809. const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m);
  7810. return DescriptorProto(m, &m);
  7811. }
  7812. class ExtensionRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7813. public:
  7814. ExtensionRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7815. : reffed_ptr(m, ref_donor) {
  7816. UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m));
  7817. }
  7818. static ExtensionRange get() {
  7819. const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(&m);
  7820. return ExtensionRange(m, &m);
  7821. }
  7822. };
  7823. class ReservedRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7824. public:
  7825. ReservedRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7826. : reffed_ptr(m, ref_donor) {
  7827. UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m));
  7828. }
  7829. static ReservedRange get() {
  7830. const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(&m);
  7831. return ReservedRange(m, &m);
  7832. }
  7833. };
  7834. };
  7835. class EnumDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7836. public:
  7837. EnumDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7838. : reffed_ptr(m, ref_donor) {
  7839. UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m));
  7840. }
  7841. static EnumDescriptorProto get() {
  7842. const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get(&m);
  7843. return EnumDescriptorProto(m, &m);
  7844. }
  7845. };
  7846. class EnumOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7847. public:
  7848. EnumOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7849. : reffed_ptr(m, ref_donor) {
  7850. UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m));
  7851. }
  7852. static EnumOptions get() {
  7853. const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
  7854. return EnumOptions(m, &m);
  7855. }
  7856. };
  7857. class EnumValueDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7858. public:
  7859. EnumValueDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7860. : reffed_ptr(m, ref_donor) {
  7861. UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m));
  7862. }
  7863. static EnumValueDescriptorProto get() {
  7864. const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProto_get(&m);
  7865. return EnumValueDescriptorProto(m, &m);
  7866. }
  7867. };
  7868. class EnumValueOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7869. public:
  7870. EnumValueOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7871. : reffed_ptr(m, ref_donor) {
  7872. UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m));
  7873. }
  7874. static EnumValueOptions get() {
  7875. const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m);
  7876. return EnumValueOptions(m, &m);
  7877. }
  7878. };
  7879. class FieldDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7880. public:
  7881. FieldDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7882. : reffed_ptr(m, ref_donor) {
  7883. UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m));
  7884. }
  7885. static FieldDescriptorProto get() {
  7886. const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_get(&m);
  7887. return FieldDescriptorProto(m, &m);
  7888. }
  7889. class Label : public ::upb::reffed_ptr<const ::upb::EnumDef> {
  7890. public:
  7891. Label(const ::upb::EnumDef* e, const void *ref_donor = NULL)
  7892. : reffed_ptr(e, ref_donor) {
  7893. UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Label_is(e));
  7894. }
  7895. static Label get() {
  7896. const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Label_get(&e);
  7897. return Label(e, &e);
  7898. }
  7899. };
  7900. class Type : public ::upb::reffed_ptr<const ::upb::EnumDef> {
  7901. public:
  7902. Type(const ::upb::EnumDef* e, const void *ref_donor = NULL)
  7903. : reffed_ptr(e, ref_donor) {
  7904. UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Type_is(e));
  7905. }
  7906. static Type get() {
  7907. const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Type_get(&e);
  7908. return Type(e, &e);
  7909. }
  7910. };
  7911. };
  7912. class FieldOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7913. public:
  7914. FieldOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7915. : reffed_ptr(m, ref_donor) {
  7916. UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m));
  7917. }
  7918. static FieldOptions get() {
  7919. const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
  7920. return FieldOptions(m, &m);
  7921. }
  7922. class CType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
  7923. public:
  7924. CType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
  7925. : reffed_ptr(e, ref_donor) {
  7926. UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_CType_is(e));
  7927. }
  7928. static CType get() {
  7929. const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(&e);
  7930. return CType(e, &e);
  7931. }
  7932. };
  7933. class JSType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
  7934. public:
  7935. JSType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
  7936. : reffed_ptr(e, ref_donor) {
  7937. UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_JSType_is(e));
  7938. }
  7939. static JSType get() {
  7940. const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get(&e);
  7941. return JSType(e, &e);
  7942. }
  7943. };
  7944. };
  7945. class FileDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7946. public:
  7947. FileDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7948. : reffed_ptr(m, ref_donor) {
  7949. UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m));
  7950. }
  7951. static FileDescriptorProto get() {
  7952. const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get(&m);
  7953. return FileDescriptorProto(m, &m);
  7954. }
  7955. };
  7956. class FileDescriptorSet : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7957. public:
  7958. FileDescriptorSet(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7959. : reffed_ptr(m, ref_donor) {
  7960. UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m));
  7961. }
  7962. static FileDescriptorSet get() {
  7963. const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
  7964. return FileDescriptorSet(m, &m);
  7965. }
  7966. };
  7967. class FileOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7968. public:
  7969. FileOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7970. : reffed_ptr(m, ref_donor) {
  7971. UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m));
  7972. }
  7973. static FileOptions get() {
  7974. const ::upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
  7975. return FileOptions(m, &m);
  7976. }
  7977. class OptimizeMode : public ::upb::reffed_ptr<const ::upb::EnumDef> {
  7978. public:
  7979. OptimizeMode(const ::upb::EnumDef* e, const void *ref_donor = NULL)
  7980. : reffed_ptr(e, ref_donor) {
  7981. UPB_ASSERT(upbdefs_google_protobuf_FileOptions_OptimizeMode_is(e));
  7982. }
  7983. static OptimizeMode get() {
  7984. const ::upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode_get(&e);
  7985. return OptimizeMode(e, &e);
  7986. }
  7987. };
  7988. };
  7989. class MessageOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  7990. public:
  7991. MessageOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  7992. : reffed_ptr(m, ref_donor) {
  7993. UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m));
  7994. }
  7995. static MessageOptions get() {
  7996. const ::upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
  7997. return MessageOptions(m, &m);
  7998. }
  7999. };
  8000. class MethodDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8001. public:
  8002. MethodDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8003. : reffed_ptr(m, ref_donor) {
  8004. UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m));
  8005. }
  8006. static MethodDescriptorProto get() {
  8007. const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_get(&m);
  8008. return MethodDescriptorProto(m, &m);
  8009. }
  8010. };
  8011. class MethodOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8012. public:
  8013. MethodOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8014. : reffed_ptr(m, ref_donor) {
  8015. UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m));
  8016. }
  8017. static MethodOptions get() {
  8018. const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
  8019. return MethodOptions(m, &m);
  8020. }
  8021. };
  8022. class OneofDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8023. public:
  8024. OneofDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8025. : reffed_ptr(m, ref_donor) {
  8026. UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m));
  8027. }
  8028. static OneofDescriptorProto get() {
  8029. const ::upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_get(&m);
  8030. return OneofDescriptorProto(m, &m);
  8031. }
  8032. };
  8033. class ServiceDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8034. public:
  8035. ServiceDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8036. : reffed_ptr(m, ref_donor) {
  8037. UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m));
  8038. }
  8039. static ServiceDescriptorProto get() {
  8040. const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_get(&m);
  8041. return ServiceDescriptorProto(m, &m);
  8042. }
  8043. };
  8044. class ServiceOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8045. public:
  8046. ServiceOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8047. : reffed_ptr(m, ref_donor) {
  8048. UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m));
  8049. }
  8050. static ServiceOptions get() {
  8051. const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
  8052. return ServiceOptions(m, &m);
  8053. }
  8054. };
  8055. class SourceCodeInfo : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8056. public:
  8057. SourceCodeInfo(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8058. : reffed_ptr(m, ref_donor) {
  8059. UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m));
  8060. }
  8061. static SourceCodeInfo get() {
  8062. const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
  8063. return SourceCodeInfo(m, &m);
  8064. }
  8065. class Location : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8066. public:
  8067. Location(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8068. : reffed_ptr(m, ref_donor) {
  8069. UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m));
  8070. }
  8071. static Location get() {
  8072. const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Location_get(&m);
  8073. return Location(m, &m);
  8074. }
  8075. };
  8076. };
  8077. class UninterpretedOption : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8078. public:
  8079. UninterpretedOption(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8080. : reffed_ptr(m, ref_donor) {
  8081. UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m));
  8082. }
  8083. static UninterpretedOption get() {
  8084. const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get(&m);
  8085. return UninterpretedOption(m, &m);
  8086. }
  8087. class NamePart : public ::upb::reffed_ptr<const ::upb::MessageDef> {
  8088. public:
  8089. NamePart(const ::upb::MessageDef* m, const void *ref_donor = NULL)
  8090. : reffed_ptr(m, ref_donor) {
  8091. UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m));
  8092. }
  8093. static NamePart get() {
  8094. const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_NamePart_get(&m);
  8095. return NamePart(m, &m);
  8096. }
  8097. };
  8098. };
  8099. } /* namespace protobuf */
  8100. } /* namespace google */
  8101. } /* namespace upbdefs */
  8102. #endif /* __cplusplus */
  8103. #endif /* UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ */
  8104. /*
  8105. ** Internal-only definitions for the decoder.
  8106. */
  8107. #ifndef UPB_DECODER_INT_H_
  8108. #define UPB_DECODER_INT_H_
  8109. /*
  8110. ** upb::pb::Decoder
  8111. **
  8112. ** A high performance, streaming, resumable decoder for the binary protobuf
  8113. ** format.
  8114. **
  8115. ** This interface works the same regardless of what decoder backend is being
  8116. ** used. A client of this class does not need to know whether decoding is using
  8117. ** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default,
  8118. ** it will always use the fastest available decoder. However, you can call
  8119. ** set_allow_jit(false) to disable any JIT decoder that might be available.
  8120. ** This is primarily useful for testing purposes.
  8121. */
  8122. #ifndef UPB_DECODER_H_
  8123. #define UPB_DECODER_H_
  8124. #ifdef __cplusplus
  8125. namespace upb {
  8126. namespace pb {
  8127. class CodeCache;
  8128. class Decoder;
  8129. class DecoderMethod;
  8130. class DecoderMethodOptions;
  8131. } /* namespace pb */
  8132. } /* namespace upb */
  8133. #endif
  8134. UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
  8135. UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
  8136. UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
  8137. UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
  8138. upb_pbdecodermethod, upb_refcounted)
  8139. /* The maximum number of bytes we are required to buffer internally between
  8140. * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
  8141. * varint, less one because we are buffering an incomplete value.
  8142. *
  8143. * Should only be used by unit tests. */
  8144. #define UPB_DECODER_MAX_RESIDUAL_BYTES 14
  8145. #ifdef __cplusplus
  8146. /* The parameters one uses to construct a DecoderMethod.
  8147. * TODO(haberman): move allowjit here? Seems more convenient for users.
  8148. * TODO(haberman): move this to be heap allocated for ABI stability. */
  8149. class upb::pb::DecoderMethodOptions {
  8150. public:
  8151. /* Parameter represents the destination handlers that this method will push
  8152. * to. */
  8153. explicit DecoderMethodOptions(const Handlers* dest_handlers);
  8154. /* Should the decoder push submessages to lazy handlers for fields that have
  8155. * them? The caller should set this iff the lazy handlers expect data that is
  8156. * in protobuf binary format and the caller wishes to lazy parse it. */
  8157. void set_lazy(bool lazy);
  8158. #else
  8159. struct upb_pbdecodermethodopts {
  8160. #endif
  8161. const upb_handlers *handlers;
  8162. bool lazy;
  8163. };
  8164. #ifdef __cplusplus
  8165. /* Represents the code to parse a protobuf according to a destination
  8166. * Handlers. */
  8167. class upb::pb::DecoderMethod {
  8168. public:
  8169. /* Include base methods from upb::ReferenceCounted. */
  8170. UPB_REFCOUNTED_CPPMETHODS
  8171. /* The destination handlers that are statically bound to this method.
  8172. * This method is only capable of outputting to a sink that uses these
  8173. * handlers. */
  8174. const Handlers* dest_handlers() const;
  8175. /* The input handlers for this decoder method. */
  8176. const BytesHandler* input_handler() const;
  8177. /* Whether this method is native. */
  8178. bool is_native() const;
  8179. /* Convenience method for generating a DecoderMethod without explicitly
  8180. * creating a CodeCache. */
  8181. static reffed_ptr<const DecoderMethod> New(const DecoderMethodOptions& opts);
  8182. private:
  8183. UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
  8184. };
  8185. #endif
  8186. /* Preallocation hint: decoder won't allocate more bytes than this when first
  8187. * constructed. This hint may be an overestimate for some build configurations.
  8188. * But if the decoder library is upgraded without recompiling the application,
  8189. * it may be an underestimate. */
  8190. #define UPB_PB_DECODER_SIZE 4416
  8191. #ifdef __cplusplus
  8192. /* A Decoder receives binary protobuf data on its input sink and pushes the
  8193. * decoded data to its output sink. */
  8194. class upb::pb::Decoder {
  8195. public:
  8196. /* Constructs a decoder instance for the given method, which must outlive this
  8197. * decoder. Any errors during parsing will be set on the given status, which
  8198. * must also outlive this decoder.
  8199. *
  8200. * The sink must match the given method. */
  8201. static Decoder* Create(Environment* env, const DecoderMethod* method,
  8202. Sink* output);
  8203. /* Returns the DecoderMethod this decoder is parsing from. */
  8204. const DecoderMethod* method() const;
  8205. /* The sink on which this decoder receives input. */
  8206. BytesSink* input();
  8207. /* Returns number of bytes successfully parsed.
  8208. *
  8209. * This can be useful for determining the stream position where an error
  8210. * occurred.
  8211. *
  8212. * This value may not be up-to-date when called from inside a parsing
  8213. * callback. */
  8214. uint64_t BytesParsed() const;
  8215. /* Gets/sets the parsing nexting limit. If the total number of nested
  8216. * submessages and repeated fields hits this limit, parsing will fail. This
  8217. * is a resource limit that controls the amount of memory used by the parsing
  8218. * stack.
  8219. *
  8220. * Setting the limit will fail if the parser is currently suspended at a depth
  8221. * greater than this, or if memory allocation of the stack fails. */
  8222. size_t max_nesting() const;
  8223. bool set_max_nesting(size_t max);
  8224. void Reset();
  8225. static const size_t kSize = UPB_PB_DECODER_SIZE;
  8226. private:
  8227. UPB_DISALLOW_POD_OPS(Decoder, upb::pb::Decoder)
  8228. };
  8229. #endif /* __cplusplus */
  8230. #ifdef __cplusplus
  8231. /* A class for caching protobuf processing code, whether bytecode for the
  8232. * interpreted decoder or machine code for the JIT.
  8233. *
  8234. * This class is not thread-safe.
  8235. *
  8236. * TODO(haberman): move this to be heap allocated for ABI stability. */
  8237. class upb::pb::CodeCache {
  8238. public:
  8239. CodeCache();
  8240. ~CodeCache();
  8241. /* Whether the cache is allowed to generate machine code. Defaults to true.
  8242. * There is no real reason to turn it off except for testing or if you are
  8243. * having a specific problem with the JIT.
  8244. *
  8245. * Note that allow_jit = true does not *guarantee* that the code will be JIT
  8246. * compiled. If this platform is not supported or the JIT was not compiled
  8247. * in, the code may still be interpreted. */
  8248. bool allow_jit() const;
  8249. /* This may only be called when the object is first constructed, and prior to
  8250. * any code generation, otherwise returns false and does nothing. */
  8251. bool set_allow_jit(bool allow);
  8252. /* Returns a DecoderMethod that can push data to the given handlers.
  8253. * If a suitable method already exists, it will be returned from the cache.
  8254. *
  8255. * Specifying the destination handlers here allows the DecoderMethod to be
  8256. * statically bound to the destination handlers if possible, which can allow
  8257. * more efficient decoding. However the returned method may or may not
  8258. * actually be statically bound. But in all cases, the returned method can
  8259. * push data to the given handlers. */
  8260. const DecoderMethod *GetDecoderMethod(const DecoderMethodOptions& opts);
  8261. /* If/when someone needs to explicitly create a dynamically-bound
  8262. * DecoderMethod*, we can add a method to get it here. */
  8263. private:
  8264. UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache)
  8265. #else
  8266. struct upb_pbcodecache {
  8267. #endif
  8268. bool allow_jit_;
  8269. /* Array of mgroups. */
  8270. upb_inttable groups;
  8271. };
  8272. UPB_BEGIN_EXTERN_C
  8273. upb_pbdecoder *upb_pbdecoder_create(upb_env *e,
  8274. const upb_pbdecodermethod *method,
  8275. upb_sink *output);
  8276. const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
  8277. upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d);
  8278. uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
  8279. size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
  8280. bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
  8281. void upb_pbdecoder_reset(upb_pbdecoder *d);
  8282. void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
  8283. const upb_handlers *h);
  8284. void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy);
  8285. /* Include refcounted methods like upb_pbdecodermethod_ref(). */
  8286. UPB_REFCOUNTED_CMETHODS(upb_pbdecodermethod, upb_pbdecodermethod_upcast)
  8287. const upb_handlers *upb_pbdecodermethod_desthandlers(
  8288. const upb_pbdecodermethod *m);
  8289. const upb_byteshandler *upb_pbdecodermethod_inputhandler(
  8290. const upb_pbdecodermethod *m);
  8291. bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
  8292. const upb_pbdecodermethod *upb_pbdecodermethod_new(
  8293. const upb_pbdecodermethodopts *opts, const void *owner);
  8294. void upb_pbcodecache_init(upb_pbcodecache *c);
  8295. void upb_pbcodecache_uninit(upb_pbcodecache *c);
  8296. bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
  8297. bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
  8298. const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
  8299. upb_pbcodecache *c, const upb_pbdecodermethodopts *opts);
  8300. UPB_END_EXTERN_C
  8301. #ifdef __cplusplus
  8302. namespace upb {
  8303. namespace pb {
  8304. /* static */
  8305. inline Decoder* Decoder::Create(Environment* env, const DecoderMethod* m,
  8306. Sink* sink) {
  8307. return upb_pbdecoder_create(env, m, sink);
  8308. }
  8309. inline const DecoderMethod* Decoder::method() const {
  8310. return upb_pbdecoder_method(this);
  8311. }
  8312. inline BytesSink* Decoder::input() {
  8313. return upb_pbdecoder_input(this);
  8314. }
  8315. inline uint64_t Decoder::BytesParsed() const {
  8316. return upb_pbdecoder_bytesparsed(this);
  8317. }
  8318. inline size_t Decoder::max_nesting() const {
  8319. return upb_pbdecoder_maxnesting(this);
  8320. }
  8321. inline bool Decoder::set_max_nesting(size_t max) {
  8322. return upb_pbdecoder_setmaxnesting(this, max);
  8323. }
  8324. inline void Decoder::Reset() { upb_pbdecoder_reset(this); }
  8325. inline DecoderMethodOptions::DecoderMethodOptions(const Handlers* h) {
  8326. upb_pbdecodermethodopts_init(this, h);
  8327. }
  8328. inline void DecoderMethodOptions::set_lazy(bool lazy) {
  8329. upb_pbdecodermethodopts_setlazy(this, lazy);
  8330. }
  8331. inline const Handlers* DecoderMethod::dest_handlers() const {
  8332. return upb_pbdecodermethod_desthandlers(this);
  8333. }
  8334. inline const BytesHandler* DecoderMethod::input_handler() const {
  8335. return upb_pbdecodermethod_inputhandler(this);
  8336. }
  8337. inline bool DecoderMethod::is_native() const {
  8338. return upb_pbdecodermethod_isnative(this);
  8339. }
  8340. /* static */
  8341. inline reffed_ptr<const DecoderMethod> DecoderMethod::New(
  8342. const DecoderMethodOptions &opts) {
  8343. const upb_pbdecodermethod *m = upb_pbdecodermethod_new(&opts, &m);
  8344. return reffed_ptr<const DecoderMethod>(m, &m);
  8345. }
  8346. inline CodeCache::CodeCache() {
  8347. upb_pbcodecache_init(this);
  8348. }
  8349. inline CodeCache::~CodeCache() {
  8350. upb_pbcodecache_uninit(this);
  8351. }
  8352. inline bool CodeCache::allow_jit() const {
  8353. return upb_pbcodecache_allowjit(this);
  8354. }
  8355. inline bool CodeCache::set_allow_jit(bool allow) {
  8356. return upb_pbcodecache_setallowjit(this, allow);
  8357. }
  8358. inline const DecoderMethod *CodeCache::GetDecoderMethod(
  8359. const DecoderMethodOptions& opts) {
  8360. return upb_pbcodecache_getdecodermethod(this, &opts);
  8361. }
  8362. } /* namespace pb */
  8363. } /* namespace upb */
  8364. #endif /* __cplusplus */
  8365. #endif /* UPB_DECODER_H_ */
  8366. #ifndef __cplusplus
  8367. UPB_DECLARE_DERIVED_TYPE(upb::pb::MessageGroup, upb::RefCounted,
  8368. mgroup, upb_refcounted)
  8369. /* Opcode definitions. The canonical meaning of each opcode is its
  8370. * implementation in the interpreter (the JIT is written to match this).
  8371. *
  8372. * All instructions have the opcode in the low byte.
  8373. * Instruction format for most instructions is:
  8374. *
  8375. * +-------------------+--------+
  8376. * | arg (24) | op (8) |
  8377. * +-------------------+--------+
  8378. *
  8379. * Exceptions are indicated below. A few opcodes are multi-word. */
  8380. typedef enum {
  8381. /* Opcodes 1-8, 13, 15-18 parse their respective descriptor types.
  8382. * Arg for all of these is the upb selector for this field. */
  8383. #define T(type) OP_PARSE_ ## type = UPB_DESCRIPTOR_TYPE_ ## type
  8384. T(DOUBLE), T(FLOAT), T(INT64), T(UINT64), T(INT32), T(FIXED64), T(FIXED32),
  8385. T(BOOL), T(UINT32), T(SFIXED32), T(SFIXED64), T(SINT32), T(SINT64),
  8386. #undef T
  8387. OP_STARTMSG = 9, /* No arg. */
  8388. OP_ENDMSG = 10, /* No arg. */
  8389. OP_STARTSEQ = 11,
  8390. OP_ENDSEQ = 12,
  8391. OP_STARTSUBMSG = 14,
  8392. OP_ENDSUBMSG = 19,
  8393. OP_STARTSTR = 20,
  8394. OP_STRING = 21,
  8395. OP_ENDSTR = 22,
  8396. OP_PUSHTAGDELIM = 23, /* No arg. */
  8397. OP_PUSHLENDELIM = 24, /* No arg. */
  8398. OP_POP = 25, /* No arg. */
  8399. OP_SETDELIM = 26, /* No arg. */
  8400. OP_SETBIGGROUPNUM = 27, /* two words:
  8401. * | unused (24) | opc (8) |
  8402. * | groupnum (32) | */
  8403. OP_CHECKDELIM = 28,
  8404. OP_CALL = 29,
  8405. OP_RET = 30,
  8406. OP_BRANCH = 31,
  8407. /* Different opcodes depending on how many bytes expected. */
  8408. OP_TAG1 = 32, /* | match tag (16) | jump target (8) | opc (8) | */
  8409. OP_TAG2 = 33, /* | match tag (16) | jump target (8) | opc (8) | */
  8410. OP_TAGN = 34, /* three words: */
  8411. /* | unused (16) | jump target(8) | opc (8) | */
  8412. /* | match tag 1 (32) | */
  8413. /* | match tag 2 (32) | */
  8414. OP_SETDISPATCH = 35, /* N words: */
  8415. /* | unused (24) | opc | */
  8416. /* | upb_inttable* (32 or 64) | */
  8417. OP_DISPATCH = 36, /* No arg. */
  8418. OP_HALT = 37 /* No arg. */
  8419. } opcode;
  8420. #define OP_MAX OP_HALT
  8421. UPB_INLINE opcode getop(uint32_t instr) { return (opcode)(instr & 0xff); }
  8422. /* Method group; represents a set of decoder methods that had their code
  8423. * emitted together, and must therefore be freed together. Immutable once
  8424. * created. It is possible we may want to expose this to users at some point.
  8425. *
  8426. * Overall ownership of Decoder objects looks like this:
  8427. *
  8428. * +----------+
  8429. * | | <---> DecoderMethod
  8430. * | method |
  8431. * CodeCache ---> | group | <---> DecoderMethod
  8432. * | |
  8433. * | (mgroup) | <---> DecoderMethod
  8434. * +----------+
  8435. */
  8436. struct mgroup {
  8437. upb_refcounted base;
  8438. /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. We own refs on the
  8439. * methods. */
  8440. upb_inttable methods;
  8441. /* When we add the ability to link to previously existing mgroups, we'll
  8442. * need an array of mgroups we reference here, and own refs on them. */
  8443. /* The bytecode for our methods, if any exists. Owned by us. */
  8444. uint32_t *bytecode;
  8445. uint32_t *bytecode_end;
  8446. #ifdef UPB_USE_JIT_X64
  8447. /* JIT-generated machine code, if any. */
  8448. upb_string_handlerfunc *jit_code;
  8449. /* The size of the jit_code (required to munmap()). */
  8450. size_t jit_size;
  8451. char *debug_info;
  8452. void *dl;
  8453. #endif
  8454. };
  8455. /* The maximum that any submessages can be nested. Matches proto2's limit.
  8456. * This specifies the size of the decoder's statically-sized array and therefore
  8457. * setting it high will cause the upb::pb::Decoder object to be larger.
  8458. *
  8459. * If necessary we can add a runtime-settable property to Decoder that allow
  8460. * this to be larger than the compile-time setting, but this would add
  8461. * complexity, particularly since we would have to decide how/if to give users
  8462. * the ability to set a custom memory allocation function. */
  8463. #define UPB_DECODER_MAX_NESTING 64
  8464. /* Internal-only struct used by the decoder. */
  8465. typedef struct {
  8466. /* Space optimization note: we store two pointers here that the JIT
  8467. * doesn't need at all; the upb_handlers* inside the sink and
  8468. * the dispatch table pointer. We can optimze so that the JIT uses
  8469. * smaller stack frames than the interpreter. The only thing we need
  8470. * to guarantee is that the fallback routines can find end_ofs. */
  8471. upb_sink sink;
  8472. /* The absolute stream offset of the end-of-frame delimiter.
  8473. * Non-delimited frames (groups and non-packed repeated fields) reuse the
  8474. * delimiter of their parent, even though the frame may not end there.
  8475. *
  8476. * NOTE: the JIT stores a slightly different value here for non-top frames.
  8477. * It stores the value relative to the end of the enclosed message. But the
  8478. * top frame is still stored the same way, which is important for ensuring
  8479. * that calls from the JIT into C work correctly. */
  8480. uint64_t end_ofs;
  8481. const uint32_t *base;
  8482. /* 0 indicates a length-delimited field.
  8483. * A positive number indicates a known group.
  8484. * A negative number indicates an unknown group. */
  8485. int32_t groupnum;
  8486. upb_inttable *dispatch; /* Not used by the JIT. */
  8487. } upb_pbdecoder_frame;
  8488. struct upb_pbdecodermethod {
  8489. upb_refcounted base;
  8490. /* While compiling, the base is relative in "ofs", after compiling it is
  8491. * absolute in "ptr". */
  8492. union {
  8493. uint32_t ofs; /* PC offset of method. */
  8494. void *ptr; /* Pointer to bytecode or machine code for this method. */
  8495. } code_base;
  8496. /* The decoder method group to which this method belongs. We own a ref.
  8497. * Owning a ref on the entire group is more coarse-grained than is strictly
  8498. * necessary; all we truly require is that methods we directly reference
  8499. * outlive us, while the group could contain many other messages we don't
  8500. * require. But the group represents the messages that were
  8501. * allocated+compiled together, so it makes the most sense to free them
  8502. * together also. */
  8503. const upb_refcounted *group;
  8504. /* Whether this method is native code or bytecode. */
  8505. bool is_native_;
  8506. /* The handler one calls to invoke this method. */
  8507. upb_byteshandler input_handler_;
  8508. /* The destination handlers this method is bound to. We own a ref. */
  8509. const upb_handlers *dest_handlers_;
  8510. /* Dispatch table -- used by both bytecode decoder and JIT when encountering a
  8511. * field number that wasn't the one we were expecting to see. See
  8512. * decoder.int.h for the layout of this table. */
  8513. upb_inttable dispatch;
  8514. };
  8515. struct upb_pbdecoder {
  8516. upb_env *env;
  8517. /* Our input sink. */
  8518. upb_bytessink input_;
  8519. /* The decoder method we are parsing with (owned). */
  8520. const upb_pbdecodermethod *method_;
  8521. size_t call_len;
  8522. const uint32_t *pc, *last;
  8523. /* Current input buffer and its stream offset. */
  8524. const char *buf, *ptr, *end, *checkpoint;
  8525. /* End of the delimited region, relative to ptr, NULL if not in this buf. */
  8526. const char *delim_end;
  8527. /* End of the delimited region, relative to ptr, end if not in this buf. */
  8528. const char *data_end;
  8529. /* Overall stream offset of "buf." */
  8530. uint64_t bufstart_ofs;
  8531. /* Buffer for residual bytes not parsed from the previous buffer. */
  8532. char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
  8533. char *residual_end;
  8534. /* Bytes of data that should be discarded from the input beore we start
  8535. * parsing again. We set this when we internally determine that we can
  8536. * safely skip the next N bytes, but this region extends past the current
  8537. * user buffer. */
  8538. size_t skip;
  8539. /* Stores the user buffer passed to our decode function. */
  8540. const char *buf_param;
  8541. size_t size_param;
  8542. const upb_bufhandle *handle;
  8543. /* Our internal stack. */
  8544. upb_pbdecoder_frame *stack, *top, *limit;
  8545. const uint32_t **callstack;
  8546. size_t stack_size;
  8547. upb_status *status;
  8548. #ifdef UPB_USE_JIT_X64
  8549. /* Used momentarily by the generated code to store a value while a user
  8550. * function is called. */
  8551. uint32_t tmp_len;
  8552. const void *saved_rsp;
  8553. #endif
  8554. };
  8555. /* Decoder entry points; used as handlers. */
  8556. void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint);
  8557. void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint);
  8558. size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
  8559. size_t size, const upb_bufhandle *handle);
  8560. bool upb_pbdecoder_end(void *closure, const void *handler_data);
  8561. /* Decoder-internal functions that the JIT calls to handle fallback paths. */
  8562. int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
  8563. size_t size, const upb_bufhandle *handle);
  8564. size_t upb_pbdecoder_suspend(upb_pbdecoder *d);
  8565. int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
  8566. uint8_t wire_type);
  8567. int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, uint64_t expected);
  8568. int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, uint64_t *u64);
  8569. int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32);
  8570. int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64);
  8571. void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg);
  8572. /* Error messages that are shared between the bytecode and JIT decoders. */
  8573. extern const char *kPbDecoderStackOverflow;
  8574. extern const char *kPbDecoderSubmessageTooLong;
  8575. /* Access to decoderplan members needed by the decoder. */
  8576. const char *upb_pbdecoder_getopname(unsigned int op);
  8577. /* JIT codegen entry point. */
  8578. void upb_pbdecoder_jit(mgroup *group);
  8579. void upb_pbdecoder_freejit(mgroup *group);
  8580. UPB_REFCOUNTED_CMETHODS(mgroup, mgroup_upcast)
  8581. /* A special label that means "do field dispatch for this message and branch to
  8582. * wherever that takes you." */
  8583. #define LABEL_DISPATCH 0
  8584. /* A special slot in the dispatch table that stores the epilogue (ENDMSG and/or
  8585. * RET) for branching to when we find an appropriate ENDGROUP tag. */
  8586. #define DISPATCH_ENDMSG 0
  8587. /* It's important to use this invalid wire type instead of 0 (which is a valid
  8588. * wire type). */
  8589. #define NO_WIRE_TYPE 0xff
  8590. /* The dispatch table layout is:
  8591. * [field number] -> [ 48-bit offset ][ 8-bit wt2 ][ 8-bit wt1 ]
  8592. *
  8593. * If wt1 matches, jump to the 48-bit offset. If wt2 matches, lookup
  8594. * (UPB_MAX_FIELDNUMBER + fieldnum) and jump there.
  8595. *
  8596. * We need two wire types because of packed/non-packed compatibility. A
  8597. * primitive repeated field can use either wire type and be valid. While we
  8598. * could key the table on fieldnum+wiretype, the table would be 8x sparser.
  8599. *
  8600. * Storing two wire types in the primary value allows us to quickly rule out
  8601. * the second wire type without needing to do a separate lookup (this case is
  8602. * less common than an unknown field). */
  8603. UPB_INLINE uint64_t upb_pbdecoder_packdispatch(uint64_t ofs, uint8_t wt1,
  8604. uint8_t wt2) {
  8605. return (ofs << 16) | (wt2 << 8) | wt1;
  8606. }
  8607. UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
  8608. uint8_t *wt1, uint8_t *wt2) {
  8609. *wt1 = (uint8_t)dispatch;
  8610. *wt2 = (uint8_t)(dispatch >> 8);
  8611. *ofs = dispatch >> 16;
  8612. }
  8613. /* All of the functions in decoder.c that return int32_t return values according
  8614. * to the following scheme:
  8615. * 1. negative values indicate a return code from the following list.
  8616. * 2. positive values indicate that error or end of buffer was hit, and
  8617. * that the decode function should immediately return the given value
  8618. * (the decoder state has already been suspended and is ready to be
  8619. * resumed). */
  8620. #define DECODE_OK -1
  8621. #define DECODE_MISMATCH -2 /* Used only from checktag_slow(). */
  8622. #define DECODE_ENDGROUP -3 /* Used only from checkunknown(). */
  8623. #define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
  8624. #endif /* __cplusplus */
  8625. #endif /* UPB_DECODER_INT_H_ */
  8626. /*
  8627. ** A number of routines for varint manipulation (we keep them all around to
  8628. ** have multiple approaches available for benchmarking).
  8629. */
  8630. #ifndef UPB_VARINT_DECODER_H_
  8631. #define UPB_VARINT_DECODER_H_
  8632. #include <assert.h>
  8633. #include <stdint.h>
  8634. #include <string.h>
  8635. #ifdef __cplusplus
  8636. extern "C" {
  8637. #endif
  8638. #define UPB_MAX_WIRE_TYPE 5
  8639. /* The maximum number of bytes that it takes to encode a 64-bit varint. */
  8640. #define UPB_PB_VARINT_MAX_LEN 10
  8641. /* Array of the "native" (ie. non-packed-repeated) wire type for the given a
  8642. * descriptor type (upb_descriptortype_t). */
  8643. extern const uint8_t upb_pb_native_wire_types[];
  8644. /* Zig-zag encoding/decoding **************************************************/
  8645. UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
  8646. return (n >> 1) ^ -(int32_t)(n & 1);
  8647. }
  8648. UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
  8649. return (n >> 1) ^ -(int64_t)(n & 1);
  8650. }
  8651. UPB_INLINE uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); }
  8652. UPB_INLINE uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); }
  8653. /* Decoding *******************************************************************/
  8654. /* All decoding functions return this struct by value. */
  8655. typedef struct {
  8656. const char *p; /* NULL if the varint was unterminated. */
  8657. uint64_t val;
  8658. } upb_decoderet;
  8659. UPB_INLINE upb_decoderet upb_decoderet_make(const char *p, uint64_t val) {
  8660. upb_decoderet ret;
  8661. ret.p = p;
  8662. ret.val = val;
  8663. return ret;
  8664. }
  8665. upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r);
  8666. upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r);
  8667. /* Template for a function that checks the first two bytes with branching
  8668. * and dispatches 2-10 bytes with a separate function. Note that this may read
  8669. * up to 10 bytes, so it must not be used unless there are at least ten bytes
  8670. * left in the buffer! */
  8671. #define UPB_VARINT_DECODER_CHECK2(name, decode_max8_function) \
  8672. UPB_INLINE upb_decoderet upb_vdecode_check2_ ## name(const char *_p) { \
  8673. uint8_t *p = (uint8_t*)_p; \
  8674. upb_decoderet r; \
  8675. if ((*p & 0x80) == 0) { \
  8676. /* Common case: one-byte varint. */ \
  8677. return upb_decoderet_make(_p + 1, *p & 0x7fU); \
  8678. } \
  8679. r = upb_decoderet_make(_p + 2, (*p & 0x7fU) | ((*(p + 1) & 0x7fU) << 7)); \
  8680. if ((*(p + 1) & 0x80) == 0) { \
  8681. /* Two-byte varint. */ \
  8682. return r; \
  8683. } \
  8684. /* Longer varint, fallback to out-of-line function. */ \
  8685. return decode_max8_function(r); \
  8686. }
  8687. UPB_VARINT_DECODER_CHECK2(branch32, upb_vdecode_max8_branch32)
  8688. UPB_VARINT_DECODER_CHECK2(branch64, upb_vdecode_max8_branch64)
  8689. #undef UPB_VARINT_DECODER_CHECK2
  8690. /* Our canonical functions for decoding varints, based on the currently
  8691. * favored best-performing implementations. */
  8692. UPB_INLINE upb_decoderet upb_vdecode_fast(const char *p) {
  8693. if (sizeof(long) == 8)
  8694. return upb_vdecode_check2_branch64(p);
  8695. else
  8696. return upb_vdecode_check2_branch32(p);
  8697. }
  8698. /* Encoding *******************************************************************/
  8699. UPB_INLINE int upb_value_size(uint64_t val) {
  8700. #ifdef __GNUC__
  8701. int high_bit = 63 - __builtin_clzll(val); /* 0-based, undef if val == 0. */
  8702. #else
  8703. int high_bit = 0;
  8704. uint64_t tmp = val;
  8705. while(tmp >>= 1) high_bit++;
  8706. #endif
  8707. return val == 0 ? 1 : high_bit / 8 + 1;
  8708. }
  8709. /* Encodes a 64-bit varint into buf (which must be >=UPB_PB_VARINT_MAX_LEN
  8710. * bytes long), returning how many bytes were used.
  8711. *
  8712. * TODO: benchmark and optimize if necessary. */
  8713. UPB_INLINE size_t upb_vencode64(uint64_t val, char *buf) {
  8714. size_t i;
  8715. if (val == 0) { buf[0] = 0; return 1; }
  8716. i = 0;
  8717. while (val) {
  8718. uint8_t byte = val & 0x7fU;
  8719. val >>= 7;
  8720. if (val) byte |= 0x80U;
  8721. buf[i++] = byte;
  8722. }
  8723. return i;
  8724. }
  8725. UPB_INLINE size_t upb_varint_size(uint64_t val) {
  8726. char buf[UPB_PB_VARINT_MAX_LEN];
  8727. return upb_vencode64(val, buf);
  8728. }
  8729. /* Encodes a 32-bit varint, *not* sign-extended. */
  8730. UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
  8731. char buf[UPB_PB_VARINT_MAX_LEN];
  8732. size_t bytes = upb_vencode64(val, buf);
  8733. uint64_t ret = 0;
  8734. UPB_ASSERT(bytes <= 5);
  8735. memcpy(&ret, buf, bytes);
  8736. UPB_ASSERT(ret <= 0xffffffffffU);
  8737. return ret;
  8738. }
  8739. #ifdef __cplusplus
  8740. } /* extern "C" */
  8741. #endif
  8742. #endif /* UPB_VARINT_DECODER_H_ */
  8743. /*
  8744. ** upb::pb::Encoder (upb_pb_encoder)
  8745. **
  8746. ** Implements a set of upb_handlers that write protobuf data to the binary wire
  8747. ** format.
  8748. **
  8749. ** This encoder implementation does not have any access to any out-of-band or
  8750. ** precomputed lengths for submessages, so it must buffer submessages internally
  8751. ** before it can emit the first byte.
  8752. */
  8753. #ifndef UPB_ENCODER_H_
  8754. #define UPB_ENCODER_H_
  8755. #ifdef __cplusplus
  8756. namespace upb {
  8757. namespace pb {
  8758. class Encoder;
  8759. } /* namespace pb */
  8760. } /* namespace upb */
  8761. #endif
  8762. UPB_DECLARE_TYPE(upb::pb::Encoder, upb_pb_encoder)
  8763. #define UPB_PBENCODER_MAX_NESTING 100
  8764. /* upb::pb::Encoder ***********************************************************/
  8765. /* Preallocation hint: decoder won't allocate more bytes than this when first
  8766. * constructed. This hint may be an overestimate for some build configurations.
  8767. * But if the decoder library is upgraded without recompiling the application,
  8768. * it may be an underestimate. */
  8769. #define UPB_PB_ENCODER_SIZE 768
  8770. #ifdef __cplusplus
  8771. class upb::pb::Encoder {
  8772. public:
  8773. /* Creates a new encoder in the given environment. The Handlers must have
  8774. * come from NewHandlers() below. */
  8775. static Encoder* Create(Environment* env, const Handlers* handlers,
  8776. BytesSink* output);
  8777. /* The input to the encoder. */
  8778. Sink* input();
  8779. /* Creates a new set of handlers for this MessageDef. */
  8780. static reffed_ptr<const Handlers> NewHandlers(const MessageDef* msg);
  8781. static const size_t kSize = UPB_PB_ENCODER_SIZE;
  8782. private:
  8783. UPB_DISALLOW_POD_OPS(Encoder, upb::pb::Encoder)
  8784. };
  8785. #endif
  8786. UPB_BEGIN_EXTERN_C
  8787. const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
  8788. const void *owner);
  8789. upb_sink *upb_pb_encoder_input(upb_pb_encoder *p);
  8790. upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h,
  8791. upb_bytessink* output);
  8792. UPB_END_EXTERN_C
  8793. #ifdef __cplusplus
  8794. namespace upb {
  8795. namespace pb {
  8796. inline Encoder* Encoder::Create(Environment* env, const Handlers* handlers,
  8797. BytesSink* output) {
  8798. return upb_pb_encoder_create(env, handlers, output);
  8799. }
  8800. inline Sink* Encoder::input() {
  8801. return upb_pb_encoder_input(this);
  8802. }
  8803. inline reffed_ptr<const Handlers> Encoder::NewHandlers(
  8804. const upb::MessageDef *md) {
  8805. const Handlers* h = upb_pb_encoder_newhandlers(md, &h);
  8806. return reffed_ptr<const Handlers>(h, &h);
  8807. }
  8808. } /* namespace pb */
  8809. } /* namespace upb */
  8810. #endif
  8811. #endif /* UPB_ENCODER_H_ */
  8812. /*
  8813. ** upb's core components like upb_decoder and upb_msg are carefully designed to
  8814. ** avoid depending on each other for maximum orthogonality. In other words,
  8815. ** you can use a upb_decoder to decode into *any* kind of structure; upb_msg is
  8816. ** just one such structure. A upb_msg can be serialized/deserialized into any
  8817. ** format, protobuf binary format is just one such format.
  8818. **
  8819. ** However, for convenience we provide functions here for doing common
  8820. ** operations like deserializing protobuf binary format into a upb_msg. The
  8821. ** compromise is that this file drags in almost all of upb as a dependency,
  8822. ** which could be undesirable if you're trying to use a trimmed-down build of
  8823. ** upb.
  8824. **
  8825. ** While these routines are convenient, they do not reuse any encoding/decoding
  8826. ** state. For example, if a decoder is JIT-based, it will be re-JITted every
  8827. ** time these functions are called. For this reason, if you are parsing lots
  8828. ** of data and efficiency is an issue, these may not be the best functions to
  8829. ** use (though they are useful for prototyping, before optimizing).
  8830. */
  8831. #ifndef UPB_GLUE_H
  8832. #define UPB_GLUE_H
  8833. #include <stdbool.h>
  8834. #ifdef __cplusplus
  8835. #include <vector>
  8836. extern "C" {
  8837. #endif
  8838. /* Loads a binary descriptor and returns a NULL-terminated array of unfrozen
  8839. * filedefs. The caller owns the returned array, which must be freed with
  8840. * upb_gfree(). */
  8841. upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
  8842. upb_status *status);
  8843. #ifdef __cplusplus
  8844. } /* extern "C" */
  8845. namespace upb {
  8846. inline bool LoadDescriptor(const char* buf, size_t n, Status* status,
  8847. std::vector<reffed_ptr<FileDef> >* files) {
  8848. FileDef** parsed_files = upb_loaddescriptor(buf, n, &parsed_files, status);
  8849. if (parsed_files) {
  8850. FileDef** p = parsed_files;
  8851. while (*p) {
  8852. files->push_back(reffed_ptr<FileDef>(*p, &parsed_files));
  8853. ++p;
  8854. }
  8855. free(parsed_files);
  8856. return true;
  8857. } else {
  8858. return false;
  8859. }
  8860. }
  8861. /* Templated so it can accept both string and std::string. */
  8862. template <typename T>
  8863. bool LoadDescriptor(const T& desc, Status* status,
  8864. std::vector<reffed_ptr<FileDef> >* files) {
  8865. return LoadDescriptor(desc.c_str(), desc.size(), status, files);
  8866. }
  8867. } /* namespace upb */
  8868. #endif
  8869. #endif /* UPB_GLUE_H */
  8870. /*
  8871. ** upb::pb::TextPrinter (upb_textprinter)
  8872. **
  8873. ** Handlers for writing to protobuf text format.
  8874. */
  8875. #ifndef UPB_TEXT_H_
  8876. #define UPB_TEXT_H_
  8877. #ifdef __cplusplus
  8878. namespace upb {
  8879. namespace pb {
  8880. class TextPrinter;
  8881. } /* namespace pb */
  8882. } /* namespace upb */
  8883. #endif
  8884. UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter)
  8885. #ifdef __cplusplus
  8886. class upb::pb::TextPrinter {
  8887. public:
  8888. /* The given handlers must have come from NewHandlers(). It must outlive the
  8889. * TextPrinter. */
  8890. static TextPrinter *Create(Environment *env, const upb::Handlers *handlers,
  8891. BytesSink *output);
  8892. void SetSingleLineMode(bool single_line);
  8893. Sink* input();
  8894. /* If handler caching becomes a requirement we can add a code cache as in
  8895. * decoder.h */
  8896. static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md);
  8897. };
  8898. #endif
  8899. UPB_BEGIN_EXTERN_C
  8900. /* C API. */
  8901. upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
  8902. upb_bytessink *output);
  8903. void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
  8904. upb_sink *upb_textprinter_input(upb_textprinter *p);
  8905. const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
  8906. const void *owner);
  8907. UPB_END_EXTERN_C
  8908. #ifdef __cplusplus
  8909. namespace upb {
  8910. namespace pb {
  8911. inline TextPrinter *TextPrinter::Create(Environment *env,
  8912. const upb::Handlers *handlers,
  8913. BytesSink *output) {
  8914. return upb_textprinter_create(env, handlers, output);
  8915. }
  8916. inline void TextPrinter::SetSingleLineMode(bool single_line) {
  8917. upb_textprinter_setsingleline(this, single_line);
  8918. }
  8919. inline Sink* TextPrinter::input() {
  8920. return upb_textprinter_input(this);
  8921. }
  8922. inline reffed_ptr<const Handlers> TextPrinter::NewHandlers(
  8923. const MessageDef *md) {
  8924. const Handlers* h = upb_textprinter_newhandlers(md, &h);
  8925. return reffed_ptr<const Handlers>(h, &h);
  8926. }
  8927. } /* namespace pb */
  8928. } /* namespace upb */
  8929. #endif
  8930. #endif /* UPB_TEXT_H_ */
  8931. /*
  8932. ** upb::json::Parser (upb_json_parser)
  8933. **
  8934. ** Parses JSON according to a specific schema.
  8935. ** Support for parsing arbitrary JSON (schema-less) will be added later.
  8936. */
  8937. #ifndef UPB_JSON_PARSER_H_
  8938. #define UPB_JSON_PARSER_H_
  8939. #ifdef __cplusplus
  8940. namespace upb {
  8941. namespace json {
  8942. class Parser;
  8943. class ParserMethod;
  8944. } /* namespace json */
  8945. } /* namespace upb */
  8946. #endif
  8947. UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser)
  8948. UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted,
  8949. upb_json_parsermethod, upb_refcounted)
  8950. /* upb::json::Parser **********************************************************/
  8951. /* Preallocation hint: parser won't allocate more bytes than this when first
  8952. * constructed. This hint may be an overestimate for some build configurations.
  8953. * But if the parser library is upgraded without recompiling the application,
  8954. * it may be an underestimate. */
  8955. #define UPB_JSON_PARSER_SIZE 5712
  8956. #ifdef __cplusplus
  8957. /* Parses an incoming BytesStream, pushing the results to the destination
  8958. * sink. */
  8959. class upb::json::Parser {
  8960. public:
  8961. static Parser* Create(Environment* env, const ParserMethod* method,
  8962. const SymbolTable* symtab,
  8963. Sink* output, bool ignore_json_unknown);
  8964. BytesSink* input();
  8965. private:
  8966. UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser)
  8967. };
  8968. class upb::json::ParserMethod {
  8969. public:
  8970. /* Include base methods from upb::ReferenceCounted. */
  8971. UPB_REFCOUNTED_CPPMETHODS
  8972. /* Returns handlers for parsing according to the specified schema. */
  8973. static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md);
  8974. /* The destination handlers that are statically bound to this method.
  8975. * This method is only capable of outputting to a sink that uses these
  8976. * handlers. */
  8977. const Handlers* dest_handlers() const;
  8978. /* The input handlers for this decoder method. */
  8979. const BytesHandler* input_handler() const;
  8980. private:
  8981. UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod)
  8982. };
  8983. #endif
  8984. UPB_BEGIN_EXTERN_C
  8985. upb_json_parser* upb_json_parser_create(upb_env* e,
  8986. const upb_json_parsermethod* m,
  8987. const upb_symtab* symtab,
  8988. upb_sink* output,
  8989. bool ignore_json_unknown);
  8990. upb_bytessink *upb_json_parser_input(upb_json_parser *p);
  8991. upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md,
  8992. const void* owner);
  8993. const upb_handlers *upb_json_parsermethod_desthandlers(
  8994. const upb_json_parsermethod *m);
  8995. const upb_byteshandler *upb_json_parsermethod_inputhandler(
  8996. const upb_json_parsermethod *m);
  8997. /* Include refcounted methods like upb_json_parsermethod_ref(). */
  8998. UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast)
  8999. UPB_END_EXTERN_C
  9000. #ifdef __cplusplus
  9001. namespace upb {
  9002. namespace json {
  9003. inline Parser* Parser::Create(Environment* env, const ParserMethod* method,
  9004. const SymbolTable* symtab,
  9005. Sink* output, bool ignore_json_unknown) {
  9006. return upb_json_parser_create(
  9007. env, method, symtab, output, ignore_json_unknown);
  9008. }
  9009. inline BytesSink* Parser::input() {
  9010. return upb_json_parser_input(this);
  9011. }
  9012. inline const Handlers* ParserMethod::dest_handlers() const {
  9013. return upb_json_parsermethod_desthandlers(this);
  9014. }
  9015. inline const BytesHandler* ParserMethod::input_handler() const {
  9016. return upb_json_parsermethod_inputhandler(this);
  9017. }
  9018. /* static */
  9019. inline reffed_ptr<const ParserMethod> ParserMethod::New(
  9020. const MessageDef* md) {
  9021. const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m);
  9022. return reffed_ptr<const ParserMethod>(m, &m);
  9023. }
  9024. } /* namespace json */
  9025. } /* namespace upb */
  9026. #endif
  9027. #endif /* UPB_JSON_PARSER_H_ */
  9028. /*
  9029. ** upb::json::Printer
  9030. **
  9031. ** Handlers that emit JSON according to a specific protobuf schema.
  9032. */
  9033. #ifndef UPB_JSON_TYPED_PRINTER_H_
  9034. #define UPB_JSON_TYPED_PRINTER_H_
  9035. #ifdef __cplusplus
  9036. namespace upb {
  9037. namespace json {
  9038. class Printer;
  9039. } /* namespace json */
  9040. } /* namespace upb */
  9041. #endif
  9042. UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer)
  9043. /* upb::json::Printer *********************************************************/
  9044. #define UPB_JSON_PRINTER_SIZE 192
  9045. #ifdef __cplusplus
  9046. /* Prints an incoming stream of data to a BytesSink in JSON format. */
  9047. class upb::json::Printer {
  9048. public:
  9049. static Printer* Create(Environment* env, const upb::Handlers* handlers,
  9050. BytesSink* output);
  9051. /* The input to the printer. */
  9052. Sink* input();
  9053. /* Returns handlers for printing according to the specified schema.
  9054. * If preserve_proto_fieldnames is true, the output JSON will use the
  9055. * original .proto field names (ie. {"my_field":3}) instead of using
  9056. * camelCased names, which is the default: (eg. {"myField":3}). */
  9057. static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md,
  9058. bool preserve_proto_fieldnames);
  9059. static const size_t kSize = UPB_JSON_PRINTER_SIZE;
  9060. private:
  9061. UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer)
  9062. };
  9063. #endif
  9064. UPB_BEGIN_EXTERN_C
  9065. /* Native C API. */
  9066. upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
  9067. upb_bytessink *output);
  9068. upb_sink *upb_json_printer_input(upb_json_printer *p);
  9069. const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
  9070. bool preserve_fieldnames,
  9071. const void *owner);
  9072. UPB_END_EXTERN_C
  9073. #ifdef __cplusplus
  9074. namespace upb {
  9075. namespace json {
  9076. inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers,
  9077. BytesSink* output) {
  9078. return upb_json_printer_create(env, handlers, output);
  9079. }
  9080. inline Sink* Printer::input() { return upb_json_printer_input(this); }
  9081. inline reffed_ptr<const Handlers> Printer::NewHandlers(
  9082. const upb::MessageDef *md, bool preserve_proto_fieldnames) {
  9083. const Handlers* h = upb_json_printer_newhandlers(
  9084. md, preserve_proto_fieldnames, &h);
  9085. return reffed_ptr<const Handlers>(h, &h);
  9086. }
  9087. } /* namespace json */
  9088. } /* namespace upb */
  9089. #endif
  9090. #endif /* UPB_JSON_TYPED_PRINTER_H_ */
  9091. #undef UPB_SIZE
  9092. #undef UPB_FIELD_AT
  9093. #undef UPB_READ_ONEOF
  9094. #undef UPB_WRITE_ONEOF