upb.h 322 KB

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