upb.h 306 KB

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