upb.h 300 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777
  1. /* Amalgamated source file */
  2. #include <stdint.h>/*
  3. * This is where we define macros used across upb.
  4. *
  5. * All of these macros are undef'd in port_undef.inc to avoid leaking them to
  6. * users.
  7. *
  8. * The correct usage is:
  9. *
  10. * #include "upb/foobar.h"
  11. * #include "upb/baz.h"
  12. *
  13. * // MUST be last included header.
  14. * #include "upb/port_def.inc"
  15. *
  16. * // Code for this file.
  17. * // <...>
  18. *
  19. * // Can be omitted for .c files, required for .h.
  20. * #include "upb/port_undef.inc"
  21. *
  22. * This file is private and must not be included by users!
  23. */
  24. #include <stdint.h>
  25. #if UINTPTR_MAX == 0xffffffff
  26. #define UPB_SIZE(size32, size64) size32
  27. #else
  28. #define UPB_SIZE(size32, size64) size64
  29. #endif
  30. /* If we always read/write as a consistent type to each address, this shouldn't
  31. * violate aliasing.
  32. */
  33. #define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs)))
  34. #define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
  35. *UPB_PTR_AT(msg, case_offset, int) == case_val \
  36. ? *UPB_PTR_AT(msg, offset, fieldtype) \
  37. : default
  38. #define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
  39. *UPB_PTR_AT(msg, case_offset, int) = case_val; \
  40. *UPB_PTR_AT(msg, offset, fieldtype) = value;
  41. #define UPB_MAPTYPE_STRING 0
  42. /* UPB_INLINE: inline if possible, emit standalone code if required. */
  43. #ifdef __cplusplus
  44. #define UPB_INLINE inline
  45. #elif defined (__GNUC__) || defined(__clang__)
  46. #define UPB_INLINE static __inline__
  47. #else
  48. #define UPB_INLINE static
  49. #endif
  50. /* Hints to the compiler about likely/unlikely branches. */
  51. #if defined (__GNUC__) || defined(__clang__)
  52. #define UPB_LIKELY(x) __builtin_expect((x),1)
  53. #define UPB_UNLIKELY(x) __builtin_expect((x),0)
  54. #else
  55. #define UPB_LIKELY(x) (x)
  56. #define UPB_UNLIKELY(x) (x)
  57. #endif
  58. /* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
  59. * doesn't provide these preprocessor symbols. */
  60. #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  61. #define UPB_BIG_ENDIAN
  62. #endif
  63. /* Macros for function attributes on compilers that support them. */
  64. #ifdef __GNUC__
  65. #define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
  66. #define UPB_NOINLINE __attribute__((noinline))
  67. #define UPB_NORETURN __attribute__((__noreturn__))
  68. #else /* !defined(__GNUC__) */
  69. #define UPB_FORCEINLINE
  70. #define UPB_NOINLINE
  71. #define UPB_NORETURN
  72. #endif
  73. #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
  74. /* C99/C++11 versions. */
  75. #include <stdio.h>
  76. #define _upb_snprintf snprintf
  77. #define _upb_vsnprintf vsnprintf
  78. #define _upb_va_copy(a, b) va_copy(a, b)
  79. #elif defined(_MSC_VER)
  80. /* Microsoft C/C++ versions. */
  81. #include <stdarg.h>
  82. #include <stdio.h>
  83. #if _MSC_VER < 1900
  84. int msvc_snprintf(char* s, size_t n, const char* format, ...);
  85. int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg);
  86. #define UPB_MSVC_VSNPRINTF
  87. #define _upb_snprintf msvc_snprintf
  88. #define _upb_vsnprintf msvc_vsnprintf
  89. #else
  90. #define _upb_snprintf snprintf
  91. #define _upb_vsnprintf vsnprintf
  92. #endif
  93. #define _upb_va_copy(a, b) va_copy(a, b)
  94. #elif defined __GNUC__
  95. /* A few hacky workarounds for functions not in C89.
  96. * For internal use only!
  97. * TODO(haberman): fix these by including our own implementations, or finding
  98. * another workaround.
  99. */
  100. #define _upb_snprintf __builtin_snprintf
  101. #define _upb_vsnprintf __builtin_vsnprintf
  102. #define _upb_va_copy(a, b) __va_copy(a, b)
  103. #else
  104. #error Need implementations of [v]snprintf and va_copy
  105. #endif
  106. #ifdef __cplusplus
  107. #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
  108. (defined(_MSC_VER) && _MSC_VER >= 1900)
  109. /* C++11 is present */
  110. #else
  111. #error upb requires C++11 for C++ support
  112. #endif
  113. #endif
  114. #define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
  115. #define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
  116. #define UPB_UNUSED(var) (void)var
  117. /* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true.
  118. */
  119. #ifdef NDEBUG
  120. #ifdef __GNUC__
  121. #define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable()
  122. #else
  123. #define UPB_ASSUME(expr) do {} if (false && (expr))
  124. #endif
  125. #else
  126. #define UPB_ASSUME(expr) assert(expr)
  127. #endif
  128. /* UPB_ASSERT(): in release mode, we use the expression without letting it be
  129. * evaluated. This prevents "unused variable" warnings. */
  130. #ifdef NDEBUG
  131. #define UPB_ASSERT(expr) do {} while (false && (expr))
  132. #else
  133. #define UPB_ASSERT(expr) assert(expr)
  134. #endif
  135. /* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
  136. * exist in debug mode. This turns into regular assert. */
  137. #define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
  138. #if defined(__GNUC__) || defined(__clang__)
  139. #define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
  140. #else
  141. #define UPB_UNREACHABLE() do { assert(0); } while(0)
  142. #endif
  143. /* UPB_INFINITY representing floating-point positive infinity. */
  144. #include <math.h>
  145. #ifdef INFINITY
  146. #define UPB_INFINITY INFINITY
  147. #else
  148. #define UPB_INFINITY (1.0 / 0.0)
  149. #endif
  150. /*
  151. ** upb_decode: parsing into a upb_msg using a upb_msglayout.
  152. */
  153. #ifndef UPB_DECODE_H_
  154. #define UPB_DECODE_H_
  155. /*
  156. ** Our memory representation for parsing tables and messages themselves.
  157. ** Functions in this file are used by generated code and possibly reflection.
  158. **
  159. ** The definitions in this file are internal to upb.
  160. **/
  161. #ifndef UPB_MSG_H_
  162. #define UPB_MSG_H_
  163. #include <stdint.h>
  164. #include <string.h>
  165. /*
  166. ** upb_table
  167. **
  168. ** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
  169. ** This file defines very fast int->upb_value (inttable) and string->upb_value
  170. ** (strtable) hash tables.
  171. **
  172. ** The table uses chained scatter with Brent's variation (inspired by the Lua
  173. ** implementation of hash tables). The hash function for strings is Austin
  174. ** Appleby's "MurmurHash."
  175. **
  176. ** The inttable uses uintptr_t as its key, which guarantees it can be used to
  177. ** store pointers or integers of at least 32 bits (upb isn't really useful on
  178. ** systems where sizeof(void*) < 4).
  179. **
  180. ** The table must be homogeneous (all values of the same type). In debug
  181. ** mode, we check this on insert and lookup.
  182. */
  183. #ifndef UPB_TABLE_H_
  184. #define UPB_TABLE_H_
  185. #include <stdint.h>
  186. #include <string.h>
  187. /*
  188. ** This file contains shared definitions that are widely used across upb.
  189. */
  190. #ifndef UPB_H_
  191. #define UPB_H_
  192. #include <assert.h>
  193. #include <stdarg.h>
  194. #include <stdbool.h>
  195. #include <stddef.h>
  196. #include <stdint.h>
  197. #include <string.h>
  198. #ifdef __cplusplus
  199. extern "C" {
  200. #endif
  201. /* upb_status *****************************************************************/
  202. #define UPB_STATUS_MAX_MESSAGE 127
  203. typedef struct {
  204. bool ok;
  205. char msg[UPB_STATUS_MAX_MESSAGE]; /* Error message; NULL-terminated. */
  206. } upb_status;
  207. const char *upb_status_errmsg(const upb_status *status);
  208. bool upb_ok(const upb_status *status);
  209. /* These are no-op if |status| is NULL. */
  210. void upb_status_clear(upb_status *status);
  211. void upb_status_seterrmsg(upb_status *status, const char *msg);
  212. void upb_status_seterrf(upb_status *status, const char *fmt, ...);
  213. void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
  214. /** upb_strview ************************************************************/
  215. typedef struct {
  216. const char *data;
  217. size_t size;
  218. } upb_strview;
  219. UPB_INLINE upb_strview upb_strview_make(const char *data, size_t size) {
  220. upb_strview ret;
  221. ret.data = data;
  222. ret.size = size;
  223. return ret;
  224. }
  225. UPB_INLINE upb_strview upb_strview_makez(const char *data) {
  226. return upb_strview_make(data, strlen(data));
  227. }
  228. UPB_INLINE bool upb_strview_eql(upb_strview a, upb_strview b) {
  229. return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
  230. }
  231. #define UPB_STRVIEW_INIT(ptr, len) {ptr, len}
  232. #define UPB_STRVIEW_FORMAT "%.*s"
  233. #define UPB_STRVIEW_ARGS(view) (int)(view).size, (view).data
  234. /** upb_alloc *****************************************************************/
  235. /* A upb_alloc is a possibly-stateful allocator object.
  236. *
  237. * It could either be an arena allocator (which doesn't require individual
  238. * free() calls) or a regular malloc() (which does). The client must therefore
  239. * free memory unless it knows that the allocator is an arena allocator. */
  240. struct upb_alloc;
  241. typedef struct upb_alloc upb_alloc;
  242. /* A malloc()/free() function.
  243. * If "size" is 0 then the function acts like free(), otherwise it acts like
  244. * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */
  245. typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
  246. size_t size);
  247. struct upb_alloc {
  248. upb_alloc_func *func;
  249. };
  250. UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
  251. UPB_ASSERT(alloc);
  252. return alloc->func(alloc, NULL, 0, size);
  253. }
  254. UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
  255. size_t size) {
  256. UPB_ASSERT(alloc);
  257. return alloc->func(alloc, ptr, oldsize, size);
  258. }
  259. UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
  260. assert(alloc);
  261. alloc->func(alloc, ptr, 0, 0);
  262. }
  263. /* The global allocator used by upb. Uses the standard malloc()/free(). */
  264. extern upb_alloc upb_alloc_global;
  265. /* Functions that hard-code the global malloc.
  266. *
  267. * We still get benefit because we can put custom logic into our global
  268. * allocator, like injecting out-of-memory faults in debug/testing builds. */
  269. UPB_INLINE void *upb_gmalloc(size_t size) {
  270. return upb_malloc(&upb_alloc_global, size);
  271. }
  272. UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
  273. return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
  274. }
  275. UPB_INLINE void upb_gfree(void *ptr) {
  276. upb_free(&upb_alloc_global, ptr);
  277. }
  278. /* upb_arena ******************************************************************/
  279. /* upb_arena is a specific allocator implementation that uses arena allocation.
  280. * The user provides an allocator that will be used to allocate the underlying
  281. * arena blocks. Arenas by nature do not require the individual allocations
  282. * to be freed. However the Arena does allow users to register cleanup
  283. * functions that will run when the arena is destroyed.
  284. *
  285. * A upb_arena is *not* thread-safe.
  286. *
  287. * You could write a thread-safe arena allocator that satisfies the
  288. * upb_alloc interface, but it would not be as efficient for the
  289. * single-threaded case. */
  290. typedef void upb_cleanup_func(void *ud);
  291. struct upb_arena;
  292. typedef struct upb_arena upb_arena;
  293. typedef struct {
  294. /* We implement the allocator interface.
  295. * This must be the first member of upb_arena! */
  296. upb_alloc alloc;
  297. char *ptr, *end;
  298. } _upb_arena_head;
  299. UPB_INLINE size_t _upb_arena_alignup(size_t size) {
  300. const size_t maxalign = 16;
  301. return ((size + maxalign - 1) / maxalign) * maxalign;
  302. }
  303. /* Creates an arena from the given initial block (if any -- n may be 0).
  304. * Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this
  305. * is a fixed-size arena and cannot grow. */
  306. upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc);
  307. void upb_arena_free(upb_arena *a);
  308. bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func);
  309. size_t upb_arena_bytesallocated(const upb_arena *a);
  310. void *_upb_arena_slowmalloc(upb_arena *a, size_t size);
  311. UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
  312. UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) {
  313. _upb_arena_head *h = (_upb_arena_head*)a;
  314. size = _upb_arena_alignup(size);
  315. if (UPB_LIKELY((size_t)(h->end - h->ptr) >= size)) {
  316. void* ret = h->ptr;
  317. h->ptr += size;
  318. return ret;
  319. } else {
  320. return _upb_arena_slowmalloc(a, size);
  321. }
  322. }
  323. UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize,
  324. size_t size) {
  325. if (oldsize == 0) {
  326. return upb_arena_malloc(a, size);
  327. } else {
  328. return upb_realloc(upb_arena_alloc(a), ptr, oldsize, size);
  329. }
  330. }
  331. UPB_INLINE upb_arena *upb_arena_new(void) {
  332. return upb_arena_init(NULL, 0, &upb_alloc_global);
  333. }
  334. /* Constants ******************************************************************/
  335. /* Generic function type. */
  336. typedef void upb_func(void);
  337. /* A list of types as they are encoded on-the-wire. */
  338. typedef enum {
  339. UPB_WIRE_TYPE_VARINT = 0,
  340. UPB_WIRE_TYPE_64BIT = 1,
  341. UPB_WIRE_TYPE_DELIMITED = 2,
  342. UPB_WIRE_TYPE_START_GROUP = 3,
  343. UPB_WIRE_TYPE_END_GROUP = 4,
  344. UPB_WIRE_TYPE_32BIT = 5
  345. } upb_wiretype_t;
  346. /* The types a field can have. Note that this list is not identical to the
  347. * types defined in descriptor.proto, which gives INT32 and SINT32 separate
  348. * types (we distinguish the two with the "integer encoding" enum below). */
  349. typedef enum {
  350. UPB_TYPE_BOOL = 1,
  351. UPB_TYPE_FLOAT = 2,
  352. UPB_TYPE_INT32 = 3,
  353. UPB_TYPE_UINT32 = 4,
  354. UPB_TYPE_ENUM = 5, /* Enum values are int32. */
  355. UPB_TYPE_MESSAGE = 6,
  356. UPB_TYPE_DOUBLE = 7,
  357. UPB_TYPE_INT64 = 8,
  358. UPB_TYPE_UINT64 = 9,
  359. UPB_TYPE_STRING = 10,
  360. UPB_TYPE_BYTES = 11
  361. } upb_fieldtype_t;
  362. /* The repeated-ness of each field; this matches descriptor.proto. */
  363. typedef enum {
  364. UPB_LABEL_OPTIONAL = 1,
  365. UPB_LABEL_REQUIRED = 2,
  366. UPB_LABEL_REPEATED = 3
  367. } upb_label_t;
  368. /* Descriptor types, as defined in descriptor.proto. */
  369. typedef enum {
  370. /* Old (long) names. TODO(haberman): remove */
  371. UPB_DESCRIPTOR_TYPE_DOUBLE = 1,
  372. UPB_DESCRIPTOR_TYPE_FLOAT = 2,
  373. UPB_DESCRIPTOR_TYPE_INT64 = 3,
  374. UPB_DESCRIPTOR_TYPE_UINT64 = 4,
  375. UPB_DESCRIPTOR_TYPE_INT32 = 5,
  376. UPB_DESCRIPTOR_TYPE_FIXED64 = 6,
  377. UPB_DESCRIPTOR_TYPE_FIXED32 = 7,
  378. UPB_DESCRIPTOR_TYPE_BOOL = 8,
  379. UPB_DESCRIPTOR_TYPE_STRING = 9,
  380. UPB_DESCRIPTOR_TYPE_GROUP = 10,
  381. UPB_DESCRIPTOR_TYPE_MESSAGE = 11,
  382. UPB_DESCRIPTOR_TYPE_BYTES = 12,
  383. UPB_DESCRIPTOR_TYPE_UINT32 = 13,
  384. UPB_DESCRIPTOR_TYPE_ENUM = 14,
  385. UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
  386. UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
  387. UPB_DESCRIPTOR_TYPE_SINT32 = 17,
  388. UPB_DESCRIPTOR_TYPE_SINT64 = 18,
  389. UPB_DTYPE_DOUBLE = 1,
  390. UPB_DTYPE_FLOAT = 2,
  391. UPB_DTYPE_INT64 = 3,
  392. UPB_DTYPE_UINT64 = 4,
  393. UPB_DTYPE_INT32 = 5,
  394. UPB_DTYPE_FIXED64 = 6,
  395. UPB_DTYPE_FIXED32 = 7,
  396. UPB_DTYPE_BOOL = 8,
  397. UPB_DTYPE_STRING = 9,
  398. UPB_DTYPE_GROUP = 10,
  399. UPB_DTYPE_MESSAGE = 11,
  400. UPB_DTYPE_BYTES = 12,
  401. UPB_DTYPE_UINT32 = 13,
  402. UPB_DTYPE_ENUM = 14,
  403. UPB_DTYPE_SFIXED32 = 15,
  404. UPB_DTYPE_SFIXED64 = 16,
  405. UPB_DTYPE_SINT32 = 17,
  406. UPB_DTYPE_SINT64 = 18
  407. } upb_descriptortype_t;
  408. #define UPB_MAP_BEGIN -1
  409. #ifdef __cplusplus
  410. } /* extern "C" */
  411. #endif
  412. #endif /* UPB_H_ */
  413. #ifdef __cplusplus
  414. extern "C" {
  415. #endif
  416. /* upb_value ******************************************************************/
  417. /* A tagged union (stored untagged inside the table) so that we can check that
  418. * clients calling table accessors are correctly typed without having to have
  419. * an explosion of accessors. */
  420. typedef enum {
  421. UPB_CTYPE_INT32 = 1,
  422. UPB_CTYPE_INT64 = 2,
  423. UPB_CTYPE_UINT32 = 3,
  424. UPB_CTYPE_UINT64 = 4,
  425. UPB_CTYPE_BOOL = 5,
  426. UPB_CTYPE_CSTR = 6,
  427. UPB_CTYPE_PTR = 7,
  428. UPB_CTYPE_CONSTPTR = 8,
  429. UPB_CTYPE_FPTR = 9,
  430. UPB_CTYPE_FLOAT = 10,
  431. UPB_CTYPE_DOUBLE = 11
  432. } upb_ctype_t;
  433. typedef struct {
  434. uint64_t val;
  435. } upb_value;
  436. /* Like strdup(), which isn't always available since it's not ANSI C. */
  437. char *upb_strdup(const char *s, upb_alloc *a);
  438. /* Variant that works with a length-delimited rather than NULL-delimited string,
  439. * as supported by strtable. */
  440. char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
  441. UPB_INLINE char *upb_gstrdup(const char *s) {
  442. return upb_strdup(s, &upb_alloc_global);
  443. }
  444. UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val) {
  445. v->val = val;
  446. }
  447. UPB_INLINE upb_value _upb_value_val(uint64_t val) {
  448. upb_value ret;
  449. _upb_value_setval(&ret, val);
  450. return ret;
  451. }
  452. /* For each value ctype, define the following set of functions:
  453. *
  454. * // Get/set an int32 from a upb_value.
  455. * int32_t upb_value_getint32(upb_value val);
  456. * void upb_value_setint32(upb_value *val, int32_t cval);
  457. *
  458. * // Construct a new upb_value from an int32.
  459. * upb_value upb_value_int32(int32_t val); */
  460. #define FUNCS(name, membername, type_t, converter, proto_type) \
  461. UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
  462. val->val = (converter)cval; \
  463. } \
  464. UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
  465. upb_value ret; \
  466. upb_value_set ## name(&ret, val); \
  467. return ret; \
  468. } \
  469. UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
  470. return (type_t)(converter)val.val; \
  471. }
  472. FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
  473. FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
  474. FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
  475. FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
  476. FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
  477. FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
  478. FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
  479. FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR)
  480. FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR)
  481. #undef FUNCS
  482. UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
  483. memcpy(&val->val, &cval, sizeof(cval));
  484. }
  485. UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
  486. memcpy(&val->val, &cval, sizeof(cval));
  487. }
  488. UPB_INLINE upb_value upb_value_float(float cval) {
  489. upb_value ret;
  490. upb_value_setfloat(&ret, cval);
  491. return ret;
  492. }
  493. UPB_INLINE upb_value upb_value_double(double cval) {
  494. upb_value ret;
  495. upb_value_setdouble(&ret, cval);
  496. return ret;
  497. }
  498. #undef SET_TYPE
  499. /* upb_tabkey *****************************************************************/
  500. /* Either:
  501. * 1. an actual integer key, or
  502. * 2. a pointer to a string prefixed by its uint32_t length, owned by us.
  503. *
  504. * ...depending on whether this is a string table or an int table. We would
  505. * make this a union of those two types, but C89 doesn't support statically
  506. * initializing a non-first union member. */
  507. typedef uintptr_t upb_tabkey;
  508. UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
  509. char* mem = (char*)key;
  510. if (len) memcpy(len, mem, sizeof(*len));
  511. return mem + sizeof(*len);
  512. }
  513. /* upb_tabval *****************************************************************/
  514. typedef struct {
  515. uint64_t val;
  516. } upb_tabval;
  517. #define UPB_TABVALUE_EMPTY_INIT {-1}
  518. /* upb_table ******************************************************************/
  519. typedef struct _upb_tabent {
  520. upb_tabkey key;
  521. upb_tabval val;
  522. /* Internal chaining. This is const so we can create static initializers for
  523. * tables. We cast away const sometimes, but *only* when the containing
  524. * upb_table is known to be non-const. This requires a bit of care, but
  525. * the subtlety is confined to table.c. */
  526. const struct _upb_tabent *next;
  527. } upb_tabent;
  528. typedef struct {
  529. size_t count; /* Number of entries in the hash part. */
  530. size_t mask; /* Mask to turn hash value -> bucket. */
  531. uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
  532. /* Hash table entries.
  533. * Making this const isn't entirely accurate; what we really want is for it to
  534. * have the same const-ness as the table it's inside. But there's no way to
  535. * declare that in C. So we have to make it const so that we can statically
  536. * initialize const hash tables. Then we cast away const when we have to.
  537. */
  538. const upb_tabent *entries;
  539. } upb_table;
  540. typedef struct {
  541. upb_table t;
  542. } upb_strtable;
  543. typedef struct {
  544. upb_table t; /* For entries that don't fit in the array part. */
  545. const upb_tabval *array; /* Array part of the table. See const note above. */
  546. size_t array_size; /* Array part size. */
  547. size_t array_count; /* Array part number of elements. */
  548. } upb_inttable;
  549. #define UPB_ARRAY_EMPTYENT -1
  550. UPB_INLINE size_t upb_table_size(const upb_table *t) {
  551. if (t->size_lg2 == 0)
  552. return 0;
  553. else
  554. return 1 << t->size_lg2;
  555. }
  556. /* Internal-only functions, in .h file only out of necessity. */
  557. UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) {
  558. return e->key == 0;
  559. }
  560. /* Used by some of the unit tests for generic hashing functionality. */
  561. uint32_t upb_murmur_hash2(const void * key, size_t len, uint32_t seed);
  562. UPB_INLINE uintptr_t upb_intkey(uintptr_t key) {
  563. return key;
  564. }
  565. UPB_INLINE uint32_t upb_inthash(uintptr_t key) {
  566. return (uint32_t)key;
  567. }
  568. static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
  569. return t->entries + (hash & t->mask);
  570. }
  571. UPB_INLINE bool upb_arrhas(upb_tabval key) {
  572. return key.val != (uint64_t)-1;
  573. }
  574. /* Initialize and uninitialize a table, respectively. If memory allocation
  575. * failed, false is returned that the table is uninitialized. */
  576. bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
  577. bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
  578. void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
  579. void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
  580. UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
  581. return upb_inttable_init2(table, ctype, &upb_alloc_global);
  582. }
  583. UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
  584. return upb_strtable_init2(table, ctype, &upb_alloc_global);
  585. }
  586. UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
  587. upb_inttable_uninit2(table, &upb_alloc_global);
  588. }
  589. UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
  590. upb_strtable_uninit2(table, &upb_alloc_global);
  591. }
  592. /* Returns the number of values in the table. */
  593. size_t upb_inttable_count(const upb_inttable *t);
  594. UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
  595. return t->t.count;
  596. }
  597. void upb_inttable_packedsize(const upb_inttable *t, size_t *size);
  598. void upb_strtable_packedsize(const upb_strtable *t, size_t *size);
  599. upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs,
  600. size_t size);
  601. upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
  602. size_t size);
  603. void upb_strtable_clear(upb_strtable *t);
  604. /* Inserts the given key into the hashtable with the given value. The key must
  605. * not already exist in the hash table. For string tables, the key must be
  606. * NULL-terminated, and the table will make an internal copy of the key.
  607. * Inttables must not insert a value of UINTPTR_MAX.
  608. *
  609. * If a table resize was required but memory allocation failed, false is
  610. * returned and the table is unchanged. */
  611. bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
  612. upb_alloc *a);
  613. bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
  614. upb_value val, upb_alloc *a);
  615. UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
  616. upb_value val) {
  617. return upb_inttable_insert2(t, key, val, &upb_alloc_global);
  618. }
  619. UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
  620. size_t len, upb_value val) {
  621. return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
  622. }
  623. /* For NULL-terminated strings. */
  624. UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
  625. upb_value val) {
  626. return upb_strtable_insert2(t, key, strlen(key), val);
  627. }
  628. /* Looks up key in this table, returning "true" if the key was found.
  629. * If v is non-NULL, copies the value for this key into *v. */
  630. bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
  631. bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
  632. upb_value *v);
  633. /* For NULL-terminated strings. */
  634. UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
  635. upb_value *v) {
  636. return upb_strtable_lookup2(t, key, strlen(key), v);
  637. }
  638. /* Removes an item from the table. Returns true if the remove was successful,
  639. * and stores the removed item in *val if non-NULL. */
  640. bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
  641. bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
  642. upb_value *val, upb_alloc *alloc);
  643. UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
  644. size_t len, upb_value *val) {
  645. return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
  646. }
  647. /* For NULL-terminated strings. */
  648. UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
  649. upb_value *v) {
  650. return upb_strtable_remove2(t, key, strlen(key), v);
  651. }
  652. /* Updates an existing entry in an inttable. If the entry does not exist,
  653. * returns false and does nothing. Unlike insert/remove, this does not
  654. * invalidate iterators. */
  655. bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
  656. /* Handy routines for treating an inttable like a stack. May not be mixed with
  657. * other insert/remove calls. */
  658. bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
  659. upb_value upb_inttable_pop(upb_inttable *t);
  660. UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
  661. return upb_inttable_push2(t, val, &upb_alloc_global);
  662. }
  663. /* Convenience routines for inttables with pointer keys. */
  664. bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
  665. upb_alloc *a);
  666. bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
  667. bool upb_inttable_lookupptr(
  668. const upb_inttable *t, const void *key, upb_value *val);
  669. UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
  670. upb_value val) {
  671. return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
  672. }
  673. /* Optimizes the table for the current set of entries, for both memory use and
  674. * lookup time. Client should call this after all entries have been inserted;
  675. * inserting more entries is legal, but will likely require a table resize. */
  676. void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
  677. UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
  678. upb_inttable_compact2(t, &upb_alloc_global);
  679. }
  680. /* A special-case inlinable version of the lookup routine for 32-bit
  681. * integers. */
  682. UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
  683. upb_value *v) {
  684. *v = upb_value_int32(0); /* Silence compiler warnings. */
  685. if (key < t->array_size) {
  686. upb_tabval arrval = t->array[key];
  687. if (upb_arrhas(arrval)) {
  688. _upb_value_setval(v, arrval.val);
  689. return true;
  690. } else {
  691. return false;
  692. }
  693. } else {
  694. const upb_tabent *e;
  695. if (t->t.entries == NULL) return false;
  696. for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
  697. if ((uint32_t)e->key == key) {
  698. _upb_value_setval(v, e->val.val);
  699. return true;
  700. }
  701. if (e->next == NULL) return false;
  702. }
  703. }
  704. }
  705. /* Exposed for testing only. */
  706. bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
  707. /* Iterators ******************************************************************/
  708. /* Iterators for int and string tables. We are subject to some kind of unusual
  709. * design constraints:
  710. *
  711. * For high-level languages:
  712. * - we must be able to guarantee that we don't crash or corrupt memory even if
  713. * the program accesses an invalidated iterator.
  714. *
  715. * For C++11 range-based for:
  716. * - iterators must be copyable
  717. * - iterators must be comparable
  718. * - it must be possible to construct an "end" value.
  719. *
  720. * Iteration order is undefined.
  721. *
  722. * Modifying the table invalidates iterators. upb_{str,int}table_done() is
  723. * guaranteed to work even on an invalidated iterator, as long as the table it
  724. * is iterating over has not been freed. Calling next() or accessing data from
  725. * an invalidated iterator yields unspecified elements from the table, but it is
  726. * guaranteed not to crash and to return real table elements (except when done()
  727. * is true). */
  728. /* upb_strtable_iter **********************************************************/
  729. /* upb_strtable_iter i;
  730. * upb_strtable_begin(&i, t);
  731. * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
  732. * const char *key = upb_strtable_iter_key(&i);
  733. * const upb_value val = upb_strtable_iter_value(&i);
  734. * // ...
  735. * }
  736. */
  737. typedef struct {
  738. const upb_strtable *t;
  739. size_t index;
  740. } upb_strtable_iter;
  741. void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
  742. void upb_strtable_next(upb_strtable_iter *i);
  743. bool upb_strtable_done(const upb_strtable_iter *i);
  744. upb_strview upb_strtable_iter_key(const upb_strtable_iter *i);
  745. upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
  746. void upb_strtable_iter_setdone(upb_strtable_iter *i);
  747. bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
  748. const upb_strtable_iter *i2);
  749. /* upb_inttable_iter **********************************************************/
  750. /* upb_inttable_iter i;
  751. * upb_inttable_begin(&i, t);
  752. * for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
  753. * uintptr_t key = upb_inttable_iter_key(&i);
  754. * upb_value val = upb_inttable_iter_value(&i);
  755. * // ...
  756. * }
  757. */
  758. typedef struct {
  759. const upb_inttable *t;
  760. size_t index;
  761. bool array_part;
  762. } upb_inttable_iter;
  763. UPB_INLINE const upb_tabent *str_tabent(const upb_strtable_iter *i) {
  764. return &i->t->t.entries[i->index];
  765. }
  766. void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
  767. void upb_inttable_next(upb_inttable_iter *i);
  768. bool upb_inttable_done(const upb_inttable_iter *i);
  769. uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i);
  770. upb_value upb_inttable_iter_value(const upb_inttable_iter *i);
  771. void upb_inttable_iter_setdone(upb_inttable_iter *i);
  772. bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
  773. const upb_inttable_iter *i2);
  774. #ifdef __cplusplus
  775. } /* extern "C" */
  776. #endif
  777. #endif /* UPB_TABLE_H_ */
  778. #ifdef __cplusplus
  779. extern "C" {
  780. #endif
  781. #define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
  782. typedef void upb_msg;
  783. /** upb_msglayout *************************************************************/
  784. /* upb_msglayout represents the memory layout of a given upb_msgdef. The
  785. * members are public so generated code can initialize them, but users MUST NOT
  786. * read or write any of its members. */
  787. /* These aren't real labels according to descriptor.proto, but in the table we
  788. * use these for map/packed fields instead of UPB_LABEL_REPEATED. */
  789. enum {
  790. _UPB_LABEL_MAP = 4,
  791. _UPB_LABEL_PACKED = 7 /* Low 3 bits are common with UPB_LABEL_REPEATED. */
  792. };
  793. typedef struct {
  794. uint32_t number;
  795. uint16_t offset;
  796. int16_t presence; /* If >0, hasbit_index. If <0, -oneof_index. */
  797. uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
  798. uint8_t descriptortype;
  799. uint8_t label;
  800. } upb_msglayout_field;
  801. typedef struct upb_msglayout {
  802. const struct upb_msglayout *const* submsgs;
  803. const upb_msglayout_field *fields;
  804. /* Must be aligned to sizeof(void*). Doesn't include internal members like
  805. * unknown fields, extension dict, pointer to msglayout, etc. */
  806. uint16_t size;
  807. uint16_t field_count;
  808. bool extendable;
  809. } upb_msglayout;
  810. /** upb_msg *******************************************************************/
  811. /* Internal members of a upb_msg. We can change this without breaking binary
  812. * compatibility. We put these before the user's data. The user's upb_msg*
  813. * points after the upb_msg_internal. */
  814. /* Used when a message is not extendable. */
  815. typedef struct {
  816. char *unknown;
  817. size_t unknown_len;
  818. size_t unknown_size;
  819. } upb_msg_internal;
  820. /* Used when a message is extendable. */
  821. typedef struct {
  822. upb_inttable *extdict;
  823. upb_msg_internal base;
  824. } upb_msg_internal_withext;
  825. /* Maps upb_fieldtype_t -> memory size. */
  826. extern char _upb_fieldtype_to_size[12];
  827. /* Creates a new messages with the given layout on the given arena. */
  828. upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a);
  829. /* Adds unknown data (serialized protobuf data) to the given message. The data
  830. * is copied into the message instance. */
  831. bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
  832. upb_arena *arena);
  833. /* Returns a reference to the message's unknown data. */
  834. const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
  835. UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
  836. return (*PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0;
  837. }
  838. UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) {
  839. return (*PTR_AT(msg, idx / 8, char)) |= (char)(1 << (idx % 8));
  840. }
  841. UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) {
  842. return (*PTR_AT(msg, idx / 8, char)) &= (char)(~(1 << (idx % 8)));
  843. }
  844. UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) {
  845. return *PTR_AT(msg, case_ofs, int32_t) == num;
  846. }
  847. UPB_INLINE bool _upb_has_submsg_nohasbit(const void *msg, size_t ofs) {
  848. return *PTR_AT(msg, ofs, const void*) != NULL;
  849. }
  850. UPB_INLINE bool _upb_isrepeated(const upb_msglayout_field *field) {
  851. return (field->label & 3) == UPB_LABEL_REPEATED;
  852. }
  853. /** upb_array *****************************************************************/
  854. /* Our internal representation for repeated fields. */
  855. typedef struct {
  856. uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */
  857. size_t len; /* Measured in elements. */
  858. size_t size; /* Measured in elements. */
  859. } upb_array;
  860. UPB_INLINE const void *_upb_array_constptr(const upb_array *arr) {
  861. return (void*)(arr->data & ~(uintptr_t)7);
  862. }
  863. UPB_INLINE void *_upb_array_ptr(upb_array *arr) {
  864. return (void*)_upb_array_constptr(arr);
  865. }
  866. /* Creates a new array on the given arena. */
  867. upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type);
  868. /* Resizes the capacity of the array to be at least min_size. */
  869. bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena);
  870. /* Fallback functions for when the accessors require a resize. */
  871. void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size,
  872. upb_fieldtype_t type, upb_arena *arena);
  873. bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value,
  874. upb_fieldtype_t type, upb_arena *arena);
  875. UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
  876. size_t *size) {
  877. const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
  878. if (arr) {
  879. if (size) *size = arr->len;
  880. return _upb_array_constptr(arr);
  881. } else {
  882. if (size) *size = 0;
  883. return NULL;
  884. }
  885. }
  886. UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
  887. size_t *size) {
  888. upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
  889. if (arr) {
  890. if (size) *size = arr->len;
  891. return _upb_array_ptr(arr);
  892. } else {
  893. if (size) *size = 0;
  894. return NULL;
  895. }
  896. }
  897. UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
  898. upb_fieldtype_t type,
  899. upb_arena *arena) {
  900. upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*);
  901. upb_array *arr = *arr_ptr;
  902. if (!arr || arr->size < size) {
  903. return _upb_array_resize_fallback(arr_ptr, size, type, arena);
  904. }
  905. arr->len = size;
  906. return _upb_array_ptr(arr);
  907. }
  908. UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
  909. size_t elem_size,
  910. upb_fieldtype_t type,
  911. const void *value,
  912. upb_arena *arena) {
  913. upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*);
  914. upb_array *arr = *arr_ptr;
  915. void* ptr;
  916. if (!arr || arr->len == arr->size) {
  917. return _upb_array_append_fallback(arr_ptr, value, type, arena);
  918. }
  919. ptr = _upb_array_ptr(arr);
  920. memcpy(PTR_AT(ptr, arr->len * elem_size, char), value, elem_size);
  921. arr->len++;
  922. return true;
  923. }
  924. /** upb_map *******************************************************************/
  925. /* Right now we use strmaps for everything. We'll likely want to use
  926. * integer-specific maps for integer-keyed maps.*/
  927. typedef struct {
  928. /* Size of key and val, based on the map type. Strings are represented as '0'
  929. * because they must be handled specially. */
  930. char key_size;
  931. char val_size;
  932. upb_strtable table;
  933. } upb_map;
  934. /* Map entries aren't actually stored, they are only used during parsing. For
  935. * parsing, it helps a lot if all map entry messages have the same layout.
  936. * The compiler and def.c must ensure that all map entries have this layout. */
  937. typedef struct {
  938. upb_msg_internal internal;
  939. union {
  940. upb_strview str; /* For str/bytes. */
  941. upb_value val; /* For all other types. */
  942. } k;
  943. union {
  944. upb_strview str; /* For str/bytes. */
  945. upb_value val; /* For all other types. */
  946. } v;
  947. } upb_map_entry;
  948. /* Creates a new map on the given arena with this key/value type. */
  949. upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size);
  950. /* Converting between internal table representation and user values.
  951. *
  952. * _upb_map_tokey() and _upb_map_fromkey() are inverses.
  953. * _upb_map_tovalue() and _upb_map_fromvalue() are inverses.
  954. *
  955. * These functions account for the fact that strings are treated differently
  956. * from other types when stored in a map.
  957. */
  958. UPB_INLINE upb_strview _upb_map_tokey(const void *key, size_t size) {
  959. if (size == UPB_MAPTYPE_STRING) {
  960. return *(upb_strview*)key;
  961. } else {
  962. return upb_strview_make((const char*)key, size);
  963. }
  964. }
  965. UPB_INLINE void _upb_map_fromkey(upb_strview key, void* out, size_t size) {
  966. if (size == UPB_MAPTYPE_STRING) {
  967. memcpy(out, &key, sizeof(key));
  968. } else {
  969. memcpy(out, key.data, size);
  970. }
  971. }
  972. UPB_INLINE upb_value _upb_map_tovalue(const void *val, size_t size,
  973. upb_arena *a) {
  974. upb_value ret = {0};
  975. if (size == UPB_MAPTYPE_STRING) {
  976. upb_strview *strp = (upb_strview*)upb_arena_malloc(a, sizeof(*strp));
  977. *strp = *(upb_strview*)val;
  978. memcpy(&ret, &strp, sizeof(strp));
  979. } else {
  980. memcpy(&ret, val, size);
  981. }
  982. return ret;
  983. }
  984. UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) {
  985. if (size == UPB_MAPTYPE_STRING) {
  986. const upb_strview *strp = (const upb_strview*)upb_value_getptr(val);
  987. memcpy(out, strp, sizeof(upb_strview));
  988. } else {
  989. memcpy(out, &val, size);
  990. }
  991. }
  992. /* Map operations, shared by reflection and generated code. */
  993. UPB_INLINE size_t _upb_map_size(const upb_map *map) {
  994. return map->table.t.count;
  995. }
  996. UPB_INLINE bool _upb_map_get(const upb_map *map, const void *key,
  997. size_t key_size, void *val, size_t val_size) {
  998. upb_value tabval;
  999. upb_strview k = _upb_map_tokey(key, key_size);
  1000. bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval);
  1001. if (ret) {
  1002. _upb_map_fromvalue(tabval, val, val_size);
  1003. }
  1004. return ret;
  1005. }
  1006. UPB_INLINE void* _upb_map_next(const upb_map *map, size_t *iter) {
  1007. upb_strtable_iter it;
  1008. it.t = &map->table;
  1009. it.index = *iter;
  1010. upb_strtable_next(&it);
  1011. if (upb_strtable_done(&it)) return NULL;
  1012. *iter = it.index;
  1013. return (void*)str_tabent(&it);
  1014. }
  1015. UPB_INLINE bool _upb_map_set(upb_map *map, const void *key, size_t key_size,
  1016. void *val, size_t val_size, upb_arena *arena) {
  1017. upb_strview strkey = _upb_map_tokey(key, key_size);
  1018. upb_value tabval = _upb_map_tovalue(val, val_size, arena);
  1019. upb_alloc *a = upb_arena_alloc(arena);
  1020. /* TODO(haberman): add overwrite operation to minimize number of lookups. */
  1021. upb_strtable_remove3(&map->table, strkey.data, strkey.size, NULL, a);
  1022. return upb_strtable_insert3(&map->table, strkey.data, strkey.size, tabval, a);
  1023. }
  1024. UPB_INLINE bool _upb_map_delete(upb_map *map, const void *key, size_t key_size) {
  1025. upb_strview k = _upb_map_tokey(key, key_size);
  1026. return upb_strtable_remove3(&map->table, k.data, k.size, NULL, NULL);
  1027. }
  1028. UPB_INLINE void _upb_map_clear(upb_map *map) {
  1029. upb_strtable_clear(&map->table);
  1030. }
  1031. /* Message map operations, these get the map from the message first. */
  1032. UPB_INLINE size_t _upb_msg_map_size(const upb_msg *msg, size_t ofs) {
  1033. upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
  1034. return map ? _upb_map_size(map) : 0;
  1035. }
  1036. UPB_INLINE bool _upb_msg_map_get(const upb_msg *msg, size_t ofs,
  1037. const void *key, size_t key_size, void *val,
  1038. size_t val_size) {
  1039. upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
  1040. if (!map) return false;
  1041. return _upb_map_get(map, key, key_size, val, val_size);
  1042. }
  1043. UPB_INLINE void *_upb_msg_map_next(const upb_msg *msg, size_t ofs,
  1044. size_t *iter) {
  1045. upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
  1046. if (!map) return NULL;
  1047. return _upb_map_next(map, iter);
  1048. }
  1049. UPB_INLINE bool _upb_msg_map_set(upb_msg *msg, size_t ofs, const void *key,
  1050. size_t key_size, void *val, size_t val_size,
  1051. upb_arena *arena) {
  1052. upb_map **map = PTR_AT(msg, ofs, upb_map *);
  1053. if (!*map) {
  1054. *map = _upb_map_new(arena, key_size, val_size);
  1055. }
  1056. return _upb_map_set(*map, key, key_size, val, val_size, arena);
  1057. }
  1058. UPB_INLINE bool _upb_msg_map_delete(upb_msg *msg, size_t ofs, const void *key,
  1059. size_t key_size) {
  1060. upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
  1061. if (!map) return false;
  1062. return _upb_map_delete(map, key, key_size);
  1063. }
  1064. UPB_INLINE void _upb_msg_map_clear(upb_msg *msg, size_t ofs) {
  1065. upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
  1066. if (!map) return;
  1067. _upb_map_clear(map);
  1068. }
  1069. /* Accessing map key/value from a pointer, used by generated code only. */
  1070. UPB_INLINE void _upb_msg_map_key(const void* msg, void* key, size_t size) {
  1071. const upb_tabent *ent = (const upb_tabent*)msg;
  1072. uint32_t u32len;
  1073. upb_strview k;
  1074. k.data = upb_tabstr(ent->key, &u32len);
  1075. k.size = u32len;
  1076. _upb_map_fromkey(k, key, size);
  1077. }
  1078. UPB_INLINE void _upb_msg_map_value(const void* msg, void* val, size_t size) {
  1079. const upb_tabent *ent = (const upb_tabent*)msg;
  1080. upb_value v;
  1081. _upb_value_setval(&v, ent->val.val);
  1082. _upb_map_fromvalue(v, val, size);
  1083. }
  1084. UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, size_t size) {
  1085. upb_tabent *ent = (upb_tabent*)msg;
  1086. /* This is like _upb_map_tovalue() except the entry already exists so we can
  1087. * reuse the allocated upb_strview for string fields. */
  1088. if (size == UPB_MAPTYPE_STRING) {
  1089. upb_strview *strp = (upb_strview*)ent->val.val;
  1090. memcpy(strp, val, sizeof(*strp));
  1091. } else {
  1092. memcpy(&ent->val.val, val, size);
  1093. }
  1094. }
  1095. #undef PTR_AT
  1096. #ifdef __cplusplus
  1097. } /* extern "C" */
  1098. #endif
  1099. #endif /* UPB_MSG_H_ */
  1100. #ifdef __cplusplus
  1101. extern "C" {
  1102. #endif
  1103. bool upb_decode(const char *buf, size_t size, upb_msg *msg,
  1104. const upb_msglayout *l, upb_arena *arena);
  1105. #ifdef __cplusplus
  1106. } /* extern "C" */
  1107. #endif
  1108. #endif /* UPB_DECODE_H_ */
  1109. /*
  1110. ** upb_encode: parsing into a upb_msg using a upb_msglayout.
  1111. */
  1112. #ifndef UPB_ENCODE_H_
  1113. #define UPB_ENCODE_H_
  1114. #ifdef __cplusplus
  1115. extern "C" {
  1116. #endif
  1117. char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
  1118. size_t *size);
  1119. #ifdef __cplusplus
  1120. } /* extern "C" */
  1121. #endif
  1122. #endif /* UPB_ENCODE_H_ */
  1123. /* This file was generated by upbc (the upb compiler) from the input
  1124. * file:
  1125. *
  1126. * google/protobuf/descriptor.proto
  1127. *
  1128. * Do not edit -- your changes will be discarded when the file is
  1129. * regenerated. */
  1130. #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
  1131. #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
  1132. #ifdef __cplusplus
  1133. extern "C" {
  1134. #endif
  1135. struct google_protobuf_FileDescriptorSet;
  1136. struct google_protobuf_FileDescriptorProto;
  1137. struct google_protobuf_DescriptorProto;
  1138. struct google_protobuf_DescriptorProto_ExtensionRange;
  1139. struct google_protobuf_DescriptorProto_ReservedRange;
  1140. struct google_protobuf_ExtensionRangeOptions;
  1141. struct google_protobuf_FieldDescriptorProto;
  1142. struct google_protobuf_OneofDescriptorProto;
  1143. struct google_protobuf_EnumDescriptorProto;
  1144. struct google_protobuf_EnumDescriptorProto_EnumReservedRange;
  1145. struct google_protobuf_EnumValueDescriptorProto;
  1146. struct google_protobuf_ServiceDescriptorProto;
  1147. struct google_protobuf_MethodDescriptorProto;
  1148. struct google_protobuf_FileOptions;
  1149. struct google_protobuf_MessageOptions;
  1150. struct google_protobuf_FieldOptions;
  1151. struct google_protobuf_OneofOptions;
  1152. struct google_protobuf_EnumOptions;
  1153. struct google_protobuf_EnumValueOptions;
  1154. struct google_protobuf_ServiceOptions;
  1155. struct google_protobuf_MethodOptions;
  1156. struct google_protobuf_UninterpretedOption;
  1157. struct google_protobuf_UninterpretedOption_NamePart;
  1158. struct google_protobuf_SourceCodeInfo;
  1159. struct google_protobuf_SourceCodeInfo_Location;
  1160. struct google_protobuf_GeneratedCodeInfo;
  1161. struct google_protobuf_GeneratedCodeInfo_Annotation;
  1162. typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet;
  1163. typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto;
  1164. typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto;
  1165. typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange;
  1166. typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange;
  1167. typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions;
  1168. typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto;
  1169. typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto;
  1170. typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto;
  1171. typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange;
  1172. typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto;
  1173. typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto;
  1174. typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto;
  1175. typedef struct google_protobuf_FileOptions google_protobuf_FileOptions;
  1176. typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions;
  1177. typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions;
  1178. typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions;
  1179. typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions;
  1180. typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions;
  1181. typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions;
  1182. typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions;
  1183. typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption;
  1184. typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart;
  1185. typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo;
  1186. typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location;
  1187. typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo;
  1188. typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation;
  1189. extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit;
  1190. extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit;
  1191. extern const upb_msglayout google_protobuf_DescriptorProto_msginit;
  1192. extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit;
  1193. extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit;
  1194. extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit;
  1195. extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit;
  1196. extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit;
  1197. extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit;
  1198. extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit;
  1199. extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit;
  1200. extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit;
  1201. extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit;
  1202. extern const upb_msglayout google_protobuf_FileOptions_msginit;
  1203. extern const upb_msglayout google_protobuf_MessageOptions_msginit;
  1204. extern const upb_msglayout google_protobuf_FieldOptions_msginit;
  1205. extern const upb_msglayout google_protobuf_OneofOptions_msginit;
  1206. extern const upb_msglayout google_protobuf_EnumOptions_msginit;
  1207. extern const upb_msglayout google_protobuf_EnumValueOptions_msginit;
  1208. extern const upb_msglayout google_protobuf_ServiceOptions_msginit;
  1209. extern const upb_msglayout google_protobuf_MethodOptions_msginit;
  1210. extern const upb_msglayout google_protobuf_UninterpretedOption_msginit;
  1211. extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit;
  1212. extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit;
  1213. extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit;
  1214. extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit;
  1215. extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit;
  1216. typedef enum {
  1217. google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
  1218. google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
  1219. google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
  1220. } google_protobuf_FieldDescriptorProto_Label;
  1221. typedef enum {
  1222. google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
  1223. google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
  1224. google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
  1225. google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
  1226. google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
  1227. google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
  1228. google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
  1229. google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
  1230. google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
  1231. google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
  1232. google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
  1233. google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
  1234. google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
  1235. google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
  1236. google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
  1237. google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
  1238. google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
  1239. google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
  1240. } google_protobuf_FieldDescriptorProto_Type;
  1241. typedef enum {
  1242. google_protobuf_FieldOptions_STRING = 0,
  1243. google_protobuf_FieldOptions_CORD = 1,
  1244. google_protobuf_FieldOptions_STRING_PIECE = 2
  1245. } google_protobuf_FieldOptions_CType;
  1246. typedef enum {
  1247. google_protobuf_FieldOptions_JS_NORMAL = 0,
  1248. google_protobuf_FieldOptions_JS_STRING = 1,
  1249. google_protobuf_FieldOptions_JS_NUMBER = 2
  1250. } google_protobuf_FieldOptions_JSType;
  1251. typedef enum {
  1252. google_protobuf_FileOptions_SPEED = 1,
  1253. google_protobuf_FileOptions_CODE_SIZE = 2,
  1254. google_protobuf_FileOptions_LITE_RUNTIME = 3
  1255. } google_protobuf_FileOptions_OptimizeMode;
  1256. typedef enum {
  1257. google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
  1258. google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
  1259. google_protobuf_MethodOptions_IDEMPOTENT = 2
  1260. } google_protobuf_MethodOptions_IdempotencyLevel;
  1261. /* google.protobuf.FileDescriptorSet */
  1262. UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) {
  1263. return (google_protobuf_FileDescriptorSet *)_upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena);
  1264. }
  1265. UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size,
  1266. upb_arena *arena) {
  1267. google_protobuf_FileDescriptorSet *ret = google_protobuf_FileDescriptorSet_new(arena);
  1268. return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, arena)) ? ret : NULL;
  1269. }
  1270. UPB_INLINE char *google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet *msg, upb_arena *arena, size_t *len) {
  1271. return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len);
  1272. }
  1273. UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
  1274. 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); }
  1275. UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) {
  1276. return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  1277. }
  1278. UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) {
  1279. return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
  1280. }
  1281. UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) {
  1282. struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
  1283. bool ok = _upb_array_append_accessor(
  1284. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1285. if (!ok) return NULL;
  1286. return sub;
  1287. }
  1288. /* google.protobuf.FileDescriptorProto */
  1289. UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) {
  1290. return (google_protobuf_FileDescriptorProto *)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
  1291. }
  1292. UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size,
  1293. upb_arena *arena) {
  1294. google_protobuf_FileDescriptorProto *ret = google_protobuf_FileDescriptorProto_new(arena);
  1295. return (ret && upb_decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, arena)) ? ret : NULL;
  1296. }
  1297. UPB_INLINE char *google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1298. return upb_encode(msg, &google_protobuf_FileDescriptorProto_msginit, arena, len);
  1299. }
  1300. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1301. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1302. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1303. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
  1304. 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); }
  1305. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); }
  1306. 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); }
  1307. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(44, 88)); }
  1308. 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); }
  1309. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(48, 96)); }
  1310. 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); }
  1311. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 104)); }
  1312. 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); }
  1313. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  1314. UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); }
  1315. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 5); }
  1316. UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); }
  1317. 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); }
  1318. 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); }
  1319. UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  1320. UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
  1321. UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  1322. _upb_sethas(msg, 1);
  1323. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  1324. }
  1325. UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  1326. _upb_sethas(msg, 2);
  1327. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
  1328. }
  1329. UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1330. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
  1331. }
  1332. UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1333. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_STRING, arena);
  1334. }
  1335. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) {
  1336. return _upb_array_append_accessor(msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
  1337. arena);
  1338. }
  1339. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1340. return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
  1341. }
  1342. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1343. return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena);
  1344. }
  1345. UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1346. struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  1347. bool ok = _upb_array_append_accessor(
  1348. msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1349. if (!ok) return NULL;
  1350. return sub;
  1351. }
  1352. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1353. return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
  1354. }
  1355. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1356. return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_MESSAGE, arena);
  1357. }
  1358. UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1359. struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  1360. bool ok = _upb_array_append_accessor(
  1361. msg, UPB_SIZE(44, 88), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1362. if (!ok) return NULL;
  1363. return sub;
  1364. }
  1365. UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1366. return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len);
  1367. }
  1368. UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1369. return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_TYPE_MESSAGE, arena);
  1370. }
  1371. UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1372. struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
  1373. bool ok = _upb_array_append_accessor(
  1374. msg, UPB_SIZE(48, 96), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1375. if (!ok) return NULL;
  1376. return sub;
  1377. }
  1378. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1379. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len);
  1380. }
  1381. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1382. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_TYPE_MESSAGE, arena);
  1383. }
  1384. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1385. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  1386. bool ok = _upb_array_append_accessor(
  1387. msg, UPB_SIZE(52, 104), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1388. if (!ok) return NULL;
  1389. return sub;
  1390. }
  1391. UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
  1392. _upb_sethas(msg, 4);
  1393. *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_FileOptions*) = value;
  1394. }
  1395. UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1396. struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg);
  1397. if (sub == NULL) {
  1398. sub = (struct google_protobuf_FileOptions*)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
  1399. if (!sub) return NULL;
  1400. google_protobuf_FileDescriptorProto_set_options(msg, sub);
  1401. }
  1402. return sub;
  1403. }
  1404. UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
  1405. _upb_sethas(msg, 5);
  1406. *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_SourceCodeInfo*) = value;
  1407. }
  1408. UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
  1409. struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg);
  1410. if (sub == NULL) {
  1411. sub = (struct google_protobuf_SourceCodeInfo*)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
  1412. if (!sub) return NULL;
  1413. google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub);
  1414. }
  1415. return sub;
  1416. }
  1417. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1418. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len);
  1419. }
  1420. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1421. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_TYPE_INT32, arena);
  1422. }
  1423. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
  1424. return _upb_array_append_accessor(msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
  1425. arena);
  1426. }
  1427. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
  1428. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len);
  1429. }
  1430. UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
  1431. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_TYPE_INT32, arena);
  1432. }
  1433. UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
  1434. return _upb_array_append_accessor(msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
  1435. arena);
  1436. }
  1437. UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
  1438. _upb_sethas(msg, 3);
  1439. *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
  1440. }
  1441. /* google.protobuf.DescriptorProto */
  1442. UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) {
  1443. return (google_protobuf_DescriptorProto *)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  1444. }
  1445. UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size,
  1446. upb_arena *arena) {
  1447. google_protobuf_DescriptorProto *ret = google_protobuf_DescriptorProto_new(arena);
  1448. return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, arena)) ? ret : NULL;
  1449. }
  1450. UPB_INLINE char *google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto *msg, upb_arena *arena, size_t *len) {
  1451. return upb_encode(msg, &google_protobuf_DescriptorProto_msginit, arena, len);
  1452. }
  1453. UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1454. UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1455. UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
  1456. 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); }
  1457. UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); }
  1458. 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); }
  1459. UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); }
  1460. 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); }
  1461. UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); }
  1462. 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); }
  1463. UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); }
  1464. 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); }
  1465. UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1466. UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_MessageOptions*); }
  1467. UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); }
  1468. 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); }
  1469. UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); }
  1470. 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); }
  1471. 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); }
  1472. UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) {
  1473. _upb_sethas(msg, 1);
  1474. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  1475. }
  1476. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) {
  1477. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  1478. }
  1479. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1480. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
  1481. }
  1482. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1483. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  1484. bool ok = _upb_array_append_accessor(
  1485. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1486. if (!ok) return NULL;
  1487. return sub;
  1488. }
  1489. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto *msg, size_t *len) {
  1490. return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  1491. }
  1492. UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1493. return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena);
  1494. }
  1495. UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1496. struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
  1497. bool ok = _upb_array_append_accessor(
  1498. msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1499. if (!ok) return NULL;
  1500. return sub;
  1501. }
  1502. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto *msg, size_t *len) {
  1503. return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  1504. }
  1505. UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1506. return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_MESSAGE, arena);
  1507. }
  1508. UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1509. struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  1510. bool ok = _upb_array_append_accessor(
  1511. msg, UPB_SIZE(24, 48), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1512. if (!ok) return NULL;
  1513. return sub;
  1514. }
  1515. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto *msg, size_t *len) {
  1516. return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
  1517. }
  1518. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1519. return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_MESSAGE, arena);
  1520. }
  1521. UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1522. struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
  1523. bool ok = _upb_array_append_accessor(
  1524. msg, UPB_SIZE(28, 56), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1525. if (!ok) return NULL;
  1526. return sub;
  1527. }
  1528. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto *msg, size_t *len) {
  1529. return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len);
  1530. }
  1531. UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1532. return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_TYPE_MESSAGE, arena);
  1533. }
  1534. UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1535. struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  1536. bool ok = _upb_array_append_accessor(
  1537. msg, UPB_SIZE(32, 64), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1538. if (!ok) return NULL;
  1539. return sub;
  1540. }
  1541. UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) {
  1542. _upb_sethas(msg, 2);
  1543. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_MessageOptions*) = value;
  1544. }
  1545. UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1546. struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg);
  1547. if (sub == NULL) {
  1548. sub = (struct google_protobuf_MessageOptions*)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
  1549. if (!sub) return NULL;
  1550. google_protobuf_DescriptorProto_set_options(msg, sub);
  1551. }
  1552. return sub;
  1553. }
  1554. UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto *msg, size_t *len) {
  1555. return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
  1556. }
  1557. UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1558. return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_MESSAGE, arena);
  1559. }
  1560. UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1561. struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
  1562. bool ok = _upb_array_append_accessor(
  1563. msg, UPB_SIZE(36, 72), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1564. if (!ok) return NULL;
  1565. return sub;
  1566. }
  1567. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto *msg, size_t *len) {
  1568. return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
  1569. }
  1570. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1571. return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena);
  1572. }
  1573. UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
  1574. struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
  1575. bool ok = _upb_array_append_accessor(
  1576. msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1577. if (!ok) return NULL;
  1578. return sub;
  1579. }
  1580. UPB_INLINE upb_strview* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto *msg, size_t *len) {
  1581. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
  1582. }
  1583. UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
  1584. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_STRING, arena);
  1585. }
  1586. UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) {
  1587. return _upb_array_append_accessor(msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
  1588. arena);
  1589. }
  1590. /* google.protobuf.DescriptorProto.ExtensionRange */
  1591. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) {
  1592. return (google_protobuf_DescriptorProto_ExtensionRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
  1593. }
  1594. UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size,
  1595. upb_arena *arena) {
  1596. google_protobuf_DescriptorProto_ExtensionRange *ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena);
  1597. return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena)) ? ret : NULL;
  1598. }
  1599. UPB_INLINE char *google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena, size_t *len) {
  1600. return upb_encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, arena, len);
  1601. }
  1602. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 1); }
  1603. UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
  1604. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 2); }
  1605. UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  1606. UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 3); }
  1607. UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); }
  1608. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
  1609. _upb_sethas(msg, 1);
  1610. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
  1611. }
  1612. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
  1613. _upb_sethas(msg, 2);
  1614. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  1615. }
  1616. UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) {
  1617. _upb_sethas(msg, 3);
  1618. *UPB_PTR_AT(msg, UPB_SIZE(12, 16), google_protobuf_ExtensionRangeOptions*) = value;
  1619. }
  1620. UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena) {
  1621. struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg);
  1622. if (sub == NULL) {
  1623. sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
  1624. if (!sub) return NULL;
  1625. google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub);
  1626. }
  1627. return sub;
  1628. }
  1629. /* google.protobuf.DescriptorProto.ReservedRange */
  1630. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) {
  1631. return (google_protobuf_DescriptorProto_ReservedRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
  1632. }
  1633. UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size,
  1634. upb_arena *arena) {
  1635. google_protobuf_DescriptorProto_ReservedRange *ret = google_protobuf_DescriptorProto_ReservedRange_new(arena);
  1636. return (ret && upb_decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena)) ? ret : NULL;
  1637. }
  1638. UPB_INLINE char *google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange *msg, upb_arena *arena, size_t *len) {
  1639. return upb_encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, arena, len);
  1640. }
  1641. UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 1); }
  1642. UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
  1643. UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 2); }
  1644. UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  1645. UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
  1646. _upb_sethas(msg, 1);
  1647. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
  1648. }
  1649. UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
  1650. _upb_sethas(msg, 2);
  1651. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  1652. }
  1653. /* google.protobuf.ExtensionRangeOptions */
  1654. UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) {
  1655. return (google_protobuf_ExtensionRangeOptions *)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
  1656. }
  1657. UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size,
  1658. upb_arena *arena) {
  1659. google_protobuf_ExtensionRangeOptions *ret = google_protobuf_ExtensionRangeOptions_new(arena);
  1660. return (ret && upb_decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, arena)) ? ret : NULL;
  1661. }
  1662. UPB_INLINE char *google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena, size_t *len) {
  1663. return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len);
  1664. }
  1665. UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
  1666. 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); }
  1667. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) {
  1668. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  1669. }
  1670. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) {
  1671. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
  1672. }
  1673. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) {
  1674. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  1675. bool ok = _upb_array_append_accessor(
  1676. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1677. if (!ok) return NULL;
  1678. return sub;
  1679. }
  1680. /* google.protobuf.FieldDescriptorProto */
  1681. UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) {
  1682. return (google_protobuf_FieldDescriptorProto *)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
  1683. }
  1684. UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size,
  1685. upb_arena *arena) {
  1686. google_protobuf_FieldDescriptorProto *ret = google_protobuf_FieldDescriptorProto_new(arena);
  1687. return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, arena)) ? ret : NULL;
  1688. }
  1689. UPB_INLINE char *google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1690. return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len);
  1691. }
  1692. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); }
  1693. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview); }
  1694. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); }
  1695. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview); }
  1696. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  1697. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t); }
  1698. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1699. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  1700. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1701. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); }
  1702. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); }
  1703. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview); }
  1704. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); }
  1705. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview); }
  1706. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 11); }
  1707. UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 120), const google_protobuf_FieldOptions*); }
  1708. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  1709. UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t); }
  1710. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); }
  1711. UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview); }
  1712. UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); }
  1713. UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool); }
  1714. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  1715. _upb_sethas(msg, 6);
  1716. *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview) = value;
  1717. }
  1718. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  1719. _upb_sethas(msg, 7);
  1720. *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview) = value;
  1721. }
  1722. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  1723. _upb_sethas(msg, 3);
  1724. *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t) = value;
  1725. }
  1726. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  1727. _upb_sethas(msg, 1);
  1728. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  1729. }
  1730. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  1731. _upb_sethas(msg, 2);
  1732. *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value;
  1733. }
  1734. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  1735. _upb_sethas(msg, 8);
  1736. *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview) = value;
  1737. }
  1738. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  1739. _upb_sethas(msg, 9);
  1740. *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview) = value;
  1741. }
  1742. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
  1743. _upb_sethas(msg, 11);
  1744. *UPB_PTR_AT(msg, UPB_SIZE(76, 120), google_protobuf_FieldOptions*) = value;
  1745. }
  1746. UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) {
  1747. struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg);
  1748. if (sub == NULL) {
  1749. sub = (struct google_protobuf_FieldOptions*)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
  1750. if (!sub) return NULL;
  1751. google_protobuf_FieldDescriptorProto_set_options(msg, sub);
  1752. }
  1753. return sub;
  1754. }
  1755. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
  1756. _upb_sethas(msg, 4);
  1757. *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t) = value;
  1758. }
  1759. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
  1760. _upb_sethas(msg, 10);
  1761. *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview) = value;
  1762. }
  1763. UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) {
  1764. _upb_sethas(msg, 5);
  1765. *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool) = value;
  1766. }
  1767. /* google.protobuf.OneofDescriptorProto */
  1768. UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) {
  1769. return (google_protobuf_OneofDescriptorProto *)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
  1770. }
  1771. UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size,
  1772. upb_arena *arena) {
  1773. google_protobuf_OneofDescriptorProto *ret = google_protobuf_OneofDescriptorProto_new(arena);
  1774. return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, arena)) ? ret : NULL;
  1775. }
  1776. UPB_INLINE char *google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1777. return upb_encode(msg, &google_protobuf_OneofDescriptorProto_msginit, arena, len);
  1778. }
  1779. UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1780. UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1781. UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1782. UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); }
  1783. UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) {
  1784. _upb_sethas(msg, 1);
  1785. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  1786. }
  1787. UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) {
  1788. _upb_sethas(msg, 2);
  1789. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = value;
  1790. }
  1791. UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_arena *arena) {
  1792. struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg);
  1793. if (sub == NULL) {
  1794. sub = (struct google_protobuf_OneofOptions*)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
  1795. if (!sub) return NULL;
  1796. google_protobuf_OneofDescriptorProto_set_options(msg, sub);
  1797. }
  1798. return sub;
  1799. }
  1800. /* google.protobuf.EnumDescriptorProto */
  1801. UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) {
  1802. return (google_protobuf_EnumDescriptorProto *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
  1803. }
  1804. UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size,
  1805. upb_arena *arena) {
  1806. google_protobuf_EnumDescriptorProto *ret = google_protobuf_EnumDescriptorProto_new(arena);
  1807. return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, arena)) ? ret : NULL;
  1808. }
  1809. UPB_INLINE char *google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1810. return upb_encode(msg, &google_protobuf_EnumDescriptorProto_msginit, arena, len);
  1811. }
  1812. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1813. UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1814. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
  1815. 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); }
  1816. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1817. UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_EnumOptions*); }
  1818. UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); }
  1819. 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); }
  1820. 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); }
  1821. UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) {
  1822. _upb_sethas(msg, 1);
  1823. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  1824. }
  1825. UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  1826. return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  1827. }
  1828. UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  1829. return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
  1830. }
  1831. UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  1832. struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
  1833. bool ok = _upb_array_append_accessor(
  1834. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1835. if (!ok) return NULL;
  1836. return sub;
  1837. }
  1838. UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) {
  1839. _upb_sethas(msg, 2);
  1840. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_EnumOptions*) = value;
  1841. }
  1842. UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  1843. struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg);
  1844. if (sub == NULL) {
  1845. sub = (struct google_protobuf_EnumOptions*)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
  1846. if (!sub) return NULL;
  1847. google_protobuf_EnumDescriptorProto_set_options(msg, sub);
  1848. }
  1849. return sub;
  1850. }
  1851. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  1852. return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  1853. }
  1854. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  1855. return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena);
  1856. }
  1857. UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
  1858. struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
  1859. bool ok = _upb_array_append_accessor(
  1860. msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1861. if (!ok) return NULL;
  1862. return sub;
  1863. }
  1864. UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
  1865. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  1866. }
  1867. UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
  1868. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_STRING, arena);
  1869. }
  1870. UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) {
  1871. return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
  1872. arena);
  1873. }
  1874. /* google.protobuf.EnumDescriptorProto.EnumReservedRange */
  1875. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) {
  1876. return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
  1877. }
  1878. UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size,
  1879. upb_arena *arena) {
  1880. google_protobuf_EnumDescriptorProto_EnumReservedRange *ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena);
  1881. return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena)) ? ret : NULL;
  1882. }
  1883. UPB_INLINE char *google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, upb_arena *arena, size_t *len) {
  1884. return upb_encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena, len);
  1885. }
  1886. UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 1); }
  1887. UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
  1888. UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 2); }
  1889. UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  1890. UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
  1891. _upb_sethas(msg, 1);
  1892. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
  1893. }
  1894. UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
  1895. _upb_sethas(msg, 2);
  1896. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  1897. }
  1898. /* google.protobuf.EnumValueDescriptorProto */
  1899. UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) {
  1900. return (google_protobuf_EnumValueDescriptorProto *)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
  1901. }
  1902. UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size,
  1903. upb_arena *arena) {
  1904. google_protobuf_EnumValueDescriptorProto *ret = google_protobuf_EnumValueDescriptorProto_new(arena);
  1905. return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, arena)) ? ret : NULL;
  1906. }
  1907. UPB_INLINE char *google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1908. return upb_encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, arena, len);
  1909. }
  1910. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1911. UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview); }
  1912. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1913. UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
  1914. UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  1915. UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); }
  1916. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) {
  1917. _upb_sethas(msg, 2);
  1918. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview) = value;
  1919. }
  1920. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
  1921. _upb_sethas(msg, 1);
  1922. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
  1923. }
  1924. UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
  1925. _upb_sethas(msg, 3);
  1926. *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = value;
  1927. }
  1928. UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena) {
  1929. struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg);
  1930. if (sub == NULL) {
  1931. sub = (struct google_protobuf_EnumValueOptions*)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
  1932. if (!sub) return NULL;
  1933. google_protobuf_EnumValueDescriptorProto_set_options(msg, sub);
  1934. }
  1935. return sub;
  1936. }
  1937. /* google.protobuf.ServiceDescriptorProto */
  1938. UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) {
  1939. return (google_protobuf_ServiceDescriptorProto *)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
  1940. }
  1941. UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size,
  1942. upb_arena *arena) {
  1943. google_protobuf_ServiceDescriptorProto *ret = google_protobuf_ServiceDescriptorProto_new(arena);
  1944. return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, arena)) ? ret : NULL;
  1945. }
  1946. UPB_INLINE char *google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1947. return upb_encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, arena, len);
  1948. }
  1949. UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  1950. UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1951. UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
  1952. 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); }
  1953. UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  1954. UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_ServiceOptions*); }
  1955. UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) {
  1956. _upb_sethas(msg, 1);
  1957. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  1958. }
  1959. UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) {
  1960. return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
  1961. }
  1962. UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) {
  1963. return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
  1964. }
  1965. UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
  1966. struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
  1967. bool ok = _upb_array_append_accessor(
  1968. msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  1969. if (!ok) return NULL;
  1970. return sub;
  1971. }
  1972. UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) {
  1973. _upb_sethas(msg, 2);
  1974. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_ServiceOptions*) = value;
  1975. }
  1976. UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
  1977. struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg);
  1978. if (sub == NULL) {
  1979. sub = (struct google_protobuf_ServiceOptions*)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
  1980. if (!sub) return NULL;
  1981. google_protobuf_ServiceDescriptorProto_set_options(msg, sub);
  1982. }
  1983. return sub;
  1984. }
  1985. /* google.protobuf.MethodDescriptorProto */
  1986. UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) {
  1987. return (google_protobuf_MethodDescriptorProto *)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
  1988. }
  1989. UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size,
  1990. upb_arena *arena) {
  1991. google_protobuf_MethodDescriptorProto *ret = google_protobuf_MethodDescriptorProto_new(arena);
  1992. return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, arena)) ? ret : NULL;
  1993. }
  1994. UPB_INLINE char *google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto *msg, upb_arena *arena, size_t *len) {
  1995. return upb_encode(msg, &google_protobuf_MethodDescriptorProto_msginit, arena, len);
  1996. }
  1997. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 3); }
  1998. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  1999. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 4); }
  2000. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
  2001. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 5); }
  2002. UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
  2003. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 6); }
  2004. UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); }
  2005. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 1); }
  2006. UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2007. UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 2); }
  2008. UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
  2009. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  2010. _upb_sethas(msg, 3);
  2011. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  2012. }
  2013. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  2014. _upb_sethas(msg, 4);
  2015. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
  2016. }
  2017. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
  2018. _upb_sethas(msg, 5);
  2019. *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
  2020. }
  2021. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
  2022. _upb_sethas(msg, 6);
  2023. *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value;
  2024. }
  2025. UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) {
  2026. struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg);
  2027. if (sub == NULL) {
  2028. sub = (struct google_protobuf_MethodOptions*)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
  2029. if (!sub) return NULL;
  2030. google_protobuf_MethodDescriptorProto_set_options(msg, sub);
  2031. }
  2032. return sub;
  2033. }
  2034. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
  2035. _upb_sethas(msg, 1);
  2036. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2037. }
  2038. UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
  2039. _upb_sethas(msg, 2);
  2040. *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
  2041. }
  2042. /* google.protobuf.FileOptions */
  2043. UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) {
  2044. return (google_protobuf_FileOptions *)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
  2045. }
  2046. UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size,
  2047. upb_arena *arena) {
  2048. google_protobuf_FileOptions *ret = google_protobuf_FileOptions_new(arena);
  2049. return (ret && upb_decode(buf, size, ret, &google_protobuf_FileOptions_msginit, arena)) ? ret : NULL;
  2050. }
  2051. UPB_INLINE char *google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions *msg, upb_arena *arena, size_t *len) {
  2052. return upb_encode(msg, &google_protobuf_FileOptions_msginit, arena, len);
  2053. }
  2054. UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 11); }
  2055. UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview); }
  2056. UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 12); }
  2057. UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview); }
  2058. UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 1); }
  2059. UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  2060. UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 2); }
  2061. UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); }
  2062. UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 13); }
  2063. UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview); }
  2064. UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 3); }
  2065. UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool); }
  2066. UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 4); }
  2067. UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool); }
  2068. UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 5); }
  2069. UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool); }
  2070. UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 6); }
  2071. UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); }
  2072. UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 7); }
  2073. UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool); }
  2074. UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 8); }
  2075. UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool); }
  2076. UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 9); }
  2077. UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool); }
  2078. UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 14); }
  2079. UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview); }
  2080. UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 15); }
  2081. UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview); }
  2082. UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 16); }
  2083. UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview); }
  2084. UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 17); }
  2085. UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview); }
  2086. UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 18); }
  2087. UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview); }
  2088. UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 10); }
  2089. UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); }
  2090. UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 19); }
  2091. UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview); }
  2092. UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 20); }
  2093. UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview); }
  2094. UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(108, 192)); }
  2095. 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(108, 192), len); }
  2096. UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) {
  2097. _upb_sethas(msg, 11);
  2098. *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview) = value;
  2099. }
  2100. UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) {
  2101. _upb_sethas(msg, 12);
  2102. *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview) = value;
  2103. }
  2104. UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) {
  2105. _upb_sethas(msg, 1);
  2106. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  2107. }
  2108. UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
  2109. _upb_sethas(msg, 2);
  2110. *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value;
  2111. }
  2112. UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) {
  2113. _upb_sethas(msg, 13);
  2114. *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview) = value;
  2115. }
  2116. UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
  2117. _upb_sethas(msg, 3);
  2118. *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool) = value;
  2119. }
  2120. UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
  2121. _upb_sethas(msg, 4);
  2122. *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool) = value;
  2123. }
  2124. UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
  2125. _upb_sethas(msg, 5);
  2126. *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool) = value;
  2127. }
  2128. UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
  2129. _upb_sethas(msg, 6);
  2130. *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value;
  2131. }
  2132. UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
  2133. _upb_sethas(msg, 7);
  2134. *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool) = value;
  2135. }
  2136. UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
  2137. _upb_sethas(msg, 8);
  2138. *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool) = value;
  2139. }
  2140. UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
  2141. _upb_sethas(msg, 9);
  2142. *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool) = value;
  2143. }
  2144. UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  2145. _upb_sethas(msg, 14);
  2146. *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview) = value;
  2147. }
  2148. UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
  2149. _upb_sethas(msg, 15);
  2150. *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview) = value;
  2151. }
  2152. UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  2153. _upb_sethas(msg, 16);
  2154. *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview) = value;
  2155. }
  2156. UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
  2157. _upb_sethas(msg, 17);
  2158. *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview) = value;
  2159. }
  2160. UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
  2161. _upb_sethas(msg, 18);
  2162. *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview) = value;
  2163. }
  2164. UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
  2165. _upb_sethas(msg, 10);
  2166. *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value;
  2167. }
  2168. UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
  2169. _upb_sethas(msg, 19);
  2170. *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview) = value;
  2171. }
  2172. UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_strview value) {
  2173. _upb_sethas(msg, 20);
  2174. *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview) = value;
  2175. }
  2176. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) {
  2177. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(108, 192), len);
  2178. }
  2179. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) {
  2180. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(108, 192), len, UPB_TYPE_MESSAGE, arena);
  2181. }
  2182. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) {
  2183. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2184. bool ok = _upb_array_append_accessor(
  2185. msg, UPB_SIZE(108, 192), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2186. if (!ok) return NULL;
  2187. return sub;
  2188. }
  2189. /* google.protobuf.MessageOptions */
  2190. UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) {
  2191. return (google_protobuf_MessageOptions *)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
  2192. }
  2193. UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size,
  2194. upb_arena *arena) {
  2195. google_protobuf_MessageOptions *ret = google_protobuf_MessageOptions_new(arena);
  2196. return (ret && upb_decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, arena)) ? ret : NULL;
  2197. }
  2198. UPB_INLINE char *google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions *msg, upb_arena *arena, size_t *len) {
  2199. return upb_encode(msg, &google_protobuf_MessageOptions_msginit, arena, len);
  2200. }
  2201. UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 1); }
  2202. UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2203. UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 2); }
  2204. UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
  2205. UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 3); }
  2206. UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool); }
  2207. UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 4); }
  2208. UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool); }
  2209. UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 8)); }
  2210. 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); }
  2211. UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) {
  2212. _upb_sethas(msg, 1);
  2213. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2214. }
  2215. UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) {
  2216. _upb_sethas(msg, 2);
  2217. *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
  2218. }
  2219. UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) {
  2220. _upb_sethas(msg, 3);
  2221. *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool) = value;
  2222. }
  2223. UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) {
  2224. _upb_sethas(msg, 4);
  2225. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool) = value;
  2226. }
  2227. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) {
  2228. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len);
  2229. }
  2230. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) {
  2231. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_TYPE_MESSAGE, arena);
  2232. }
  2233. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) {
  2234. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2235. bool ok = _upb_array_append_accessor(
  2236. msg, UPB_SIZE(8, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2237. if (!ok) return NULL;
  2238. return sub;
  2239. }
  2240. /* google.protobuf.FieldOptions */
  2241. UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) {
  2242. return (google_protobuf_FieldOptions *)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
  2243. }
  2244. UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size,
  2245. upb_arena *arena) {
  2246. google_protobuf_FieldOptions *ret = google_protobuf_FieldOptions_new(arena);
  2247. return (ret && upb_decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, arena)) ? ret : NULL;
  2248. }
  2249. UPB_INLINE char *google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions *msg, upb_arena *arena, size_t *len) {
  2250. return upb_encode(msg, &google_protobuf_FieldOptions_msginit, arena, len);
  2251. }
  2252. UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 1); }
  2253. UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  2254. UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 3); }
  2255. UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); }
  2256. UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 4); }
  2257. UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool); }
  2258. UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 5); }
  2259. UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool); }
  2260. UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 2); }
  2261. UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); }
  2262. UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 6); }
  2263. UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool); }
  2264. UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 32)); }
  2265. 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); }
  2266. UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) {
  2267. _upb_sethas(msg, 1);
  2268. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  2269. }
  2270. UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
  2271. _upb_sethas(msg, 3);
  2272. *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value;
  2273. }
  2274. UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
  2275. _upb_sethas(msg, 4);
  2276. *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool) = value;
  2277. }
  2278. UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
  2279. _upb_sethas(msg, 5);
  2280. *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool) = value;
  2281. }
  2282. UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) {
  2283. _upb_sethas(msg, 2);
  2284. *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value;
  2285. }
  2286. UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
  2287. _upb_sethas(msg, 6);
  2288. *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool) = value;
  2289. }
  2290. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) {
  2291. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 32), len);
  2292. }
  2293. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) {
  2294. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_TYPE_MESSAGE, arena);
  2295. }
  2296. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) {
  2297. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2298. bool ok = _upb_array_append_accessor(
  2299. msg, UPB_SIZE(28, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2300. if (!ok) return NULL;
  2301. return sub;
  2302. }
  2303. /* google.protobuf.OneofOptions */
  2304. UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) {
  2305. return (google_protobuf_OneofOptions *)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
  2306. }
  2307. UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size,
  2308. upb_arena *arena) {
  2309. google_protobuf_OneofOptions *ret = google_protobuf_OneofOptions_new(arena);
  2310. return (ret && upb_decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, arena)) ? ret : NULL;
  2311. }
  2312. UPB_INLINE char *google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions *msg, upb_arena *arena, size_t *len) {
  2313. return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len);
  2314. }
  2315. UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
  2316. 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); }
  2317. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) {
  2318. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  2319. }
  2320. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) {
  2321. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
  2322. }
  2323. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) {
  2324. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2325. bool ok = _upb_array_append_accessor(
  2326. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2327. if (!ok) return NULL;
  2328. return sub;
  2329. }
  2330. /* google.protobuf.EnumOptions */
  2331. UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) {
  2332. return (google_protobuf_EnumOptions *)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
  2333. }
  2334. UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size,
  2335. upb_arena *arena) {
  2336. google_protobuf_EnumOptions *ret = google_protobuf_EnumOptions_new(arena);
  2337. return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, arena)) ? ret : NULL;
  2338. }
  2339. UPB_INLINE char *google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions *msg, upb_arena *arena, size_t *len) {
  2340. return upb_encode(msg, &google_protobuf_EnumOptions_msginit, arena, len);
  2341. }
  2342. UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 1); }
  2343. UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2344. UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 2); }
  2345. UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
  2346. UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
  2347. 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); }
  2348. UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) {
  2349. _upb_sethas(msg, 1);
  2350. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2351. }
  2352. UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) {
  2353. _upb_sethas(msg, 2);
  2354. *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
  2355. }
  2356. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) {
  2357. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  2358. }
  2359. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) {
  2360. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
  2361. }
  2362. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) {
  2363. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2364. bool ok = _upb_array_append_accessor(
  2365. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2366. if (!ok) return NULL;
  2367. return sub;
  2368. }
  2369. /* google.protobuf.EnumValueOptions */
  2370. UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) {
  2371. return (google_protobuf_EnumValueOptions *)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
  2372. }
  2373. UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size,
  2374. upb_arena *arena) {
  2375. google_protobuf_EnumValueOptions *ret = google_protobuf_EnumValueOptions_new(arena);
  2376. return (ret && upb_decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, arena)) ? ret : NULL;
  2377. }
  2378. UPB_INLINE char *google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions *msg, upb_arena *arena, size_t *len) {
  2379. return upb_encode(msg, &google_protobuf_EnumValueOptions_msginit, arena, len);
  2380. }
  2381. UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_has_field(msg, 1); }
  2382. UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2383. UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
  2384. 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); }
  2385. UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) {
  2386. _upb_sethas(msg, 1);
  2387. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2388. }
  2389. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) {
  2390. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  2391. }
  2392. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) {
  2393. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
  2394. }
  2395. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) {
  2396. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2397. bool ok = _upb_array_append_accessor(
  2398. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2399. if (!ok) return NULL;
  2400. return sub;
  2401. }
  2402. /* google.protobuf.ServiceOptions */
  2403. UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) {
  2404. return (google_protobuf_ServiceOptions *)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
  2405. }
  2406. UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size,
  2407. upb_arena *arena) {
  2408. google_protobuf_ServiceOptions *ret = google_protobuf_ServiceOptions_new(arena);
  2409. return (ret && upb_decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, arena)) ? ret : NULL;
  2410. }
  2411. UPB_INLINE char *google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions *msg, upb_arena *arena, size_t *len) {
  2412. return upb_encode(msg, &google_protobuf_ServiceOptions_msginit, arena, len);
  2413. }
  2414. UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_has_field(msg, 1); }
  2415. UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2416. UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
  2417. 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); }
  2418. UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) {
  2419. _upb_sethas(msg, 1);
  2420. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2421. }
  2422. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) {
  2423. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
  2424. }
  2425. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) {
  2426. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
  2427. }
  2428. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) {
  2429. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2430. bool ok = _upb_array_append_accessor(
  2431. msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2432. if (!ok) return NULL;
  2433. return sub;
  2434. }
  2435. /* google.protobuf.MethodOptions */
  2436. UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) {
  2437. return (google_protobuf_MethodOptions *)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
  2438. }
  2439. UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size,
  2440. upb_arena *arena) {
  2441. google_protobuf_MethodOptions *ret = google_protobuf_MethodOptions_new(arena);
  2442. return (ret && upb_decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, arena)) ? ret : NULL;
  2443. }
  2444. UPB_INLINE char *google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions *msg, upb_arena *arena, size_t *len) {
  2445. return upb_encode(msg, &google_protobuf_MethodOptions_msginit, arena, len);
  2446. }
  2447. UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 2); }
  2448. UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); }
  2449. UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 1); }
  2450. UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  2451. UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 24)); }
  2452. 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); }
  2453. UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
  2454. _upb_sethas(msg, 2);
  2455. *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value;
  2456. }
  2457. UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) {
  2458. _upb_sethas(msg, 1);
  2459. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  2460. }
  2461. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) {
  2462. return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 24), len);
  2463. }
  2464. UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) {
  2465. return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_TYPE_MESSAGE, arena);
  2466. }
  2467. UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) {
  2468. struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2469. bool ok = _upb_array_append_accessor(
  2470. msg, UPB_SIZE(20, 24), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2471. if (!ok) return NULL;
  2472. return sub;
  2473. }
  2474. /* google.protobuf.UninterpretedOption */
  2475. UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) {
  2476. return (google_protobuf_UninterpretedOption *)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
  2477. }
  2478. UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size,
  2479. upb_arena *arena) {
  2480. google_protobuf_UninterpretedOption *ret = google_protobuf_UninterpretedOption_new(arena);
  2481. return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, arena)) ? ret : NULL;
  2482. }
  2483. UPB_INLINE char *google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption *msg, upb_arena *arena, size_t *len) {
  2484. return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len);
  2485. }
  2486. UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(56, 80)); }
  2487. 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); }
  2488. UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 4); }
  2489. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); }
  2490. UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 1); }
  2491. UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); }
  2492. UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 2); }
  2493. UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); }
  2494. UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 3); }
  2495. UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); }
  2496. UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 5); }
  2497. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview); }
  2498. UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 6); }
  2499. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview); }
  2500. UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) {
  2501. return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len);
  2502. }
  2503. UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) {
  2504. return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_TYPE_MESSAGE, arena);
  2505. }
  2506. UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) {
  2507. struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
  2508. bool ok = _upb_array_append_accessor(
  2509. msg, UPB_SIZE(56, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2510. if (!ok) return NULL;
  2511. return sub;
  2512. }
  2513. UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  2514. _upb_sethas(msg, 4);
  2515. *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview) = value;
  2516. }
  2517. UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
  2518. _upb_sethas(msg, 1);
  2519. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t) = value;
  2520. }
  2521. UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
  2522. _upb_sethas(msg, 2);
  2523. *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t) = value;
  2524. }
  2525. UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
  2526. _upb_sethas(msg, 3);
  2527. *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double) = value;
  2528. }
  2529. UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  2530. _upb_sethas(msg, 5);
  2531. *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview) = value;
  2532. }
  2533. UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
  2534. _upb_sethas(msg, 6);
  2535. *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview) = value;
  2536. }
  2537. /* google.protobuf.UninterpretedOption.NamePart */
  2538. UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) {
  2539. return (google_protobuf_UninterpretedOption_NamePart *)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
  2540. }
  2541. UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size,
  2542. upb_arena *arena) {
  2543. google_protobuf_UninterpretedOption_NamePart *ret = google_protobuf_UninterpretedOption_NamePart_new(arena);
  2544. return (ret && upb_decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, arena)) ? ret : NULL;
  2545. }
  2546. UPB_INLINE char *google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart *msg, upb_arena *arena, size_t *len) {
  2547. return upb_encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, arena, len);
  2548. }
  2549. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 2); }
  2550. UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  2551. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 1); }
  2552. UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
  2553. UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) {
  2554. _upb_sethas(msg, 2);
  2555. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  2556. }
  2557. UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
  2558. _upb_sethas(msg, 1);
  2559. *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
  2560. }
  2561. /* google.protobuf.SourceCodeInfo */
  2562. UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) {
  2563. return (google_protobuf_SourceCodeInfo *)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
  2564. }
  2565. UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size,
  2566. upb_arena *arena) {
  2567. google_protobuf_SourceCodeInfo *ret = google_protobuf_SourceCodeInfo_new(arena);
  2568. return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, arena)) ? ret : NULL;
  2569. }
  2570. UPB_INLINE char *google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo *msg, upb_arena *arena, size_t *len) {
  2571. return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len);
  2572. }
  2573. UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
  2574. 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); }
  2575. UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) {
  2576. return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  2577. }
  2578. UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) {
  2579. return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
  2580. }
  2581. UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) {
  2582. struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
  2583. bool ok = _upb_array_append_accessor(
  2584. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2585. if (!ok) return NULL;
  2586. return sub;
  2587. }
  2588. /* google.protobuf.SourceCodeInfo.Location */
  2589. UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) {
  2590. return (google_protobuf_SourceCodeInfo_Location *)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
  2591. }
  2592. UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size,
  2593. upb_arena *arena) {
  2594. google_protobuf_SourceCodeInfo_Location *ret = google_protobuf_SourceCodeInfo_Location_new(arena);
  2595. return (ret && upb_decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, arena)) ? ret : NULL;
  2596. }
  2597. UPB_INLINE char *google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location *msg, upb_arena *arena, size_t *len) {
  2598. return upb_encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, arena, len);
  2599. }
  2600. 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); }
  2601. 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); }
  2602. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 1); }
  2603. UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
  2604. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 2); }
  2605. UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
  2606. 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); }
  2607. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  2608. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
  2609. }
  2610. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  2611. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_INT32, arena);
  2612. }
  2613. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
  2614. return _upb_array_append_accessor(msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
  2615. arena);
  2616. }
  2617. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  2618. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
  2619. }
  2620. UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  2621. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_INT32, arena);
  2622. }
  2623. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
  2624. return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
  2625. arena);
  2626. }
  2627. UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
  2628. _upb_sethas(msg, 1);
  2629. *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
  2630. }
  2631. UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
  2632. _upb_sethas(msg, 2);
  2633. *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
  2634. }
  2635. UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
  2636. return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
  2637. }
  2638. UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
  2639. return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_STRING, arena);
  2640. }
  2641. UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) {
  2642. return _upb_array_append_accessor(msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
  2643. arena);
  2644. }
  2645. /* google.protobuf.GeneratedCodeInfo */
  2646. UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) {
  2647. return (google_protobuf_GeneratedCodeInfo *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena);
  2648. }
  2649. UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size,
  2650. upb_arena *arena) {
  2651. google_protobuf_GeneratedCodeInfo *ret = google_protobuf_GeneratedCodeInfo_new(arena);
  2652. return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, arena)) ? ret : NULL;
  2653. }
  2654. UPB_INLINE char *google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena, size_t *len) {
  2655. return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len);
  2656. }
  2657. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
  2658. 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); }
  2659. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) {
  2660. return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
  2661. }
  2662. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) {
  2663. return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
  2664. }
  2665. UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) {
  2666. struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
  2667. bool ok = _upb_array_append_accessor(
  2668. msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
  2669. if (!ok) return NULL;
  2670. return sub;
  2671. }
  2672. /* google.protobuf.GeneratedCodeInfo.Annotation */
  2673. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) {
  2674. return (google_protobuf_GeneratedCodeInfo_Annotation *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
  2675. }
  2676. UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size,
  2677. upb_arena *arena) {
  2678. google_protobuf_GeneratedCodeInfo_Annotation *ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena);
  2679. return (ret && upb_decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena)) ? ret : NULL;
  2680. }
  2681. UPB_INLINE char *google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_arena *arena, size_t *len) {
  2682. return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena, len);
  2683. }
  2684. 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); }
  2685. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 3); }
  2686. UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview); }
  2687. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 1); }
  2688. UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
  2689. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 2); }
  2690. UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
  2691. UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) {
  2692. return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len);
  2693. }
  2694. UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) {
  2695. return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_TYPE_INT32, arena);
  2696. }
  2697. UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) {
  2698. return _upb_array_append_accessor(msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
  2699. arena);
  2700. }
  2701. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) {
  2702. _upb_sethas(msg, 3);
  2703. *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview) = value;
  2704. }
  2705. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
  2706. _upb_sethas(msg, 1);
  2707. *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
  2708. }
  2709. UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
  2710. _upb_sethas(msg, 2);
  2711. *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
  2712. }
  2713. #ifdef __cplusplus
  2714. } /* extern "C" */
  2715. #endif
  2716. #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */
  2717. /*
  2718. ** Defs are upb's internal representation of the constructs that can appear
  2719. ** in a .proto file:
  2720. **
  2721. ** - upb_msgdef: describes a "message" construct.
  2722. ** - upb_fielddef: describes a message field.
  2723. ** - upb_filedef: describes a .proto file and its defs.
  2724. ** - upb_enumdef: describes an enum.
  2725. ** - upb_oneofdef: describes a oneof.
  2726. **
  2727. ** TODO: definitions of services.
  2728. */
  2729. #ifndef UPB_DEF_H_
  2730. #define UPB_DEF_H_
  2731. #ifdef __cplusplus
  2732. extern "C" {
  2733. #endif /* __cplusplus */
  2734. struct upb_enumdef;
  2735. typedef struct upb_enumdef upb_enumdef;
  2736. struct upb_fielddef;
  2737. typedef struct upb_fielddef upb_fielddef;
  2738. struct upb_filedef;
  2739. typedef struct upb_filedef upb_filedef;
  2740. struct upb_msgdef;
  2741. typedef struct upb_msgdef upb_msgdef;
  2742. struct upb_oneofdef;
  2743. typedef struct upb_oneofdef upb_oneofdef;
  2744. struct upb_symtab;
  2745. typedef struct upb_symtab upb_symtab;
  2746. typedef enum {
  2747. UPB_SYNTAX_PROTO2 = 2,
  2748. UPB_SYNTAX_PROTO3 = 3
  2749. } upb_syntax_t;
  2750. /* All the different kind of well known type messages. For simplicity of check,
  2751. * number wrappers and string wrappers are grouped together. Make sure the
  2752. * order and merber of these groups are not changed.
  2753. */
  2754. typedef enum {
  2755. UPB_WELLKNOWN_UNSPECIFIED,
  2756. UPB_WELLKNOWN_ANY,
  2757. UPB_WELLKNOWN_FIELDMASK,
  2758. UPB_WELLKNOWN_DURATION,
  2759. UPB_WELLKNOWN_TIMESTAMP,
  2760. /* number wrappers */
  2761. UPB_WELLKNOWN_DOUBLEVALUE,
  2762. UPB_WELLKNOWN_FLOATVALUE,
  2763. UPB_WELLKNOWN_INT64VALUE,
  2764. UPB_WELLKNOWN_UINT64VALUE,
  2765. UPB_WELLKNOWN_INT32VALUE,
  2766. UPB_WELLKNOWN_UINT32VALUE,
  2767. /* string wrappers */
  2768. UPB_WELLKNOWN_STRINGVALUE,
  2769. UPB_WELLKNOWN_BYTESVALUE,
  2770. UPB_WELLKNOWN_BOOLVALUE,
  2771. UPB_WELLKNOWN_VALUE,
  2772. UPB_WELLKNOWN_LISTVALUE,
  2773. UPB_WELLKNOWN_STRUCT
  2774. } upb_wellknowntype_t;
  2775. /* upb_fielddef ***************************************************************/
  2776. /* Maximum field number allowed for FieldDefs. This is an inherent limit of the
  2777. * protobuf wire format. */
  2778. #define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
  2779. const char *upb_fielddef_fullname(const upb_fielddef *f);
  2780. upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
  2781. upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
  2782. upb_label_t upb_fielddef_label(const upb_fielddef *f);
  2783. uint32_t upb_fielddef_number(const upb_fielddef *f);
  2784. const char *upb_fielddef_name(const upb_fielddef *f);
  2785. const char *upb_fielddef_jsonname(const upb_fielddef *f);
  2786. bool upb_fielddef_isextension(const upb_fielddef *f);
  2787. bool upb_fielddef_lazy(const upb_fielddef *f);
  2788. bool upb_fielddef_packed(const upb_fielddef *f);
  2789. const upb_filedef *upb_fielddef_file(const upb_fielddef *f);
  2790. const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
  2791. const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
  2792. const upb_oneofdef *upb_fielddef_realcontainingoneof(const upb_fielddef *f);
  2793. uint32_t upb_fielddef_index(const upb_fielddef *f);
  2794. bool upb_fielddef_issubmsg(const upb_fielddef *f);
  2795. bool upb_fielddef_isstring(const upb_fielddef *f);
  2796. bool upb_fielddef_isseq(const upb_fielddef *f);
  2797. bool upb_fielddef_isprimitive(const upb_fielddef *f);
  2798. bool upb_fielddef_ismap(const upb_fielddef *f);
  2799. int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
  2800. int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
  2801. uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
  2802. uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
  2803. bool upb_fielddef_defaultbool(const upb_fielddef *f);
  2804. float upb_fielddef_defaultfloat(const upb_fielddef *f);
  2805. double upb_fielddef_defaultdouble(const upb_fielddef *f);
  2806. const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
  2807. bool upb_fielddef_hassubdef(const upb_fielddef *f);
  2808. bool upb_fielddef_haspresence(const upb_fielddef *f);
  2809. const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
  2810. const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
  2811. const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f);
  2812. /* Internal only. */
  2813. uint32_t upb_fielddef_selectorbase(const upb_fielddef *f);
  2814. /* upb_oneofdef ***************************************************************/
  2815. typedef upb_inttable_iter upb_oneof_iter;
  2816. const char *upb_oneofdef_name(const upb_oneofdef *o);
  2817. const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
  2818. int upb_oneofdef_numfields(const upb_oneofdef *o);
  2819. uint32_t upb_oneofdef_index(const upb_oneofdef *o);
  2820. bool upb_oneofdef_issynthetic(const upb_oneofdef *o);
  2821. /* Oneof lookups:
  2822. * - ntof: look up a field by name.
  2823. * - ntofz: look up a field by name (as a null-terminated string).
  2824. * - itof: look up a field by number. */
  2825. const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
  2826. const char *name, size_t length);
  2827. UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
  2828. const char *name) {
  2829. return upb_oneofdef_ntof(o, name, strlen(name));
  2830. }
  2831. const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
  2832. /* upb_oneof_iter i;
  2833. * for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
  2834. * // ...
  2835. * }
  2836. */
  2837. void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
  2838. void upb_oneof_next(upb_oneof_iter *iter);
  2839. bool upb_oneof_done(upb_oneof_iter *iter);
  2840. upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
  2841. void upb_oneof_iter_setdone(upb_oneof_iter *iter);
  2842. bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1,
  2843. const upb_oneof_iter *iter2);
  2844. /* upb_msgdef *****************************************************************/
  2845. typedef upb_inttable_iter upb_msg_field_iter;
  2846. typedef upb_strtable_iter upb_msg_oneof_iter;
  2847. /* Well-known field tag numbers for map-entry messages. */
  2848. #define UPB_MAPENTRY_KEY 1
  2849. #define UPB_MAPENTRY_VALUE 2
  2850. /* Well-known field tag numbers for Any messages. */
  2851. #define UPB_ANY_TYPE 1
  2852. #define UPB_ANY_VALUE 2
  2853. /* Well-known field tag numbers for timestamp messages. */
  2854. #define UPB_DURATION_SECONDS 1
  2855. #define UPB_DURATION_NANOS 2
  2856. /* Well-known field tag numbers for duration messages. */
  2857. #define UPB_TIMESTAMP_SECONDS 1
  2858. #define UPB_TIMESTAMP_NANOS 2
  2859. const char *upb_msgdef_fullname(const upb_msgdef *m);
  2860. const upb_filedef *upb_msgdef_file(const upb_msgdef *m);
  2861. const char *upb_msgdef_name(const upb_msgdef *m);
  2862. int upb_msgdef_numfields(const upb_msgdef *m);
  2863. int upb_msgdef_numoneofs(const upb_msgdef *m);
  2864. int upb_msgdef_numrealoneofs(const upb_msgdef *m);
  2865. upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
  2866. bool upb_msgdef_mapentry(const upb_msgdef *m);
  2867. upb_wellknowntype_t upb_msgdef_wellknowntype(const upb_msgdef *m);
  2868. bool upb_msgdef_isnumberwrapper(const upb_msgdef *m);
  2869. const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
  2870. const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
  2871. size_t len);
  2872. const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
  2873. size_t len);
  2874. const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m);
  2875. const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i);
  2876. UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
  2877. const char *name) {
  2878. return upb_msgdef_ntoo(m, name, strlen(name));
  2879. }
  2880. UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m,
  2881. const char *name) {
  2882. return upb_msgdef_ntof(m, name, strlen(name));
  2883. }
  2884. /* Internal-only. */
  2885. size_t upb_msgdef_selectorcount(const upb_msgdef *m);
  2886. uint32_t upb_msgdef_submsgfieldcount(const upb_msgdef *m);
  2887. /* Lookup of either field or oneof by name. Returns whether either was found.
  2888. * If the return is true, then the found def will be set, and the non-found
  2889. * one set to NULL. */
  2890. bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
  2891. const upb_fielddef **f, const upb_oneofdef **o);
  2892. UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
  2893. const upb_fielddef **f,
  2894. const upb_oneofdef **o) {
  2895. return upb_msgdef_lookupname(m, name, strlen(name), f, o);
  2896. }
  2897. /* Returns a field by either JSON name or regular proto name. */
  2898. const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m,
  2899. const char *name, size_t len);
  2900. /* Iteration over fields and oneofs. For example:
  2901. *
  2902. * upb_msg_field_iter i;
  2903. * for(upb_msg_field_begin(&i, m);
  2904. * !upb_msg_field_done(&i);
  2905. * upb_msg_field_next(&i)) {
  2906. * upb_fielddef *f = upb_msg_iter_field(&i);
  2907. * // ...
  2908. * }
  2909. *
  2910. * For C we don't have separate iterators for const and non-const.
  2911. * It is the caller's responsibility to cast the upb_fielddef* to
  2912. * const if the upb_msgdef* is const. */
  2913. void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
  2914. void upb_msg_field_next(upb_msg_field_iter *iter);
  2915. bool upb_msg_field_done(const upb_msg_field_iter *iter);
  2916. upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
  2917. void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
  2918. bool upb_msg_field_iter_isequal(const upb_msg_field_iter * iter1,
  2919. const upb_msg_field_iter * iter2);
  2920. /* Similar to above, we also support iterating through the oneofs in a
  2921. * msgdef. */
  2922. void upb_msg_oneof_begin(upb_msg_oneof_iter * iter, const upb_msgdef *m);
  2923. void upb_msg_oneof_next(upb_msg_oneof_iter * iter);
  2924. bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
  2925. const upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
  2926. void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter * iter);
  2927. bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1,
  2928. const upb_msg_oneof_iter *iter2);
  2929. /* upb_enumdef ****************************************************************/
  2930. typedef upb_strtable_iter upb_enum_iter;
  2931. const char *upb_enumdef_fullname(const upb_enumdef *e);
  2932. const char *upb_enumdef_name(const upb_enumdef *e);
  2933. const upb_filedef *upb_enumdef_file(const upb_enumdef *e);
  2934. int32_t upb_enumdef_default(const upb_enumdef *e);
  2935. int upb_enumdef_numvals(const upb_enumdef *e);
  2936. /* Enum lookups:
  2937. * - ntoi: look up a name with specified length.
  2938. * - ntoiz: look up a name provided as a null-terminated string.
  2939. * - iton: look up an integer, returning the name as a null-terminated
  2940. * string. */
  2941. bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
  2942. int32_t *num);
  2943. UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
  2944. const char *name, int32_t *num) {
  2945. return upb_enumdef_ntoi(e, name, strlen(name), num);
  2946. }
  2947. const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
  2948. /* upb_enum_iter i;
  2949. * for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
  2950. * // ...
  2951. * }
  2952. */
  2953. void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
  2954. void upb_enum_next(upb_enum_iter *iter);
  2955. bool upb_enum_done(upb_enum_iter *iter);
  2956. const char *upb_enum_iter_name(upb_enum_iter *iter);
  2957. int32_t upb_enum_iter_number(upb_enum_iter *iter);
  2958. /* upb_filedef ****************************************************************/
  2959. const char *upb_filedef_name(const upb_filedef *f);
  2960. const char *upb_filedef_package(const upb_filedef *f);
  2961. const char *upb_filedef_phpprefix(const upb_filedef *f);
  2962. const char *upb_filedef_phpnamespace(const upb_filedef *f);
  2963. upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
  2964. int upb_filedef_depcount(const upb_filedef *f);
  2965. int upb_filedef_msgcount(const upb_filedef *f);
  2966. int upb_filedef_enumcount(const upb_filedef *f);
  2967. const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
  2968. const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
  2969. const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
  2970. /* upb_symtab *****************************************************************/
  2971. upb_symtab *upb_symtab_new(void);
  2972. void upb_symtab_free(upb_symtab* s);
  2973. const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
  2974. const upb_msgdef *upb_symtab_lookupmsg2(
  2975. const upb_symtab *s, const char *sym, size_t len);
  2976. const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
  2977. const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name);
  2978. int upb_symtab_filecount(const upb_symtab *s);
  2979. const upb_filedef *upb_symtab_addfile(
  2980. upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
  2981. upb_status *status);
  2982. /* For generated code only: loads a generated descriptor. */
  2983. typedef struct upb_def_init {
  2984. struct upb_def_init **deps; /* Dependencies of this file. */
  2985. const upb_msglayout **layouts; /* Pre-order layouts of all messages. */
  2986. const char *filename;
  2987. upb_strview descriptor; /* Serialized descriptor. */
  2988. } upb_def_init;
  2989. bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init);
  2990. #ifdef __cplusplus
  2991. } /* extern "C" */
  2992. #endif /* __cplusplus */
  2993. #endif /* UPB_DEF_H_ */
  2994. #ifndef UPB_REFLECTION_H_
  2995. #define UPB_REFLECTION_H_
  2996. typedef union {
  2997. bool bool_val;
  2998. float float_val;
  2999. double double_val;
  3000. int32_t int32_val;
  3001. int64_t int64_val;
  3002. uint32_t uint32_val;
  3003. uint64_t uint64_val;
  3004. const upb_map* map_val;
  3005. const upb_msg* msg_val;
  3006. const upb_array* array_val;
  3007. upb_strview str_val;
  3008. } upb_msgval;
  3009. typedef union {
  3010. upb_map* map;
  3011. upb_msg* msg;
  3012. upb_array* array;
  3013. } upb_mutmsgval;
  3014. /** upb_msg *******************************************************************/
  3015. /* Creates a new message of the given type in the given arena. */
  3016. upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a);
  3017. /* Returns the value associated with this field. */
  3018. upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f);
  3019. /* Returns a mutable pointer to a map, array, or submessage value. If the given
  3020. * arena is non-NULL this will construct a new object if it was not previously
  3021. * present. May not be called for primitive fields. */
  3022. upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, upb_arena *a);
  3023. /* May only be called for fields where upb_fielddef_haspresence(f) == true. */
  3024. bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f);
  3025. /* Returns whether any field is set in the oneof. */
  3026. bool upb_msg_hasoneof(const upb_msg *msg, const upb_oneofdef *o);
  3027. /* Sets the given field to the given value. For a msg/array/map/string, the
  3028. * value must be in the same arena. */
  3029. void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val,
  3030. upb_arena *a);
  3031. /* Clears any field presence and sets the value back to its default. */
  3032. void upb_msg_clearfield(upb_msg *msg, const upb_fielddef *f);
  3033. /* Iterate over present fields.
  3034. *
  3035. * size_t iter = UPB_MSG_BEGIN;
  3036. * const upb_fielddef *f;
  3037. * upb_msgval val;
  3038. * while (upb_msg_next(msg, m, ext_pool, &f, &val, &iter)) {
  3039. * process_field(f, val);
  3040. * }
  3041. *
  3042. * If ext_pool is NULL, no extensions will be returned. If the given symtab
  3043. * returns extensions that don't match what is in this message, those extensions
  3044. * will be skipped.
  3045. */
  3046. #define UPB_MSG_BEGIN -1
  3047. bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m,
  3048. const upb_symtab *ext_pool, const upb_fielddef **f,
  3049. upb_msgval *val, size_t *iter);
  3050. /* Adds unknown data (serialized protobuf data) to the given message. The data
  3051. * is copied into the message instance. */
  3052. void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
  3053. upb_arena *arena);
  3054. /* Returns a reference to the message's unknown data. */
  3055. const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
  3056. /** upb_array *****************************************************************/
  3057. /* Creates a new array on the given arena that holds elements of this type. */
  3058. upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type);
  3059. /* Returns the size of the array. */
  3060. size_t upb_array_size(const upb_array *arr);
  3061. /* Returns the given element, which must be within the array's current size. */
  3062. upb_msgval upb_array_get(const upb_array *arr, size_t i);
  3063. /* Sets the given element, which must be within the array's current size. */
  3064. void upb_array_set(upb_array *arr, size_t i, upb_msgval val);
  3065. /* Appends an element to the array. Returns false on allocation failure. */
  3066. bool upb_array_append(upb_array *array, upb_msgval val, upb_arena *arena);
  3067. /* Changes the size of a vector. New elements are initialized to empty/0.
  3068. * Returns false on allocation failure. */
  3069. bool upb_array_resize(upb_array *array, size_t size, upb_arena *arena);
  3070. /** upb_map *******************************************************************/
  3071. /* Creates a new map on the given arena with the given key/value size. */
  3072. upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type,
  3073. upb_fieldtype_t value_type);
  3074. /* Returns the number of entries in the map. */
  3075. size_t upb_map_size(const upb_map *map);
  3076. /* Stores a value for the given key into |*val| (or the zero value if the key is
  3077. * not present). Returns whether the key was present. The |val| pointer may be
  3078. * NULL, in which case the function tests whether the given key is present. */
  3079. bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
  3080. /* Removes all entries in the map. */
  3081. void upb_map_clear(upb_map *map);
  3082. /* Sets the given key to the given value. Returns true if this was a new key in
  3083. * the map, or false if an existing key was replaced. */
  3084. bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
  3085. upb_arena *arena);
  3086. /* Deletes this key from the table. Returns true if the key was present. */
  3087. bool upb_map_delete(upb_map *map, upb_msgval key);
  3088. /* Map iteration:
  3089. *
  3090. * size_t iter = UPB_MAP_BEGIN;
  3091. * while (upb_mapiter_next(map, &iter)) {
  3092. * upb_msgval key = upb_mapiter_key(map, iter);
  3093. * upb_msgval val = upb_mapiter_value(map, iter);
  3094. *
  3095. * // If mutating is desired.
  3096. * upb_mapiter_setvalue(map, iter, value2);
  3097. * }
  3098. */
  3099. /* Advances to the next entry. Returns false if no more entries are present. */
  3100. bool upb_mapiter_next(const upb_map *map, size_t *iter);
  3101. /* Returns the key and value for this entry of the map. */
  3102. upb_msgval upb_mapiter_key(const upb_map *map, size_t iter);
  3103. upb_msgval upb_mapiter_value(const upb_map *map, size_t iter);
  3104. /* Sets the value for this entry. The iterator must not be done, and the
  3105. * iterator must not have been initialized const. */
  3106. void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value);
  3107. #endif /* UPB_REFLECTION_H_ */
  3108. /*
  3109. ** upb::Handlers (upb_handlers)
  3110. **
  3111. ** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the
  3112. ** message can have associated functions that will be called when we are
  3113. ** parsing or visiting a stream of data. This is similar to how handlers work
  3114. ** in SAX (the Simple API for XML).
  3115. **
  3116. ** The handlers have no idea where the data is coming from, so a single set of
  3117. ** handlers could be used with two completely different data sources (for
  3118. ** example, a parser and a visitor over in-memory objects). This decoupling is
  3119. ** the most important feature of upb, because it allows parsers and serializers
  3120. ** to be highly reusable.
  3121. **
  3122. ** This is a mixed C/C++ interface that offers a full API to both languages.
  3123. ** See the top-level README for more information.
  3124. */
  3125. #ifndef UPB_HANDLERS_H
  3126. #define UPB_HANDLERS_H
  3127. #ifdef __cplusplus
  3128. namespace upb {
  3129. class HandlersPtr;
  3130. class HandlerCache;
  3131. template <class T> class Handler;
  3132. template <class T> struct CanonicalType;
  3133. } /* namespace upb */
  3134. #endif
  3135. /* The maximum depth that the handler graph can have. This is a resource limit
  3136. * for the C stack since we sometimes need to recursively traverse the graph.
  3137. * Cycles are ok; the traversal will stop when it detects a cycle, but we must
  3138. * hit the cycle before the maximum depth is reached.
  3139. *
  3140. * If having a single static limit is too inflexible, we can add another variant
  3141. * of Handlers::Freeze that allows specifying this as a parameter. */
  3142. #define UPB_MAX_HANDLER_DEPTH 64
  3143. /* All the different types of handlers that can be registered.
  3144. * Only needed for the advanced functions in upb::Handlers. */
  3145. typedef enum {
  3146. UPB_HANDLER_INT32,
  3147. UPB_HANDLER_INT64,
  3148. UPB_HANDLER_UINT32,
  3149. UPB_HANDLER_UINT64,
  3150. UPB_HANDLER_FLOAT,
  3151. UPB_HANDLER_DOUBLE,
  3152. UPB_HANDLER_BOOL,
  3153. UPB_HANDLER_STARTSTR,
  3154. UPB_HANDLER_STRING,
  3155. UPB_HANDLER_ENDSTR,
  3156. UPB_HANDLER_STARTSUBMSG,
  3157. UPB_HANDLER_ENDSUBMSG,
  3158. UPB_HANDLER_STARTSEQ,
  3159. UPB_HANDLER_ENDSEQ
  3160. } upb_handlertype_t;
  3161. #define UPB_HANDLER_MAX (UPB_HANDLER_ENDSEQ+1)
  3162. #define UPB_BREAK NULL
  3163. /* A convenient definition for when no closure is needed. */
  3164. extern char _upb_noclosure;
  3165. #define UPB_NO_CLOSURE &_upb_noclosure
  3166. /* A selector refers to a specific field handler in the Handlers object
  3167. * (for example: the STARTSUBMSG handler for field "field15"). */
  3168. typedef int32_t upb_selector_t;
  3169. /* Static selectors for upb::Handlers. */
  3170. #define UPB_STARTMSG_SELECTOR 0
  3171. #define UPB_ENDMSG_SELECTOR 1
  3172. #define UPB_UNKNOWN_SELECTOR 2
  3173. #define UPB_STATIC_SELECTOR_COUNT 3 /* Warning: also in upb/def.c. */
  3174. /* Static selectors for upb::BytesHandler. */
  3175. #define UPB_STARTSTR_SELECTOR 0
  3176. #define UPB_STRING_SELECTOR 1
  3177. #define UPB_ENDSTR_SELECTOR 2
  3178. #ifdef __cplusplus
  3179. template<class T> const void *UniquePtrForType() {
  3180. static const char ch = 0;
  3181. return &ch;
  3182. }
  3183. #endif
  3184. /* upb_handlers ************************************************************/
  3185. /* Handler attributes, to be registered with the handler itself. */
  3186. typedef struct {
  3187. const void *handler_data;
  3188. const void *closure_type;
  3189. const void *return_closure_type;
  3190. bool alwaysok;
  3191. } upb_handlerattr;
  3192. #define UPB_HANDLERATTR_INIT {NULL, NULL, NULL, false}
  3193. /* Bufhandle, data passed along with a buffer to indicate its provenance. */
  3194. typedef struct {
  3195. /* The beginning of the buffer. This may be different than the pointer
  3196. * passed to a StringBuf handler because the handler may receive data
  3197. * that is from the middle or end of a larger buffer. */
  3198. const char *buf;
  3199. /* The offset within the attached object where this buffer begins. Only
  3200. * meaningful if there is an attached object. */
  3201. size_t objofs;
  3202. /* The attached object (if any) and a pointer representing its type. */
  3203. const void *obj;
  3204. const void *objtype;
  3205. #ifdef __cplusplus
  3206. template <class T>
  3207. void SetAttachedObject(const T* _obj) {
  3208. obj = _obj;
  3209. objtype = UniquePtrForType<T>();
  3210. }
  3211. template <class T>
  3212. const T *GetAttachedObject() const {
  3213. return objtype == UniquePtrForType<T>() ? static_cast<const T *>(obj)
  3214. : NULL;
  3215. }
  3216. #endif
  3217. } upb_bufhandle;
  3218. #define UPB_BUFHANDLE_INIT {NULL, 0, NULL, NULL}
  3219. /* Handler function typedefs. */
  3220. typedef void upb_handlerfree(void *d);
  3221. typedef bool upb_unknown_handlerfunc(void *c, const void *hd, const char *buf,
  3222. size_t n);
  3223. typedef bool upb_startmsg_handlerfunc(void *c, const void*);
  3224. typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status);
  3225. typedef void* upb_startfield_handlerfunc(void *c, const void *hd);
  3226. typedef bool upb_endfield_handlerfunc(void *c, const void *hd);
  3227. typedef bool upb_int32_handlerfunc(void *c, const void *hd, int32_t val);
  3228. typedef bool upb_int64_handlerfunc(void *c, const void *hd, int64_t val);
  3229. typedef bool upb_uint32_handlerfunc(void *c, const void *hd, uint32_t val);
  3230. typedef bool upb_uint64_handlerfunc(void *c, const void *hd, uint64_t val);
  3231. typedef bool upb_float_handlerfunc(void *c, const void *hd, float val);
  3232. typedef bool upb_double_handlerfunc(void *c, const void *hd, double val);
  3233. typedef bool upb_bool_handlerfunc(void *c, const void *hd, bool val);
  3234. typedef void *upb_startstr_handlerfunc(void *c, const void *hd,
  3235. size_t size_hint);
  3236. typedef size_t upb_string_handlerfunc(void *c, const void *hd, const char *buf,
  3237. size_t n, const upb_bufhandle* handle);
  3238. struct upb_handlers;
  3239. typedef struct upb_handlers upb_handlers;
  3240. #ifdef __cplusplus
  3241. extern "C" {
  3242. #endif
  3243. /* Mutating accessors. */
  3244. const upb_status *upb_handlers_status(upb_handlers *h);
  3245. void upb_handlers_clearerr(upb_handlers *h);
  3246. const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h);
  3247. bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree);
  3248. bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func,
  3249. const upb_handlerattr *attr);
  3250. bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
  3251. const upb_handlerattr *attr);
  3252. bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
  3253. const upb_handlerattr *attr);
  3254. bool upb_handlers_setint32(upb_handlers *h, const upb_fielddef *f,
  3255. upb_int32_handlerfunc *func,
  3256. const upb_handlerattr *attr);
  3257. bool upb_handlers_setint64(upb_handlers *h, const upb_fielddef *f,
  3258. upb_int64_handlerfunc *func,
  3259. const upb_handlerattr *attr);
  3260. bool upb_handlers_setuint32(upb_handlers *h, const upb_fielddef *f,
  3261. upb_uint32_handlerfunc *func,
  3262. const upb_handlerattr *attr);
  3263. bool upb_handlers_setuint64(upb_handlers *h, const upb_fielddef *f,
  3264. upb_uint64_handlerfunc *func,
  3265. const upb_handlerattr *attr);
  3266. bool upb_handlers_setfloat(upb_handlers *h, const upb_fielddef *f,
  3267. upb_float_handlerfunc *func,
  3268. const upb_handlerattr *attr);
  3269. bool upb_handlers_setdouble(upb_handlers *h, const upb_fielddef *f,
  3270. upb_double_handlerfunc *func,
  3271. const upb_handlerattr *attr);
  3272. bool upb_handlers_setbool(upb_handlers *h, const upb_fielddef *f,
  3273. upb_bool_handlerfunc *func,
  3274. const upb_handlerattr *attr);
  3275. bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f,
  3276. upb_startstr_handlerfunc *func,
  3277. const upb_handlerattr *attr);
  3278. bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f,
  3279. upb_string_handlerfunc *func,
  3280. const upb_handlerattr *attr);
  3281. bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f,
  3282. upb_endfield_handlerfunc *func,
  3283. const upb_handlerattr *attr);
  3284. bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f,
  3285. upb_startfield_handlerfunc *func,
  3286. const upb_handlerattr *attr);
  3287. bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f,
  3288. upb_startfield_handlerfunc *func,
  3289. const upb_handlerattr *attr);
  3290. bool upb_handlers_setendsubmsg(upb_handlers *h, const upb_fielddef *f,
  3291. upb_endfield_handlerfunc *func,
  3292. const upb_handlerattr *attr);
  3293. bool upb_handlers_setendseq(upb_handlers *h, const upb_fielddef *f,
  3294. upb_endfield_handlerfunc *func,
  3295. const upb_handlerattr *attr);
  3296. /* Read-only accessors. */
  3297. const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
  3298. const upb_fielddef *f);
  3299. const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
  3300. upb_selector_t sel);
  3301. upb_func *upb_handlers_gethandler(const upb_handlers *h, upb_selector_t s,
  3302. const void **handler_data);
  3303. bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t s,
  3304. upb_handlerattr *attr);
  3305. /* "Static" methods */
  3306. upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f);
  3307. bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
  3308. upb_selector_t *s);
  3309. UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) {
  3310. return start + 1;
  3311. }
  3312. #ifdef __cplusplus
  3313. } /* extern "C" */
  3314. namespace upb {
  3315. typedef upb_handlers Handlers;
  3316. }
  3317. /* Convenience macros for creating a Handler object that is wrapped with a
  3318. * type-safe wrapper function that converts the "void*" parameters/returns
  3319. * of the underlying C API into nice C++ function.
  3320. *
  3321. * Sample usage:
  3322. * void OnValue1(MyClosure* c, const MyHandlerData* d, int32_t val) {
  3323. * // do stuff ...
  3324. * }
  3325. *
  3326. * // Handler that doesn't need any data bound to it.
  3327. * void OnValue2(MyClosure* c, int32_t val) {
  3328. * // do stuff ...
  3329. * }
  3330. *
  3331. * // Handler that returns bool so it can return failure if necessary.
  3332. * bool OnValue3(MyClosure* c, int32_t val) {
  3333. * // do stuff ...
  3334. * return ok;
  3335. * }
  3336. *
  3337. * // Member function handler.
  3338. * class MyClosure {
  3339. * public:
  3340. * void OnValue(int32_t val) {
  3341. * // do stuff ...
  3342. * }
  3343. * };
  3344. *
  3345. * // Takes ownership of the MyHandlerData.
  3346. * handlers->SetInt32Handler(f1, UpbBind(OnValue1, new MyHandlerData(...)));
  3347. * handlers->SetInt32Handler(f2, UpbMakeHandler(OnValue2));
  3348. * handlers->SetInt32Handler(f1, UpbMakeHandler(OnValue3));
  3349. * handlers->SetInt32Handler(f2, UpbMakeHandler(&MyClosure::OnValue));
  3350. */
  3351. /* In C++11, the "template" disambiguator can appear even outside templates,
  3352. * so all calls can safely use this pair of macros. */
  3353. #define UpbMakeHandler(f) upb::MatchFunc(f).template GetFunc<f>()
  3354. /* We have to be careful to only evaluate "d" once. */
  3355. #define UpbBind(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
  3356. /* Handler: a struct that contains the (handler, data, deleter) tuple that is
  3357. * used to register all handlers. Users can Make() these directly but it's
  3358. * more convenient to use the UpbMakeHandler/UpbBind macros above. */
  3359. template <class T> class upb::Handler {
  3360. public:
  3361. /* The underlying, handler function signature that upb uses internally. */
  3362. typedef T FuncPtr;
  3363. /* Intentionally implicit. */
  3364. template <class F> Handler(F func);
  3365. ~Handler() { UPB_ASSERT(registered_); }
  3366. void AddCleanup(upb_handlers* h) const;
  3367. FuncPtr handler() const { return handler_; }
  3368. const upb_handlerattr& attr() const { return attr_; }
  3369. private:
  3370. Handler(const Handler&) = delete;
  3371. Handler& operator=(const Handler&) = delete;
  3372. FuncPtr handler_;
  3373. mutable upb_handlerattr attr_;
  3374. mutable bool registered_;
  3375. void *cleanup_data_;
  3376. upb_handlerfree *cleanup_func_;
  3377. };
  3378. /* A upb::Handlers object represents the set of handlers associated with a
  3379. * message in the graph of messages. You can think of it as a big virtual
  3380. * table with functions corresponding to all the events that can fire while
  3381. * parsing or visiting a message of a specific type.
  3382. *
  3383. * Any handlers that are not set behave as if they had successfully consumed
  3384. * the value. Any unset Start* handlers will propagate their closure to the
  3385. * inner frame.
  3386. *
  3387. * The easiest way to create the *Handler objects needed by the Set* methods is
  3388. * with the UpbBind() and UpbMakeHandler() macros; see below. */
  3389. class upb::HandlersPtr {
  3390. public:
  3391. HandlersPtr(upb_handlers* ptr) : ptr_(ptr) {}
  3392. upb_handlers* ptr() const { return ptr_; }
  3393. typedef upb_selector_t Selector;
  3394. typedef upb_handlertype_t Type;
  3395. typedef Handler<void *(*)(void *, const void *)> StartFieldHandler;
  3396. typedef Handler<bool (*)(void *, const void *)> EndFieldHandler;
  3397. typedef Handler<bool (*)(void *, const void *)> StartMessageHandler;
  3398. typedef Handler<bool (*)(void *, const void *, upb_status *)>
  3399. EndMessageHandler;
  3400. typedef Handler<void *(*)(void *, const void *, size_t)> StartStringHandler;
  3401. typedef Handler<size_t (*)(void *, const void *, const char *, size_t,
  3402. const upb_bufhandle *)>
  3403. StringHandler;
  3404. template <class T> struct ValueHandler {
  3405. typedef Handler<bool(*)(void *, const void *, T)> H;
  3406. };
  3407. typedef ValueHandler<int32_t>::H Int32Handler;
  3408. typedef ValueHandler<int64_t>::H Int64Handler;
  3409. typedef ValueHandler<uint32_t>::H UInt32Handler;
  3410. typedef ValueHandler<uint64_t>::H UInt64Handler;
  3411. typedef ValueHandler<float>::H FloatHandler;
  3412. typedef ValueHandler<double>::H DoubleHandler;
  3413. typedef ValueHandler<bool>::H BoolHandler;
  3414. /* Any function pointer can be converted to this and converted back to its
  3415. * correct type. */
  3416. typedef void GenericFunction();
  3417. typedef void HandlersCallback(const void *closure, upb_handlers *h);
  3418. /* Returns the msgdef associated with this handlers object. */
  3419. MessageDefPtr message_def() const {
  3420. return MessageDefPtr(upb_handlers_msgdef(ptr()));
  3421. }
  3422. /* Adds the given pointer and function to the list of cleanup functions that
  3423. * will be run when these handlers are freed. If this pointer has previously
  3424. * been registered, the function returns false and does nothing. */
  3425. bool AddCleanup(void *ptr, upb_handlerfree *cleanup) {
  3426. return upb_handlers_addcleanup(ptr_, ptr, cleanup);
  3427. }
  3428. /* Sets the startmsg handler for the message, which is defined as follows:
  3429. *
  3430. * bool startmsg(MyType* closure) {
  3431. * // Called when the message begins. Returns true if processing should
  3432. * // continue.
  3433. * return true;
  3434. * }
  3435. */
  3436. bool SetStartMessageHandler(const StartMessageHandler &h) {
  3437. h.AddCleanup(ptr());
  3438. return upb_handlers_setstartmsg(ptr(), h.handler(), &h.attr());
  3439. }
  3440. /* Sets the endmsg handler for the message, which is defined as follows:
  3441. *
  3442. * bool endmsg(MyType* closure, upb_status *status) {
  3443. * // Called when processing of this message ends, whether in success or
  3444. * // failure. "status" indicates the final status of processing, and
  3445. * // can also be modified in-place to update the final status.
  3446. * }
  3447. */
  3448. bool SetEndMessageHandler(const EndMessageHandler& h) {
  3449. h.AddCleanup(ptr());
  3450. return upb_handlers_setendmsg(ptr(), h.handler(), &h.attr());
  3451. }
  3452. /* Sets the value handler for the given field, which is defined as follows
  3453. * (this is for an int32 field; other field types will pass their native
  3454. * C/C++ type for "val"):
  3455. *
  3456. * bool OnValue(MyClosure* c, const MyHandlerData* d, int32_t val) {
  3457. * // Called when the field's value is encountered. "d" contains
  3458. * // whatever data was bound to this field when it was registered.
  3459. * // Returns true if processing should continue.
  3460. * return true;
  3461. * }
  3462. *
  3463. * handers->SetInt32Handler(f, UpbBind(OnValue, new MyHandlerData(...)));
  3464. *
  3465. * The value type must exactly match f->type().
  3466. * For example, a handler that takes an int32_t parameter may only be used for
  3467. * fields of type UPB_TYPE_INT32 and UPB_TYPE_ENUM.
  3468. *
  3469. * Returns false if the handler failed to register; in this case the cleanup
  3470. * handler (if any) will be called immediately.
  3471. */
  3472. bool SetInt32Handler(FieldDefPtr f, const Int32Handler &h) {
  3473. h.AddCleanup(ptr());
  3474. return upb_handlers_setint32(ptr(), f.ptr(), h.handler(), &h.attr());
  3475. }
  3476. bool SetInt64Handler (FieldDefPtr f, const Int64Handler& h) {
  3477. h.AddCleanup(ptr());
  3478. return upb_handlers_setint64(ptr(), f.ptr(), h.handler(), &h.attr());
  3479. }
  3480. bool SetUInt32Handler(FieldDefPtr f, const UInt32Handler& h) {
  3481. h.AddCleanup(ptr());
  3482. return upb_handlers_setuint32(ptr(), f.ptr(), h.handler(), &h.attr());
  3483. }
  3484. bool SetUInt64Handler(FieldDefPtr f, const UInt64Handler& h) {
  3485. h.AddCleanup(ptr());
  3486. return upb_handlers_setuint64(ptr(), f.ptr(), h.handler(), &h.attr());
  3487. }
  3488. bool SetFloatHandler (FieldDefPtr f, const FloatHandler& h) {
  3489. h.AddCleanup(ptr());
  3490. return upb_handlers_setfloat(ptr(), f.ptr(), h.handler(), &h.attr());
  3491. }
  3492. bool SetDoubleHandler(FieldDefPtr f, const DoubleHandler& h) {
  3493. h.AddCleanup(ptr());
  3494. return upb_handlers_setdouble(ptr(), f.ptr(), h.handler(), &h.attr());
  3495. }
  3496. bool SetBoolHandler(FieldDefPtr f, const BoolHandler &h) {
  3497. h.AddCleanup(ptr());
  3498. return upb_handlers_setbool(ptr(), f.ptr(), h.handler(), &h.attr());
  3499. }
  3500. /* Like the previous, but templated on the type on the value (ie. int32).
  3501. * This is mostly useful to call from other templates. To call this you must
  3502. * specify the template parameter explicitly, ie:
  3503. * h->SetValueHandler<T>(f, UpbBind(MyHandler<T>, MyData)); */
  3504. template <class T>
  3505. bool SetValueHandler(
  3506. FieldDefPtr f,
  3507. const typename ValueHandler<typename CanonicalType<T>::Type>::H &handler);
  3508. /* Sets handlers for a string field, which are defined as follows:
  3509. *
  3510. * MySubClosure* startstr(MyClosure* c, const MyHandlerData* d,
  3511. * size_t size_hint) {
  3512. * // Called when a string value begins. The return value indicates the
  3513. * // closure for the string. "size_hint" indicates the size of the
  3514. * // string if it is known, however if the string is length-delimited
  3515. * // and the end-of-string is not available size_hint will be zero.
  3516. * // This case is indistinguishable from the case where the size is
  3517. * // known to be zero.
  3518. * //
  3519. * // TODO(haberman): is it important to distinguish these cases?
  3520. * // If we had ssize_t as a type we could make -1 "unknown", but
  3521. * // ssize_t is POSIX (not ANSI) and therefore less portable.
  3522. * // In practice I suspect it won't be important to distinguish.
  3523. * return closure;
  3524. * }
  3525. *
  3526. * size_t str(MyClosure* closure, const MyHandlerData* d,
  3527. * const char *str, size_t len) {
  3528. * // Called for each buffer of string data; the multiple physical buffers
  3529. * // are all part of the same logical string. The return value indicates
  3530. * // how many bytes were consumed. If this number is less than "len",
  3531. * // this will also indicate that processing should be halted for now,
  3532. * // like returning false or UPB_BREAK from any other callback. If
  3533. * // number is greater than "len", the excess bytes will be skipped over
  3534. * // and not passed to the callback.
  3535. * return len;
  3536. * }
  3537. *
  3538. * bool endstr(MyClosure* c, const MyHandlerData* d) {
  3539. * // Called when a string value ends. Return value indicates whether
  3540. * // processing should continue.
  3541. * return true;
  3542. * }
  3543. */
  3544. bool SetStartStringHandler(FieldDefPtr f, const StartStringHandler &h) {
  3545. h.AddCleanup(ptr());
  3546. return upb_handlers_setstartstr(ptr(), f.ptr(), h.handler(), &h.attr());
  3547. }
  3548. bool SetStringHandler(FieldDefPtr f, const StringHandler& h) {
  3549. h.AddCleanup(ptr());
  3550. return upb_handlers_setstring(ptr(), f.ptr(), h.handler(), &h.attr());
  3551. }
  3552. bool SetEndStringHandler(FieldDefPtr f, const EndFieldHandler& h) {
  3553. h.AddCleanup(ptr());
  3554. return upb_handlers_setendstr(ptr(), f.ptr(), h.handler(), &h.attr());
  3555. }
  3556. /* Sets the startseq handler, which is defined as follows:
  3557. *
  3558. * MySubClosure *startseq(MyClosure* c, const MyHandlerData* d) {
  3559. * // Called when a sequence (repeated field) begins. The returned
  3560. * // pointer indicates the closure for the sequence (or UPB_BREAK
  3561. * // to interrupt processing).
  3562. * return closure;
  3563. * }
  3564. *
  3565. * h->SetStartSequenceHandler(f, UpbBind(startseq, new MyHandlerData(...)));
  3566. *
  3567. * Returns "false" if "f" does not belong to this message or is not a
  3568. * repeated field.
  3569. */
  3570. bool SetStartSequenceHandler(FieldDefPtr f, const StartFieldHandler &h) {
  3571. h.AddCleanup(ptr());
  3572. return upb_handlers_setstartseq(ptr(), f.ptr(), h.handler(), &h.attr());
  3573. }
  3574. /* Sets the startsubmsg handler for the given field, which is defined as
  3575. * follows:
  3576. *
  3577. * MySubClosure* startsubmsg(MyClosure* c, const MyHandlerData* d) {
  3578. * // Called when a submessage begins. The returned pointer indicates the
  3579. * // closure for the sequence (or UPB_BREAK to interrupt processing).
  3580. * return closure;
  3581. * }
  3582. *
  3583. * h->SetStartSubMessageHandler(f, UpbBind(startsubmsg,
  3584. * new MyHandlerData(...)));
  3585. *
  3586. * Returns "false" if "f" does not belong to this message or is not a
  3587. * submessage/group field.
  3588. */
  3589. bool SetStartSubMessageHandler(FieldDefPtr f, const StartFieldHandler& h) {
  3590. h.AddCleanup(ptr());
  3591. return upb_handlers_setstartsubmsg(ptr(), f.ptr(), h.handler(), &h.attr());
  3592. }
  3593. /* Sets the endsubmsg handler for the given field, which is defined as
  3594. * follows:
  3595. *
  3596. * bool endsubmsg(MyClosure* c, const MyHandlerData* d) {
  3597. * // Called when a submessage ends. Returns true to continue processing.
  3598. * return true;
  3599. * }
  3600. *
  3601. * Returns "false" if "f" does not belong to this message or is not a
  3602. * submessage/group field.
  3603. */
  3604. bool SetEndSubMessageHandler(FieldDefPtr f, const EndFieldHandler &h) {
  3605. h.AddCleanup(ptr());
  3606. return upb_handlers_setendsubmsg(ptr(), f.ptr(), h.handler(), &h.attr());
  3607. }
  3608. /* Starts the endsubseq handler for the given field, which is defined as
  3609. * follows:
  3610. *
  3611. * bool endseq(MyClosure* c, const MyHandlerData* d) {
  3612. * // Called when a sequence ends. Returns true continue processing.
  3613. * return true;
  3614. * }
  3615. *
  3616. * Returns "false" if "f" does not belong to this message or is not a
  3617. * repeated field.
  3618. */
  3619. bool SetEndSequenceHandler(FieldDefPtr f, const EndFieldHandler &h) {
  3620. h.AddCleanup(ptr());
  3621. return upb_handlers_setendseq(ptr(), f.ptr(), h.handler(), &h.attr());
  3622. }
  3623. private:
  3624. upb_handlers* ptr_;
  3625. };
  3626. #endif /* __cplusplus */
  3627. /* upb_handlercache ***********************************************************/
  3628. /* A upb_handlercache lazily builds and caches upb_handlers. You pass it a
  3629. * function (with optional closure) that can build handlers for a given
  3630. * message on-demand, and the cache maintains a map of msgdef->handlers. */
  3631. #ifdef __cplusplus
  3632. extern "C" {
  3633. #endif
  3634. struct upb_handlercache;
  3635. typedef struct upb_handlercache upb_handlercache;
  3636. typedef void upb_handlers_callback(const void *closure, upb_handlers *h);
  3637. upb_handlercache *upb_handlercache_new(upb_handlers_callback *callback,
  3638. const void *closure);
  3639. void upb_handlercache_free(upb_handlercache *cache);
  3640. const upb_handlers *upb_handlercache_get(upb_handlercache *cache,
  3641. const upb_msgdef *md);
  3642. bool upb_handlercache_addcleanup(upb_handlercache *h, void *p,
  3643. upb_handlerfree *hfree);
  3644. #ifdef __cplusplus
  3645. } /* extern "C" */
  3646. class upb::HandlerCache {
  3647. public:
  3648. HandlerCache(upb_handlers_callback *callback, const void *closure)
  3649. : ptr_(upb_handlercache_new(callback, closure), upb_handlercache_free) {}
  3650. HandlerCache(HandlerCache&&) = default;
  3651. HandlerCache& operator=(HandlerCache&&) = default;
  3652. HandlerCache(upb_handlercache* c) : ptr_(c, upb_handlercache_free) {}
  3653. upb_handlercache* ptr() { return ptr_.get(); }
  3654. const upb_handlers *Get(MessageDefPtr md) {
  3655. return upb_handlercache_get(ptr_.get(), md.ptr());
  3656. }
  3657. private:
  3658. std::unique_ptr<upb_handlercache, decltype(&upb_handlercache_free)> ptr_;
  3659. };
  3660. #endif /* __cplusplus */
  3661. /* upb_byteshandler ***********************************************************/
  3662. typedef struct {
  3663. upb_func *func;
  3664. /* It is wasteful to include the entire attributes here:
  3665. *
  3666. * * Some of the information is redundant (like storing the closure type
  3667. * separately for each handler that must match).
  3668. * * Some of the info is only needed prior to freeze() (like closure types).
  3669. * * alignment padding wastes a lot of space for alwaysok_.
  3670. *
  3671. * If/when the size and locality of handlers is an issue, we can optimize this
  3672. * not to store the entire attr like this. We do not expose the table's
  3673. * layout to allow this optimization in the future. */
  3674. upb_handlerattr attr;
  3675. } upb_handlers_tabent;
  3676. #define UPB_TABENT_INIT {NULL, UPB_HANDLERATTR_INIT}
  3677. typedef struct {
  3678. upb_handlers_tabent table[3];
  3679. } upb_byteshandler;
  3680. #define UPB_BYTESHANDLER_INIT \
  3681. { \
  3682. { UPB_TABENT_INIT, UPB_TABENT_INIT, UPB_TABENT_INIT } \
  3683. }
  3684. UPB_INLINE void upb_byteshandler_init(upb_byteshandler *handler) {
  3685. upb_byteshandler init = UPB_BYTESHANDLER_INIT;
  3686. *handler = init;
  3687. }
  3688. #ifdef __cplusplus
  3689. extern "C" {
  3690. #endif
  3691. /* Caller must ensure that "d" outlives the handlers. */
  3692. bool upb_byteshandler_setstartstr(upb_byteshandler *h,
  3693. upb_startstr_handlerfunc *func, void *d);
  3694. bool upb_byteshandler_setstring(upb_byteshandler *h,
  3695. upb_string_handlerfunc *func, void *d);
  3696. bool upb_byteshandler_setendstr(upb_byteshandler *h,
  3697. upb_endfield_handlerfunc *func, void *d);
  3698. #ifdef __cplusplus
  3699. } /* extern "C" */
  3700. namespace upb {
  3701. typedef upb_byteshandler BytesHandler;
  3702. }
  3703. #endif
  3704. /** Message handlers ******************************************************************/
  3705. #ifdef __cplusplus
  3706. extern "C" {
  3707. #endif
  3708. /* These are the handlers used internally by upb_msgfactory_getmergehandlers().
  3709. * They write scalar data to a known offset from the message pointer.
  3710. *
  3711. * These would be trivial for anyone to implement themselves, but it's better
  3712. * to use these because some JITs will recognize and specialize these instead
  3713. * of actually calling the function. */
  3714. /* Sets a handler for the given primitive field that will write the data at the
  3715. * given offset. If hasbit > 0, also sets a hasbit at the given bit offset
  3716. * (addressing each byte low to high). */
  3717. bool upb_msg_setscalarhandler(upb_handlers *h,
  3718. const upb_fielddef *f,
  3719. size_t offset,
  3720. int32_t hasbit);
  3721. /* If the given handler is a msghandlers_primitive field, returns true and sets
  3722. * *type, *offset and *hasbit. Otherwise returns false. */
  3723. bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
  3724. upb_selector_t s,
  3725. upb_fieldtype_t *type,
  3726. size_t *offset,
  3727. int32_t *hasbit);
  3728. #ifdef __cplusplus
  3729. } /* extern "C" */
  3730. #endif
  3731. /*
  3732. ** Inline definitions for handlers.h, which are particularly long and a bit
  3733. ** tricky.
  3734. */
  3735. #ifndef UPB_HANDLERS_INL_H_
  3736. #define UPB_HANDLERS_INL_H_
  3737. #include <limits.h>
  3738. #include <stddef.h>
  3739. #ifdef __cplusplus
  3740. /* Type detection and typedefs for integer types.
  3741. * For platforms where there are multiple 32-bit or 64-bit types, we need to be
  3742. * able to enumerate them so we can properly create overloads for all variants.
  3743. *
  3744. * If any platform existed where there were three integer types with the same
  3745. * size, this would have to become more complicated. For example, short, int,
  3746. * and long could all be 32-bits. Even more diabolically, short, int, long,
  3747. * and long long could all be 64 bits and still be standard-compliant.
  3748. * However, few platforms are this strange, and it's unlikely that upb will be
  3749. * used on the strangest ones. */
  3750. /* Can't count on stdint.h limits like INT32_MAX, because in C++ these are
  3751. * only defined when __STDC_LIMIT_MACROS are defined before the *first* include
  3752. * of stdint.h. We can't guarantee that someone else didn't include these first
  3753. * without defining __STDC_LIMIT_MACROS. */
  3754. #define UPB_INT32_MAX 0x7fffffffLL
  3755. #define UPB_INT32_MIN (-UPB_INT32_MAX - 1)
  3756. #define UPB_INT64_MAX 0x7fffffffffffffffLL
  3757. #define UPB_INT64_MIN (-UPB_INT64_MAX - 1)
  3758. #if INT_MAX == UPB_INT32_MAX && INT_MIN == UPB_INT32_MIN
  3759. #define UPB_INT_IS_32BITS 1
  3760. #endif
  3761. #if LONG_MAX == UPB_INT32_MAX && LONG_MIN == UPB_INT32_MIN
  3762. #define UPB_LONG_IS_32BITS 1
  3763. #endif
  3764. #if LONG_MAX == UPB_INT64_MAX && LONG_MIN == UPB_INT64_MIN
  3765. #define UPB_LONG_IS_64BITS 1
  3766. #endif
  3767. #if LLONG_MAX == UPB_INT64_MAX && LLONG_MIN == UPB_INT64_MIN
  3768. #define UPB_LLONG_IS_64BITS 1
  3769. #endif
  3770. /* We use macros instead of typedefs so we can undefine them later and avoid
  3771. * leaking them outside this header file. */
  3772. #if UPB_INT_IS_32BITS
  3773. #define UPB_INT32_T int
  3774. #define UPB_UINT32_T unsigned int
  3775. #if UPB_LONG_IS_32BITS
  3776. #define UPB_TWO_32BIT_TYPES 1
  3777. #define UPB_INT32ALT_T long
  3778. #define UPB_UINT32ALT_T unsigned long
  3779. #endif /* UPB_LONG_IS_32BITS */
  3780. #elif UPB_LONG_IS_32BITS /* && !UPB_INT_IS_32BITS */
  3781. #define UPB_INT32_T long
  3782. #define UPB_UINT32_T unsigned long
  3783. #endif /* UPB_INT_IS_32BITS */
  3784. #if UPB_LONG_IS_64BITS
  3785. #define UPB_INT64_T long
  3786. #define UPB_UINT64_T unsigned long
  3787. #if UPB_LLONG_IS_64BITS
  3788. #define UPB_TWO_64BIT_TYPES 1
  3789. #define UPB_INT64ALT_T long long
  3790. #define UPB_UINT64ALT_T unsigned long long
  3791. #endif /* UPB_LLONG_IS_64BITS */
  3792. #elif UPB_LLONG_IS_64BITS /* && !UPB_LONG_IS_64BITS */
  3793. #define UPB_INT64_T long long
  3794. #define UPB_UINT64_T unsigned long long
  3795. #endif /* UPB_LONG_IS_64BITS */
  3796. #undef UPB_INT32_MAX
  3797. #undef UPB_INT32_MIN
  3798. #undef UPB_INT64_MAX
  3799. #undef UPB_INT64_MIN
  3800. #undef UPB_INT_IS_32BITS
  3801. #undef UPB_LONG_IS_32BITS
  3802. #undef UPB_LONG_IS_64BITS
  3803. #undef UPB_LLONG_IS_64BITS
  3804. namespace upb {
  3805. typedef void CleanupFunc(void *ptr);
  3806. /* Template to remove "const" from "const T*" and just return "T*".
  3807. *
  3808. * We define a nonsense default because otherwise it will fail to instantiate as
  3809. * a function parameter type even in cases where we don't expect any caller to
  3810. * actually match the overload. */
  3811. class CouldntRemoveConst {};
  3812. template <class T> struct remove_constptr { typedef CouldntRemoveConst type; };
  3813. template <class T> struct remove_constptr<const T *> { typedef T *type; };
  3814. /* Template that we use below to remove a template specialization from
  3815. * consideration if it matches a specific type. */
  3816. template <class T, class U> struct disable_if_same { typedef void Type; };
  3817. template <class T> struct disable_if_same<T, T> {};
  3818. template <class T> void DeletePointer(void *p) { delete static_cast<T>(p); }
  3819. template <class T1, class T2>
  3820. struct FirstUnlessVoidOrBool {
  3821. typedef T1 value;
  3822. };
  3823. template <class T2>
  3824. struct FirstUnlessVoidOrBool<void, T2> {
  3825. typedef T2 value;
  3826. };
  3827. template <class T2>
  3828. struct FirstUnlessVoidOrBool<bool, T2> {
  3829. typedef T2 value;
  3830. };
  3831. template<class T, class U>
  3832. struct is_same {
  3833. static bool value;
  3834. };
  3835. template<class T>
  3836. struct is_same<T, T> {
  3837. static bool value;
  3838. };
  3839. template<class T, class U>
  3840. bool is_same<T, U>::value = false;
  3841. template<class T>
  3842. bool is_same<T, T>::value = true;
  3843. /* FuncInfo *******************************************************************/
  3844. /* Info about the user's original, pre-wrapped function. */
  3845. template <class C, class R = void>
  3846. struct FuncInfo {
  3847. /* The type of the closure that the function takes (its first param). */
  3848. typedef C Closure;
  3849. /* The return type. */
  3850. typedef R Return;
  3851. };
  3852. /* Func ***********************************************************************/
  3853. /* Func1, Func2, Func3: Template classes representing a function and its
  3854. * signature.
  3855. *
  3856. * Since the function is a template parameter, calling the function can be
  3857. * inlined at compile-time and does not require a function pointer at runtime.
  3858. * These functions are not bound to a handler data so have no data or cleanup
  3859. * handler. */
  3860. struct UnboundFunc {
  3861. CleanupFunc *GetCleanup() { return nullptr; }
  3862. void *GetData() { return nullptr; }
  3863. };
  3864. template <class R, class P1, R F(P1), class I>
  3865. struct Func1 : public UnboundFunc {
  3866. typedef R Return;
  3867. typedef I FuncInfo;
  3868. static R Call(P1 p1) { return F(p1); }
  3869. };
  3870. template <class R, class P1, class P2, R F(P1, P2), class I>
  3871. struct Func2 : public UnboundFunc {
  3872. typedef R Return;
  3873. typedef I FuncInfo;
  3874. static R Call(P1 p1, P2 p2) { return F(p1, p2); }
  3875. };
  3876. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
  3877. struct Func3 : public UnboundFunc {
  3878. typedef R Return;
  3879. typedef I FuncInfo;
  3880. static R Call(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); }
  3881. };
  3882. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  3883. class I>
  3884. struct Func4 : public UnboundFunc {
  3885. typedef R Return;
  3886. typedef I FuncInfo;
  3887. static R Call(P1 p1, P2 p2, P3 p3, P4 p4) { return F(p1, p2, p3, p4); }
  3888. };
  3889. template <class R, class P1, class P2, class P3, class P4, class P5,
  3890. R F(P1, P2, P3, P4, P5), class I>
  3891. struct Func5 : public UnboundFunc {
  3892. typedef R Return;
  3893. typedef I FuncInfo;
  3894. static R Call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
  3895. return F(p1, p2, p3, p4, p5);
  3896. }
  3897. };
  3898. /* BoundFunc ******************************************************************/
  3899. /* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that
  3900. * shall be bound to the function's second parameter.
  3901. *
  3902. * Note that the second parameter is a const pointer, but our stored bound value
  3903. * is non-const so we can free it when the handlers are destroyed. */
  3904. template <class T>
  3905. struct BoundFunc {
  3906. typedef typename remove_constptr<T>::type MutableP2;
  3907. explicit BoundFunc(MutableP2 data_) : data(data_) {}
  3908. CleanupFunc *GetCleanup() { return &DeletePointer<MutableP2>; }
  3909. MutableP2 GetData() { return data; }
  3910. MutableP2 data;
  3911. };
  3912. template <class R, class P1, class P2, R F(P1, P2), class I>
  3913. struct BoundFunc2 : public BoundFunc<P2> {
  3914. typedef BoundFunc<P2> Base;
  3915. typedef I FuncInfo;
  3916. explicit BoundFunc2(typename Base::MutableP2 arg) : Base(arg) {}
  3917. };
  3918. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
  3919. struct BoundFunc3 : public BoundFunc<P2> {
  3920. typedef BoundFunc<P2> Base;
  3921. typedef I FuncInfo;
  3922. explicit BoundFunc3(typename Base::MutableP2 arg) : Base(arg) {}
  3923. };
  3924. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  3925. class I>
  3926. struct BoundFunc4 : public BoundFunc<P2> {
  3927. typedef BoundFunc<P2> Base;
  3928. typedef I FuncInfo;
  3929. explicit BoundFunc4(typename Base::MutableP2 arg) : Base(arg) {}
  3930. };
  3931. template <class R, class P1, class P2, class P3, class P4, class P5,
  3932. R F(P1, P2, P3, P4, P5), class I>
  3933. struct BoundFunc5 : public BoundFunc<P2> {
  3934. typedef BoundFunc<P2> Base;
  3935. typedef I FuncInfo;
  3936. explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {}
  3937. };
  3938. /* FuncSig ********************************************************************/
  3939. /* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function
  3940. * *signature*, but without a specific function attached.
  3941. *
  3942. * These classes contain member functions that can be invoked with a
  3943. * specific function to return a Func/BoundFunc class. */
  3944. template <class R, class P1>
  3945. struct FuncSig1 {
  3946. template <R F(P1)>
  3947. Func1<R, P1, F, FuncInfo<P1, R> > GetFunc() {
  3948. return Func1<R, P1, F, FuncInfo<P1, R> >();
  3949. }
  3950. };
  3951. template <class R, class P1, class P2>
  3952. struct FuncSig2 {
  3953. template <R F(P1, P2)>
  3954. Func2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc() {
  3955. return Func2<R, P1, P2, F, FuncInfo<P1, R> >();
  3956. }
  3957. template <R F(P1, P2)>
  3958. BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc(
  3959. typename remove_constptr<P2>::type param2) {
  3960. return BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> >(param2);
  3961. }
  3962. };
  3963. template <class R, class P1, class P2, class P3>
  3964. struct FuncSig3 {
  3965. template <R F(P1, P2, P3)>
  3966. Func3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc() {
  3967. return Func3<R, P1, P2, P3, F, FuncInfo<P1, R> >();
  3968. }
  3969. template <R F(P1, P2, P3)>
  3970. BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc(
  3971. typename remove_constptr<P2>::type param2) {
  3972. return BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> >(param2);
  3973. }
  3974. };
  3975. template <class R, class P1, class P2, class P3, class P4>
  3976. struct FuncSig4 {
  3977. template <R F(P1, P2, P3, P4)>
  3978. Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc() {
  3979. return Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >();
  3980. }
  3981. template <R F(P1, P2, P3, P4)>
  3982. BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc(
  3983. typename remove_constptr<P2>::type param2) {
  3984. return BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >(param2);
  3985. }
  3986. };
  3987. template <class R, class P1, class P2, class P3, class P4, class P5>
  3988. struct FuncSig5 {
  3989. template <R F(P1, P2, P3, P4, P5)>
  3990. Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc() {
  3991. return Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >();
  3992. }
  3993. template <R F(P1, P2, P3, P4, P5)>
  3994. BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc(
  3995. typename remove_constptr<P2>::type param2) {
  3996. return BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >(param2);
  3997. }
  3998. };
  3999. /* Overloaded template function that can construct the appropriate FuncSig*
  4000. * class given a function pointer by deducing the template parameters. */
  4001. template <class R, class P1>
  4002. inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) {
  4003. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4004. return FuncSig1<R, P1>();
  4005. }
  4006. template <class R, class P1, class P2>
  4007. inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) {
  4008. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4009. return FuncSig2<R, P1, P2>();
  4010. }
  4011. template <class R, class P1, class P2, class P3>
  4012. inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) {
  4013. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4014. return FuncSig3<R, P1, P2, P3>();
  4015. }
  4016. template <class R, class P1, class P2, class P3, class P4>
  4017. inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) {
  4018. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4019. return FuncSig4<R, P1, P2, P3, P4>();
  4020. }
  4021. template <class R, class P1, class P2, class P3, class P4, class P5>
  4022. inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) {
  4023. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4024. return FuncSig5<R, P1, P2, P3, P4, P5>();
  4025. }
  4026. /* MethodSig ******************************************************************/
  4027. /* CallMethod*: a function template that calls a given method. */
  4028. template <class R, class C, R (C::*F)()>
  4029. R CallMethod0(C *obj) {
  4030. return ((*obj).*F)();
  4031. }
  4032. template <class R, class C, class P1, R (C::*F)(P1)>
  4033. R CallMethod1(C *obj, P1 arg1) {
  4034. return ((*obj).*F)(arg1);
  4035. }
  4036. template <class R, class C, class P1, class P2, R (C::*F)(P1, P2)>
  4037. R CallMethod2(C *obj, P1 arg1, P2 arg2) {
  4038. return ((*obj).*F)(arg1, arg2);
  4039. }
  4040. template <class R, class C, class P1, class P2, class P3, R (C::*F)(P1, P2, P3)>
  4041. R CallMethod3(C *obj, P1 arg1, P2 arg2, P3 arg3) {
  4042. return ((*obj).*F)(arg1, arg2, arg3);
  4043. }
  4044. template <class R, class C, class P1, class P2, class P3, class P4,
  4045. R (C::*F)(P1, P2, P3, P4)>
  4046. R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) {
  4047. return ((*obj).*F)(arg1, arg2, arg3, arg4);
  4048. }
  4049. /* MethodSig: like FuncSig, but for member functions.
  4050. *
  4051. * GetFunc() returns a normal FuncN object, so after calling GetFunc() no
  4052. * more logic is required to special-case methods. */
  4053. template <class R, class C>
  4054. struct MethodSig0 {
  4055. template <R (C::*F)()>
  4056. Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> > GetFunc() {
  4057. return Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> >();
  4058. }
  4059. };
  4060. template <class R, class C, class P1>
  4061. struct MethodSig1 {
  4062. template <R (C::*F)(P1)>
  4063. Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc() {
  4064. return Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >();
  4065. }
  4066. template <R (C::*F)(P1)>
  4067. BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc(
  4068. typename remove_constptr<P1>::type param1) {
  4069. return BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >(
  4070. param1);
  4071. }
  4072. };
  4073. template <class R, class C, class P1, class P2>
  4074. struct MethodSig2 {
  4075. template <R (C::*F)(P1, P2)>
  4076. Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
  4077. GetFunc() {
  4078. return Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
  4079. FuncInfo<C *, R> >();
  4080. }
  4081. template <R (C::*F)(P1, P2)>
  4082. BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
  4083. GetFunc(typename remove_constptr<P1>::type param1) {
  4084. return BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
  4085. FuncInfo<C *, R> >(param1);
  4086. }
  4087. };
  4088. template <class R, class C, class P1, class P2, class P3>
  4089. struct MethodSig3 {
  4090. template <R (C::*F)(P1, P2, P3)>
  4091. Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>, FuncInfo<C *, R> >
  4092. GetFunc() {
  4093. return Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4094. FuncInfo<C *, R> >();
  4095. }
  4096. template <R (C::*F)(P1, P2, P3)>
  4097. BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4098. FuncInfo<C *, R> >
  4099. GetFunc(typename remove_constptr<P1>::type param1) {
  4100. return BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
  4101. FuncInfo<C *, R> >(param1);
  4102. }
  4103. };
  4104. template <class R, class C, class P1, class P2, class P3, class P4>
  4105. struct MethodSig4 {
  4106. template <R (C::*F)(P1, P2, P3, P4)>
  4107. Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4108. FuncInfo<C *, R> >
  4109. GetFunc() {
  4110. return Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4111. FuncInfo<C *, R> >();
  4112. }
  4113. template <R (C::*F)(P1, P2, P3, P4)>
  4114. BoundFunc5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
  4115. FuncInfo<C *, R> >
  4116. GetFunc(typename remove_constptr<P1>::type param1) {
  4117. return BoundFunc5<R, C *, P1, P2, P3, P4,
  4118. CallMethod4<R, C, P1, P2, P3, P4, F>, FuncInfo<C *, R> >(
  4119. param1);
  4120. }
  4121. };
  4122. template <class R, class C>
  4123. inline MethodSig0<R, C> MatchFunc(R (C::*f)()) {
  4124. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4125. return MethodSig0<R, C>();
  4126. }
  4127. template <class R, class C, class P1>
  4128. inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) {
  4129. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4130. return MethodSig1<R, C, P1>();
  4131. }
  4132. template <class R, class C, class P1, class P2>
  4133. inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) {
  4134. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4135. return MethodSig2<R, C, P1, P2>();
  4136. }
  4137. template <class R, class C, class P1, class P2, class P3>
  4138. inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) {
  4139. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4140. return MethodSig3<R, C, P1, P2, P3>();
  4141. }
  4142. template <class R, class C, class P1, class P2, class P3, class P4>
  4143. inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) {
  4144. UPB_UNUSED(f); /* Only used for template parameter deduction. */
  4145. return MethodSig4<R, C, P1, P2, P3, P4>();
  4146. }
  4147. /* MaybeWrapReturn ************************************************************/
  4148. /* Template class that attempts to wrap the return value of the function so it
  4149. * matches the expected type. There are two main adjustments it may make:
  4150. *
  4151. * 1. If the function returns void, make it return the expected type and with
  4152. * a value that always indicates success.
  4153. * 2. If the function returns bool, make it return the expected type with a
  4154. * value that indicates success or failure.
  4155. *
  4156. * The "expected type" for return is:
  4157. * 1. void* for start handlers. If the closure parameter has a different type
  4158. * we will cast it to void* for the return in the success case.
  4159. * 2. size_t for string buffer handlers.
  4160. * 3. bool for everything else. */
  4161. /* Template parameters are FuncN type and desired return type. */
  4162. template <class F, class R, class Enable = void>
  4163. struct MaybeWrapReturn;
  4164. /* If the return type matches, return the given function unwrapped. */
  4165. template <class F>
  4166. struct MaybeWrapReturn<F, typename F::Return> {
  4167. typedef F Func;
  4168. };
  4169. /* Function wrapper that munges the return value from void to (bool)true. */
  4170. template <class P1, class P2, void F(P1, P2)>
  4171. bool ReturnTrue2(P1 p1, P2 p2) {
  4172. F(p1, p2);
  4173. return true;
  4174. }
  4175. template <class P1, class P2, class P3, void F(P1, P2, P3)>
  4176. bool ReturnTrue3(P1 p1, P2 p2, P3 p3) {
  4177. F(p1, p2, p3);
  4178. return true;
  4179. }
  4180. /* Function wrapper that munges the return value from void to (void*)arg1 */
  4181. template <class P1, class P2, void F(P1, P2)>
  4182. void *ReturnClosure2(P1 p1, P2 p2) {
  4183. F(p1, p2);
  4184. return p1;
  4185. }
  4186. template <class P1, class P2, class P3, void F(P1, P2, P3)>
  4187. void *ReturnClosure3(P1 p1, P2 p2, P3 p3) {
  4188. F(p1, p2, p3);
  4189. return p1;
  4190. }
  4191. /* Function wrapper that munges the return value from R to void*. */
  4192. template <class R, class P1, class P2, R F(P1, P2)>
  4193. void *CastReturnToVoidPtr2(P1 p1, P2 p2) {
  4194. return F(p1, p2);
  4195. }
  4196. template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
  4197. void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) {
  4198. return F(p1, p2, p3);
  4199. }
  4200. /* Function wrapper that munges the return value from bool to void*. */
  4201. template <class P1, class P2, bool F(P1, P2)>
  4202. void *ReturnClosureOrBreak2(P1 p1, P2 p2) {
  4203. return F(p1, p2) ? p1 : UPB_BREAK;
  4204. }
  4205. template <class P1, class P2, class P3, bool F(P1, P2, P3)>
  4206. void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) {
  4207. return F(p1, p2, p3) ? p1 : UPB_BREAK;
  4208. }
  4209. /* For the string callback, which takes five params, returns the size param. */
  4210. template <class P1, class P2,
  4211. void F(P1, P2, const char *, size_t, const upb_bufhandle *)>
  4212. size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4,
  4213. const upb_bufhandle *p5) {
  4214. F(p1, p2, p3, p4, p5);
  4215. return p4;
  4216. }
  4217. /* For the string callback, which takes five params, returns the size param or
  4218. * zero. */
  4219. template <class P1, class P2,
  4220. bool F(P1, P2, const char *, size_t, const upb_bufhandle *)>
  4221. size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4,
  4222. const upb_bufhandle *p5) {
  4223. return F(p1, p2, p3, p4, p5) ? p4 : 0;
  4224. }
  4225. /* If we have a function returning void but want a function returning bool, wrap
  4226. * it in a function that returns true. */
  4227. template <class P1, class P2, void F(P1, P2), class I>
  4228. struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> {
  4229. typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func;
  4230. };
  4231. template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
  4232. struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> {
  4233. typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func;
  4234. };
  4235. /* If our function returns void but we want one returning void*, wrap it in a
  4236. * function that returns the first argument. */
  4237. template <class P1, class P2, void F(P1, P2), class I>
  4238. struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> {
  4239. typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func;
  4240. };
  4241. template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
  4242. struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> {
  4243. typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func;
  4244. };
  4245. /* If our function returns R* but we want one returning void*, wrap it in a
  4246. * function that casts to void*. */
  4247. template <class R, class P1, class P2, R *F(P1, P2), class I>
  4248. struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *,
  4249. typename disable_if_same<R *, void *>::Type> {
  4250. typedef Func2<void *, P1, P2, CastReturnToVoidPtr2<R *, P1, P2, F>, I> Func;
  4251. };
  4252. template <class R, class P1, class P2, class P3, R *F(P1, P2, P3), class I>
  4253. struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *,
  4254. typename disable_if_same<R *, void *>::Type> {
  4255. typedef Func3<void *, P1, P2, P3, CastReturnToVoidPtr3<R *, P1, P2, P3, F>, I>
  4256. Func;
  4257. };
  4258. /* If our function returns bool but we want one returning void*, wrap it in a
  4259. * function that returns either the first param or UPB_BREAK. */
  4260. template <class P1, class P2, bool F(P1, P2), class I>
  4261. struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> {
  4262. typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func;
  4263. };
  4264. template <class P1, class P2, class P3, bool F(P1, P2, P3), class I>
  4265. struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> {
  4266. typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I>
  4267. Func;
  4268. };
  4269. /* If our function returns void but we want one returning size_t, wrap it in a
  4270. * function that returns the size argument. */
  4271. template <class P1, class P2,
  4272. void F(P1, P2, const char *, size_t, const upb_bufhandle *), class I>
  4273. struct MaybeWrapReturn<
  4274. Func5<void, P1, P2, const char *, size_t, const upb_bufhandle *, F, I>,
  4275. size_t> {
  4276. typedef Func5<size_t, P1, P2, const char *, size_t, const upb_bufhandle *,
  4277. ReturnStringLen<P1, P2, F>, I> Func;
  4278. };
  4279. /* If our function returns bool but we want one returning size_t, wrap it in a
  4280. * function that returns either 0 or the buf size. */
  4281. template <class P1, class P2,
  4282. bool F(P1, P2, const char *, size_t, const upb_bufhandle *), class I>
  4283. struct MaybeWrapReturn<
  4284. Func5<bool, P1, P2, const char *, size_t, const upb_bufhandle *, F, I>,
  4285. size_t> {
  4286. typedef Func5<size_t, P1, P2, const char *, size_t, const upb_bufhandle *,
  4287. ReturnNOr0<P1, P2, F>, I> Func;
  4288. };
  4289. /* ConvertParams **************************************************************/
  4290. /* Template class that converts the function parameters if necessary, and
  4291. * ignores the HandlerData parameter if appropriate.
  4292. *
  4293. * Template parameter is the are FuncN function type. */
  4294. template <class F, class T>
  4295. struct ConvertParams;
  4296. /* Function that discards the handler data parameter. */
  4297. template <class R, class P1, R F(P1)>
  4298. R IgnoreHandlerData2(void *p1, const void *hd) {
  4299. UPB_UNUSED(hd);
  4300. return F(static_cast<P1>(p1));
  4301. }
  4302. template <class R, class P1, class P2Wrapper, class P2Wrapped,
  4303. R F(P1, P2Wrapped)>
  4304. R IgnoreHandlerData3(void *p1, const void *hd, P2Wrapper p2) {
  4305. UPB_UNUSED(hd);
  4306. return F(static_cast<P1>(p1), p2);
  4307. }
  4308. template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
  4309. R IgnoreHandlerData4(void *p1, const void *hd, P2 p2, P3 p3) {
  4310. UPB_UNUSED(hd);
  4311. return F(static_cast<P1>(p1), p2, p3);
  4312. }
  4313. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4)>
  4314. R IgnoreHandlerData5(void *p1, const void *hd, P2 p2, P3 p3, P4 p4) {
  4315. UPB_UNUSED(hd);
  4316. return F(static_cast<P1>(p1), p2, p3, p4);
  4317. }
  4318. template <class R, class P1, R F(P1, const char*, size_t)>
  4319. R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2,
  4320. size_t p3, const upb_bufhandle *handle) {
  4321. UPB_UNUSED(hd);
  4322. UPB_UNUSED(handle);
  4323. return F(static_cast<P1>(p1), p2, p3);
  4324. }
  4325. /* Function that casts the handler data parameter. */
  4326. template <class R, class P1, class P2, R F(P1, P2)>
  4327. R CastHandlerData2(void *c, const void *hd) {
  4328. return F(static_cast<P1>(c), static_cast<P2>(hd));
  4329. }
  4330. template <class R, class P1, class P2, class P3Wrapper, class P3Wrapped,
  4331. R F(P1, P2, P3Wrapped)>
  4332. R CastHandlerData3(void *c, const void *hd, P3Wrapper p3) {
  4333. return F(static_cast<P1>(c), static_cast<P2>(hd), p3);
  4334. }
  4335. template <class R, class P1, class P2, class P3, class P4, class P5,
  4336. R F(P1, P2, P3, P4, P5)>
  4337. R CastHandlerData5(void *c, const void *hd, P3 p3, P4 p4, P5 p5) {
  4338. return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4, p5);
  4339. }
  4340. template <class R, class P1, class P2, R F(P1, P2, const char *, size_t)>
  4341. R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
  4342. size_t p4, const upb_bufhandle *handle) {
  4343. UPB_UNUSED(handle);
  4344. return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4);
  4345. }
  4346. /* For unbound functions, ignore the handler data. */
  4347. template <class R, class P1, R F(P1), class I, class T>
  4348. struct ConvertParams<Func1<R, P1, F, I>, T> {
  4349. typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
  4350. };
  4351. template <class R, class P1, class P2, R F(P1, P2), class I,
  4352. class R2, class P1_2, class P2_2, class P3_2>
  4353. struct ConvertParams<Func2<R, P1, P2, F, I>,
  4354. R2 (*)(P1_2, P2_2, P3_2)> {
  4355. typedef Func3<R, void *, const void *, P3_2,
  4356. IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
  4357. };
  4358. /* For StringBuffer only; this ignores both the handler data and the
  4359. * upb_bufhandle. */
  4360. template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
  4361. struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
  4362. typedef Func5<R, void *, const void *, const char *, size_t,
  4363. const upb_bufhandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
  4364. I> Func;
  4365. };
  4366. template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
  4367. class I, class T>
  4368. struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
  4369. typedef Func5<R, void *, const void *, P2, P3, P4,
  4370. IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
  4371. };
  4372. /* For bound functions, cast the handler data. */
  4373. template <class R, class P1, class P2, R F(P1, P2), class I, class T>
  4374. struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
  4375. typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
  4376. Func;
  4377. };
  4378. template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
  4379. class R2, class P1_2, class P2_2, class P3_2>
  4380. struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
  4381. R2 (*)(P1_2, P2_2, P3_2)> {
  4382. typedef Func3<R, void *, const void *, P3_2,
  4383. CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
  4384. };
  4385. /* For StringBuffer only; this ignores the upb_bufhandle. */
  4386. template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
  4387. class I, class T>
  4388. struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
  4389. typedef Func5<R, void *, const void *, const char *, size_t,
  4390. const upb_bufhandle *,
  4391. CastHandlerDataIgnoreHandle<R, P1, P2, F>, I>
  4392. Func;
  4393. };
  4394. template <class R, class P1, class P2, class P3, class P4, class P5,
  4395. R F(P1, P2, P3, P4, P5), class I, class T>
  4396. struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
  4397. typedef Func5<R, void *, const void *, P3, P4, P5,
  4398. CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
  4399. };
  4400. /* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
  4401. * variant C type. */
  4402. #define TYPE_METHODS(utype, ltype, ctype, vtype) \
  4403. template <> \
  4404. struct CanonicalType<vtype> { \
  4405. typedef ctype Type; \
  4406. }; \
  4407. template <> \
  4408. inline bool HandlersPtr::SetValueHandler<vtype>( \
  4409. FieldDefPtr f, const HandlersPtr::utype##Handler &handler) { \
  4410. handler.AddCleanup(ptr()); \
  4411. return upb_handlers_set##ltype(ptr(), f.ptr(), handler.handler(), \
  4412. &handler.attr()); \
  4413. }
  4414. TYPE_METHODS(Double, double, double, double)
  4415. TYPE_METHODS(Float, float, float, float)
  4416. TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
  4417. TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
  4418. TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T)
  4419. TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T)
  4420. TYPE_METHODS(Bool, bool, bool, bool)
  4421. #ifdef UPB_TWO_32BIT_TYPES
  4422. TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T)
  4423. TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T)
  4424. #endif
  4425. #ifdef UPB_TWO_64BIT_TYPES
  4426. TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T)
  4427. TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T)
  4428. #endif
  4429. #undef TYPE_METHODS
  4430. template <> struct CanonicalType<Status*> {
  4431. typedef Status* Type;
  4432. };
  4433. template <class F> struct ReturnOf;
  4434. template <class R, class P1, class P2>
  4435. struct ReturnOf<R (*)(P1, P2)> {
  4436. typedef R Return;
  4437. };
  4438. template <class R, class P1, class P2, class P3>
  4439. struct ReturnOf<R (*)(P1, P2, P3)> {
  4440. typedef R Return;
  4441. };
  4442. template <class R, class P1, class P2, class P3, class P4>
  4443. struct ReturnOf<R (*)(P1, P2, P3, P4)> {
  4444. typedef R Return;
  4445. };
  4446. template <class R, class P1, class P2, class P3, class P4, class P5>
  4447. struct ReturnOf<R (*)(P1, P2, P3, P4, P5)> {
  4448. typedef R Return;
  4449. };
  4450. template <class T>
  4451. template <class F>
  4452. inline Handler<T>::Handler(F func)
  4453. : registered_(false),
  4454. cleanup_data_(func.GetData()),
  4455. cleanup_func_(func.GetCleanup()) {
  4456. attr_.handler_data = func.GetData();
  4457. typedef typename ReturnOf<T>::Return Return;
  4458. typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
  4459. typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
  4460. ReturnWrappedFunc;
  4461. handler_ = ReturnWrappedFunc().Call;
  4462. /* Set attributes based on what templates can statically tell us about the
  4463. * user's function. */
  4464. /* If the original function returns void, then we know that we wrapped it to
  4465. * always return ok. */
  4466. bool always_ok = is_same<typename F::FuncInfo::Return, void>::value;
  4467. attr_.alwaysok = always_ok;
  4468. /* Closure parameter and return type. */
  4469. attr_.closure_type = UniquePtrForType<typename F::FuncInfo::Closure>();
  4470. /* We use the closure type (from the first parameter) if the return type is
  4471. * void or bool, since these are the two cases we wrap to return the closure's
  4472. * type anyway.
  4473. *
  4474. * This is all nonsense for non START* handlers, but it doesn't matter because
  4475. * in that case the value will be ignored. */
  4476. typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
  4477. typename F::FuncInfo::Closure>::value
  4478. EffectiveReturn;
  4479. attr_.return_closure_type = UniquePtrForType<EffectiveReturn>();
  4480. }
  4481. template <class T>
  4482. inline void Handler<T>::AddCleanup(upb_handlers* h) const {
  4483. UPB_ASSERT(!registered_);
  4484. registered_ = true;
  4485. if (cleanup_func_) {
  4486. bool ok = upb_handlers_addcleanup(h, cleanup_data_, cleanup_func_);
  4487. UPB_ASSERT(ok);
  4488. }
  4489. }
  4490. } /* namespace upb */
  4491. #endif /* __cplusplus */
  4492. #undef UPB_TWO_32BIT_TYPES
  4493. #undef UPB_TWO_64BIT_TYPES
  4494. #undef UPB_INT32_T
  4495. #undef UPB_UINT32_T
  4496. #undef UPB_INT32ALT_T
  4497. #undef UPB_UINT32ALT_T
  4498. #undef UPB_INT64_T
  4499. #undef UPB_UINT64_T
  4500. #undef UPB_INT64ALT_T
  4501. #undef UPB_UINT64ALT_T
  4502. #endif /* UPB_HANDLERS_INL_H_ */
  4503. #endif /* UPB_HANDLERS_H */
  4504. /*
  4505. ** upb::Sink (upb_sink)
  4506. ** upb::BytesSink (upb_bytessink)
  4507. **
  4508. ** A upb_sink is an object that binds a upb_handlers object to some runtime
  4509. ** state. It is the object that can actually receive data via the upb_handlers
  4510. ** interface.
  4511. **
  4512. ** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
  4513. ** thread-safe. You can create as many of them as you want, but each one may
  4514. ** only be used in a single thread at a time.
  4515. **
  4516. ** If we compare with class-based OOP, a you can think of a upb_def as an
  4517. ** abstract base class, a upb_handlers as a concrete derived class, and a
  4518. ** upb_sink as an object (class instance).
  4519. */
  4520. #ifndef UPB_SINK_H
  4521. #define UPB_SINK_H
  4522. #ifdef __cplusplus
  4523. namespace upb {
  4524. class BytesSink;
  4525. class Sink;
  4526. }
  4527. #endif
  4528. /* upb_sink *******************************************************************/
  4529. #ifdef __cplusplus
  4530. extern "C" {
  4531. #endif
  4532. typedef struct {
  4533. const upb_handlers *handlers;
  4534. void *closure;
  4535. } upb_sink;
  4536. #define PUTVAL(type, ctype) \
  4537. UPB_INLINE bool upb_sink_put##type(upb_sink s, upb_selector_t sel, \
  4538. ctype val) { \
  4539. typedef upb_##type##_handlerfunc functype; \
  4540. functype *func; \
  4541. const void *hd; \
  4542. if (!s.handlers) return true; \
  4543. func = (functype *)upb_handlers_gethandler(s.handlers, sel, &hd); \
  4544. if (!func) return true; \
  4545. return func(s.closure, hd, val); \
  4546. }
  4547. PUTVAL(int32, int32_t)
  4548. PUTVAL(int64, int64_t)
  4549. PUTVAL(uint32, uint32_t)
  4550. PUTVAL(uint64, uint64_t)
  4551. PUTVAL(float, float)
  4552. PUTVAL(double, double)
  4553. PUTVAL(bool, bool)
  4554. #undef PUTVAL
  4555. UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c) {
  4556. s->handlers = h;
  4557. s->closure = c;
  4558. }
  4559. UPB_INLINE size_t upb_sink_putstring(upb_sink s, upb_selector_t sel,
  4560. const char *buf, size_t n,
  4561. const upb_bufhandle *handle) {
  4562. typedef upb_string_handlerfunc func;
  4563. func *handler;
  4564. const void *hd;
  4565. if (!s.handlers) return n;
  4566. handler = (func *)upb_handlers_gethandler(s.handlers, sel, &hd);
  4567. if (!handler) return n;
  4568. return handler(s.closure, hd, buf, n, handle);
  4569. }
  4570. UPB_INLINE bool upb_sink_putunknown(upb_sink s, const char *buf, size_t n) {
  4571. typedef upb_unknown_handlerfunc func;
  4572. func *handler;
  4573. const void *hd;
  4574. if (!s.handlers) return true;
  4575. handler =
  4576. (func *)upb_handlers_gethandler(s.handlers, UPB_UNKNOWN_SELECTOR, &hd);
  4577. if (!handler) return n;
  4578. return handler(s.closure, hd, buf, n);
  4579. }
  4580. UPB_INLINE bool upb_sink_startmsg(upb_sink s) {
  4581. typedef upb_startmsg_handlerfunc func;
  4582. func *startmsg;
  4583. const void *hd;
  4584. if (!s.handlers) return true;
  4585. startmsg =
  4586. (func *)upb_handlers_gethandler(s.handlers, UPB_STARTMSG_SELECTOR, &hd);
  4587. if (!startmsg) return true;
  4588. return startmsg(s.closure, hd);
  4589. }
  4590. UPB_INLINE bool upb_sink_endmsg(upb_sink s, upb_status *status) {
  4591. typedef upb_endmsg_handlerfunc func;
  4592. func *endmsg;
  4593. const void *hd;
  4594. if (!s.handlers) return true;
  4595. endmsg =
  4596. (func *)upb_handlers_gethandler(s.handlers, UPB_ENDMSG_SELECTOR, &hd);
  4597. if (!endmsg) return true;
  4598. return endmsg(s.closure, hd, status);
  4599. }
  4600. UPB_INLINE bool upb_sink_startseq(upb_sink s, upb_selector_t sel,
  4601. upb_sink *sub) {
  4602. typedef upb_startfield_handlerfunc func;
  4603. func *startseq;
  4604. const void *hd;
  4605. sub->closure = s.closure;
  4606. sub->handlers = s.handlers;
  4607. if (!s.handlers) return true;
  4608. startseq = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4609. if (!startseq) return true;
  4610. sub->closure = startseq(s.closure, hd);
  4611. return sub->closure ? true : false;
  4612. }
  4613. UPB_INLINE bool upb_sink_endseq(upb_sink s, upb_selector_t sel) {
  4614. typedef upb_endfield_handlerfunc func;
  4615. func *endseq;
  4616. const void *hd;
  4617. if (!s.handlers) return true;
  4618. endseq = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4619. if (!endseq) return true;
  4620. return endseq(s.closure, hd);
  4621. }
  4622. UPB_INLINE bool upb_sink_startstr(upb_sink s, upb_selector_t sel,
  4623. size_t size_hint, upb_sink *sub) {
  4624. typedef upb_startstr_handlerfunc func;
  4625. func *startstr;
  4626. const void *hd;
  4627. sub->closure = s.closure;
  4628. sub->handlers = s.handlers;
  4629. if (!s.handlers) return true;
  4630. startstr = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4631. if (!startstr) return true;
  4632. sub->closure = startstr(s.closure, hd, size_hint);
  4633. return sub->closure ? true : false;
  4634. }
  4635. UPB_INLINE bool upb_sink_endstr(upb_sink s, upb_selector_t sel) {
  4636. typedef upb_endfield_handlerfunc func;
  4637. func *endstr;
  4638. const void *hd;
  4639. if (!s.handlers) return true;
  4640. endstr = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4641. if (!endstr) return true;
  4642. return endstr(s.closure, hd);
  4643. }
  4644. UPB_INLINE bool upb_sink_startsubmsg(upb_sink s, upb_selector_t sel,
  4645. upb_sink *sub) {
  4646. typedef upb_startfield_handlerfunc func;
  4647. func *startsubmsg;
  4648. const void *hd;
  4649. sub->closure = s.closure;
  4650. if (!s.handlers) {
  4651. sub->handlers = NULL;
  4652. return true;
  4653. }
  4654. sub->handlers = upb_handlers_getsubhandlers_sel(s.handlers, sel);
  4655. startsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4656. if (!startsubmsg) return true;
  4657. sub->closure = startsubmsg(s.closure, hd);
  4658. return sub->closure ? true : false;
  4659. }
  4660. UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_sink sub,
  4661. upb_selector_t sel) {
  4662. typedef upb_endfield_handlerfunc func;
  4663. func *endsubmsg;
  4664. const void *hd;
  4665. if (!s.handlers) return true;
  4666. endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
  4667. if (!endsubmsg) return true;
  4668. return endsubmsg(sub.closure, hd);
  4669. }
  4670. #ifdef __cplusplus
  4671. } /* extern "C" */
  4672. /* A upb::Sink is an object that binds a upb::Handlers object to some runtime
  4673. * state. It represents an endpoint to which data can be sent.
  4674. *
  4675. * TODO(haberman): right now all of these functions take selectors. Should they
  4676. * take selectorbase instead?
  4677. *
  4678. * ie. instead of calling:
  4679. * sink->StartString(FOO_FIELD_START_STRING, ...)
  4680. * a selector base would let you say:
  4681. * sink->StartString(FOO_FIELD, ...)
  4682. *
  4683. * This would make call sites a little nicer and require emitting fewer selector
  4684. * definitions in .h files.
  4685. *
  4686. * But the current scheme has the benefit that you can retrieve a function
  4687. * pointer for any handler with handlers->GetHandler(selector), without having
  4688. * to have a separate GetHandler() function for each handler type. The JIT
  4689. * compiler uses this. To accommodate we'd have to expose a separate
  4690. * GetHandler() for every handler type.
  4691. *
  4692. * Also to ponder: selectors right now are independent of a specific Handlers
  4693. * instance. In other words, they allocate a number to every possible handler
  4694. * that *could* be registered, without knowing anything about what handlers
  4695. * *are* registered. That means that using selectors as table offsets prohibits
  4696. * us from compacting the handler table at Freeze() time. If the table is very
  4697. * sparse, this could be wasteful.
  4698. *
  4699. * Having another selector-like thing that is specific to a Handlers instance
  4700. * would allow this compacting, but then it would be impossible to write code
  4701. * ahead-of-time that can be bound to any Handlers instance at runtime. For
  4702. * example, a .proto file parser written as straight C will not know what
  4703. * Handlers it will be bound to, so when it calls sink->StartString() what
  4704. * selector will it pass? It needs a selector like we have today, that is
  4705. * independent of any particular upb::Handlers.
  4706. *
  4707. * Is there a way then to allow Handlers table compaction? */
  4708. class upb::Sink {
  4709. public:
  4710. /* Constructor with no initialization; must be Reset() before use. */
  4711. Sink() {}
  4712. Sink(const Sink&) = default;
  4713. Sink& operator=(const Sink&) = default;
  4714. Sink(const upb_sink& sink) : sink_(sink) {}
  4715. Sink &operator=(const upb_sink &sink) {
  4716. sink_ = sink;
  4717. return *this;
  4718. }
  4719. upb_sink sink() { return sink_; }
  4720. /* Constructs a new sink for the given frozen handlers and closure.
  4721. *
  4722. * TODO: once the Handlers know the expected closure type, verify that T
  4723. * matches it. */
  4724. template <class T> Sink(const upb_handlers* handlers, T* closure) {
  4725. Reset(handlers, closure);
  4726. }
  4727. upb_sink* ptr() { return &sink_; }
  4728. /* Resets the value of the sink. */
  4729. template <class T> void Reset(const upb_handlers* handlers, T* closure) {
  4730. upb_sink_reset(&sink_, handlers, closure);
  4731. }
  4732. /* Returns the top-level object that is bound to this sink.
  4733. *
  4734. * TODO: once the Handlers know the expected closure type, verify that T
  4735. * matches it. */
  4736. template <class T> T* GetObject() const {
  4737. return static_cast<T*>(sink_.closure);
  4738. }
  4739. /* Functions for pushing data into the sink.
  4740. *
  4741. * These return false if processing should stop (either due to error or just
  4742. * to suspend).
  4743. *
  4744. * These may not be called from within one of the same sink's handlers (in
  4745. * other words, handlers are not re-entrant). */
  4746. /* Should be called at the start and end of every message; both the top-level
  4747. * message and submessages. This means that submessages should use the
  4748. * following sequence:
  4749. * sink->StartSubMessage(startsubmsg_selector);
  4750. * sink->StartMessage();
  4751. * // ...
  4752. * sink->EndMessage(&status);
  4753. * sink->EndSubMessage(endsubmsg_selector); */
  4754. bool StartMessage() { return upb_sink_startmsg(sink_); }
  4755. bool EndMessage(upb_status *status) {
  4756. return upb_sink_endmsg(sink_, status);
  4757. }
  4758. /* Putting of individual values. These work for both repeated and
  4759. * non-repeated fields, but for repeated fields you must wrap them in
  4760. * calls to StartSequence()/EndSequence(). */
  4761. bool PutInt32(HandlersPtr::Selector s, int32_t val) {
  4762. return upb_sink_putint32(sink_, s, val);
  4763. }
  4764. bool PutInt64(HandlersPtr::Selector s, int64_t val) {
  4765. return upb_sink_putint64(sink_, s, val);
  4766. }
  4767. bool PutUInt32(HandlersPtr::Selector s, uint32_t val) {
  4768. return upb_sink_putuint32(sink_, s, val);
  4769. }
  4770. bool PutUInt64(HandlersPtr::Selector s, uint64_t val) {
  4771. return upb_sink_putuint64(sink_, s, val);
  4772. }
  4773. bool PutFloat(HandlersPtr::Selector s, float val) {
  4774. return upb_sink_putfloat(sink_, s, val);
  4775. }
  4776. bool PutDouble(HandlersPtr::Selector s, double val) {
  4777. return upb_sink_putdouble(sink_, s, val);
  4778. }
  4779. bool PutBool(HandlersPtr::Selector s, bool val) {
  4780. return upb_sink_putbool(sink_, s, val);
  4781. }
  4782. /* Putting of string/bytes values. Each string can consist of zero or more
  4783. * non-contiguous buffers of data.
  4784. *
  4785. * For StartString(), the function will write a sink for the string to "sub."
  4786. * The sub-sink must be used for any/all PutStringBuffer() calls. */
  4787. bool StartString(HandlersPtr::Selector s, size_t size_hint, Sink* sub) {
  4788. upb_sink sub_c;
  4789. bool ret = upb_sink_startstr(sink_, s, size_hint, &sub_c);
  4790. *sub = sub_c;
  4791. return ret;
  4792. }
  4793. size_t PutStringBuffer(HandlersPtr::Selector s, const char *buf, size_t len,
  4794. const upb_bufhandle *handle) {
  4795. return upb_sink_putstring(sink_, s, buf, len, handle);
  4796. }
  4797. bool EndString(HandlersPtr::Selector s) {
  4798. return upb_sink_endstr(sink_, s);
  4799. }
  4800. /* For submessage fields.
  4801. *
  4802. * For StartSubMessage(), the function will write a sink for the string to
  4803. * "sub." The sub-sink must be used for any/all handlers called within the
  4804. * submessage. */
  4805. bool StartSubMessage(HandlersPtr::Selector s, Sink* sub) {
  4806. upb_sink sub_c;
  4807. bool ret = upb_sink_startsubmsg(sink_, s, &sub_c);
  4808. *sub = sub_c;
  4809. return ret;
  4810. }
  4811. bool EndSubMessage(HandlersPtr::Selector s, Sink sub) {
  4812. return upb_sink_endsubmsg(sink_, sub.sink_, s);
  4813. }
  4814. /* For repeated fields of any type, the sequence of values must be wrapped in
  4815. * these calls.
  4816. *
  4817. * For StartSequence(), the function will write a sink for the string to
  4818. * "sub." The sub-sink must be used for any/all handlers called within the
  4819. * sequence. */
  4820. bool StartSequence(HandlersPtr::Selector s, Sink* sub) {
  4821. upb_sink sub_c;
  4822. bool ret = upb_sink_startseq(sink_, s, &sub_c);
  4823. *sub = sub_c;
  4824. return ret;
  4825. }
  4826. bool EndSequence(HandlersPtr::Selector s) {
  4827. return upb_sink_endseq(sink_, s);
  4828. }
  4829. /* Copy and assign specifically allowed.
  4830. * We don't even bother making these members private because so many
  4831. * functions need them and this is mainly just a dumb data container anyway.
  4832. */
  4833. private:
  4834. upb_sink sink_;
  4835. };
  4836. #endif /* __cplusplus */
  4837. /* upb_bytessink **************************************************************/
  4838. typedef struct {
  4839. const upb_byteshandler *handler;
  4840. void *closure;
  4841. } upb_bytessink ;
  4842. UPB_INLINE void upb_bytessink_reset(upb_bytessink* s, const upb_byteshandler *h,
  4843. void *closure) {
  4844. s->handler = h;
  4845. s->closure = closure;
  4846. }
  4847. UPB_INLINE bool upb_bytessink_start(upb_bytessink s, size_t size_hint,
  4848. void **subc) {
  4849. typedef upb_startstr_handlerfunc func;
  4850. func *start;
  4851. *subc = s.closure;
  4852. if (!s.handler) return true;
  4853. start = (func *)s.handler->table[UPB_STARTSTR_SELECTOR].func;
  4854. if (!start) return true;
  4855. *subc = start(s.closure,
  4856. s.handler->table[UPB_STARTSTR_SELECTOR].attr.handler_data,
  4857. size_hint);
  4858. return *subc != NULL;
  4859. }
  4860. UPB_INLINE size_t upb_bytessink_putbuf(upb_bytessink s, void *subc,
  4861. const char *buf, size_t size,
  4862. const upb_bufhandle* handle) {
  4863. typedef upb_string_handlerfunc func;
  4864. func *putbuf;
  4865. if (!s.handler) return true;
  4866. putbuf = (func *)s.handler->table[UPB_STRING_SELECTOR].func;
  4867. if (!putbuf) return true;
  4868. return putbuf(subc, s.handler->table[UPB_STRING_SELECTOR].attr.handler_data,
  4869. buf, size, handle);
  4870. }
  4871. UPB_INLINE bool upb_bytessink_end(upb_bytessink s) {
  4872. typedef upb_endfield_handlerfunc func;
  4873. func *end;
  4874. if (!s.handler) return true;
  4875. end = (func *)s.handler->table[UPB_ENDSTR_SELECTOR].func;
  4876. if (!end) return true;
  4877. return end(s.closure,
  4878. s.handler->table[UPB_ENDSTR_SELECTOR].attr.handler_data);
  4879. }
  4880. #ifdef __cplusplus
  4881. class upb::BytesSink {
  4882. public:
  4883. BytesSink() {}
  4884. BytesSink(const BytesSink&) = default;
  4885. BytesSink& operator=(const BytesSink&) = default;
  4886. BytesSink(const upb_bytessink& sink) : sink_(sink) {}
  4887. BytesSink &operator=(const upb_bytessink &sink) {
  4888. sink_ = sink;
  4889. return *this;
  4890. }
  4891. upb_bytessink sink() { return sink_; }
  4892. /* Constructs a new sink for the given frozen handlers and closure.
  4893. *
  4894. * TODO(haberman): once the Handlers know the expected closure type, verify
  4895. * that T matches it. */
  4896. template <class T> BytesSink(const upb_byteshandler* handler, T* closure) {
  4897. upb_bytessink_reset(sink_, handler, closure);
  4898. }
  4899. /* Resets the value of the sink. */
  4900. template <class T> void Reset(const upb_byteshandler* handler, T* closure) {
  4901. upb_bytessink_reset(&sink_, handler, closure);
  4902. }
  4903. bool Start(size_t size_hint, void **subc) {
  4904. return upb_bytessink_start(sink_, size_hint, subc);
  4905. }
  4906. size_t PutBuffer(void *subc, const char *buf, size_t len,
  4907. const upb_bufhandle *handle) {
  4908. return upb_bytessink_putbuf(sink_, subc, buf, len, handle);
  4909. }
  4910. bool End() {
  4911. return upb_bytessink_end(sink_);
  4912. }
  4913. private:
  4914. upb_bytessink sink_;
  4915. };
  4916. #endif /* __cplusplus */
  4917. /* upb_bufsrc *****************************************************************/
  4918. #ifdef __cplusplus
  4919. extern "C" {
  4920. #endif
  4921. bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink sink);
  4922. #ifdef __cplusplus
  4923. } /* extern "C" */
  4924. namespace upb {
  4925. template <class T> bool PutBuffer(const T& str, BytesSink sink) {
  4926. return upb_bufsrc_putbuf(str.data(), str.size(), sink.sink());
  4927. }
  4928. }
  4929. #endif /* __cplusplus */
  4930. #endif
  4931. /*
  4932. ** Internal-only definitions for the decoder.
  4933. */
  4934. #ifndef UPB_DECODER_INT_H_
  4935. #define UPB_DECODER_INT_H_
  4936. /*
  4937. ** upb::pb::Decoder
  4938. **
  4939. ** A high performance, streaming, resumable decoder for the binary protobuf
  4940. ** format.
  4941. **
  4942. ** This interface works the same regardless of what decoder backend is being
  4943. ** used. A client of this class does not need to know whether decoding is using
  4944. ** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default,
  4945. ** it will always use the fastest available decoder. However, you can call
  4946. ** set_allow_jit(false) to disable any JIT decoder that might be available.
  4947. ** This is primarily useful for testing purposes.
  4948. */
  4949. #ifndef UPB_DECODER_H_
  4950. #define UPB_DECODER_H_
  4951. #ifdef __cplusplus
  4952. namespace upb {
  4953. namespace pb {
  4954. class CodeCache;
  4955. class DecoderPtr;
  4956. class DecoderMethodPtr;
  4957. class DecoderMethodOptions;
  4958. } /* namespace pb */
  4959. } /* namespace upb */
  4960. #endif
  4961. /* The maximum number of bytes we are required to buffer internally between
  4962. * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
  4963. * varint, less one because we are buffering an incomplete value.
  4964. *
  4965. * Should only be used by unit tests. */
  4966. #define UPB_DECODER_MAX_RESIDUAL_BYTES 14
  4967. /* upb_pbdecodermethod ********************************************************/
  4968. struct upb_pbdecodermethod;
  4969. typedef struct upb_pbdecodermethod upb_pbdecodermethod;
  4970. #ifdef __cplusplus
  4971. extern "C" {
  4972. #endif
  4973. const upb_handlers *upb_pbdecodermethod_desthandlers(
  4974. const upb_pbdecodermethod *m);
  4975. const upb_byteshandler *upb_pbdecodermethod_inputhandler(
  4976. const upb_pbdecodermethod *m);
  4977. bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
  4978. #ifdef __cplusplus
  4979. } /* extern "C" */
  4980. /* Represents the code to parse a protobuf according to a destination
  4981. * Handlers. */
  4982. class upb::pb::DecoderMethodPtr {
  4983. public:
  4984. DecoderMethodPtr() : ptr_(nullptr) {}
  4985. DecoderMethodPtr(const upb_pbdecodermethod* ptr) : ptr_(ptr) {}
  4986. const upb_pbdecodermethod* ptr() { return ptr_; }
  4987. /* The destination handlers that are statically bound to this method.
  4988. * This method is only capable of outputting to a sink that uses these
  4989. * handlers. */
  4990. const Handlers *dest_handlers() const {
  4991. return upb_pbdecodermethod_desthandlers(ptr_);
  4992. }
  4993. /* The input handlers for this decoder method. */
  4994. const BytesHandler* input_handler() const {
  4995. return upb_pbdecodermethod_inputhandler(ptr_);
  4996. }
  4997. /* Whether this method is native. */
  4998. bool is_native() const {
  4999. return upb_pbdecodermethod_isnative(ptr_);
  5000. }
  5001. private:
  5002. const upb_pbdecodermethod* ptr_;
  5003. };
  5004. #endif
  5005. /* upb_pbdecoder **************************************************************/
  5006. /* Preallocation hint: decoder won't allocate more bytes than this when first
  5007. * constructed. This hint may be an overestimate for some build configurations.
  5008. * But if the decoder library is upgraded without recompiling the application,
  5009. * it may be an underestimate. */
  5010. #define UPB_PB_DECODER_SIZE 4416
  5011. struct upb_pbdecoder;
  5012. typedef struct upb_pbdecoder upb_pbdecoder;
  5013. #ifdef __cplusplus
  5014. extern "C" {
  5015. #endif
  5016. upb_pbdecoder *upb_pbdecoder_create(upb_arena *arena,
  5017. const upb_pbdecodermethod *method,
  5018. upb_sink output, upb_status *status);
  5019. const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
  5020. upb_bytessink upb_pbdecoder_input(upb_pbdecoder *d);
  5021. uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
  5022. size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
  5023. bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
  5024. void upb_pbdecoder_reset(upb_pbdecoder *d);
  5025. #ifdef __cplusplus
  5026. } /* extern "C" */
  5027. /* A Decoder receives binary protobuf data on its input sink and pushes the
  5028. * decoded data to its output sink. */
  5029. class upb::pb::DecoderPtr {
  5030. public:
  5031. DecoderPtr() : ptr_(nullptr) {}
  5032. DecoderPtr(upb_pbdecoder* ptr) : ptr_(ptr) {}
  5033. upb_pbdecoder* ptr() { return ptr_; }
  5034. /* Constructs a decoder instance for the given method, which must outlive this
  5035. * decoder. Any errors during parsing will be set on the given status, which
  5036. * must also outlive this decoder.
  5037. *
  5038. * The sink must match the given method. */
  5039. static DecoderPtr Create(Arena *arena, DecoderMethodPtr method,
  5040. upb::Sink output, Status *status) {
  5041. return DecoderPtr(upb_pbdecoder_create(arena->ptr(), method.ptr(),
  5042. output.sink(), status->ptr()));
  5043. }
  5044. /* Returns the DecoderMethod this decoder is parsing from. */
  5045. const DecoderMethodPtr method() const {
  5046. return DecoderMethodPtr(upb_pbdecoder_method(ptr_));
  5047. }
  5048. /* The sink on which this decoder receives input. */
  5049. BytesSink input() { return BytesSink(upb_pbdecoder_input(ptr())); }
  5050. /* Returns number of bytes successfully parsed.
  5051. *
  5052. * This can be useful for determining the stream position where an error
  5053. * occurred.
  5054. *
  5055. * This value may not be up-to-date when called from inside a parsing
  5056. * callback. */
  5057. uint64_t BytesParsed() { return upb_pbdecoder_bytesparsed(ptr()); }
  5058. /* Gets/sets the parsing nexting limit. If the total number of nested
  5059. * submessages and repeated fields hits this limit, parsing will fail. This
  5060. * is a resource limit that controls the amount of memory used by the parsing
  5061. * stack.
  5062. *
  5063. * Setting the limit will fail if the parser is currently suspended at a depth
  5064. * greater than this, or if memory allocation of the stack fails. */
  5065. size_t max_nesting() { return upb_pbdecoder_maxnesting(ptr()); }
  5066. bool set_max_nesting(size_t max) { return upb_pbdecoder_maxnesting(ptr()); }
  5067. void Reset() { upb_pbdecoder_reset(ptr()); }
  5068. static const size_t kSize = UPB_PB_DECODER_SIZE;
  5069. private:
  5070. upb_pbdecoder *ptr_;
  5071. };
  5072. #endif /* __cplusplus */
  5073. /* upb_pbcodecache ************************************************************/
  5074. /* Lazily builds and caches decoder methods that will push data to the given
  5075. * handlers. The destination handlercache must outlive this object. */
  5076. struct upb_pbcodecache;
  5077. typedef struct upb_pbcodecache upb_pbcodecache;
  5078. #ifdef __cplusplus
  5079. extern "C" {
  5080. #endif
  5081. upb_pbcodecache *upb_pbcodecache_new(upb_handlercache *dest);
  5082. void upb_pbcodecache_free(upb_pbcodecache *c);
  5083. bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
  5084. void upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
  5085. void upb_pbcodecache_setlazy(upb_pbcodecache *c, bool lazy);
  5086. const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c,
  5087. const upb_msgdef *md);
  5088. #ifdef __cplusplus
  5089. } /* extern "C" */
  5090. /* A class for caching protobuf processing code, whether bytecode for the
  5091. * interpreted decoder or machine code for the JIT.
  5092. *
  5093. * This class is not thread-safe. */
  5094. class upb::pb::CodeCache {
  5095. public:
  5096. CodeCache(upb::HandlerCache *dest)
  5097. : ptr_(upb_pbcodecache_new(dest->ptr()), upb_pbcodecache_free) {}
  5098. CodeCache(CodeCache&&) = default;
  5099. CodeCache& operator=(CodeCache&&) = default;
  5100. upb_pbcodecache* ptr() { return ptr_.get(); }
  5101. const upb_pbcodecache* ptr() const { return ptr_.get(); }
  5102. /* Whether the cache is allowed to generate machine code. Defaults to true.
  5103. * There is no real reason to turn it off except for testing or if you are
  5104. * having a specific problem with the JIT.
  5105. *
  5106. * Note that allow_jit = true does not *guarantee* that the code will be JIT
  5107. * compiled. If this platform is not supported or the JIT was not compiled
  5108. * in, the code may still be interpreted. */
  5109. bool allow_jit() const { return upb_pbcodecache_allowjit(ptr()); }
  5110. /* This may only be called when the object is first constructed, and prior to
  5111. * any code generation. */
  5112. void set_allow_jit(bool allow) { upb_pbcodecache_setallowjit(ptr(), allow); }
  5113. /* Should the decoder push submessages to lazy handlers for fields that have
  5114. * them? The caller should set this iff the lazy handlers expect data that is
  5115. * in protobuf binary format and the caller wishes to lazy parse it. */
  5116. void set_lazy(bool lazy) { upb_pbcodecache_setlazy(ptr(), lazy); }
  5117. /* Returns a DecoderMethod that can push data to the given handlers.
  5118. * If a suitable method already exists, it will be returned from the cache. */
  5119. const DecoderMethodPtr Get(MessageDefPtr md) {
  5120. return DecoderMethodPtr(upb_pbcodecache_get(ptr(), md.ptr()));
  5121. }
  5122. private:
  5123. std::unique_ptr<upb_pbcodecache, decltype(&upb_pbcodecache_free)> ptr_;
  5124. };
  5125. #endif /* __cplusplus */
  5126. #endif /* UPB_DECODER_H_ */
  5127. /* Opcode definitions. The canonical meaning of each opcode is its
  5128. * implementation in the interpreter (the JIT is written to match this).
  5129. *
  5130. * All instructions have the opcode in the low byte.
  5131. * Instruction format for most instructions is:
  5132. *
  5133. * +-------------------+--------+
  5134. * | arg (24) | op (8) |
  5135. * +-------------------+--------+
  5136. *
  5137. * Exceptions are indicated below. A few opcodes are multi-word. */
  5138. typedef enum {
  5139. /* Opcodes 1-8, 13, 15-18 parse their respective descriptor types.
  5140. * Arg for all of these is the upb selector for this field. */
  5141. #define T(type) OP_PARSE_ ## type = UPB_DESCRIPTOR_TYPE_ ## type
  5142. T(DOUBLE), T(FLOAT), T(INT64), T(UINT64), T(INT32), T(FIXED64), T(FIXED32),
  5143. T(BOOL), T(UINT32), T(SFIXED32), T(SFIXED64), T(SINT32), T(SINT64),
  5144. #undef T
  5145. OP_STARTMSG = 9, /* No arg. */
  5146. OP_ENDMSG = 10, /* No arg. */
  5147. OP_STARTSEQ = 11,
  5148. OP_ENDSEQ = 12,
  5149. OP_STARTSUBMSG = 14,
  5150. OP_ENDSUBMSG = 19,
  5151. OP_STARTSTR = 20,
  5152. OP_STRING = 21,
  5153. OP_ENDSTR = 22,
  5154. OP_PUSHTAGDELIM = 23, /* No arg. */
  5155. OP_PUSHLENDELIM = 24, /* No arg. */
  5156. OP_POP = 25, /* No arg. */
  5157. OP_SETDELIM = 26, /* No arg. */
  5158. OP_SETBIGGROUPNUM = 27, /* two words:
  5159. * | unused (24) | opc (8) |
  5160. * | groupnum (32) | */
  5161. OP_CHECKDELIM = 28,
  5162. OP_CALL = 29,
  5163. OP_RET = 30,
  5164. OP_BRANCH = 31,
  5165. /* Different opcodes depending on how many bytes expected. */
  5166. OP_TAG1 = 32, /* | match tag (16) | jump target (8) | opc (8) | */
  5167. OP_TAG2 = 33, /* | match tag (16) | jump target (8) | opc (8) | */
  5168. OP_TAGN = 34, /* three words: */
  5169. /* | unused (16) | jump target(8) | opc (8) | */
  5170. /* | match tag 1 (32) | */
  5171. /* | match tag 2 (32) | */
  5172. OP_SETDISPATCH = 35, /* N words: */
  5173. /* | unused (24) | opc | */
  5174. /* | upb_inttable* (32 or 64) | */
  5175. OP_DISPATCH = 36, /* No arg. */
  5176. OP_HALT = 37 /* No arg. */
  5177. } opcode;
  5178. #define OP_MAX OP_HALT
  5179. UPB_INLINE opcode getop(uint32_t instr) { return (opcode)(instr & 0xff); }
  5180. struct upb_pbcodecache {
  5181. upb_arena *arena;
  5182. upb_handlercache *dest;
  5183. bool allow_jit;
  5184. bool lazy;
  5185. /* Map of upb_msgdef -> mgroup. */
  5186. upb_inttable groups;
  5187. };
  5188. /* Method group; represents a set of decoder methods that had their code
  5189. * emitted together. Immutable once created. */
  5190. typedef struct {
  5191. /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. Owned by us.
  5192. *
  5193. * Ideally this would be on pbcodecache (if we were actually caching code).
  5194. * Right now we don't actually cache anything, which is wasteful. */
  5195. upb_inttable methods;
  5196. /* The bytecode for our methods, if any exists. Owned by us. */
  5197. uint32_t *bytecode;
  5198. uint32_t *bytecode_end;
  5199. } mgroup;
  5200. /* The maximum that any submessages can be nested. Matches proto2's limit.
  5201. * This specifies the size of the decoder's statically-sized array and therefore
  5202. * setting it high will cause the upb::pb::Decoder object to be larger.
  5203. *
  5204. * If necessary we can add a runtime-settable property to Decoder that allow
  5205. * this to be larger than the compile-time setting, but this would add
  5206. * complexity, particularly since we would have to decide how/if to give users
  5207. * the ability to set a custom memory allocation function. */
  5208. #define UPB_DECODER_MAX_NESTING 64
  5209. /* Internal-only struct used by the decoder. */
  5210. typedef struct {
  5211. /* Space optimization note: we store two pointers here that the JIT
  5212. * doesn't need at all; the upb_handlers* inside the sink and
  5213. * the dispatch table pointer. We can optimize so that the JIT uses
  5214. * smaller stack frames than the interpreter. The only thing we need
  5215. * to guarantee is that the fallback routines can find end_ofs. */
  5216. upb_sink sink;
  5217. /* The absolute stream offset of the end-of-frame delimiter.
  5218. * Non-delimited frames (groups and non-packed repeated fields) reuse the
  5219. * delimiter of their parent, even though the frame may not end there.
  5220. *
  5221. * NOTE: the JIT stores a slightly different value here for non-top frames.
  5222. * It stores the value relative to the end of the enclosed message. But the
  5223. * top frame is still stored the same way, which is important for ensuring
  5224. * that calls from the JIT into C work correctly. */
  5225. uint64_t end_ofs;
  5226. const uint32_t *base;
  5227. /* 0 indicates a length-delimited field.
  5228. * A positive number indicates a known group.
  5229. * A negative number indicates an unknown group. */
  5230. int32_t groupnum;
  5231. upb_inttable *dispatch; /* Not used by the JIT. */
  5232. } upb_pbdecoder_frame;
  5233. struct upb_pbdecodermethod {
  5234. /* While compiling, the base is relative in "ofs", after compiling it is
  5235. * absolute in "ptr". */
  5236. union {
  5237. uint32_t ofs; /* PC offset of method. */
  5238. void *ptr; /* Pointer to bytecode or machine code for this method. */
  5239. } code_base;
  5240. /* The decoder method group to which this method belongs. */
  5241. const mgroup *group;
  5242. /* Whether this method is native code or bytecode. */
  5243. bool is_native_;
  5244. /* The handler one calls to invoke this method. */
  5245. upb_byteshandler input_handler_;
  5246. /* The destination handlers this method is bound to. We own a ref. */
  5247. const upb_handlers *dest_handlers_;
  5248. /* Dispatch table -- used by both bytecode decoder and JIT when encountering a
  5249. * field number that wasn't the one we were expecting to see. See
  5250. * decoder.int.h for the layout of this table. */
  5251. upb_inttable dispatch;
  5252. };
  5253. struct upb_pbdecoder {
  5254. upb_arena *arena;
  5255. /* Our input sink. */
  5256. upb_bytessink input_;
  5257. /* The decoder method we are parsing with (owned). */
  5258. const upb_pbdecodermethod *method_;
  5259. size_t call_len;
  5260. const uint32_t *pc, *last;
  5261. /* Current input buffer and its stream offset. */
  5262. const char *buf, *ptr, *end, *checkpoint;
  5263. /* End of the delimited region, relative to ptr, NULL if not in this buf. */
  5264. const char *delim_end;
  5265. /* End of the delimited region, relative to ptr, end if not in this buf. */
  5266. const char *data_end;
  5267. /* Overall stream offset of "buf." */
  5268. uint64_t bufstart_ofs;
  5269. /* Buffer for residual bytes not parsed from the previous buffer. */
  5270. char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
  5271. char *residual_end;
  5272. /* Bytes of data that should be discarded from the input beore we start
  5273. * parsing again. We set this when we internally determine that we can
  5274. * safely skip the next N bytes, but this region extends past the current
  5275. * user buffer. */
  5276. size_t skip;
  5277. /* Stores the user buffer passed to our decode function. */
  5278. const char *buf_param;
  5279. size_t size_param;
  5280. const upb_bufhandle *handle;
  5281. /* Our internal stack. */
  5282. upb_pbdecoder_frame *stack, *top, *limit;
  5283. const uint32_t **callstack;
  5284. size_t stack_size;
  5285. upb_status *status;
  5286. };
  5287. /* Decoder entry points; used as handlers. */
  5288. void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint);
  5289. size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
  5290. size_t size, const upb_bufhandle *handle);
  5291. bool upb_pbdecoder_end(void *closure, const void *handler_data);
  5292. /* Decoder-internal functions that the JIT calls to handle fallback paths. */
  5293. int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
  5294. size_t size, const upb_bufhandle *handle);
  5295. size_t upb_pbdecoder_suspend(upb_pbdecoder *d);
  5296. int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
  5297. uint8_t wire_type);
  5298. int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, uint64_t expected);
  5299. int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, uint64_t *u64);
  5300. int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32);
  5301. int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64);
  5302. void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg);
  5303. /* Error messages that are shared between the bytecode and JIT decoders. */
  5304. extern const char *kPbDecoderStackOverflow;
  5305. extern const char *kPbDecoderSubmessageTooLong;
  5306. /* Access to decoderplan members needed by the decoder. */
  5307. const char *upb_pbdecoder_getopname(unsigned int op);
  5308. /* A special label that means "do field dispatch for this message and branch to
  5309. * wherever that takes you." */
  5310. #define LABEL_DISPATCH 0
  5311. /* A special slot in the dispatch table that stores the epilogue (ENDMSG and/or
  5312. * RET) for branching to when we find an appropriate ENDGROUP tag. */
  5313. #define DISPATCH_ENDMSG 0
  5314. /* It's important to use this invalid wire type instead of 0 (which is a valid
  5315. * wire type). */
  5316. #define NO_WIRE_TYPE 0xff
  5317. /* The dispatch table layout is:
  5318. * [field number] -> [ 48-bit offset ][ 8-bit wt2 ][ 8-bit wt1 ]
  5319. *
  5320. * If wt1 matches, jump to the 48-bit offset. If wt2 matches, lookup
  5321. * (UPB_MAX_FIELDNUMBER + fieldnum) and jump there.
  5322. *
  5323. * We need two wire types because of packed/non-packed compatibility. A
  5324. * primitive repeated field can use either wire type and be valid. While we
  5325. * could key the table on fieldnum+wiretype, the table would be 8x sparser.
  5326. *
  5327. * Storing two wire types in the primary value allows us to quickly rule out
  5328. * the second wire type without needing to do a separate lookup (this case is
  5329. * less common than an unknown field). */
  5330. UPB_INLINE uint64_t upb_pbdecoder_packdispatch(uint64_t ofs, uint8_t wt1,
  5331. uint8_t wt2) {
  5332. return (ofs << 16) | (wt2 << 8) | wt1;
  5333. }
  5334. UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
  5335. uint8_t *wt1, uint8_t *wt2) {
  5336. *wt1 = (uint8_t)dispatch;
  5337. *wt2 = (uint8_t)(dispatch >> 8);
  5338. *ofs = dispatch >> 16;
  5339. }
  5340. /* All of the functions in decoder.c that return int32_t return values according
  5341. * to the following scheme:
  5342. * 1. negative values indicate a return code from the following list.
  5343. * 2. positive values indicate that error or end of buffer was hit, and
  5344. * that the decode function should immediately return the given value
  5345. * (the decoder state has already been suspended and is ready to be
  5346. * resumed). */
  5347. #define DECODE_OK -1
  5348. #define DECODE_MISMATCH -2 /* Used only from checktag_slow(). */
  5349. #define DECODE_ENDGROUP -3 /* Used only from checkunknown(). */
  5350. #define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
  5351. #endif /* UPB_DECODER_INT_H_ */
  5352. /*
  5353. ** A number of routines for varint manipulation (we keep them all around to
  5354. ** have multiple approaches available for benchmarking).
  5355. */
  5356. #ifndef UPB_VARINT_DECODER_H_
  5357. #define UPB_VARINT_DECODER_H_
  5358. #include <assert.h>
  5359. #include <stdint.h>
  5360. #include <string.h>
  5361. #ifdef __cplusplus
  5362. extern "C" {
  5363. #endif
  5364. #define UPB_MAX_WIRE_TYPE 5
  5365. /* The maximum number of bytes that it takes to encode a 64-bit varint. */
  5366. #define UPB_PB_VARINT_MAX_LEN 10
  5367. /* Array of the "native" (ie. non-packed-repeated) wire type for the given a
  5368. * descriptor type (upb_descriptortype_t). */
  5369. extern const uint8_t upb_pb_native_wire_types[];
  5370. UPB_INLINE uint64_t byteswap64(uint64_t val) {
  5371. uint64_t byte = 0xff;
  5372. return (val & (byte << 56) >> 56)
  5373. | (val & (byte << 48) >> 40)
  5374. | (val & (byte << 40) >> 24)
  5375. | (val & (byte << 32) >> 8)
  5376. | (val & (byte << 24) << 8)
  5377. | (val & (byte << 16) << 24)
  5378. | (val & (byte << 8) << 40)
  5379. | (val & (byte << 0) << 56);
  5380. }
  5381. /* Zig-zag encoding/decoding **************************************************/
  5382. UPB_INLINE int32_t upb_zzdec_32(uint64_t _n) {
  5383. uint32_t n = (uint32_t)_n;
  5384. return (n >> 1) ^ -(int32_t)(n & 1);
  5385. }
  5386. UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
  5387. return (n >> 1) ^ -(int64_t)(n & 1);
  5388. }
  5389. UPB_INLINE uint32_t upb_zzenc_32(int32_t n) {
  5390. return ((uint32_t)n << 1) ^ (n >> 31);
  5391. }
  5392. UPB_INLINE uint64_t upb_zzenc_64(int64_t n) {
  5393. return ((uint64_t)n << 1) ^ (n >> 63);
  5394. }
  5395. /* Decoding *******************************************************************/
  5396. /* All decoding functions return this struct by value. */
  5397. typedef struct {
  5398. const char *p; /* NULL if the varint was unterminated. */
  5399. uint64_t val;
  5400. } upb_decoderet;
  5401. UPB_INLINE upb_decoderet upb_decoderet_make(const char *p, uint64_t val) {
  5402. upb_decoderet ret;
  5403. ret.p = p;
  5404. ret.val = val;
  5405. return ret;
  5406. }
  5407. upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r);
  5408. upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r);
  5409. /* Template for a function that checks the first two bytes with branching
  5410. * and dispatches 2-10 bytes with a separate function. Note that this may read
  5411. * up to 10 bytes, so it must not be used unless there are at least ten bytes
  5412. * left in the buffer! */
  5413. #define UPB_VARINT_DECODER_CHECK2(name, decode_max8_function) \
  5414. UPB_INLINE upb_decoderet upb_vdecode_check2_ ## name(const char *_p) { \
  5415. uint8_t *p = (uint8_t*)_p; \
  5416. upb_decoderet r; \
  5417. if ((*p & 0x80) == 0) { \
  5418. /* Common case: one-byte varint. */ \
  5419. return upb_decoderet_make(_p + 1, *p & 0x7fU); \
  5420. } \
  5421. r = upb_decoderet_make(_p + 2, (*p & 0x7fU) | ((*(p + 1) & 0x7fU) << 7)); \
  5422. if ((*(p + 1) & 0x80) == 0) { \
  5423. /* Two-byte varint. */ \
  5424. return r; \
  5425. } \
  5426. /* Longer varint, fallback to out-of-line function. */ \
  5427. return decode_max8_function(r); \
  5428. }
  5429. UPB_VARINT_DECODER_CHECK2(branch32, upb_vdecode_max8_branch32)
  5430. UPB_VARINT_DECODER_CHECK2(branch64, upb_vdecode_max8_branch64)
  5431. #undef UPB_VARINT_DECODER_CHECK2
  5432. /* Our canonical functions for decoding varints, based on the currently
  5433. * favored best-performing implementations. */
  5434. UPB_INLINE upb_decoderet upb_vdecode_fast(const char *p) {
  5435. if (sizeof(long) == 8)
  5436. return upb_vdecode_check2_branch64(p);
  5437. else
  5438. return upb_vdecode_check2_branch32(p);
  5439. }
  5440. /* Encoding *******************************************************************/
  5441. UPB_INLINE int upb_value_size(uint64_t val) {
  5442. #ifdef __GNUC__
  5443. int high_bit = 63 - __builtin_clzll(val); /* 0-based, undef if val == 0. */
  5444. #else
  5445. int high_bit = 0;
  5446. uint64_t tmp = val;
  5447. while(tmp >>= 1) high_bit++;
  5448. #endif
  5449. return val == 0 ? 1 : high_bit / 8 + 1;
  5450. }
  5451. /* Encodes a 64-bit varint into buf (which must be >=UPB_PB_VARINT_MAX_LEN
  5452. * bytes long), returning how many bytes were used.
  5453. *
  5454. * TODO: benchmark and optimize if necessary. */
  5455. UPB_INLINE size_t upb_vencode64(uint64_t val, char *buf) {
  5456. size_t i;
  5457. if (val == 0) { buf[0] = 0; return 1; }
  5458. i = 0;
  5459. while (val) {
  5460. uint8_t byte = val & 0x7fU;
  5461. val >>= 7;
  5462. if (val) byte |= 0x80U;
  5463. buf[i++] = byte;
  5464. }
  5465. return i;
  5466. }
  5467. UPB_INLINE size_t upb_varint_size(uint64_t val) {
  5468. char buf[UPB_PB_VARINT_MAX_LEN];
  5469. return upb_vencode64(val, buf);
  5470. }
  5471. /* Encodes a 32-bit varint, *not* sign-extended. */
  5472. UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
  5473. char buf[UPB_PB_VARINT_MAX_LEN];
  5474. size_t bytes = upb_vencode64(val, buf);
  5475. uint64_t ret = 0;
  5476. UPB_ASSERT(bytes <= 5);
  5477. memcpy(&ret, buf, bytes);
  5478. #ifdef UPB_BIG_ENDIAN
  5479. ret = byteswap64(ret);
  5480. #endif
  5481. UPB_ASSERT(ret <= 0xffffffffffU);
  5482. return ret;
  5483. }
  5484. #ifdef __cplusplus
  5485. } /* extern "C" */
  5486. #endif
  5487. #endif /* UPB_VARINT_DECODER_H_ */
  5488. /*
  5489. ** upb::pb::Encoder (upb_pb_encoder)
  5490. **
  5491. ** Implements a set of upb_handlers that write protobuf data to the binary wire
  5492. ** format.
  5493. **
  5494. ** This encoder implementation does not have any access to any out-of-band or
  5495. ** precomputed lengths for submessages, so it must buffer submessages internally
  5496. ** before it can emit the first byte.
  5497. */
  5498. #ifndef UPB_ENCODER_H_
  5499. #define UPB_ENCODER_H_
  5500. #ifdef __cplusplus
  5501. namespace upb {
  5502. namespace pb {
  5503. class EncoderPtr;
  5504. } /* namespace pb */
  5505. } /* namespace upb */
  5506. #endif
  5507. #define UPB_PBENCODER_MAX_NESTING 100
  5508. /* upb_pb_encoder *************************************************************/
  5509. /* Preallocation hint: decoder won't allocate more bytes than this when first
  5510. * constructed. This hint may be an overestimate for some build configurations.
  5511. * But if the decoder library is upgraded without recompiling the application,
  5512. * it may be an underestimate. */
  5513. #define UPB_PB_ENCODER_SIZE 784
  5514. struct upb_pb_encoder;
  5515. typedef struct upb_pb_encoder upb_pb_encoder;
  5516. #ifdef __cplusplus
  5517. extern "C" {
  5518. #endif
  5519. upb_sink upb_pb_encoder_input(upb_pb_encoder *p);
  5520. upb_pb_encoder* upb_pb_encoder_create(upb_arena* a, const upb_handlers* h,
  5521. upb_bytessink output);
  5522. /* Lazily builds and caches handlers that will push encoded data to a bytessink.
  5523. * Any msgdef objects used with this object must outlive it. */
  5524. upb_handlercache *upb_pb_encoder_newcache(void);
  5525. #ifdef __cplusplus
  5526. } /* extern "C" { */
  5527. class upb::pb::EncoderPtr {
  5528. public:
  5529. EncoderPtr(upb_pb_encoder* ptr) : ptr_(ptr) {}
  5530. upb_pb_encoder* ptr() { return ptr_; }
  5531. /* Creates a new encoder in the given environment. The Handlers must have
  5532. * come from NewHandlers() below. */
  5533. static EncoderPtr Create(Arena* arena, const Handlers* handlers,
  5534. BytesSink output) {
  5535. return EncoderPtr(
  5536. upb_pb_encoder_create(arena->ptr(), handlers, output.sink()));
  5537. }
  5538. /* The input to the encoder. */
  5539. upb::Sink input() { return upb_pb_encoder_input(ptr()); }
  5540. /* Creates a new set of handlers for this MessageDef. */
  5541. static HandlerCache NewCache() {
  5542. return HandlerCache(upb_pb_encoder_newcache());
  5543. }
  5544. static const size_t kSize = UPB_PB_ENCODER_SIZE;
  5545. private:
  5546. upb_pb_encoder* ptr_;
  5547. };
  5548. #endif /* __cplusplus */
  5549. #endif /* UPB_ENCODER_H_ */
  5550. /*
  5551. ** upb::pb::TextPrinter (upb_textprinter)
  5552. **
  5553. ** Handlers for writing to protobuf text format.
  5554. */
  5555. #ifndef UPB_TEXT_H_
  5556. #define UPB_TEXT_H_
  5557. #ifdef __cplusplus
  5558. namespace upb {
  5559. namespace pb {
  5560. class TextPrinterPtr;
  5561. } /* namespace pb */
  5562. } /* namespace upb */
  5563. #endif
  5564. /* upb_textprinter ************************************************************/
  5565. struct upb_textprinter;
  5566. typedef struct upb_textprinter upb_textprinter;
  5567. #ifdef __cplusplus
  5568. extern "C" {
  5569. #endif
  5570. /* C API. */
  5571. upb_textprinter *upb_textprinter_create(upb_arena *arena, const upb_handlers *h,
  5572. upb_bytessink output);
  5573. void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
  5574. upb_sink upb_textprinter_input(upb_textprinter *p);
  5575. upb_handlercache *upb_textprinter_newcache(void);
  5576. #ifdef __cplusplus
  5577. } /* extern "C" */
  5578. class upb::pb::TextPrinterPtr {
  5579. public:
  5580. TextPrinterPtr(upb_textprinter* ptr) : ptr_(ptr) {}
  5581. /* The given handlers must have come from NewHandlers(). It must outlive the
  5582. * TextPrinter. */
  5583. static TextPrinterPtr Create(Arena *arena, upb::HandlersPtr *handlers,
  5584. BytesSink output) {
  5585. return TextPrinterPtr(
  5586. upb_textprinter_create(arena->ptr(), handlers->ptr(), output.sink()));
  5587. }
  5588. void SetSingleLineMode(bool single_line) {
  5589. upb_textprinter_setsingleline(ptr_, single_line);
  5590. }
  5591. Sink input() { return upb_textprinter_input(ptr_); }
  5592. /* If handler caching becomes a requirement we can add a code cache as in
  5593. * decoder.h */
  5594. static HandlerCache NewCache() {
  5595. return HandlerCache(upb_textprinter_newcache());
  5596. }
  5597. private:
  5598. upb_textprinter* ptr_;
  5599. };
  5600. #endif
  5601. #endif /* UPB_TEXT_H_ */
  5602. /*
  5603. ** upb::json::Parser (upb_json_parser)
  5604. **
  5605. ** Parses JSON according to a specific schema.
  5606. ** Support for parsing arbitrary JSON (schema-less) will be added later.
  5607. */
  5608. #ifndef UPB_JSON_PARSER_H_
  5609. #define UPB_JSON_PARSER_H_
  5610. #ifdef __cplusplus
  5611. namespace upb {
  5612. namespace json {
  5613. class CodeCache;
  5614. class ParserPtr;
  5615. class ParserMethodPtr;
  5616. } /* namespace json */
  5617. } /* namespace upb */
  5618. #endif
  5619. /* upb_json_parsermethod ******************************************************/
  5620. struct upb_json_parsermethod;
  5621. typedef struct upb_json_parsermethod upb_json_parsermethod;
  5622. #ifdef __cplusplus
  5623. extern "C" {
  5624. #endif
  5625. const upb_byteshandler* upb_json_parsermethod_inputhandler(
  5626. const upb_json_parsermethod* m);
  5627. #ifdef __cplusplus
  5628. } /* extern "C" */
  5629. class upb::json::ParserMethodPtr {
  5630. public:
  5631. ParserMethodPtr() : ptr_(nullptr) {}
  5632. ParserMethodPtr(const upb_json_parsermethod* ptr) : ptr_(ptr) {}
  5633. const upb_json_parsermethod* ptr() const { return ptr_; }
  5634. const BytesHandler* input_handler() const {
  5635. return upb_json_parsermethod_inputhandler(ptr());
  5636. }
  5637. private:
  5638. const upb_json_parsermethod* ptr_;
  5639. };
  5640. #endif /* __cplusplus */
  5641. /* upb_json_parser ************************************************************/
  5642. /* Preallocation hint: parser won't allocate more bytes than this when first
  5643. * constructed. This hint may be an overestimate for some build configurations.
  5644. * But if the parser library is upgraded without recompiling the application,
  5645. * it may be an underestimate. */
  5646. #define UPB_JSON_PARSER_SIZE 5712
  5647. struct upb_json_parser;
  5648. typedef struct upb_json_parser upb_json_parser;
  5649. #ifdef __cplusplus
  5650. extern "C" {
  5651. #endif
  5652. upb_json_parser* upb_json_parser_create(upb_arena* a,
  5653. const upb_json_parsermethod* m,
  5654. const upb_symtab* symtab,
  5655. upb_sink output,
  5656. upb_status *status,
  5657. bool ignore_json_unknown);
  5658. upb_bytessink upb_json_parser_input(upb_json_parser* p);
  5659. #ifdef __cplusplus
  5660. } /* extern "C" */
  5661. /* Parses an incoming BytesStream, pushing the results to the destination
  5662. * sink. */
  5663. class upb::json::ParserPtr {
  5664. public:
  5665. ParserPtr(upb_json_parser* ptr) : ptr_(ptr) {}
  5666. static ParserPtr Create(Arena* arena, ParserMethodPtr method,
  5667. SymbolTable* symtab, Sink output, Status* status,
  5668. bool ignore_json_unknown) {
  5669. upb_symtab* symtab_ptr = symtab ? symtab->ptr() : nullptr;
  5670. return ParserPtr(upb_json_parser_create(
  5671. arena->ptr(), method.ptr(), symtab_ptr, output.sink(), status->ptr(),
  5672. ignore_json_unknown));
  5673. }
  5674. BytesSink input() { return upb_json_parser_input(ptr_); }
  5675. private:
  5676. upb_json_parser* ptr_;
  5677. };
  5678. #endif /* __cplusplus */
  5679. /* upb_json_codecache *********************************************************/
  5680. /* Lazily builds and caches decoder methods that will push data to the given
  5681. * handlers. The upb_symtab object(s) must outlive this object. */
  5682. struct upb_json_codecache;
  5683. typedef struct upb_json_codecache upb_json_codecache;
  5684. #ifdef __cplusplus
  5685. extern "C" {
  5686. #endif
  5687. upb_json_codecache *upb_json_codecache_new(void);
  5688. void upb_json_codecache_free(upb_json_codecache *cache);
  5689. const upb_json_parsermethod* upb_json_codecache_get(upb_json_codecache* cache,
  5690. const upb_msgdef* md);
  5691. #ifdef __cplusplus
  5692. } /* extern "C" */
  5693. class upb::json::CodeCache {
  5694. public:
  5695. CodeCache() : ptr_(upb_json_codecache_new(), upb_json_codecache_free) {}
  5696. /* Returns a DecoderMethod that can push data to the given handlers.
  5697. * If a suitable method already exists, it will be returned from the cache. */
  5698. ParserMethodPtr Get(MessageDefPtr md) {
  5699. return upb_json_codecache_get(ptr_.get(), md.ptr());
  5700. }
  5701. private:
  5702. std::unique_ptr<upb_json_codecache, decltype(&upb_json_codecache_free)> ptr_;
  5703. };
  5704. #endif
  5705. #endif /* UPB_JSON_PARSER_H_ */
  5706. /*
  5707. ** upb::json::Printer
  5708. **
  5709. ** Handlers that emit JSON according to a specific protobuf schema.
  5710. */
  5711. #ifndef UPB_JSON_TYPED_PRINTER_H_
  5712. #define UPB_JSON_TYPED_PRINTER_H_
  5713. #ifdef __cplusplus
  5714. namespace upb {
  5715. namespace json {
  5716. class PrinterPtr;
  5717. } /* namespace json */
  5718. } /* namespace upb */
  5719. #endif
  5720. /* upb_json_printer ***********************************************************/
  5721. #define UPB_JSON_PRINTER_SIZE 192
  5722. struct upb_json_printer;
  5723. typedef struct upb_json_printer upb_json_printer;
  5724. #ifdef __cplusplus
  5725. extern "C" {
  5726. #endif
  5727. /* Native C API. */
  5728. upb_json_printer *upb_json_printer_create(upb_arena *a, const upb_handlers *h,
  5729. upb_bytessink output);
  5730. upb_sink upb_json_printer_input(upb_json_printer *p);
  5731. const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
  5732. bool preserve_fieldnames,
  5733. const void *owner);
  5734. /* Lazily builds and caches handlers that will push encoded data to a bytessink.
  5735. * Any msgdef objects used with this object must outlive it. */
  5736. upb_handlercache *upb_json_printer_newcache(bool preserve_proto_fieldnames);
  5737. #ifdef __cplusplus
  5738. } /* extern "C" */
  5739. /* Prints an incoming stream of data to a BytesSink in JSON format. */
  5740. class upb::json::PrinterPtr {
  5741. public:
  5742. PrinterPtr(upb_json_printer* ptr) : ptr_(ptr) {}
  5743. static PrinterPtr Create(Arena *arena, const upb::Handlers *handlers,
  5744. BytesSink output) {
  5745. return PrinterPtr(
  5746. upb_json_printer_create(arena->ptr(), handlers, output.sink()));
  5747. }
  5748. /* The input to the printer. */
  5749. Sink input() { return upb_json_printer_input(ptr_); }
  5750. static const size_t kSize = UPB_JSON_PRINTER_SIZE;
  5751. static HandlerCache NewCache(bool preserve_proto_fieldnames) {
  5752. return upb_json_printer_newcache(preserve_proto_fieldnames);
  5753. }
  5754. private:
  5755. upb_json_printer* ptr_;
  5756. };
  5757. #endif /* __cplusplus */
  5758. #endif /* UPB_JSON_TYPED_PRINTER_H_ */
  5759. /* See port_def.inc. This should #undef all macros #defined there. */
  5760. #undef UPB_MAPTYPE_STRING
  5761. #undef UPB_SIZE
  5762. #undef UPB_PTR_AT
  5763. #undef UPB_READ_ONEOF
  5764. #undef UPB_WRITE_ONEOF
  5765. #undef UPB_INLINE
  5766. #undef UPB_FORCEINLINE
  5767. #undef UPB_NOINLINE
  5768. #undef UPB_NORETURN
  5769. #undef UPB_MAX
  5770. #undef UPB_MIN
  5771. #undef UPB_UNUSED
  5772. #undef UPB_ASSUME
  5773. #undef UPB_ASSERT
  5774. #undef UPB_ASSERT_DEBUGVAR
  5775. #undef UPB_UNREACHABLE
  5776. #undef UPB_INFINITY
  5777. #undef UPB_MSVC_VSNPRINTF
  5778. #undef _upb_snprintf
  5779. #undef _upb_vsnprintf
  5780. #undef _upb_va_copy