upb.h 306 KB

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