Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GPBDictionary.m 374KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #import "GPBDictionary_PackagePrivate.h"
  31. #import "GPBCodedInputStream_PackagePrivate.h"
  32. #import "GPBCodedOutputStream_PackagePrivate.h"
  33. #import "GPBDescriptor_PackagePrivate.h"
  34. #import "GPBMessage_PackagePrivate.h"
  35. #import "GPBUtilities_PackagePrivate.h"
  36. // ------------------------------ NOTE ------------------------------
  37. // At the moment, this is all using NSNumbers in NSDictionaries under
  38. // the hood, but it is all hidden so we can come back and optimize
  39. // with direct CFDictionary usage later. The reason that wasn't
  40. // done yet is needing to support 32bit iOS builds. Otherwise
  41. // it would be pretty simple to store all this data in CFDictionaries
  42. // directly.
  43. // ------------------------------------------------------------------
  44. // Direct access is use for speed, to avoid even internally declaring things
  45. // read/write, etc. The warning is enabled in the project to ensure code calling
  46. // protos can turn on -Wdirect-ivar-access without issues.
  47. #pragma clang diagnostic push
  48. #pragma clang diagnostic ignored "-Wdirect-ivar-access"
  49. // Used to include code only visible to specific versions of the static
  50. // analyzer. Useful for wrapping code that only exists to silence the analyzer.
  51. // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
  52. // END_APPLE_BUILD_VERSION using:
  53. // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
  54. // Example usage:
  55. // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
  56. #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
  57. (defined(__clang_analyzer__) && \
  58. (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
  59. __apple_build_version__ <= END_APPLE_BUILD_VERSION))
  60. enum {
  61. kMapKeyFieldNumber = 1,
  62. kMapValueFieldNumber = 2,
  63. };
  64. static BOOL DictDefault_IsValidValue(int32_t value) {
  65. // Anything but the bad value marker is allowed.
  66. return (value != kGPBUnrecognizedEnumeratorValue);
  67. }
  68. //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
  69. //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
  70. //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
  71. //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
  72. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
  73. //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
  74. //% } else {
  75. //% NSCAssert(NO, @"Unexpected type %d", dataType);
  76. //% return 0;
  77. //% }
  78. //%}
  79. //%
  80. //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
  81. //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
  82. //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
  83. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
  84. //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
  85. //% } else {
  86. //% NSCAssert(NO, @"Unexpected type %d", dataType);
  87. //% }
  88. //%}
  89. //%
  90. //%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
  91. //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
  92. //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
  93. //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
  94. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
  95. //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
  96. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
  97. //% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
  98. //% } else {
  99. //% NSCAssert(NO, @"Unexpected type %d", dataType);
  100. //% return 0;
  101. //% }
  102. //%}
  103. //%
  104. //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
  105. //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
  106. //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
  107. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
  108. //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
  109. //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
  110. //% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
  111. //% } else {
  112. //% NSCAssert(NO, @"Unexpected type %d", dataType);
  113. //% }
  114. //%}
  115. //%
  116. //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
  117. //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
  118. //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
  119. //% #pragma unused(dataType) // For when asserts are off in release.
  120. //% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
  121. //%}
  122. //%
  123. //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
  124. //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
  125. //% #pragma unused(dataType) // For when asserts are off in release.
  126. //% [stream write##VALUE_NAME##:fieldNum value:value];
  127. //%}
  128. //%
  129. //%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
  130. //%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
  131. //%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
  132. //%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
  133. //%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
  134. //%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
  135. //%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
  136. //%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
  137. //%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
  138. //%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
  139. //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
  140. //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
  141. // This block of code is generated, do not edit it directly.
  142. static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
  143. if (dataType == GPBDataTypeInt32) {
  144. return GPBComputeInt32Size(fieldNum, value);
  145. } else if (dataType == GPBDataTypeSInt32) {
  146. return GPBComputeSInt32Size(fieldNum, value);
  147. } else if (dataType == GPBDataTypeSFixed32) {
  148. return GPBComputeSFixed32Size(fieldNum, value);
  149. } else {
  150. NSCAssert(NO, @"Unexpected type %d", dataType);
  151. return 0;
  152. }
  153. }
  154. static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
  155. if (dataType == GPBDataTypeInt32) {
  156. [stream writeInt32:fieldNum value:value];
  157. } else if (dataType == GPBDataTypeSInt32) {
  158. [stream writeSInt32:fieldNum value:value];
  159. } else if (dataType == GPBDataTypeSFixed32) {
  160. [stream writeSFixed32:fieldNum value:value];
  161. } else {
  162. NSCAssert(NO, @"Unexpected type %d", dataType);
  163. }
  164. }
  165. static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
  166. if (dataType == GPBDataTypeUInt32) {
  167. return GPBComputeUInt32Size(fieldNum, value);
  168. } else if (dataType == GPBDataTypeFixed32) {
  169. return GPBComputeFixed32Size(fieldNum, value);
  170. } else {
  171. NSCAssert(NO, @"Unexpected type %d", dataType);
  172. return 0;
  173. }
  174. }
  175. static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
  176. if (dataType == GPBDataTypeUInt32) {
  177. [stream writeUInt32:fieldNum value:value];
  178. } else if (dataType == GPBDataTypeFixed32) {
  179. [stream writeFixed32:fieldNum value:value];
  180. } else {
  181. NSCAssert(NO, @"Unexpected type %d", dataType);
  182. }
  183. }
  184. static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
  185. if (dataType == GPBDataTypeInt64) {
  186. return GPBComputeInt64Size(fieldNum, value);
  187. } else if (dataType == GPBDataTypeSInt64) {
  188. return GPBComputeSInt64Size(fieldNum, value);
  189. } else if (dataType == GPBDataTypeSFixed64) {
  190. return GPBComputeSFixed64Size(fieldNum, value);
  191. } else {
  192. NSCAssert(NO, @"Unexpected type %d", dataType);
  193. return 0;
  194. }
  195. }
  196. static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
  197. if (dataType == GPBDataTypeInt64) {
  198. [stream writeInt64:fieldNum value:value];
  199. } else if (dataType == GPBDataTypeSInt64) {
  200. [stream writeSInt64:fieldNum value:value];
  201. } else if (dataType == GPBDataTypeSFixed64) {
  202. [stream writeSFixed64:fieldNum value:value];
  203. } else {
  204. NSCAssert(NO, @"Unexpected type %d", dataType);
  205. }
  206. }
  207. static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
  208. if (dataType == GPBDataTypeUInt64) {
  209. return GPBComputeUInt64Size(fieldNum, value);
  210. } else if (dataType == GPBDataTypeFixed64) {
  211. return GPBComputeFixed64Size(fieldNum, value);
  212. } else {
  213. NSCAssert(NO, @"Unexpected type %d", dataType);
  214. return 0;
  215. }
  216. }
  217. static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
  218. if (dataType == GPBDataTypeUInt64) {
  219. [stream writeUInt64:fieldNum value:value];
  220. } else if (dataType == GPBDataTypeFixed64) {
  221. [stream writeFixed64:fieldNum value:value];
  222. } else {
  223. NSCAssert(NO, @"Unexpected type %d", dataType);
  224. }
  225. }
  226. static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
  227. NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
  228. #pragma unused(dataType) // For when asserts are off in release.
  229. return GPBComputeBoolSize(fieldNum, value);
  230. }
  231. static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
  232. NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
  233. #pragma unused(dataType) // For when asserts are off in release.
  234. [stream writeBool:fieldNum value:value];
  235. }
  236. static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
  237. NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
  238. #pragma unused(dataType) // For when asserts are off in release.
  239. return GPBComputeEnumSize(fieldNum, value);
  240. }
  241. static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
  242. NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
  243. #pragma unused(dataType) // For when asserts are off in release.
  244. [stream writeEnum:fieldNum value:value];
  245. }
  246. static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
  247. NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
  248. #pragma unused(dataType) // For when asserts are off in release.
  249. return GPBComputeFloatSize(fieldNum, value);
  250. }
  251. static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
  252. NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
  253. #pragma unused(dataType) // For when asserts are off in release.
  254. [stream writeFloat:fieldNum value:value];
  255. }
  256. static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
  257. NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
  258. #pragma unused(dataType) // For when asserts are off in release.
  259. return GPBComputeDoubleSize(fieldNum, value);
  260. }
  261. static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
  262. NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
  263. #pragma unused(dataType) // For when asserts are off in release.
  264. [stream writeDouble:fieldNum value:value];
  265. }
  266. static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
  267. NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
  268. #pragma unused(dataType) // For when asserts are off in release.
  269. return GPBComputeStringSize(fieldNum, value);
  270. }
  271. static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
  272. NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
  273. #pragma unused(dataType) // For when asserts are off in release.
  274. [stream writeString:fieldNum value:value];
  275. }
  276. static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
  277. if (dataType == GPBDataTypeMessage) {
  278. return GPBComputeMessageSize(fieldNum, value);
  279. } else if (dataType == GPBDataTypeString) {
  280. return GPBComputeStringSize(fieldNum, value);
  281. } else if (dataType == GPBDataTypeBytes) {
  282. return GPBComputeBytesSize(fieldNum, value);
  283. } else {
  284. NSCAssert(NO, @"Unexpected type %d", dataType);
  285. return 0;
  286. }
  287. }
  288. static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
  289. if (dataType == GPBDataTypeMessage) {
  290. [stream writeMessage:fieldNum value:value];
  291. } else if (dataType == GPBDataTypeString) {
  292. [stream writeString:fieldNum value:value];
  293. } else if (dataType == GPBDataTypeBytes) {
  294. [stream writeBytes:fieldNum value:value];
  295. } else {
  296. NSCAssert(NO, @"Unexpected type %d", dataType);
  297. }
  298. }
  299. //%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
  300. size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
  301. GPBDataType mapValueType = GPBGetFieldDataType(field);
  302. size_t result = 0;
  303. NSString *key;
  304. NSEnumerator *keys = [dict keyEnumerator];
  305. while ((key = [keys nextObject])) {
  306. id obj = dict[key];
  307. size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
  308. msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
  309. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  310. }
  311. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  312. result += tagSize * dict.count;
  313. return result;
  314. }
  315. void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
  316. NSDictionary *dict,
  317. GPBFieldDescriptor *field) {
  318. NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
  319. GPBDataType mapValueType = GPBGetFieldDataType(field);
  320. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  321. NSString *key;
  322. NSEnumerator *keys = [dict keyEnumerator];
  323. while ((key = [keys nextObject])) {
  324. id obj = dict[key];
  325. // Write the tag.
  326. [outputStream writeInt32NoTag:tag];
  327. // Write the size of the message.
  328. size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
  329. msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
  330. // Write the size and fields.
  331. [outputStream writeInt32NoTag:(int32_t)msgSize];
  332. [outputStream writeString:kMapKeyFieldNumber value:key];
  333. WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
  334. }
  335. }
  336. BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
  337. NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
  338. NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
  339. #pragma unused(field) // For when asserts are off in release.
  340. GPBMessage *msg;
  341. NSEnumerator *objects = [dict objectEnumerator];
  342. while ((msg = [objects nextObject])) {
  343. if (!msg.initialized) {
  344. return NO;
  345. }
  346. }
  347. return YES;
  348. }
  349. // Note: if the type is an object, it the retain pass back to the caller.
  350. static void ReadValue(GPBCodedInputStream *stream,
  351. GPBGenericValue *valueToFill,
  352. GPBDataType type,
  353. GPBExtensionRegistry *registry,
  354. GPBFieldDescriptor *field) {
  355. switch (type) {
  356. case GPBDataTypeBool:
  357. valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
  358. break;
  359. case GPBDataTypeFixed32:
  360. valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
  361. break;
  362. case GPBDataTypeSFixed32:
  363. valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
  364. break;
  365. case GPBDataTypeFloat:
  366. valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
  367. break;
  368. case GPBDataTypeFixed64:
  369. valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
  370. break;
  371. case GPBDataTypeSFixed64:
  372. valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
  373. break;
  374. case GPBDataTypeDouble:
  375. valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
  376. break;
  377. case GPBDataTypeInt32:
  378. valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
  379. break;
  380. case GPBDataTypeInt64:
  381. valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
  382. break;
  383. case GPBDataTypeSInt32:
  384. valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
  385. break;
  386. case GPBDataTypeSInt64:
  387. valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
  388. break;
  389. case GPBDataTypeUInt32:
  390. valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
  391. break;
  392. case GPBDataTypeUInt64:
  393. valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
  394. break;
  395. case GPBDataTypeBytes:
  396. [valueToFill->valueData release];
  397. valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
  398. break;
  399. case GPBDataTypeString:
  400. [valueToFill->valueString release];
  401. valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
  402. break;
  403. case GPBDataTypeMessage: {
  404. GPBMessage *message = [[field.msgClass alloc] init];
  405. [stream readMessage:message extensionRegistry:registry];
  406. [valueToFill->valueMessage release];
  407. valueToFill->valueMessage = message;
  408. break;
  409. }
  410. case GPBDataTypeGroup:
  411. NSCAssert(NO, @"Can't happen");
  412. break;
  413. case GPBDataTypeEnum:
  414. valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
  415. break;
  416. }
  417. }
  418. void GPBDictionaryReadEntry(id mapDictionary,
  419. GPBCodedInputStream *stream,
  420. GPBExtensionRegistry *registry,
  421. GPBFieldDescriptor *field,
  422. GPBMessage *parentMessage) {
  423. GPBDataType keyDataType = field.mapKeyDataType;
  424. GPBDataType valueDataType = GPBGetFieldDataType(field);
  425. GPBGenericValue key;
  426. GPBGenericValue value;
  427. // Zero them (but pick up any enum default for proto2).
  428. key.valueString = value.valueString = nil;
  429. if (valueDataType == GPBDataTypeEnum) {
  430. value = field.defaultValue;
  431. }
  432. GPBCodedInputStreamState *state = &stream->state_;
  433. uint32_t keyTag =
  434. GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
  435. uint32_t valueTag =
  436. GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
  437. BOOL hitError = NO;
  438. while (YES) {
  439. uint32_t tag = GPBCodedInputStreamReadTag(state);
  440. if (tag == keyTag) {
  441. ReadValue(stream, &key, keyDataType, registry, field);
  442. } else if (tag == valueTag) {
  443. ReadValue(stream, &value, valueDataType, registry, field);
  444. } else if (tag == 0) {
  445. // zero signals EOF / limit reached
  446. break;
  447. } else { // Unknown
  448. if (![stream skipField:tag]){
  449. hitError = YES;
  450. break;
  451. }
  452. }
  453. }
  454. if (!hitError) {
  455. // Handle the special defaults and/or missing key/value.
  456. if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
  457. key.valueString = [@"" retain];
  458. }
  459. if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
  460. #pragma clang diagnostic push
  461. #pragma clang diagnostic ignored "-Wswitch-enum"
  462. switch (valueDataType) {
  463. case GPBDataTypeString:
  464. value.valueString = [@"" retain];
  465. break;
  466. case GPBDataTypeBytes:
  467. value.valueData = [GPBEmptyNSData() retain];
  468. break;
  469. #if defined(__clang_analyzer__)
  470. case GPBDataTypeGroup:
  471. // Maps can't really have Groups as the value type, but this case is needed
  472. // so the analyzer won't report the posibility of send nil in for the value
  473. // in the NSMutableDictionary case below.
  474. #endif
  475. case GPBDataTypeMessage: {
  476. value.valueMessage = [[field.msgClass alloc] init];
  477. break;
  478. }
  479. default:
  480. // Nothing
  481. break;
  482. }
  483. #pragma clang diagnostic pop
  484. }
  485. if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
  486. #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
  487. // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
  488. // be raised as needed for new Xcodes.
  489. //
  490. // This is only needed on a "shallow" analyze; on a "deep" analyze, the
  491. // existing code path gets this correct. In shallow, the analyzer decides
  492. // GPBDataTypeIsObject(valueDataType) is both false and true on a single
  493. // path through this function, allowing nil to be used for the
  494. // setObject:forKey:.
  495. if (value.valueString == nil) {
  496. value.valueString = [@"" retain];
  497. }
  498. #endif
  499. // mapDictionary is an NSMutableDictionary
  500. [(NSMutableDictionary *)mapDictionary setObject:value.valueString
  501. forKey:key.valueString];
  502. } else {
  503. if (valueDataType == GPBDataTypeEnum) {
  504. if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
  505. [field isValidEnumValue:value.valueEnum]) {
  506. [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
  507. } else {
  508. NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
  509. forKey:&key
  510. keyDataType:keyDataType];
  511. [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
  512. }
  513. } else {
  514. [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
  515. }
  516. }
  517. }
  518. if (GPBDataTypeIsObject(keyDataType)) {
  519. [key.valueString release];
  520. }
  521. if (GPBDataTypeIsObject(valueDataType)) {
  522. [value.valueString release];
  523. }
  524. }
  525. //
  526. // Macros for the common basic cases.
  527. //
  528. //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
  529. //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
  530. //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
  531. //%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
  532. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
  533. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
  534. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
  535. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
  536. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
  537. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
  538. //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
  539. //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
  540. //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
  541. //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
  542. //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
  543. //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
  544. //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
  545. //%#pragma mark - KEY_NAME -> VALUE_NAME
  546. //%
  547. //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
  548. //% @package
  549. //% NSMutableDictionary *_dictionary;
  550. //%}
  551. //%
  552. //%- (instancetype)init {
  553. //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
  554. //%}
  555. //%
  556. //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
  557. //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
  558. //% ##VNAME$S## count:(NSUInteger)count {
  559. //% self = [super init];
  560. //% if (self) {
  561. //% _dictionary = [[NSMutableDictionary alloc] init];
  562. //% if (count && VNAME_VAR##s && keys) {
  563. //% for (NSUInteger i = 0; i < count; ++i) {
  564. //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR##s[i], ______)##DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR##s[i]) forKey:WRAPPED##KHELPER(keys[i])];
  565. //% }
  566. //% }
  567. //% }
  568. //% return self;
  569. //%}
  570. //%
  571. //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
  572. //% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
  573. //% if (self) {
  574. //% if (dictionary) {
  575. //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  576. //% }
  577. //% }
  578. //% return self;
  579. //%}
  580. //%
  581. //%- (instancetype)initWithCapacity:(NSUInteger)numItems {
  582. //% #pragma unused(numItems)
  583. //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
  584. //%}
  585. //%
  586. //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
  587. //%
  588. //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
  589. //%
  590. //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
  591. //%
  592. //%@end
  593. //%
  594. //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
  595. //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
  596. //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
  597. //%#pragma mark - KEY_NAME -> VALUE_NAME
  598. //%
  599. //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
  600. //% @package
  601. //% NSMutableDictionary *_dictionary;
  602. //% GPBEnumValidationFunc _validationFunc;
  603. //%}
  604. //%
  605. //%@synthesize validationFunc = _validationFunc;
  606. //%
  607. //%- (instancetype)init {
  608. //% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  609. //%}
  610. //%
  611. //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  612. //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  613. //%}
  614. //%
  615. //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  616. //% rawValues:(const VALUE_TYPE [])rawValues
  617. //% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
  618. //% count:(NSUInteger)count {
  619. //% self = [super init];
  620. //% if (self) {
  621. //% _dictionary = [[NSMutableDictionary alloc] init];
  622. //% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  623. //% if (count && rawValues && keys) {
  624. //% for (NSUInteger i = 0; i < count; ++i) {
  625. //%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
  626. //% }
  627. //% }
  628. //% }
  629. //% return self;
  630. //%}
  631. //%
  632. //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
  633. //% self = [self initWithValidationFunction:dictionary.validationFunc
  634. //% rawValues:NULL
  635. //% forKeys:NULL
  636. //% count:0];
  637. //% if (self) {
  638. //% if (dictionary) {
  639. //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  640. //% }
  641. //% }
  642. //% return self;
  643. //%}
  644. //%
  645. //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  646. //% capacity:(NSUInteger)numItems {
  647. //% #pragma unused(numItems)
  648. //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  649. //%}
  650. //%
  651. //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
  652. //%
  653. //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
  654. //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
  655. //% if (wrapped && value) {
  656. //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
  657. //% if (!_validationFunc(result)) {
  658. //% result = kGPBUnrecognizedEnumeratorValue;
  659. //% }
  660. //% *value = result;
  661. //% }
  662. //% return (wrapped != NULL);
  663. //%}
  664. //%
  665. //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
  666. //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
  667. //% if (wrapped && rawValue) {
  668. //% *rawValue = UNWRAP##VALUE_NAME(wrapped);
  669. //% }
  670. //% return (wrapped != NULL);
  671. //%}
  672. //%
  673. //%- (void)enumerateKeysAndEnumsUsingBlock:
  674. //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
  675. //% GPBEnumValidationFunc func = _validationFunc;
  676. //% BOOL stop = NO;
  677. //% NSEnumerator *keys = [_dictionary keyEnumerator];
  678. //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
  679. //% while ((aKey = [keys nextObject])) {
  680. //% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
  681. //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
  682. //% if (!func(unwrapped)) {
  683. //% unwrapped = kGPBUnrecognizedEnumeratorValue;
  684. //% }
  685. //% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
  686. //% if (stop) {
  687. //% break;
  688. //% }
  689. //% }
  690. //%}
  691. //%
  692. //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
  693. //%
  694. //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
  695. //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
  696. //% [NSException raise:NSInvalidArgumentException
  697. //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
  698. //% value];
  699. //% }
  700. //%
  701. //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
  702. //% if (_autocreator) {
  703. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  704. //% }
  705. //%}
  706. //%
  707. //%@end
  708. //%
  709. //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
  710. //%- (void)dealloc {
  711. //% NSAssert(!_autocreator,
  712. //% @"%@: Autocreator must be cleared before release, autocreator: %@",
  713. //% [self class], _autocreator);
  714. //% [_dictionary release];
  715. //% [super dealloc];
  716. //%}
  717. //%
  718. //%- (instancetype)copyWithZone:(NSZone *)zone {
  719. //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
  720. //%}
  721. //%
  722. //%- (BOOL)isEqual:(id)other {
  723. //% if (self == other) {
  724. //% return YES;
  725. //% }
  726. //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
  727. //% return NO;
  728. //% }
  729. //% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
  730. //% return [_dictionary isEqual:otherDictionary->_dictionary];
  731. //%}
  732. //%
  733. //%- (NSUInteger)hash {
  734. //% return _dictionary.count;
  735. //%}
  736. //%
  737. //%- (NSString *)description {
  738. //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  739. //%}
  740. //%
  741. //%- (NSUInteger)count {
  742. //% return _dictionary.count;
  743. //%}
  744. //%
  745. //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
  746. //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
  747. //% BOOL stop = NO;
  748. //% NSDictionary *internal = _dictionary;
  749. //% NSEnumerator *keys = [internal keyEnumerator];
  750. //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
  751. //% while ((aKey = [keys nextObject])) {
  752. //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
  753. //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
  754. //% if (stop) {
  755. //% break;
  756. //% }
  757. //% }
  758. //%}
  759. //%
  760. //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  761. //% NSDictionary *internal = _dictionary;
  762. //% NSUInteger count = internal.count;
  763. //% if (count == 0) {
  764. //% return 0;
  765. //% }
  766. //%
  767. //% GPBDataType valueDataType = GPBGetFieldDataType(field);
  768. //% GPBDataType keyDataType = field.mapKeyDataType;
  769. //% size_t result = 0;
  770. //% NSEnumerator *keys = [internal keyEnumerator];
  771. //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
  772. //% while ((aKey = [keys nextObject])) {
  773. //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
  774. //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
  775. //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
  776. //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  777. //% }
  778. //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  779. //% result += tagSize * count;
  780. //% return result;
  781. //%}
  782. //%
  783. //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  784. //% asField:(GPBFieldDescriptor *)field {
  785. //% GPBDataType valueDataType = GPBGetFieldDataType(field);
  786. //% GPBDataType keyDataType = field.mapKeyDataType;
  787. //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  788. //% NSDictionary *internal = _dictionary;
  789. //% NSEnumerator *keys = [internal keyEnumerator];
  790. //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
  791. //% while ((aKey = [keys nextObject])) {
  792. //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
  793. //% [outputStream writeInt32NoTag:tag];
  794. //% // Write the size of the message.
  795. //% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
  796. //% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
  797. //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  798. //% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  799. //% [outputStream writeInt32NoTag:(int32_t)msgSize];
  800. //% // Write the fields.
  801. //% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  802. //% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  803. //% }
  804. //%}
  805. //%
  806. //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
  807. //% forGPBGenericValueKey:(GPBGenericValue *)key {
  808. //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
  809. //%}
  810. //%
  811. //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  812. //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
  813. //% #pragma unused(stop)
  814. //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
  815. //% }];
  816. //%}
  817. //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
  818. //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
  819. //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
  820. //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
  821. //% if (otherDictionary) {
  822. //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  823. //% if (_autocreator) {
  824. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  825. //% }
  826. //% }
  827. //%}
  828. //%
  829. //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
  830. //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
  831. //% if (_autocreator) {
  832. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  833. //% }
  834. //%}
  835. //%
  836. //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
  837. //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
  838. //%}
  839. //%
  840. //%- (void)removeAll {
  841. //% [_dictionary removeAllObjects];
  842. //%}
  843. //
  844. // Custom Generation for Bool keys
  845. //
  846. //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
  847. //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
  848. //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
  849. //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
  850. //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
  851. //%#pragma mark - Bool -> VALUE_NAME
  852. //%
  853. //%@implementation GPBBool##VALUE_NAME##Dictionary {
  854. //% @package
  855. //% VALUE_TYPE _values[2];
  856. //%BOOL_DICT_HAS_STORAGE_##HELPER()}
  857. //%
  858. //%- (instancetype)init {
  859. //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
  860. //%}
  861. //%
  862. //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
  863. //%
  864. //%- (instancetype)initWithCapacity:(NSUInteger)numItems {
  865. //% #pragma unused(numItems)
  866. //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
  867. //%}
  868. //%
  869. //%BOOL_DICT_DEALLOC##HELPER()
  870. //%
  871. //%- (instancetype)copyWithZone:(NSZone *)zone {
  872. //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
  873. //%}
  874. //%
  875. //%- (BOOL)isEqual:(id)other {
  876. //% if (self == other) {
  877. //% return YES;
  878. //% }
  879. //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
  880. //% return NO;
  881. //% }
  882. //% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
  883. //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
  884. //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
  885. //% return NO;
  886. //% }
  887. //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
  888. //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
  889. //% return NO;
  890. //% }
  891. //% return YES;
  892. //%}
  893. //%
  894. //%- (NSUInteger)hash {
  895. //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
  896. //%}
  897. //%
  898. //%- (NSString *)description {
  899. //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  900. //% if (BOOL_DICT_W_HAS##HELPER(0, )) {
  901. //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
  902. //% }
  903. //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
  904. //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
  905. //% }
  906. //% [result appendString:@" }"];
  907. //% return result;
  908. //%}
  909. //%
  910. //%- (NSUInteger)count {
  911. //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
  912. //%}
  913. //%
  914. //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
  915. //%
  916. //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
  917. //%
  918. //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  919. //% if (BOOL_DICT_HAS##HELPER(0, )) {
  920. //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
  921. //% }
  922. //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
  923. //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
  924. //% }
  925. //%}
  926. //%
  927. //%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
  928. //% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
  929. //% BOOL stop = NO;
  930. //% if (BOOL_DICT_HAS##HELPER(0, )) {
  931. //% block(NO, _values[0], &stop);
  932. //% }
  933. //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
  934. //% block(YES, _values[1], &stop);
  935. //% }
  936. //%}
  937. //%
  938. //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  939. //% GPBDataType valueDataType = GPBGetFieldDataType(field);
  940. //% NSUInteger count = 0;
  941. //% size_t result = 0;
  942. //% for (int i = 0; i < 2; ++i) {
  943. //% if (BOOL_DICT_HAS##HELPER(i, )) {
  944. //% ++count;
  945. //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  946. //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  947. //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  948. //% }
  949. //% }
  950. //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  951. //% result += tagSize * count;
  952. //% return result;
  953. //%}
  954. //%
  955. //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  956. //% asField:(GPBFieldDescriptor *)field {
  957. //% GPBDataType valueDataType = GPBGetFieldDataType(field);
  958. //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  959. //% for (int i = 0; i < 2; ++i) {
  960. //% if (BOOL_DICT_HAS##HELPER(i, )) {
  961. //% // Write the tag.
  962. //% [outputStream writeInt32NoTag:tag];
  963. //% // Write the size of the message.
  964. //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  965. //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  966. //% [outputStream writeInt32NoTag:(int32_t)msgSize];
  967. //% // Write the fields.
  968. //% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  969. //% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  970. //% }
  971. //% }
  972. //%}
  973. //%
  974. //%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
  975. //%
  976. //%@end
  977. //%
  978. //
  979. // Helpers for PODs
  980. //
  981. //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
  982. //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
  983. //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
  984. //% if (wrapped && value) {
  985. //% *value = UNWRAP##VALUE_NAME(wrapped);
  986. //% }
  987. //% return (wrapped != NULL);
  988. //%}
  989. //%PDDM-DEFINE WRAPPEDPOD(VALUE)
  990. //%@(VALUE)
  991. //%PDDM-DEFINE UNWRAPUInt32(VALUE)
  992. //%[VALUE unsignedIntValue]
  993. //%PDDM-DEFINE UNWRAPInt32(VALUE)
  994. //%[VALUE intValue]
  995. //%PDDM-DEFINE UNWRAPUInt64(VALUE)
  996. //%[VALUE unsignedLongLongValue]
  997. //%PDDM-DEFINE UNWRAPInt64(VALUE)
  998. //%[VALUE longLongValue]
  999. //%PDDM-DEFINE UNWRAPBool(VALUE)
  1000. //%[VALUE boolValue]
  1001. //%PDDM-DEFINE UNWRAPFloat(VALUE)
  1002. //%[VALUE floatValue]
  1003. //%PDDM-DEFINE UNWRAPDouble(VALUE)
  1004. //%[VALUE doubleValue]
  1005. //%PDDM-DEFINE UNWRAPEnum(VALUE)
  1006. //%[VALUE intValue]
  1007. //%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
  1008. //%[NSString stringWithFormat:@"%u", VALUE]
  1009. //%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
  1010. //%[NSString stringWithFormat:@"%d", VALUE]
  1011. //%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
  1012. //%[NSString stringWithFormat:@"%llu", VALUE]
  1013. //%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
  1014. //%[NSString stringWithFormat:@"%lld", VALUE]
  1015. //%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
  1016. //%(VALUE ? @"true" : @"false")
  1017. //%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
  1018. //%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
  1019. //%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
  1020. //%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
  1021. //%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
  1022. //%@(VALUE)
  1023. //%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
  1024. //%NSNumber *
  1025. //%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
  1026. //%VAL1 != VAL2
  1027. //%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
  1028. // Empty
  1029. //%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
  1030. // Empty
  1031. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
  1032. //%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
  1033. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
  1034. // Empty
  1035. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
  1036. // Empty
  1037. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
  1038. // Empty
  1039. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
  1040. // Empty
  1041. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
  1042. // Empty
  1043. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
  1044. // Empty
  1045. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
  1046. // Empty
  1047. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
  1048. //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
  1049. //% forKey:(GPBGenericValue *)key
  1050. //% keyDataType:(GPBDataType)keyDataType {
  1051. //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
  1052. //% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  1053. //% NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  1054. //% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  1055. //% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
  1056. //% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  1057. //% [outputStream release];
  1058. //% return data;
  1059. //%}
  1060. //%
  1061. //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
  1062. //%value##VALUE_NAME
  1063. //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
  1064. // Empty
  1065. //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
  1066. // Empty
  1067. //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
  1068. //% BOOL _valueSet[2];
  1069. //%
  1070. //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
  1071. //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
  1072. //% ##VALUE_NAME$S## forKeys:(const BOOL [])keys
  1073. //% ##VALUE_NAME$S## count:(NSUInteger)count {
  1074. //% self = [super init];
  1075. //% if (self) {
  1076. //% for (NSUInteger i = 0; i < count; ++i) {
  1077. //% int idx = keys[i] ? 1 : 0;
  1078. //% _values[idx] = values[i];
  1079. //% _valueSet[idx] = YES;
  1080. //% }
  1081. //% }
  1082. //% return self;
  1083. //%}
  1084. //%
  1085. //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
  1086. //% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
  1087. //% if (self) {
  1088. //% if (dictionary) {
  1089. //% for (int i = 0; i < 2; ++i) {
  1090. //% if (dictionary->_valueSet[i]) {
  1091. //% _values[i] = dictionary->_values[i];
  1092. //% _valueSet[i] = YES;
  1093. //% }
  1094. //% }
  1095. //% }
  1096. //% }
  1097. //% return self;
  1098. //%}
  1099. //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
  1100. //%#if !defined(NS_BLOCK_ASSERTIONS)
  1101. //%- (void)dealloc {
  1102. //% NSAssert(!_autocreator,
  1103. //% @"%@: Autocreator must be cleared before release, autocreator: %@",
  1104. //% [self class], _autocreator);
  1105. //% [super dealloc];
  1106. //%}
  1107. //%#endif // !defined(NS_BLOCK_ASSERTIONS)
  1108. //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
  1109. //%BOOL_DICT_HASPOD(IDX, REF)
  1110. //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
  1111. //%REF##_valueSet[IDX]
  1112. //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
  1113. //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
  1114. //% int idx = (key ? 1 : 0);
  1115. //% if (_valueSet[idx]) {
  1116. //% if (value) {
  1117. //% *value = _values[idx];
  1118. //% }
  1119. //% return YES;
  1120. //% }
  1121. //% return NO;
  1122. //%}
  1123. //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
  1124. //%- (void)setGPBGenericValue:(GPBGenericValue *)value
  1125. //% forGPBGenericValueKey:(GPBGenericValue *)key {
  1126. //% int idx = (key->valueBool ? 1 : 0);
  1127. //% _values[idx] = value->value##VALUE_NAME;
  1128. //% _valueSet[idx] = YES;
  1129. //%}
  1130. //%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
  1131. //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
  1132. //% if (otherDictionary) {
  1133. //% for (int i = 0; i < 2; ++i) {
  1134. //% if (otherDictionary->_valueSet[i]) {
  1135. //% _valueSet[i] = YES;
  1136. //% _values[i] = otherDictionary->_values[i];
  1137. //% }
  1138. //% }
  1139. //% if (_autocreator) {
  1140. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  1141. //% }
  1142. //% }
  1143. //%}
  1144. //%
  1145. //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
  1146. //% int idx = (key ? 1 : 0);
  1147. //% _values[idx] = value;
  1148. //% _valueSet[idx] = YES;
  1149. //% if (_autocreator) {
  1150. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  1151. //% }
  1152. //%}
  1153. //%
  1154. //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
  1155. //% _valueSet[aKey ? 1 : 0] = NO;
  1156. //%}
  1157. //%
  1158. //%- (void)removeAll {
  1159. //% _valueSet[0] = NO;
  1160. //% _valueSet[1] = NO;
  1161. //%}
  1162. //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
  1163. //%STR_FORMAT_##VALUE_NAME()
  1164. //%PDDM-DEFINE STR_FORMAT_UInt32()
  1165. //%%u
  1166. //%PDDM-DEFINE STR_FORMAT_Int32()
  1167. //%%d
  1168. //%PDDM-DEFINE STR_FORMAT_UInt64()
  1169. //%%llu
  1170. //%PDDM-DEFINE STR_FORMAT_Int64()
  1171. //%%lld
  1172. //%PDDM-DEFINE STR_FORMAT_Bool()
  1173. //%%d
  1174. //%PDDM-DEFINE STR_FORMAT_Float()
  1175. //%%f
  1176. //%PDDM-DEFINE STR_FORMAT_Double()
  1177. //%%lf
  1178. //
  1179. // Helpers for Objects
  1180. //
  1181. //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
  1182. //%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
  1183. //% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
  1184. //% return result;
  1185. //%}
  1186. //%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
  1187. //%VALUE
  1188. //%PDDM-DEFINE UNWRAPString(VALUE)
  1189. //%VALUE
  1190. //%PDDM-DEFINE UNWRAPObject(VALUE)
  1191. //%VALUE
  1192. //%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
  1193. //%VALUE
  1194. //%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
  1195. //%VALUE
  1196. //%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
  1197. //%ENUM_TYPEOBJECT_##TYPE()
  1198. //%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
  1199. //%NSString *
  1200. //%PDDM-DEFINE ENUM_TYPEOBJECT_id()
  1201. //%id ##
  1202. //%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
  1203. //%![VAL1 isEqual:VAL2]
  1204. //%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
  1205. //%- (BOOL)isInitialized {
  1206. //% for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  1207. //% if (!msg.initialized) {
  1208. //% return NO;
  1209. //% }
  1210. //% }
  1211. //% return YES;
  1212. //%}
  1213. //%
  1214. //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
  1215. //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
  1216. //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
  1217. //% NSEnumerator *keys = [_dictionary keyEnumerator];
  1218. //% id aKey;
  1219. //% NSMutableDictionary *internalDict = newDict->_dictionary;
  1220. //% while ((aKey = [keys nextObject])) {
  1221. //% GPBMessage *msg = _dictionary[aKey];
  1222. //% GPBMessage *copiedMsg = [msg copyWithZone:zone];
  1223. //% [internalDict setObject:copiedMsg forKey:aKey];
  1224. //% [copiedMsg release];
  1225. //% }
  1226. //% return newDict;
  1227. //%}
  1228. //%
  1229. //%
  1230. //%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
  1231. //%- (BOOL)isInitialized {
  1232. //% if (_values[0] && ![_values[0] isInitialized]) {
  1233. //% return NO;
  1234. //% }
  1235. //% if (_values[1] && ![_values[1] isInitialized]) {
  1236. //% return NO;
  1237. //% }
  1238. //% return YES;
  1239. //%}
  1240. //%
  1241. //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
  1242. //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
  1243. //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
  1244. //% for (int i = 0; i < 2; ++i) {
  1245. //% if (_values[i] != nil) {
  1246. //% newDict->_values[i] = [_values[i] copyWithZone:zone];
  1247. //% }
  1248. //% }
  1249. //% return newDict;
  1250. //%}
  1251. //%
  1252. //%
  1253. //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
  1254. // Empty
  1255. //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
  1256. //%valueString
  1257. //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
  1258. //%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
  1259. //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
  1260. //%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
  1261. //%##EXTRA_INDENT$S## }
  1262. //%
  1263. //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
  1264. //%##EXTRA_INDENT$S## if (!##KEY_NAME) {
  1265. //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
  1266. //%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
  1267. //%##EXTRA_INDENT$S## }
  1268. //%
  1269. //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
  1270. // Empty
  1271. //%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
  1272. //%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
  1273. //% forKeys:(const BOOL [])keys
  1274. //% count:(NSUInteger)count {
  1275. //% self = [super init];
  1276. //% if (self) {
  1277. //% for (NSUInteger i = 0; i < count; ++i) {
  1278. //% if (!objects[i]) {
  1279. //% [NSException raise:NSInvalidArgumentException
  1280. //% format:@"Attempting to add nil object to a Dictionary"];
  1281. //% }
  1282. //% int idx = keys[i] ? 1 : 0;
  1283. //% [_values[idx] release];
  1284. //% _values[idx] = (VALUE_TYPE)[objects[i] retain];
  1285. //% }
  1286. //% }
  1287. //% return self;
  1288. //%}
  1289. //%
  1290. //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
  1291. //% self = [self initWithObjects:NULL forKeys:NULL count:0];
  1292. //% if (self) {
  1293. //% if (dictionary) {
  1294. //% _values[0] = [dictionary->_values[0] retain];
  1295. //% _values[1] = [dictionary->_values[1] retain];
  1296. //% }
  1297. //% }
  1298. //% return self;
  1299. //%}
  1300. //%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
  1301. //%- (void)dealloc {
  1302. //% NSAssert(!_autocreator,
  1303. //% @"%@: Autocreator must be cleared before release, autocreator: %@",
  1304. //% [self class], _autocreator);
  1305. //% [_values[0] release];
  1306. //% [_values[1] release];
  1307. //% [super dealloc];
  1308. //%}
  1309. //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
  1310. //%(BOOL_DICT_HASOBJECT(IDX, REF))
  1311. //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
  1312. //%REF##_values[IDX] != nil
  1313. //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
  1314. //%- (VALUE_TYPE)objectForKey:(BOOL)key {
  1315. //% return _values[key ? 1 : 0];
  1316. //%}
  1317. //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
  1318. //%- (void)setGPBGenericValue:(GPBGenericValue *)value
  1319. //% forGPBGenericValueKey:(GPBGenericValue *)key {
  1320. //% int idx = (key->valueBool ? 1 : 0);
  1321. //% [_values[idx] release];
  1322. //% _values[idx] = [value->valueString retain];
  1323. //%}
  1324. //%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
  1325. //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
  1326. //% if (otherDictionary) {
  1327. //% for (int i = 0; i < 2; ++i) {
  1328. //% if (otherDictionary->_values[i] != nil) {
  1329. //% [_values[i] release];
  1330. //% _values[i] = [otherDictionary->_values[i] retain];
  1331. //% }
  1332. //% }
  1333. //% if (_autocreator) {
  1334. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  1335. //% }
  1336. //% }
  1337. //%}
  1338. //%
  1339. //%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
  1340. //% if (!object) {
  1341. //% [NSException raise:NSInvalidArgumentException
  1342. //% format:@"Attempting to add nil object to a Dictionary"];
  1343. //% }
  1344. //% int idx = (key ? 1 : 0);
  1345. //% [_values[idx] release];
  1346. //% _values[idx] = [object retain];
  1347. //% if (_autocreator) {
  1348. //% GPBAutocreatedDictionaryModified(_autocreator, self);
  1349. //% }
  1350. //%}
  1351. //%
  1352. //%- (void)removeObjectForKey:(BOOL)aKey {
  1353. //% int idx = (aKey ? 1 : 0);
  1354. //% [_values[idx] release];
  1355. //% _values[idx] = nil;
  1356. //%}
  1357. //%
  1358. //%- (void)removeAll {
  1359. //% for (int i = 0; i < 2; ++i) {
  1360. //% [_values[i] release];
  1361. //% _values[i] = nil;
  1362. //% }
  1363. //%}
  1364. //%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
  1365. //%%@
  1366. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
  1367. // This block of code is generated, do not edit it directly.
  1368. #pragma mark - UInt32 -> UInt32
  1369. @implementation GPBUInt32UInt32Dictionary {
  1370. @package
  1371. NSMutableDictionary *_dictionary;
  1372. }
  1373. - (instancetype)init {
  1374. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  1375. }
  1376. - (instancetype)initWithUInt32s:(const uint32_t [])values
  1377. forKeys:(const uint32_t [])keys
  1378. count:(NSUInteger)count {
  1379. self = [super init];
  1380. if (self) {
  1381. _dictionary = [[NSMutableDictionary alloc] init];
  1382. if (count && values && keys) {
  1383. for (NSUInteger i = 0; i < count; ++i) {
  1384. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  1385. }
  1386. }
  1387. }
  1388. return self;
  1389. }
  1390. - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
  1391. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  1392. if (self) {
  1393. if (dictionary) {
  1394. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  1395. }
  1396. }
  1397. return self;
  1398. }
  1399. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  1400. #pragma unused(numItems)
  1401. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  1402. }
  1403. - (void)dealloc {
  1404. NSAssert(!_autocreator,
  1405. @"%@: Autocreator must be cleared before release, autocreator: %@",
  1406. [self class], _autocreator);
  1407. [_dictionary release];
  1408. [super dealloc];
  1409. }
  1410. - (instancetype)copyWithZone:(NSZone *)zone {
  1411. return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  1412. }
  1413. - (BOOL)isEqual:(id)other {
  1414. if (self == other) {
  1415. return YES;
  1416. }
  1417. if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
  1418. return NO;
  1419. }
  1420. GPBUInt32UInt32Dictionary *otherDictionary = other;
  1421. return [_dictionary isEqual:otherDictionary->_dictionary];
  1422. }
  1423. - (NSUInteger)hash {
  1424. return _dictionary.count;
  1425. }
  1426. - (NSString *)description {
  1427. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  1428. }
  1429. - (NSUInteger)count {
  1430. return _dictionary.count;
  1431. }
  1432. - (void)enumerateKeysAndUInt32sUsingBlock:
  1433. (void (^)(uint32_t key, uint32_t value, BOOL *stop))block {
  1434. BOOL stop = NO;
  1435. NSDictionary *internal = _dictionary;
  1436. NSEnumerator *keys = [internal keyEnumerator];
  1437. NSNumber *aKey;
  1438. while ((aKey = [keys nextObject])) {
  1439. NSNumber *aValue = internal[aKey];
  1440. block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop);
  1441. if (stop) {
  1442. break;
  1443. }
  1444. }
  1445. }
  1446. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  1447. NSDictionary *internal = _dictionary;
  1448. NSUInteger count = internal.count;
  1449. if (count == 0) {
  1450. return 0;
  1451. }
  1452. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1453. GPBDataType keyDataType = field.mapKeyDataType;
  1454. size_t result = 0;
  1455. NSEnumerator *keys = [internal keyEnumerator];
  1456. NSNumber *aKey;
  1457. while ((aKey = [keys nextObject])) {
  1458. NSNumber *aValue = internal[aKey];
  1459. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  1460. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  1461. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  1462. }
  1463. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  1464. result += tagSize * count;
  1465. return result;
  1466. }
  1467. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  1468. asField:(GPBFieldDescriptor *)field {
  1469. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1470. GPBDataType keyDataType = field.mapKeyDataType;
  1471. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  1472. NSDictionary *internal = _dictionary;
  1473. NSEnumerator *keys = [internal keyEnumerator];
  1474. NSNumber *aKey;
  1475. while ((aKey = [keys nextObject])) {
  1476. NSNumber *aValue = internal[aKey];
  1477. [outputStream writeInt32NoTag:tag];
  1478. // Write the size of the message.
  1479. uint32_t unwrappedKey = [aKey unsignedIntValue];
  1480. uint32_t unwrappedValue = [aValue unsignedIntValue];
  1481. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1482. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  1483. [outputStream writeInt32NoTag:(int32_t)msgSize];
  1484. // Write the fields.
  1485. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1486. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  1487. }
  1488. }
  1489. - (void)setGPBGenericValue:(GPBGenericValue *)value
  1490. forGPBGenericValueKey:(GPBGenericValue *)key {
  1491. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
  1492. }
  1493. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  1494. [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) {
  1495. #pragma unused(stop)
  1496. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
  1497. }];
  1498. }
  1499. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
  1500. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  1501. if (wrapped && value) {
  1502. *value = [wrapped unsignedIntValue];
  1503. }
  1504. return (wrapped != NULL);
  1505. }
  1506. - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
  1507. if (otherDictionary) {
  1508. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  1509. if (_autocreator) {
  1510. GPBAutocreatedDictionaryModified(_autocreator, self);
  1511. }
  1512. }
  1513. }
  1514. - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
  1515. [_dictionary setObject:@(value) forKey:@(key)];
  1516. if (_autocreator) {
  1517. GPBAutocreatedDictionaryModified(_autocreator, self);
  1518. }
  1519. }
  1520. - (void)removeUInt32ForKey:(uint32_t)aKey {
  1521. [_dictionary removeObjectForKey:@(aKey)];
  1522. }
  1523. - (void)removeAll {
  1524. [_dictionary removeAllObjects];
  1525. }
  1526. @end
  1527. #pragma mark - UInt32 -> Int32
  1528. @implementation GPBUInt32Int32Dictionary {
  1529. @package
  1530. NSMutableDictionary *_dictionary;
  1531. }
  1532. - (instancetype)init {
  1533. return [self initWithInt32s:NULL forKeys:NULL count:0];
  1534. }
  1535. - (instancetype)initWithInt32s:(const int32_t [])values
  1536. forKeys:(const uint32_t [])keys
  1537. count:(NSUInteger)count {
  1538. self = [super init];
  1539. if (self) {
  1540. _dictionary = [[NSMutableDictionary alloc] init];
  1541. if (count && values && keys) {
  1542. for (NSUInteger i = 0; i < count; ++i) {
  1543. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  1544. }
  1545. }
  1546. }
  1547. return self;
  1548. }
  1549. - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
  1550. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  1551. if (self) {
  1552. if (dictionary) {
  1553. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  1554. }
  1555. }
  1556. return self;
  1557. }
  1558. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  1559. #pragma unused(numItems)
  1560. return [self initWithInt32s:NULL forKeys:NULL count:0];
  1561. }
  1562. - (void)dealloc {
  1563. NSAssert(!_autocreator,
  1564. @"%@: Autocreator must be cleared before release, autocreator: %@",
  1565. [self class], _autocreator);
  1566. [_dictionary release];
  1567. [super dealloc];
  1568. }
  1569. - (instancetype)copyWithZone:(NSZone *)zone {
  1570. return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  1571. }
  1572. - (BOOL)isEqual:(id)other {
  1573. if (self == other) {
  1574. return YES;
  1575. }
  1576. if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
  1577. return NO;
  1578. }
  1579. GPBUInt32Int32Dictionary *otherDictionary = other;
  1580. return [_dictionary isEqual:otherDictionary->_dictionary];
  1581. }
  1582. - (NSUInteger)hash {
  1583. return _dictionary.count;
  1584. }
  1585. - (NSString *)description {
  1586. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  1587. }
  1588. - (NSUInteger)count {
  1589. return _dictionary.count;
  1590. }
  1591. - (void)enumerateKeysAndInt32sUsingBlock:
  1592. (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
  1593. BOOL stop = NO;
  1594. NSDictionary *internal = _dictionary;
  1595. NSEnumerator *keys = [internal keyEnumerator];
  1596. NSNumber *aKey;
  1597. while ((aKey = [keys nextObject])) {
  1598. NSNumber *aValue = internal[aKey];
  1599. block([aKey unsignedIntValue], [aValue intValue], &stop);
  1600. if (stop) {
  1601. break;
  1602. }
  1603. }
  1604. }
  1605. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  1606. NSDictionary *internal = _dictionary;
  1607. NSUInteger count = internal.count;
  1608. if (count == 0) {
  1609. return 0;
  1610. }
  1611. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1612. GPBDataType keyDataType = field.mapKeyDataType;
  1613. size_t result = 0;
  1614. NSEnumerator *keys = [internal keyEnumerator];
  1615. NSNumber *aKey;
  1616. while ((aKey = [keys nextObject])) {
  1617. NSNumber *aValue = internal[aKey];
  1618. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  1619. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  1620. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  1621. }
  1622. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  1623. result += tagSize * count;
  1624. return result;
  1625. }
  1626. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  1627. asField:(GPBFieldDescriptor *)field {
  1628. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1629. GPBDataType keyDataType = field.mapKeyDataType;
  1630. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  1631. NSDictionary *internal = _dictionary;
  1632. NSEnumerator *keys = [internal keyEnumerator];
  1633. NSNumber *aKey;
  1634. while ((aKey = [keys nextObject])) {
  1635. NSNumber *aValue = internal[aKey];
  1636. [outputStream writeInt32NoTag:tag];
  1637. // Write the size of the message.
  1638. uint32_t unwrappedKey = [aKey unsignedIntValue];
  1639. int32_t unwrappedValue = [aValue intValue];
  1640. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1641. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  1642. [outputStream writeInt32NoTag:(int32_t)msgSize];
  1643. // Write the fields.
  1644. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1645. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  1646. }
  1647. }
  1648. - (void)setGPBGenericValue:(GPBGenericValue *)value
  1649. forGPBGenericValueKey:(GPBGenericValue *)key {
  1650. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
  1651. }
  1652. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  1653. [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
  1654. #pragma unused(stop)
  1655. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
  1656. }];
  1657. }
  1658. - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
  1659. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  1660. if (wrapped && value) {
  1661. *value = [wrapped intValue];
  1662. }
  1663. return (wrapped != NULL);
  1664. }
  1665. - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
  1666. if (otherDictionary) {
  1667. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  1668. if (_autocreator) {
  1669. GPBAutocreatedDictionaryModified(_autocreator, self);
  1670. }
  1671. }
  1672. }
  1673. - (void)setInt32:(int32_t)value forKey:(uint32_t)key {
  1674. [_dictionary setObject:@(value) forKey:@(key)];
  1675. if (_autocreator) {
  1676. GPBAutocreatedDictionaryModified(_autocreator, self);
  1677. }
  1678. }
  1679. - (void)removeInt32ForKey:(uint32_t)aKey {
  1680. [_dictionary removeObjectForKey:@(aKey)];
  1681. }
  1682. - (void)removeAll {
  1683. [_dictionary removeAllObjects];
  1684. }
  1685. @end
  1686. #pragma mark - UInt32 -> UInt64
  1687. @implementation GPBUInt32UInt64Dictionary {
  1688. @package
  1689. NSMutableDictionary *_dictionary;
  1690. }
  1691. - (instancetype)init {
  1692. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  1693. }
  1694. - (instancetype)initWithUInt64s:(const uint64_t [])values
  1695. forKeys:(const uint32_t [])keys
  1696. count:(NSUInteger)count {
  1697. self = [super init];
  1698. if (self) {
  1699. _dictionary = [[NSMutableDictionary alloc] init];
  1700. if (count && values && keys) {
  1701. for (NSUInteger i = 0; i < count; ++i) {
  1702. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  1703. }
  1704. }
  1705. }
  1706. return self;
  1707. }
  1708. - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
  1709. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  1710. if (self) {
  1711. if (dictionary) {
  1712. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  1713. }
  1714. }
  1715. return self;
  1716. }
  1717. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  1718. #pragma unused(numItems)
  1719. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  1720. }
  1721. - (void)dealloc {
  1722. NSAssert(!_autocreator,
  1723. @"%@: Autocreator must be cleared before release, autocreator: %@",
  1724. [self class], _autocreator);
  1725. [_dictionary release];
  1726. [super dealloc];
  1727. }
  1728. - (instancetype)copyWithZone:(NSZone *)zone {
  1729. return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  1730. }
  1731. - (BOOL)isEqual:(id)other {
  1732. if (self == other) {
  1733. return YES;
  1734. }
  1735. if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
  1736. return NO;
  1737. }
  1738. GPBUInt32UInt64Dictionary *otherDictionary = other;
  1739. return [_dictionary isEqual:otherDictionary->_dictionary];
  1740. }
  1741. - (NSUInteger)hash {
  1742. return _dictionary.count;
  1743. }
  1744. - (NSString *)description {
  1745. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  1746. }
  1747. - (NSUInteger)count {
  1748. return _dictionary.count;
  1749. }
  1750. - (void)enumerateKeysAndUInt64sUsingBlock:
  1751. (void (^)(uint32_t key, uint64_t value, BOOL *stop))block {
  1752. BOOL stop = NO;
  1753. NSDictionary *internal = _dictionary;
  1754. NSEnumerator *keys = [internal keyEnumerator];
  1755. NSNumber *aKey;
  1756. while ((aKey = [keys nextObject])) {
  1757. NSNumber *aValue = internal[aKey];
  1758. block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop);
  1759. if (stop) {
  1760. break;
  1761. }
  1762. }
  1763. }
  1764. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  1765. NSDictionary *internal = _dictionary;
  1766. NSUInteger count = internal.count;
  1767. if (count == 0) {
  1768. return 0;
  1769. }
  1770. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1771. GPBDataType keyDataType = field.mapKeyDataType;
  1772. size_t result = 0;
  1773. NSEnumerator *keys = [internal keyEnumerator];
  1774. NSNumber *aKey;
  1775. while ((aKey = [keys nextObject])) {
  1776. NSNumber *aValue = internal[aKey];
  1777. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  1778. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  1779. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  1780. }
  1781. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  1782. result += tagSize * count;
  1783. return result;
  1784. }
  1785. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  1786. asField:(GPBFieldDescriptor *)field {
  1787. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1788. GPBDataType keyDataType = field.mapKeyDataType;
  1789. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  1790. NSDictionary *internal = _dictionary;
  1791. NSEnumerator *keys = [internal keyEnumerator];
  1792. NSNumber *aKey;
  1793. while ((aKey = [keys nextObject])) {
  1794. NSNumber *aValue = internal[aKey];
  1795. [outputStream writeInt32NoTag:tag];
  1796. // Write the size of the message.
  1797. uint32_t unwrappedKey = [aKey unsignedIntValue];
  1798. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  1799. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1800. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  1801. [outputStream writeInt32NoTag:(int32_t)msgSize];
  1802. // Write the fields.
  1803. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1804. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  1805. }
  1806. }
  1807. - (void)setGPBGenericValue:(GPBGenericValue *)value
  1808. forGPBGenericValueKey:(GPBGenericValue *)key {
  1809. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
  1810. }
  1811. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  1812. [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) {
  1813. #pragma unused(stop)
  1814. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
  1815. }];
  1816. }
  1817. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
  1818. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  1819. if (wrapped && value) {
  1820. *value = [wrapped unsignedLongLongValue];
  1821. }
  1822. return (wrapped != NULL);
  1823. }
  1824. - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
  1825. if (otherDictionary) {
  1826. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  1827. if (_autocreator) {
  1828. GPBAutocreatedDictionaryModified(_autocreator, self);
  1829. }
  1830. }
  1831. }
  1832. - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
  1833. [_dictionary setObject:@(value) forKey:@(key)];
  1834. if (_autocreator) {
  1835. GPBAutocreatedDictionaryModified(_autocreator, self);
  1836. }
  1837. }
  1838. - (void)removeUInt64ForKey:(uint32_t)aKey {
  1839. [_dictionary removeObjectForKey:@(aKey)];
  1840. }
  1841. - (void)removeAll {
  1842. [_dictionary removeAllObjects];
  1843. }
  1844. @end
  1845. #pragma mark - UInt32 -> Int64
  1846. @implementation GPBUInt32Int64Dictionary {
  1847. @package
  1848. NSMutableDictionary *_dictionary;
  1849. }
  1850. - (instancetype)init {
  1851. return [self initWithInt64s:NULL forKeys:NULL count:0];
  1852. }
  1853. - (instancetype)initWithInt64s:(const int64_t [])values
  1854. forKeys:(const uint32_t [])keys
  1855. count:(NSUInteger)count {
  1856. self = [super init];
  1857. if (self) {
  1858. _dictionary = [[NSMutableDictionary alloc] init];
  1859. if (count && values && keys) {
  1860. for (NSUInteger i = 0; i < count; ++i) {
  1861. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  1862. }
  1863. }
  1864. }
  1865. return self;
  1866. }
  1867. - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
  1868. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  1869. if (self) {
  1870. if (dictionary) {
  1871. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  1872. }
  1873. }
  1874. return self;
  1875. }
  1876. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  1877. #pragma unused(numItems)
  1878. return [self initWithInt64s:NULL forKeys:NULL count:0];
  1879. }
  1880. - (void)dealloc {
  1881. NSAssert(!_autocreator,
  1882. @"%@: Autocreator must be cleared before release, autocreator: %@",
  1883. [self class], _autocreator);
  1884. [_dictionary release];
  1885. [super dealloc];
  1886. }
  1887. - (instancetype)copyWithZone:(NSZone *)zone {
  1888. return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  1889. }
  1890. - (BOOL)isEqual:(id)other {
  1891. if (self == other) {
  1892. return YES;
  1893. }
  1894. if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
  1895. return NO;
  1896. }
  1897. GPBUInt32Int64Dictionary *otherDictionary = other;
  1898. return [_dictionary isEqual:otherDictionary->_dictionary];
  1899. }
  1900. - (NSUInteger)hash {
  1901. return _dictionary.count;
  1902. }
  1903. - (NSString *)description {
  1904. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  1905. }
  1906. - (NSUInteger)count {
  1907. return _dictionary.count;
  1908. }
  1909. - (void)enumerateKeysAndInt64sUsingBlock:
  1910. (void (^)(uint32_t key, int64_t value, BOOL *stop))block {
  1911. BOOL stop = NO;
  1912. NSDictionary *internal = _dictionary;
  1913. NSEnumerator *keys = [internal keyEnumerator];
  1914. NSNumber *aKey;
  1915. while ((aKey = [keys nextObject])) {
  1916. NSNumber *aValue = internal[aKey];
  1917. block([aKey unsignedIntValue], [aValue longLongValue], &stop);
  1918. if (stop) {
  1919. break;
  1920. }
  1921. }
  1922. }
  1923. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  1924. NSDictionary *internal = _dictionary;
  1925. NSUInteger count = internal.count;
  1926. if (count == 0) {
  1927. return 0;
  1928. }
  1929. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1930. GPBDataType keyDataType = field.mapKeyDataType;
  1931. size_t result = 0;
  1932. NSEnumerator *keys = [internal keyEnumerator];
  1933. NSNumber *aKey;
  1934. while ((aKey = [keys nextObject])) {
  1935. NSNumber *aValue = internal[aKey];
  1936. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  1937. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  1938. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  1939. }
  1940. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  1941. result += tagSize * count;
  1942. return result;
  1943. }
  1944. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  1945. asField:(GPBFieldDescriptor *)field {
  1946. GPBDataType valueDataType = GPBGetFieldDataType(field);
  1947. GPBDataType keyDataType = field.mapKeyDataType;
  1948. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  1949. NSDictionary *internal = _dictionary;
  1950. NSEnumerator *keys = [internal keyEnumerator];
  1951. NSNumber *aKey;
  1952. while ((aKey = [keys nextObject])) {
  1953. NSNumber *aValue = internal[aKey];
  1954. [outputStream writeInt32NoTag:tag];
  1955. // Write the size of the message.
  1956. uint32_t unwrappedKey = [aKey unsignedIntValue];
  1957. int64_t unwrappedValue = [aValue longLongValue];
  1958. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1959. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  1960. [outputStream writeInt32NoTag:(int32_t)msgSize];
  1961. // Write the fields.
  1962. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  1963. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  1964. }
  1965. }
  1966. - (void)setGPBGenericValue:(GPBGenericValue *)value
  1967. forGPBGenericValueKey:(GPBGenericValue *)key {
  1968. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
  1969. }
  1970. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  1971. [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) {
  1972. #pragma unused(stop)
  1973. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
  1974. }];
  1975. }
  1976. - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
  1977. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  1978. if (wrapped && value) {
  1979. *value = [wrapped longLongValue];
  1980. }
  1981. return (wrapped != NULL);
  1982. }
  1983. - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
  1984. if (otherDictionary) {
  1985. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  1986. if (_autocreator) {
  1987. GPBAutocreatedDictionaryModified(_autocreator, self);
  1988. }
  1989. }
  1990. }
  1991. - (void)setInt64:(int64_t)value forKey:(uint32_t)key {
  1992. [_dictionary setObject:@(value) forKey:@(key)];
  1993. if (_autocreator) {
  1994. GPBAutocreatedDictionaryModified(_autocreator, self);
  1995. }
  1996. }
  1997. - (void)removeInt64ForKey:(uint32_t)aKey {
  1998. [_dictionary removeObjectForKey:@(aKey)];
  1999. }
  2000. - (void)removeAll {
  2001. [_dictionary removeAllObjects];
  2002. }
  2003. @end
  2004. #pragma mark - UInt32 -> Bool
  2005. @implementation GPBUInt32BoolDictionary {
  2006. @package
  2007. NSMutableDictionary *_dictionary;
  2008. }
  2009. - (instancetype)init {
  2010. return [self initWithBools:NULL forKeys:NULL count:0];
  2011. }
  2012. - (instancetype)initWithBools:(const BOOL [])values
  2013. forKeys:(const uint32_t [])keys
  2014. count:(NSUInteger)count {
  2015. self = [super init];
  2016. if (self) {
  2017. _dictionary = [[NSMutableDictionary alloc] init];
  2018. if (count && values && keys) {
  2019. for (NSUInteger i = 0; i < count; ++i) {
  2020. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  2021. }
  2022. }
  2023. }
  2024. return self;
  2025. }
  2026. - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
  2027. self = [self initWithBools:NULL forKeys:NULL count:0];
  2028. if (self) {
  2029. if (dictionary) {
  2030. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2031. }
  2032. }
  2033. return self;
  2034. }
  2035. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2036. #pragma unused(numItems)
  2037. return [self initWithBools:NULL forKeys:NULL count:0];
  2038. }
  2039. - (void)dealloc {
  2040. NSAssert(!_autocreator,
  2041. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2042. [self class], _autocreator);
  2043. [_dictionary release];
  2044. [super dealloc];
  2045. }
  2046. - (instancetype)copyWithZone:(NSZone *)zone {
  2047. return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
  2048. }
  2049. - (BOOL)isEqual:(id)other {
  2050. if (self == other) {
  2051. return YES;
  2052. }
  2053. if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
  2054. return NO;
  2055. }
  2056. GPBUInt32BoolDictionary *otherDictionary = other;
  2057. return [_dictionary isEqual:otherDictionary->_dictionary];
  2058. }
  2059. - (NSUInteger)hash {
  2060. return _dictionary.count;
  2061. }
  2062. - (NSString *)description {
  2063. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2064. }
  2065. - (NSUInteger)count {
  2066. return _dictionary.count;
  2067. }
  2068. - (void)enumerateKeysAndBoolsUsingBlock:
  2069. (void (^)(uint32_t key, BOOL value, BOOL *stop))block {
  2070. BOOL stop = NO;
  2071. NSDictionary *internal = _dictionary;
  2072. NSEnumerator *keys = [internal keyEnumerator];
  2073. NSNumber *aKey;
  2074. while ((aKey = [keys nextObject])) {
  2075. NSNumber *aValue = internal[aKey];
  2076. block([aKey unsignedIntValue], [aValue boolValue], &stop);
  2077. if (stop) {
  2078. break;
  2079. }
  2080. }
  2081. }
  2082. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2083. NSDictionary *internal = _dictionary;
  2084. NSUInteger count = internal.count;
  2085. if (count == 0) {
  2086. return 0;
  2087. }
  2088. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2089. GPBDataType keyDataType = field.mapKeyDataType;
  2090. size_t result = 0;
  2091. NSEnumerator *keys = [internal keyEnumerator];
  2092. NSNumber *aKey;
  2093. while ((aKey = [keys nextObject])) {
  2094. NSNumber *aValue = internal[aKey];
  2095. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2096. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  2097. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2098. }
  2099. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2100. result += tagSize * count;
  2101. return result;
  2102. }
  2103. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2104. asField:(GPBFieldDescriptor *)field {
  2105. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2106. GPBDataType keyDataType = field.mapKeyDataType;
  2107. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2108. NSDictionary *internal = _dictionary;
  2109. NSEnumerator *keys = [internal keyEnumerator];
  2110. NSNumber *aKey;
  2111. while ((aKey = [keys nextObject])) {
  2112. NSNumber *aValue = internal[aKey];
  2113. [outputStream writeInt32NoTag:tag];
  2114. // Write the size of the message.
  2115. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2116. BOOL unwrappedValue = [aValue boolValue];
  2117. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2118. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2119. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2120. // Write the fields.
  2121. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2122. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2123. }
  2124. }
  2125. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2126. forGPBGenericValueKey:(GPBGenericValue *)key {
  2127. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
  2128. }
  2129. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2130. [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) {
  2131. #pragma unused(stop)
  2132. block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
  2133. }];
  2134. }
  2135. - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
  2136. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  2137. if (wrapped && value) {
  2138. *value = [wrapped boolValue];
  2139. }
  2140. return (wrapped != NULL);
  2141. }
  2142. - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
  2143. if (otherDictionary) {
  2144. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2145. if (_autocreator) {
  2146. GPBAutocreatedDictionaryModified(_autocreator, self);
  2147. }
  2148. }
  2149. }
  2150. - (void)setBool:(BOOL)value forKey:(uint32_t)key {
  2151. [_dictionary setObject:@(value) forKey:@(key)];
  2152. if (_autocreator) {
  2153. GPBAutocreatedDictionaryModified(_autocreator, self);
  2154. }
  2155. }
  2156. - (void)removeBoolForKey:(uint32_t)aKey {
  2157. [_dictionary removeObjectForKey:@(aKey)];
  2158. }
  2159. - (void)removeAll {
  2160. [_dictionary removeAllObjects];
  2161. }
  2162. @end
  2163. #pragma mark - UInt32 -> Float
  2164. @implementation GPBUInt32FloatDictionary {
  2165. @package
  2166. NSMutableDictionary *_dictionary;
  2167. }
  2168. - (instancetype)init {
  2169. return [self initWithFloats:NULL forKeys:NULL count:0];
  2170. }
  2171. - (instancetype)initWithFloats:(const float [])values
  2172. forKeys:(const uint32_t [])keys
  2173. count:(NSUInteger)count {
  2174. self = [super init];
  2175. if (self) {
  2176. _dictionary = [[NSMutableDictionary alloc] init];
  2177. if (count && values && keys) {
  2178. for (NSUInteger i = 0; i < count; ++i) {
  2179. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  2180. }
  2181. }
  2182. }
  2183. return self;
  2184. }
  2185. - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
  2186. self = [self initWithFloats:NULL forKeys:NULL count:0];
  2187. if (self) {
  2188. if (dictionary) {
  2189. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2190. }
  2191. }
  2192. return self;
  2193. }
  2194. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2195. #pragma unused(numItems)
  2196. return [self initWithFloats:NULL forKeys:NULL count:0];
  2197. }
  2198. - (void)dealloc {
  2199. NSAssert(!_autocreator,
  2200. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2201. [self class], _autocreator);
  2202. [_dictionary release];
  2203. [super dealloc];
  2204. }
  2205. - (instancetype)copyWithZone:(NSZone *)zone {
  2206. return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
  2207. }
  2208. - (BOOL)isEqual:(id)other {
  2209. if (self == other) {
  2210. return YES;
  2211. }
  2212. if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
  2213. return NO;
  2214. }
  2215. GPBUInt32FloatDictionary *otherDictionary = other;
  2216. return [_dictionary isEqual:otherDictionary->_dictionary];
  2217. }
  2218. - (NSUInteger)hash {
  2219. return _dictionary.count;
  2220. }
  2221. - (NSString *)description {
  2222. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2223. }
  2224. - (NSUInteger)count {
  2225. return _dictionary.count;
  2226. }
  2227. - (void)enumerateKeysAndFloatsUsingBlock:
  2228. (void (^)(uint32_t key, float value, BOOL *stop))block {
  2229. BOOL stop = NO;
  2230. NSDictionary *internal = _dictionary;
  2231. NSEnumerator *keys = [internal keyEnumerator];
  2232. NSNumber *aKey;
  2233. while ((aKey = [keys nextObject])) {
  2234. NSNumber *aValue = internal[aKey];
  2235. block([aKey unsignedIntValue], [aValue floatValue], &stop);
  2236. if (stop) {
  2237. break;
  2238. }
  2239. }
  2240. }
  2241. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2242. NSDictionary *internal = _dictionary;
  2243. NSUInteger count = internal.count;
  2244. if (count == 0) {
  2245. return 0;
  2246. }
  2247. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2248. GPBDataType keyDataType = field.mapKeyDataType;
  2249. size_t result = 0;
  2250. NSEnumerator *keys = [internal keyEnumerator];
  2251. NSNumber *aKey;
  2252. while ((aKey = [keys nextObject])) {
  2253. NSNumber *aValue = internal[aKey];
  2254. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2255. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  2256. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2257. }
  2258. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2259. result += tagSize * count;
  2260. return result;
  2261. }
  2262. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2263. asField:(GPBFieldDescriptor *)field {
  2264. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2265. GPBDataType keyDataType = field.mapKeyDataType;
  2266. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2267. NSDictionary *internal = _dictionary;
  2268. NSEnumerator *keys = [internal keyEnumerator];
  2269. NSNumber *aKey;
  2270. while ((aKey = [keys nextObject])) {
  2271. NSNumber *aValue = internal[aKey];
  2272. [outputStream writeInt32NoTag:tag];
  2273. // Write the size of the message.
  2274. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2275. float unwrappedValue = [aValue floatValue];
  2276. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2277. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2278. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2279. // Write the fields.
  2280. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2281. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2282. }
  2283. }
  2284. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2285. forGPBGenericValueKey:(GPBGenericValue *)key {
  2286. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
  2287. }
  2288. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2289. [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) {
  2290. #pragma unused(stop)
  2291. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  2292. }];
  2293. }
  2294. - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
  2295. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  2296. if (wrapped && value) {
  2297. *value = [wrapped floatValue];
  2298. }
  2299. return (wrapped != NULL);
  2300. }
  2301. - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
  2302. if (otherDictionary) {
  2303. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2304. if (_autocreator) {
  2305. GPBAutocreatedDictionaryModified(_autocreator, self);
  2306. }
  2307. }
  2308. }
  2309. - (void)setFloat:(float)value forKey:(uint32_t)key {
  2310. [_dictionary setObject:@(value) forKey:@(key)];
  2311. if (_autocreator) {
  2312. GPBAutocreatedDictionaryModified(_autocreator, self);
  2313. }
  2314. }
  2315. - (void)removeFloatForKey:(uint32_t)aKey {
  2316. [_dictionary removeObjectForKey:@(aKey)];
  2317. }
  2318. - (void)removeAll {
  2319. [_dictionary removeAllObjects];
  2320. }
  2321. @end
  2322. #pragma mark - UInt32 -> Double
  2323. @implementation GPBUInt32DoubleDictionary {
  2324. @package
  2325. NSMutableDictionary *_dictionary;
  2326. }
  2327. - (instancetype)init {
  2328. return [self initWithDoubles:NULL forKeys:NULL count:0];
  2329. }
  2330. - (instancetype)initWithDoubles:(const double [])values
  2331. forKeys:(const uint32_t [])keys
  2332. count:(NSUInteger)count {
  2333. self = [super init];
  2334. if (self) {
  2335. _dictionary = [[NSMutableDictionary alloc] init];
  2336. if (count && values && keys) {
  2337. for (NSUInteger i = 0; i < count; ++i) {
  2338. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  2339. }
  2340. }
  2341. }
  2342. return self;
  2343. }
  2344. - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
  2345. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  2346. if (self) {
  2347. if (dictionary) {
  2348. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2349. }
  2350. }
  2351. return self;
  2352. }
  2353. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2354. #pragma unused(numItems)
  2355. return [self initWithDoubles:NULL forKeys:NULL count:0];
  2356. }
  2357. - (void)dealloc {
  2358. NSAssert(!_autocreator,
  2359. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2360. [self class], _autocreator);
  2361. [_dictionary release];
  2362. [super dealloc];
  2363. }
  2364. - (instancetype)copyWithZone:(NSZone *)zone {
  2365. return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  2366. }
  2367. - (BOOL)isEqual:(id)other {
  2368. if (self == other) {
  2369. return YES;
  2370. }
  2371. if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
  2372. return NO;
  2373. }
  2374. GPBUInt32DoubleDictionary *otherDictionary = other;
  2375. return [_dictionary isEqual:otherDictionary->_dictionary];
  2376. }
  2377. - (NSUInteger)hash {
  2378. return _dictionary.count;
  2379. }
  2380. - (NSString *)description {
  2381. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2382. }
  2383. - (NSUInteger)count {
  2384. return _dictionary.count;
  2385. }
  2386. - (void)enumerateKeysAndDoublesUsingBlock:
  2387. (void (^)(uint32_t key, double value, BOOL *stop))block {
  2388. BOOL stop = NO;
  2389. NSDictionary *internal = _dictionary;
  2390. NSEnumerator *keys = [internal keyEnumerator];
  2391. NSNumber *aKey;
  2392. while ((aKey = [keys nextObject])) {
  2393. NSNumber *aValue = internal[aKey];
  2394. block([aKey unsignedIntValue], [aValue doubleValue], &stop);
  2395. if (stop) {
  2396. break;
  2397. }
  2398. }
  2399. }
  2400. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2401. NSDictionary *internal = _dictionary;
  2402. NSUInteger count = internal.count;
  2403. if (count == 0) {
  2404. return 0;
  2405. }
  2406. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2407. GPBDataType keyDataType = field.mapKeyDataType;
  2408. size_t result = 0;
  2409. NSEnumerator *keys = [internal keyEnumerator];
  2410. NSNumber *aKey;
  2411. while ((aKey = [keys nextObject])) {
  2412. NSNumber *aValue = internal[aKey];
  2413. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2414. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  2415. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2416. }
  2417. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2418. result += tagSize * count;
  2419. return result;
  2420. }
  2421. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2422. asField:(GPBFieldDescriptor *)field {
  2423. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2424. GPBDataType keyDataType = field.mapKeyDataType;
  2425. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2426. NSDictionary *internal = _dictionary;
  2427. NSEnumerator *keys = [internal keyEnumerator];
  2428. NSNumber *aKey;
  2429. while ((aKey = [keys nextObject])) {
  2430. NSNumber *aValue = internal[aKey];
  2431. [outputStream writeInt32NoTag:tag];
  2432. // Write the size of the message.
  2433. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2434. double unwrappedValue = [aValue doubleValue];
  2435. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2436. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2437. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2438. // Write the fields.
  2439. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2440. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2441. }
  2442. }
  2443. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2444. forGPBGenericValueKey:(GPBGenericValue *)key {
  2445. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
  2446. }
  2447. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2448. [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) {
  2449. #pragma unused(stop)
  2450. block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  2451. }];
  2452. }
  2453. - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
  2454. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  2455. if (wrapped && value) {
  2456. *value = [wrapped doubleValue];
  2457. }
  2458. return (wrapped != NULL);
  2459. }
  2460. - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
  2461. if (otherDictionary) {
  2462. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2463. if (_autocreator) {
  2464. GPBAutocreatedDictionaryModified(_autocreator, self);
  2465. }
  2466. }
  2467. }
  2468. - (void)setDouble:(double)value forKey:(uint32_t)key {
  2469. [_dictionary setObject:@(value) forKey:@(key)];
  2470. if (_autocreator) {
  2471. GPBAutocreatedDictionaryModified(_autocreator, self);
  2472. }
  2473. }
  2474. - (void)removeDoubleForKey:(uint32_t)aKey {
  2475. [_dictionary removeObjectForKey:@(aKey)];
  2476. }
  2477. - (void)removeAll {
  2478. [_dictionary removeAllObjects];
  2479. }
  2480. @end
  2481. #pragma mark - UInt32 -> Enum
  2482. @implementation GPBUInt32EnumDictionary {
  2483. @package
  2484. NSMutableDictionary *_dictionary;
  2485. GPBEnumValidationFunc _validationFunc;
  2486. }
  2487. @synthesize validationFunc = _validationFunc;
  2488. - (instancetype)init {
  2489. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  2490. }
  2491. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  2492. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  2493. }
  2494. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  2495. rawValues:(const int32_t [])rawValues
  2496. forKeys:(const uint32_t [])keys
  2497. count:(NSUInteger)count {
  2498. self = [super init];
  2499. if (self) {
  2500. _dictionary = [[NSMutableDictionary alloc] init];
  2501. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  2502. if (count && rawValues && keys) {
  2503. for (NSUInteger i = 0; i < count; ++i) {
  2504. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  2505. }
  2506. }
  2507. }
  2508. return self;
  2509. }
  2510. - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
  2511. self = [self initWithValidationFunction:dictionary.validationFunc
  2512. rawValues:NULL
  2513. forKeys:NULL
  2514. count:0];
  2515. if (self) {
  2516. if (dictionary) {
  2517. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2518. }
  2519. }
  2520. return self;
  2521. }
  2522. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  2523. capacity:(NSUInteger)numItems {
  2524. #pragma unused(numItems)
  2525. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  2526. }
  2527. - (void)dealloc {
  2528. NSAssert(!_autocreator,
  2529. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2530. [self class], _autocreator);
  2531. [_dictionary release];
  2532. [super dealloc];
  2533. }
  2534. - (instancetype)copyWithZone:(NSZone *)zone {
  2535. return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
  2536. }
  2537. - (BOOL)isEqual:(id)other {
  2538. if (self == other) {
  2539. return YES;
  2540. }
  2541. if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
  2542. return NO;
  2543. }
  2544. GPBUInt32EnumDictionary *otherDictionary = other;
  2545. return [_dictionary isEqual:otherDictionary->_dictionary];
  2546. }
  2547. - (NSUInteger)hash {
  2548. return _dictionary.count;
  2549. }
  2550. - (NSString *)description {
  2551. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2552. }
  2553. - (NSUInteger)count {
  2554. return _dictionary.count;
  2555. }
  2556. - (void)enumerateKeysAndRawValuesUsingBlock:
  2557. (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
  2558. BOOL stop = NO;
  2559. NSDictionary *internal = _dictionary;
  2560. NSEnumerator *keys = [internal keyEnumerator];
  2561. NSNumber *aKey;
  2562. while ((aKey = [keys nextObject])) {
  2563. NSNumber *aValue = internal[aKey];
  2564. block([aKey unsignedIntValue], [aValue intValue], &stop);
  2565. if (stop) {
  2566. break;
  2567. }
  2568. }
  2569. }
  2570. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2571. NSDictionary *internal = _dictionary;
  2572. NSUInteger count = internal.count;
  2573. if (count == 0) {
  2574. return 0;
  2575. }
  2576. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2577. GPBDataType keyDataType = field.mapKeyDataType;
  2578. size_t result = 0;
  2579. NSEnumerator *keys = [internal keyEnumerator];
  2580. NSNumber *aKey;
  2581. while ((aKey = [keys nextObject])) {
  2582. NSNumber *aValue = internal[aKey];
  2583. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2584. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  2585. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2586. }
  2587. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2588. result += tagSize * count;
  2589. return result;
  2590. }
  2591. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2592. asField:(GPBFieldDescriptor *)field {
  2593. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2594. GPBDataType keyDataType = field.mapKeyDataType;
  2595. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2596. NSDictionary *internal = _dictionary;
  2597. NSEnumerator *keys = [internal keyEnumerator];
  2598. NSNumber *aKey;
  2599. while ((aKey = [keys nextObject])) {
  2600. NSNumber *aValue = internal[aKey];
  2601. [outputStream writeInt32NoTag:tag];
  2602. // Write the size of the message.
  2603. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2604. int32_t unwrappedValue = [aValue intValue];
  2605. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2606. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2607. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2608. // Write the fields.
  2609. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2610. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2611. }
  2612. }
  2613. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  2614. forKey:(GPBGenericValue *)key
  2615. keyDataType:(GPBDataType)keyDataType {
  2616. size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
  2617. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  2618. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  2619. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  2620. WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
  2621. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  2622. [outputStream release];
  2623. return data;
  2624. }
  2625. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2626. forGPBGenericValueKey:(GPBGenericValue *)key {
  2627. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
  2628. }
  2629. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2630. [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
  2631. #pragma unused(stop)
  2632. block([NSString stringWithFormat:@"%u", key], @(value));
  2633. }];
  2634. }
  2635. - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
  2636. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  2637. if (wrapped && value) {
  2638. int32_t result = [wrapped intValue];
  2639. if (!_validationFunc(result)) {
  2640. result = kGPBUnrecognizedEnumeratorValue;
  2641. }
  2642. *value = result;
  2643. }
  2644. return (wrapped != NULL);
  2645. }
  2646. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
  2647. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  2648. if (wrapped && rawValue) {
  2649. *rawValue = [wrapped intValue];
  2650. }
  2651. return (wrapped != NULL);
  2652. }
  2653. - (void)enumerateKeysAndEnumsUsingBlock:
  2654. (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
  2655. GPBEnumValidationFunc func = _validationFunc;
  2656. BOOL stop = NO;
  2657. NSEnumerator *keys = [_dictionary keyEnumerator];
  2658. NSNumber *aKey;
  2659. while ((aKey = [keys nextObject])) {
  2660. NSNumber *aValue = _dictionary[aKey];
  2661. int32_t unwrapped = [aValue intValue];
  2662. if (!func(unwrapped)) {
  2663. unwrapped = kGPBUnrecognizedEnumeratorValue;
  2664. }
  2665. block([aKey unsignedIntValue], unwrapped, &stop);
  2666. if (stop) {
  2667. break;
  2668. }
  2669. }
  2670. }
  2671. - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
  2672. if (otherDictionary) {
  2673. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2674. if (_autocreator) {
  2675. GPBAutocreatedDictionaryModified(_autocreator, self);
  2676. }
  2677. }
  2678. }
  2679. - (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
  2680. [_dictionary setObject:@(value) forKey:@(key)];
  2681. if (_autocreator) {
  2682. GPBAutocreatedDictionaryModified(_autocreator, self);
  2683. }
  2684. }
  2685. - (void)removeEnumForKey:(uint32_t)aKey {
  2686. [_dictionary removeObjectForKey:@(aKey)];
  2687. }
  2688. - (void)removeAll {
  2689. [_dictionary removeAllObjects];
  2690. }
  2691. - (void)setEnum:(int32_t)value forKey:(uint32_t)key {
  2692. if (!_validationFunc(value)) {
  2693. [NSException raise:NSInvalidArgumentException
  2694. format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
  2695. value];
  2696. }
  2697. [_dictionary setObject:@(value) forKey:@(key)];
  2698. if (_autocreator) {
  2699. GPBAutocreatedDictionaryModified(_autocreator, self);
  2700. }
  2701. }
  2702. @end
  2703. #pragma mark - UInt32 -> Object
  2704. @implementation GPBUInt32ObjectDictionary {
  2705. @package
  2706. NSMutableDictionary *_dictionary;
  2707. }
  2708. - (instancetype)init {
  2709. return [self initWithObjects:NULL forKeys:NULL count:0];
  2710. }
  2711. - (instancetype)initWithObjects:(const id [])objects
  2712. forKeys:(const uint32_t [])keys
  2713. count:(NSUInteger)count {
  2714. self = [super init];
  2715. if (self) {
  2716. _dictionary = [[NSMutableDictionary alloc] init];
  2717. if (count && objects && keys) {
  2718. for (NSUInteger i = 0; i < count; ++i) {
  2719. if (!objects[i]) {
  2720. [NSException raise:NSInvalidArgumentException
  2721. format:@"Attempting to add nil object to a Dictionary"];
  2722. }
  2723. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  2724. }
  2725. }
  2726. }
  2727. return self;
  2728. }
  2729. - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
  2730. self = [self initWithObjects:NULL forKeys:NULL count:0];
  2731. if (self) {
  2732. if (dictionary) {
  2733. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2734. }
  2735. }
  2736. return self;
  2737. }
  2738. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2739. #pragma unused(numItems)
  2740. return [self initWithObjects:NULL forKeys:NULL count:0];
  2741. }
  2742. - (void)dealloc {
  2743. NSAssert(!_autocreator,
  2744. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2745. [self class], _autocreator);
  2746. [_dictionary release];
  2747. [super dealloc];
  2748. }
  2749. - (instancetype)copyWithZone:(NSZone *)zone {
  2750. return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  2751. }
  2752. - (BOOL)isEqual:(id)other {
  2753. if (self == other) {
  2754. return YES;
  2755. }
  2756. if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
  2757. return NO;
  2758. }
  2759. GPBUInt32ObjectDictionary *otherDictionary = other;
  2760. return [_dictionary isEqual:otherDictionary->_dictionary];
  2761. }
  2762. - (NSUInteger)hash {
  2763. return _dictionary.count;
  2764. }
  2765. - (NSString *)description {
  2766. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2767. }
  2768. - (NSUInteger)count {
  2769. return _dictionary.count;
  2770. }
  2771. - (void)enumerateKeysAndObjectsUsingBlock:
  2772. (void (^)(uint32_t key, id object, BOOL *stop))block {
  2773. BOOL stop = NO;
  2774. NSDictionary *internal = _dictionary;
  2775. NSEnumerator *keys = [internal keyEnumerator];
  2776. NSNumber *aKey;
  2777. while ((aKey = [keys nextObject])) {
  2778. id aObject = internal[aKey];
  2779. block([aKey unsignedIntValue], aObject, &stop);
  2780. if (stop) {
  2781. break;
  2782. }
  2783. }
  2784. }
  2785. - (BOOL)isInitialized {
  2786. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  2787. if (!msg.initialized) {
  2788. return NO;
  2789. }
  2790. }
  2791. return YES;
  2792. }
  2793. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  2794. GPBUInt32ObjectDictionary *newDict =
  2795. [[GPBUInt32ObjectDictionary alloc] init];
  2796. NSEnumerator *keys = [_dictionary keyEnumerator];
  2797. id aKey;
  2798. NSMutableDictionary *internalDict = newDict->_dictionary;
  2799. while ((aKey = [keys nextObject])) {
  2800. GPBMessage *msg = _dictionary[aKey];
  2801. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  2802. [internalDict setObject:copiedMsg forKey:aKey];
  2803. [copiedMsg release];
  2804. }
  2805. return newDict;
  2806. }
  2807. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2808. NSDictionary *internal = _dictionary;
  2809. NSUInteger count = internal.count;
  2810. if (count == 0) {
  2811. return 0;
  2812. }
  2813. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2814. GPBDataType keyDataType = field.mapKeyDataType;
  2815. size_t result = 0;
  2816. NSEnumerator *keys = [internal keyEnumerator];
  2817. NSNumber *aKey;
  2818. while ((aKey = [keys nextObject])) {
  2819. id aObject = internal[aKey];
  2820. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2821. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  2822. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2823. }
  2824. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2825. result += tagSize * count;
  2826. return result;
  2827. }
  2828. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2829. asField:(GPBFieldDescriptor *)field {
  2830. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2831. GPBDataType keyDataType = field.mapKeyDataType;
  2832. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2833. NSDictionary *internal = _dictionary;
  2834. NSEnumerator *keys = [internal keyEnumerator];
  2835. NSNumber *aKey;
  2836. while ((aKey = [keys nextObject])) {
  2837. id aObject = internal[aKey];
  2838. [outputStream writeInt32NoTag:tag];
  2839. // Write the size of the message.
  2840. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2841. id unwrappedValue = aObject;
  2842. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2843. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2844. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2845. // Write the fields.
  2846. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2847. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2848. }
  2849. }
  2850. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2851. forGPBGenericValueKey:(GPBGenericValue *)key {
  2852. [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
  2853. }
  2854. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2855. [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
  2856. #pragma unused(stop)
  2857. block([NSString stringWithFormat:@"%u", key], object);
  2858. }];
  2859. }
  2860. - (id)objectForKey:(uint32_t)key {
  2861. id result = [_dictionary objectForKey:@(key)];
  2862. return result;
  2863. }
  2864. - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
  2865. if (otherDictionary) {
  2866. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2867. if (_autocreator) {
  2868. GPBAutocreatedDictionaryModified(_autocreator, self);
  2869. }
  2870. }
  2871. }
  2872. - (void)setObject:(id)object forKey:(uint32_t)key {
  2873. if (!object) {
  2874. [NSException raise:NSInvalidArgumentException
  2875. format:@"Attempting to add nil object to a Dictionary"];
  2876. }
  2877. [_dictionary setObject:object forKey:@(key)];
  2878. if (_autocreator) {
  2879. GPBAutocreatedDictionaryModified(_autocreator, self);
  2880. }
  2881. }
  2882. - (void)removeObjectForKey:(uint32_t)aKey {
  2883. [_dictionary removeObjectForKey:@(aKey)];
  2884. }
  2885. - (void)removeAll {
  2886. [_dictionary removeAllObjects];
  2887. }
  2888. @end
  2889. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
  2890. // This block of code is generated, do not edit it directly.
  2891. #pragma mark - Int32 -> UInt32
  2892. @implementation GPBInt32UInt32Dictionary {
  2893. @package
  2894. NSMutableDictionary *_dictionary;
  2895. }
  2896. - (instancetype)init {
  2897. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  2898. }
  2899. - (instancetype)initWithUInt32s:(const uint32_t [])values
  2900. forKeys:(const int32_t [])keys
  2901. count:(NSUInteger)count {
  2902. self = [super init];
  2903. if (self) {
  2904. _dictionary = [[NSMutableDictionary alloc] init];
  2905. if (count && values && keys) {
  2906. for (NSUInteger i = 0; i < count; ++i) {
  2907. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  2908. }
  2909. }
  2910. }
  2911. return self;
  2912. }
  2913. - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
  2914. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  2915. if (self) {
  2916. if (dictionary) {
  2917. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2918. }
  2919. }
  2920. return self;
  2921. }
  2922. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2923. #pragma unused(numItems)
  2924. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  2925. }
  2926. - (void)dealloc {
  2927. NSAssert(!_autocreator,
  2928. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2929. [self class], _autocreator);
  2930. [_dictionary release];
  2931. [super dealloc];
  2932. }
  2933. - (instancetype)copyWithZone:(NSZone *)zone {
  2934. return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  2935. }
  2936. - (BOOL)isEqual:(id)other {
  2937. if (self == other) {
  2938. return YES;
  2939. }
  2940. if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
  2941. return NO;
  2942. }
  2943. GPBInt32UInt32Dictionary *otherDictionary = other;
  2944. return [_dictionary isEqual:otherDictionary->_dictionary];
  2945. }
  2946. - (NSUInteger)hash {
  2947. return _dictionary.count;
  2948. }
  2949. - (NSString *)description {
  2950. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2951. }
  2952. - (NSUInteger)count {
  2953. return _dictionary.count;
  2954. }
  2955. - (void)enumerateKeysAndUInt32sUsingBlock:
  2956. (void (^)(int32_t key, uint32_t value, BOOL *stop))block {
  2957. BOOL stop = NO;
  2958. NSDictionary *internal = _dictionary;
  2959. NSEnumerator *keys = [internal keyEnumerator];
  2960. NSNumber *aKey;
  2961. while ((aKey = [keys nextObject])) {
  2962. NSNumber *aValue = internal[aKey];
  2963. block([aKey intValue], [aValue unsignedIntValue], &stop);
  2964. if (stop) {
  2965. break;
  2966. }
  2967. }
  2968. }
  2969. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2970. NSDictionary *internal = _dictionary;
  2971. NSUInteger count = internal.count;
  2972. if (count == 0) {
  2973. return 0;
  2974. }
  2975. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2976. GPBDataType keyDataType = field.mapKeyDataType;
  2977. size_t result = 0;
  2978. NSEnumerator *keys = [internal keyEnumerator];
  2979. NSNumber *aKey;
  2980. while ((aKey = [keys nextObject])) {
  2981. NSNumber *aValue = internal[aKey];
  2982. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  2983. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  2984. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2985. }
  2986. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2987. result += tagSize * count;
  2988. return result;
  2989. }
  2990. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2991. asField:(GPBFieldDescriptor *)field {
  2992. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2993. GPBDataType keyDataType = field.mapKeyDataType;
  2994. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2995. NSDictionary *internal = _dictionary;
  2996. NSEnumerator *keys = [internal keyEnumerator];
  2997. NSNumber *aKey;
  2998. while ((aKey = [keys nextObject])) {
  2999. NSNumber *aValue = internal[aKey];
  3000. [outputStream writeInt32NoTag:tag];
  3001. // Write the size of the message.
  3002. int32_t unwrappedKey = [aKey intValue];
  3003. uint32_t unwrappedValue = [aValue unsignedIntValue];
  3004. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3005. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3006. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3007. // Write the fields.
  3008. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3009. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3010. }
  3011. }
  3012. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3013. forGPBGenericValueKey:(GPBGenericValue *)key {
  3014. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
  3015. }
  3016. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3017. [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
  3018. #pragma unused(stop)
  3019. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
  3020. }];
  3021. }
  3022. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
  3023. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3024. if (wrapped && value) {
  3025. *value = [wrapped unsignedIntValue];
  3026. }
  3027. return (wrapped != NULL);
  3028. }
  3029. - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
  3030. if (otherDictionary) {
  3031. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3032. if (_autocreator) {
  3033. GPBAutocreatedDictionaryModified(_autocreator, self);
  3034. }
  3035. }
  3036. }
  3037. - (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
  3038. [_dictionary setObject:@(value) forKey:@(key)];
  3039. if (_autocreator) {
  3040. GPBAutocreatedDictionaryModified(_autocreator, self);
  3041. }
  3042. }
  3043. - (void)removeUInt32ForKey:(int32_t)aKey {
  3044. [_dictionary removeObjectForKey:@(aKey)];
  3045. }
  3046. - (void)removeAll {
  3047. [_dictionary removeAllObjects];
  3048. }
  3049. @end
  3050. #pragma mark - Int32 -> Int32
  3051. @implementation GPBInt32Int32Dictionary {
  3052. @package
  3053. NSMutableDictionary *_dictionary;
  3054. }
  3055. - (instancetype)init {
  3056. return [self initWithInt32s:NULL forKeys:NULL count:0];
  3057. }
  3058. - (instancetype)initWithInt32s:(const int32_t [])values
  3059. forKeys:(const int32_t [])keys
  3060. count:(NSUInteger)count {
  3061. self = [super init];
  3062. if (self) {
  3063. _dictionary = [[NSMutableDictionary alloc] init];
  3064. if (count && values && keys) {
  3065. for (NSUInteger i = 0; i < count; ++i) {
  3066. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3067. }
  3068. }
  3069. }
  3070. return self;
  3071. }
  3072. - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
  3073. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  3074. if (self) {
  3075. if (dictionary) {
  3076. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3077. }
  3078. }
  3079. return self;
  3080. }
  3081. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3082. #pragma unused(numItems)
  3083. return [self initWithInt32s:NULL forKeys:NULL count:0];
  3084. }
  3085. - (void)dealloc {
  3086. NSAssert(!_autocreator,
  3087. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3088. [self class], _autocreator);
  3089. [_dictionary release];
  3090. [super dealloc];
  3091. }
  3092. - (instancetype)copyWithZone:(NSZone *)zone {
  3093. return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  3094. }
  3095. - (BOOL)isEqual:(id)other {
  3096. if (self == other) {
  3097. return YES;
  3098. }
  3099. if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
  3100. return NO;
  3101. }
  3102. GPBInt32Int32Dictionary *otherDictionary = other;
  3103. return [_dictionary isEqual:otherDictionary->_dictionary];
  3104. }
  3105. - (NSUInteger)hash {
  3106. return _dictionary.count;
  3107. }
  3108. - (NSString *)description {
  3109. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3110. }
  3111. - (NSUInteger)count {
  3112. return _dictionary.count;
  3113. }
  3114. - (void)enumerateKeysAndInt32sUsingBlock:
  3115. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  3116. BOOL stop = NO;
  3117. NSDictionary *internal = _dictionary;
  3118. NSEnumerator *keys = [internal keyEnumerator];
  3119. NSNumber *aKey;
  3120. while ((aKey = [keys nextObject])) {
  3121. NSNumber *aValue = internal[aKey];
  3122. block([aKey intValue], [aValue intValue], &stop);
  3123. if (stop) {
  3124. break;
  3125. }
  3126. }
  3127. }
  3128. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3129. NSDictionary *internal = _dictionary;
  3130. NSUInteger count = internal.count;
  3131. if (count == 0) {
  3132. return 0;
  3133. }
  3134. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3135. GPBDataType keyDataType = field.mapKeyDataType;
  3136. size_t result = 0;
  3137. NSEnumerator *keys = [internal keyEnumerator];
  3138. NSNumber *aKey;
  3139. while ((aKey = [keys nextObject])) {
  3140. NSNumber *aValue = internal[aKey];
  3141. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3142. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  3143. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3144. }
  3145. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3146. result += tagSize * count;
  3147. return result;
  3148. }
  3149. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3150. asField:(GPBFieldDescriptor *)field {
  3151. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3152. GPBDataType keyDataType = field.mapKeyDataType;
  3153. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3154. NSDictionary *internal = _dictionary;
  3155. NSEnumerator *keys = [internal keyEnumerator];
  3156. NSNumber *aKey;
  3157. while ((aKey = [keys nextObject])) {
  3158. NSNumber *aValue = internal[aKey];
  3159. [outputStream writeInt32NoTag:tag];
  3160. // Write the size of the message.
  3161. int32_t unwrappedKey = [aKey intValue];
  3162. int32_t unwrappedValue = [aValue intValue];
  3163. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3164. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3165. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3166. // Write the fields.
  3167. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3168. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3169. }
  3170. }
  3171. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3172. forGPBGenericValueKey:(GPBGenericValue *)key {
  3173. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
  3174. }
  3175. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3176. [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
  3177. #pragma unused(stop)
  3178. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
  3179. }];
  3180. }
  3181. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
  3182. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3183. if (wrapped && value) {
  3184. *value = [wrapped intValue];
  3185. }
  3186. return (wrapped != NULL);
  3187. }
  3188. - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
  3189. if (otherDictionary) {
  3190. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3191. if (_autocreator) {
  3192. GPBAutocreatedDictionaryModified(_autocreator, self);
  3193. }
  3194. }
  3195. }
  3196. - (void)setInt32:(int32_t)value forKey:(int32_t)key {
  3197. [_dictionary setObject:@(value) forKey:@(key)];
  3198. if (_autocreator) {
  3199. GPBAutocreatedDictionaryModified(_autocreator, self);
  3200. }
  3201. }
  3202. - (void)removeInt32ForKey:(int32_t)aKey {
  3203. [_dictionary removeObjectForKey:@(aKey)];
  3204. }
  3205. - (void)removeAll {
  3206. [_dictionary removeAllObjects];
  3207. }
  3208. @end
  3209. #pragma mark - Int32 -> UInt64
  3210. @implementation GPBInt32UInt64Dictionary {
  3211. @package
  3212. NSMutableDictionary *_dictionary;
  3213. }
  3214. - (instancetype)init {
  3215. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  3216. }
  3217. - (instancetype)initWithUInt64s:(const uint64_t [])values
  3218. forKeys:(const int32_t [])keys
  3219. count:(NSUInteger)count {
  3220. self = [super init];
  3221. if (self) {
  3222. _dictionary = [[NSMutableDictionary alloc] init];
  3223. if (count && values && keys) {
  3224. for (NSUInteger i = 0; i < count; ++i) {
  3225. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3226. }
  3227. }
  3228. }
  3229. return self;
  3230. }
  3231. - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
  3232. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  3233. if (self) {
  3234. if (dictionary) {
  3235. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3236. }
  3237. }
  3238. return self;
  3239. }
  3240. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3241. #pragma unused(numItems)
  3242. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  3243. }
  3244. - (void)dealloc {
  3245. NSAssert(!_autocreator,
  3246. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3247. [self class], _autocreator);
  3248. [_dictionary release];
  3249. [super dealloc];
  3250. }
  3251. - (instancetype)copyWithZone:(NSZone *)zone {
  3252. return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  3253. }
  3254. - (BOOL)isEqual:(id)other {
  3255. if (self == other) {
  3256. return YES;
  3257. }
  3258. if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
  3259. return NO;
  3260. }
  3261. GPBInt32UInt64Dictionary *otherDictionary = other;
  3262. return [_dictionary isEqual:otherDictionary->_dictionary];
  3263. }
  3264. - (NSUInteger)hash {
  3265. return _dictionary.count;
  3266. }
  3267. - (NSString *)description {
  3268. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3269. }
  3270. - (NSUInteger)count {
  3271. return _dictionary.count;
  3272. }
  3273. - (void)enumerateKeysAndUInt64sUsingBlock:
  3274. (void (^)(int32_t key, uint64_t value, BOOL *stop))block {
  3275. BOOL stop = NO;
  3276. NSDictionary *internal = _dictionary;
  3277. NSEnumerator *keys = [internal keyEnumerator];
  3278. NSNumber *aKey;
  3279. while ((aKey = [keys nextObject])) {
  3280. NSNumber *aValue = internal[aKey];
  3281. block([aKey intValue], [aValue unsignedLongLongValue], &stop);
  3282. if (stop) {
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3288. NSDictionary *internal = _dictionary;
  3289. NSUInteger count = internal.count;
  3290. if (count == 0) {
  3291. return 0;
  3292. }
  3293. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3294. GPBDataType keyDataType = field.mapKeyDataType;
  3295. size_t result = 0;
  3296. NSEnumerator *keys = [internal keyEnumerator];
  3297. NSNumber *aKey;
  3298. while ((aKey = [keys nextObject])) {
  3299. NSNumber *aValue = internal[aKey];
  3300. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3301. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  3302. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3303. }
  3304. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3305. result += tagSize * count;
  3306. return result;
  3307. }
  3308. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3309. asField:(GPBFieldDescriptor *)field {
  3310. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3311. GPBDataType keyDataType = field.mapKeyDataType;
  3312. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3313. NSDictionary *internal = _dictionary;
  3314. NSEnumerator *keys = [internal keyEnumerator];
  3315. NSNumber *aKey;
  3316. while ((aKey = [keys nextObject])) {
  3317. NSNumber *aValue = internal[aKey];
  3318. [outputStream writeInt32NoTag:tag];
  3319. // Write the size of the message.
  3320. int32_t unwrappedKey = [aKey intValue];
  3321. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  3322. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3323. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3324. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3325. // Write the fields.
  3326. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3327. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3328. }
  3329. }
  3330. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3331. forGPBGenericValueKey:(GPBGenericValue *)key {
  3332. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
  3333. }
  3334. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3335. [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
  3336. #pragma unused(stop)
  3337. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
  3338. }];
  3339. }
  3340. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
  3341. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3342. if (wrapped && value) {
  3343. *value = [wrapped unsignedLongLongValue];
  3344. }
  3345. return (wrapped != NULL);
  3346. }
  3347. - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
  3348. if (otherDictionary) {
  3349. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3350. if (_autocreator) {
  3351. GPBAutocreatedDictionaryModified(_autocreator, self);
  3352. }
  3353. }
  3354. }
  3355. - (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
  3356. [_dictionary setObject:@(value) forKey:@(key)];
  3357. if (_autocreator) {
  3358. GPBAutocreatedDictionaryModified(_autocreator, self);
  3359. }
  3360. }
  3361. - (void)removeUInt64ForKey:(int32_t)aKey {
  3362. [_dictionary removeObjectForKey:@(aKey)];
  3363. }
  3364. - (void)removeAll {
  3365. [_dictionary removeAllObjects];
  3366. }
  3367. @end
  3368. #pragma mark - Int32 -> Int64
  3369. @implementation GPBInt32Int64Dictionary {
  3370. @package
  3371. NSMutableDictionary *_dictionary;
  3372. }
  3373. - (instancetype)init {
  3374. return [self initWithInt64s:NULL forKeys:NULL count:0];
  3375. }
  3376. - (instancetype)initWithInt64s:(const int64_t [])values
  3377. forKeys:(const int32_t [])keys
  3378. count:(NSUInteger)count {
  3379. self = [super init];
  3380. if (self) {
  3381. _dictionary = [[NSMutableDictionary alloc] init];
  3382. if (count && values && keys) {
  3383. for (NSUInteger i = 0; i < count; ++i) {
  3384. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3385. }
  3386. }
  3387. }
  3388. return self;
  3389. }
  3390. - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
  3391. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  3392. if (self) {
  3393. if (dictionary) {
  3394. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3395. }
  3396. }
  3397. return self;
  3398. }
  3399. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3400. #pragma unused(numItems)
  3401. return [self initWithInt64s:NULL forKeys:NULL count:0];
  3402. }
  3403. - (void)dealloc {
  3404. NSAssert(!_autocreator,
  3405. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3406. [self class], _autocreator);
  3407. [_dictionary release];
  3408. [super dealloc];
  3409. }
  3410. - (instancetype)copyWithZone:(NSZone *)zone {
  3411. return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  3412. }
  3413. - (BOOL)isEqual:(id)other {
  3414. if (self == other) {
  3415. return YES;
  3416. }
  3417. if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
  3418. return NO;
  3419. }
  3420. GPBInt32Int64Dictionary *otherDictionary = other;
  3421. return [_dictionary isEqual:otherDictionary->_dictionary];
  3422. }
  3423. - (NSUInteger)hash {
  3424. return _dictionary.count;
  3425. }
  3426. - (NSString *)description {
  3427. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3428. }
  3429. - (NSUInteger)count {
  3430. return _dictionary.count;
  3431. }
  3432. - (void)enumerateKeysAndInt64sUsingBlock:
  3433. (void (^)(int32_t key, int64_t value, BOOL *stop))block {
  3434. BOOL stop = NO;
  3435. NSDictionary *internal = _dictionary;
  3436. NSEnumerator *keys = [internal keyEnumerator];
  3437. NSNumber *aKey;
  3438. while ((aKey = [keys nextObject])) {
  3439. NSNumber *aValue = internal[aKey];
  3440. block([aKey intValue], [aValue longLongValue], &stop);
  3441. if (stop) {
  3442. break;
  3443. }
  3444. }
  3445. }
  3446. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3447. NSDictionary *internal = _dictionary;
  3448. NSUInteger count = internal.count;
  3449. if (count == 0) {
  3450. return 0;
  3451. }
  3452. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3453. GPBDataType keyDataType = field.mapKeyDataType;
  3454. size_t result = 0;
  3455. NSEnumerator *keys = [internal keyEnumerator];
  3456. NSNumber *aKey;
  3457. while ((aKey = [keys nextObject])) {
  3458. NSNumber *aValue = internal[aKey];
  3459. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3460. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  3461. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3462. }
  3463. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3464. result += tagSize * count;
  3465. return result;
  3466. }
  3467. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3468. asField:(GPBFieldDescriptor *)field {
  3469. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3470. GPBDataType keyDataType = field.mapKeyDataType;
  3471. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3472. NSDictionary *internal = _dictionary;
  3473. NSEnumerator *keys = [internal keyEnumerator];
  3474. NSNumber *aKey;
  3475. while ((aKey = [keys nextObject])) {
  3476. NSNumber *aValue = internal[aKey];
  3477. [outputStream writeInt32NoTag:tag];
  3478. // Write the size of the message.
  3479. int32_t unwrappedKey = [aKey intValue];
  3480. int64_t unwrappedValue = [aValue longLongValue];
  3481. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3482. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3483. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3484. // Write the fields.
  3485. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3486. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3487. }
  3488. }
  3489. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3490. forGPBGenericValueKey:(GPBGenericValue *)key {
  3491. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
  3492. }
  3493. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3494. [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
  3495. #pragma unused(stop)
  3496. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
  3497. }];
  3498. }
  3499. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
  3500. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3501. if (wrapped && value) {
  3502. *value = [wrapped longLongValue];
  3503. }
  3504. return (wrapped != NULL);
  3505. }
  3506. - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
  3507. if (otherDictionary) {
  3508. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3509. if (_autocreator) {
  3510. GPBAutocreatedDictionaryModified(_autocreator, self);
  3511. }
  3512. }
  3513. }
  3514. - (void)setInt64:(int64_t)value forKey:(int32_t)key {
  3515. [_dictionary setObject:@(value) forKey:@(key)];
  3516. if (_autocreator) {
  3517. GPBAutocreatedDictionaryModified(_autocreator, self);
  3518. }
  3519. }
  3520. - (void)removeInt64ForKey:(int32_t)aKey {
  3521. [_dictionary removeObjectForKey:@(aKey)];
  3522. }
  3523. - (void)removeAll {
  3524. [_dictionary removeAllObjects];
  3525. }
  3526. @end
  3527. #pragma mark - Int32 -> Bool
  3528. @implementation GPBInt32BoolDictionary {
  3529. @package
  3530. NSMutableDictionary *_dictionary;
  3531. }
  3532. - (instancetype)init {
  3533. return [self initWithBools:NULL forKeys:NULL count:0];
  3534. }
  3535. - (instancetype)initWithBools:(const BOOL [])values
  3536. forKeys:(const int32_t [])keys
  3537. count:(NSUInteger)count {
  3538. self = [super init];
  3539. if (self) {
  3540. _dictionary = [[NSMutableDictionary alloc] init];
  3541. if (count && values && keys) {
  3542. for (NSUInteger i = 0; i < count; ++i) {
  3543. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3544. }
  3545. }
  3546. }
  3547. return self;
  3548. }
  3549. - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
  3550. self = [self initWithBools:NULL forKeys:NULL count:0];
  3551. if (self) {
  3552. if (dictionary) {
  3553. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3554. }
  3555. }
  3556. return self;
  3557. }
  3558. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3559. #pragma unused(numItems)
  3560. return [self initWithBools:NULL forKeys:NULL count:0];
  3561. }
  3562. - (void)dealloc {
  3563. NSAssert(!_autocreator,
  3564. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3565. [self class], _autocreator);
  3566. [_dictionary release];
  3567. [super dealloc];
  3568. }
  3569. - (instancetype)copyWithZone:(NSZone *)zone {
  3570. return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
  3571. }
  3572. - (BOOL)isEqual:(id)other {
  3573. if (self == other) {
  3574. return YES;
  3575. }
  3576. if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
  3577. return NO;
  3578. }
  3579. GPBInt32BoolDictionary *otherDictionary = other;
  3580. return [_dictionary isEqual:otherDictionary->_dictionary];
  3581. }
  3582. - (NSUInteger)hash {
  3583. return _dictionary.count;
  3584. }
  3585. - (NSString *)description {
  3586. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3587. }
  3588. - (NSUInteger)count {
  3589. return _dictionary.count;
  3590. }
  3591. - (void)enumerateKeysAndBoolsUsingBlock:
  3592. (void (^)(int32_t key, BOOL value, BOOL *stop))block {
  3593. BOOL stop = NO;
  3594. NSDictionary *internal = _dictionary;
  3595. NSEnumerator *keys = [internal keyEnumerator];
  3596. NSNumber *aKey;
  3597. while ((aKey = [keys nextObject])) {
  3598. NSNumber *aValue = internal[aKey];
  3599. block([aKey intValue], [aValue boolValue], &stop);
  3600. if (stop) {
  3601. break;
  3602. }
  3603. }
  3604. }
  3605. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3606. NSDictionary *internal = _dictionary;
  3607. NSUInteger count = internal.count;
  3608. if (count == 0) {
  3609. return 0;
  3610. }
  3611. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3612. GPBDataType keyDataType = field.mapKeyDataType;
  3613. size_t result = 0;
  3614. NSEnumerator *keys = [internal keyEnumerator];
  3615. NSNumber *aKey;
  3616. while ((aKey = [keys nextObject])) {
  3617. NSNumber *aValue = internal[aKey];
  3618. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3619. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  3620. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3621. }
  3622. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3623. result += tagSize * count;
  3624. return result;
  3625. }
  3626. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3627. asField:(GPBFieldDescriptor *)field {
  3628. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3629. GPBDataType keyDataType = field.mapKeyDataType;
  3630. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3631. NSDictionary *internal = _dictionary;
  3632. NSEnumerator *keys = [internal keyEnumerator];
  3633. NSNumber *aKey;
  3634. while ((aKey = [keys nextObject])) {
  3635. NSNumber *aValue = internal[aKey];
  3636. [outputStream writeInt32NoTag:tag];
  3637. // Write the size of the message.
  3638. int32_t unwrappedKey = [aKey intValue];
  3639. BOOL unwrappedValue = [aValue boolValue];
  3640. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3641. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3642. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3643. // Write the fields.
  3644. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3645. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3646. }
  3647. }
  3648. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3649. forGPBGenericValueKey:(GPBGenericValue *)key {
  3650. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
  3651. }
  3652. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3653. [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
  3654. #pragma unused(stop)
  3655. block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
  3656. }];
  3657. }
  3658. - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
  3659. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3660. if (wrapped && value) {
  3661. *value = [wrapped boolValue];
  3662. }
  3663. return (wrapped != NULL);
  3664. }
  3665. - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
  3666. if (otherDictionary) {
  3667. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3668. if (_autocreator) {
  3669. GPBAutocreatedDictionaryModified(_autocreator, self);
  3670. }
  3671. }
  3672. }
  3673. - (void)setBool:(BOOL)value forKey:(int32_t)key {
  3674. [_dictionary setObject:@(value) forKey:@(key)];
  3675. if (_autocreator) {
  3676. GPBAutocreatedDictionaryModified(_autocreator, self);
  3677. }
  3678. }
  3679. - (void)removeBoolForKey:(int32_t)aKey {
  3680. [_dictionary removeObjectForKey:@(aKey)];
  3681. }
  3682. - (void)removeAll {
  3683. [_dictionary removeAllObjects];
  3684. }
  3685. @end
  3686. #pragma mark - Int32 -> Float
  3687. @implementation GPBInt32FloatDictionary {
  3688. @package
  3689. NSMutableDictionary *_dictionary;
  3690. }
  3691. - (instancetype)init {
  3692. return [self initWithFloats:NULL forKeys:NULL count:0];
  3693. }
  3694. - (instancetype)initWithFloats:(const float [])values
  3695. forKeys:(const int32_t [])keys
  3696. count:(NSUInteger)count {
  3697. self = [super init];
  3698. if (self) {
  3699. _dictionary = [[NSMutableDictionary alloc] init];
  3700. if (count && values && keys) {
  3701. for (NSUInteger i = 0; i < count; ++i) {
  3702. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3703. }
  3704. }
  3705. }
  3706. return self;
  3707. }
  3708. - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
  3709. self = [self initWithFloats:NULL forKeys:NULL count:0];
  3710. if (self) {
  3711. if (dictionary) {
  3712. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3713. }
  3714. }
  3715. return self;
  3716. }
  3717. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3718. #pragma unused(numItems)
  3719. return [self initWithFloats:NULL forKeys:NULL count:0];
  3720. }
  3721. - (void)dealloc {
  3722. NSAssert(!_autocreator,
  3723. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3724. [self class], _autocreator);
  3725. [_dictionary release];
  3726. [super dealloc];
  3727. }
  3728. - (instancetype)copyWithZone:(NSZone *)zone {
  3729. return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
  3730. }
  3731. - (BOOL)isEqual:(id)other {
  3732. if (self == other) {
  3733. return YES;
  3734. }
  3735. if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
  3736. return NO;
  3737. }
  3738. GPBInt32FloatDictionary *otherDictionary = other;
  3739. return [_dictionary isEqual:otherDictionary->_dictionary];
  3740. }
  3741. - (NSUInteger)hash {
  3742. return _dictionary.count;
  3743. }
  3744. - (NSString *)description {
  3745. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3746. }
  3747. - (NSUInteger)count {
  3748. return _dictionary.count;
  3749. }
  3750. - (void)enumerateKeysAndFloatsUsingBlock:
  3751. (void (^)(int32_t key, float value, BOOL *stop))block {
  3752. BOOL stop = NO;
  3753. NSDictionary *internal = _dictionary;
  3754. NSEnumerator *keys = [internal keyEnumerator];
  3755. NSNumber *aKey;
  3756. while ((aKey = [keys nextObject])) {
  3757. NSNumber *aValue = internal[aKey];
  3758. block([aKey intValue], [aValue floatValue], &stop);
  3759. if (stop) {
  3760. break;
  3761. }
  3762. }
  3763. }
  3764. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3765. NSDictionary *internal = _dictionary;
  3766. NSUInteger count = internal.count;
  3767. if (count == 0) {
  3768. return 0;
  3769. }
  3770. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3771. GPBDataType keyDataType = field.mapKeyDataType;
  3772. size_t result = 0;
  3773. NSEnumerator *keys = [internal keyEnumerator];
  3774. NSNumber *aKey;
  3775. while ((aKey = [keys nextObject])) {
  3776. NSNumber *aValue = internal[aKey];
  3777. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3778. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  3779. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3780. }
  3781. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3782. result += tagSize * count;
  3783. return result;
  3784. }
  3785. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3786. asField:(GPBFieldDescriptor *)field {
  3787. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3788. GPBDataType keyDataType = field.mapKeyDataType;
  3789. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3790. NSDictionary *internal = _dictionary;
  3791. NSEnumerator *keys = [internal keyEnumerator];
  3792. NSNumber *aKey;
  3793. while ((aKey = [keys nextObject])) {
  3794. NSNumber *aValue = internal[aKey];
  3795. [outputStream writeInt32NoTag:tag];
  3796. // Write the size of the message.
  3797. int32_t unwrappedKey = [aKey intValue];
  3798. float unwrappedValue = [aValue floatValue];
  3799. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3800. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3801. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3802. // Write the fields.
  3803. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3804. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3805. }
  3806. }
  3807. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3808. forGPBGenericValueKey:(GPBGenericValue *)key {
  3809. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
  3810. }
  3811. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3812. [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
  3813. #pragma unused(stop)
  3814. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  3815. }];
  3816. }
  3817. - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
  3818. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3819. if (wrapped && value) {
  3820. *value = [wrapped floatValue];
  3821. }
  3822. return (wrapped != NULL);
  3823. }
  3824. - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
  3825. if (otherDictionary) {
  3826. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3827. if (_autocreator) {
  3828. GPBAutocreatedDictionaryModified(_autocreator, self);
  3829. }
  3830. }
  3831. }
  3832. - (void)setFloat:(float)value forKey:(int32_t)key {
  3833. [_dictionary setObject:@(value) forKey:@(key)];
  3834. if (_autocreator) {
  3835. GPBAutocreatedDictionaryModified(_autocreator, self);
  3836. }
  3837. }
  3838. - (void)removeFloatForKey:(int32_t)aKey {
  3839. [_dictionary removeObjectForKey:@(aKey)];
  3840. }
  3841. - (void)removeAll {
  3842. [_dictionary removeAllObjects];
  3843. }
  3844. @end
  3845. #pragma mark - Int32 -> Double
  3846. @implementation GPBInt32DoubleDictionary {
  3847. @package
  3848. NSMutableDictionary *_dictionary;
  3849. }
  3850. - (instancetype)init {
  3851. return [self initWithDoubles:NULL forKeys:NULL count:0];
  3852. }
  3853. - (instancetype)initWithDoubles:(const double [])values
  3854. forKeys:(const int32_t [])keys
  3855. count:(NSUInteger)count {
  3856. self = [super init];
  3857. if (self) {
  3858. _dictionary = [[NSMutableDictionary alloc] init];
  3859. if (count && values && keys) {
  3860. for (NSUInteger i = 0; i < count; ++i) {
  3861. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3862. }
  3863. }
  3864. }
  3865. return self;
  3866. }
  3867. - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
  3868. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  3869. if (self) {
  3870. if (dictionary) {
  3871. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3872. }
  3873. }
  3874. return self;
  3875. }
  3876. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3877. #pragma unused(numItems)
  3878. return [self initWithDoubles:NULL forKeys:NULL count:0];
  3879. }
  3880. - (void)dealloc {
  3881. NSAssert(!_autocreator,
  3882. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3883. [self class], _autocreator);
  3884. [_dictionary release];
  3885. [super dealloc];
  3886. }
  3887. - (instancetype)copyWithZone:(NSZone *)zone {
  3888. return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  3889. }
  3890. - (BOOL)isEqual:(id)other {
  3891. if (self == other) {
  3892. return YES;
  3893. }
  3894. if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
  3895. return NO;
  3896. }
  3897. GPBInt32DoubleDictionary *otherDictionary = other;
  3898. return [_dictionary isEqual:otherDictionary->_dictionary];
  3899. }
  3900. - (NSUInteger)hash {
  3901. return _dictionary.count;
  3902. }
  3903. - (NSString *)description {
  3904. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3905. }
  3906. - (NSUInteger)count {
  3907. return _dictionary.count;
  3908. }
  3909. - (void)enumerateKeysAndDoublesUsingBlock:
  3910. (void (^)(int32_t key, double value, BOOL *stop))block {
  3911. BOOL stop = NO;
  3912. NSDictionary *internal = _dictionary;
  3913. NSEnumerator *keys = [internal keyEnumerator];
  3914. NSNumber *aKey;
  3915. while ((aKey = [keys nextObject])) {
  3916. NSNumber *aValue = internal[aKey];
  3917. block([aKey intValue], [aValue doubleValue], &stop);
  3918. if (stop) {
  3919. break;
  3920. }
  3921. }
  3922. }
  3923. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3924. NSDictionary *internal = _dictionary;
  3925. NSUInteger count = internal.count;
  3926. if (count == 0) {
  3927. return 0;
  3928. }
  3929. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3930. GPBDataType keyDataType = field.mapKeyDataType;
  3931. size_t result = 0;
  3932. NSEnumerator *keys = [internal keyEnumerator];
  3933. NSNumber *aKey;
  3934. while ((aKey = [keys nextObject])) {
  3935. NSNumber *aValue = internal[aKey];
  3936. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3937. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  3938. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3939. }
  3940. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3941. result += tagSize * count;
  3942. return result;
  3943. }
  3944. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3945. asField:(GPBFieldDescriptor *)field {
  3946. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3947. GPBDataType keyDataType = field.mapKeyDataType;
  3948. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3949. NSDictionary *internal = _dictionary;
  3950. NSEnumerator *keys = [internal keyEnumerator];
  3951. NSNumber *aKey;
  3952. while ((aKey = [keys nextObject])) {
  3953. NSNumber *aValue = internal[aKey];
  3954. [outputStream writeInt32NoTag:tag];
  3955. // Write the size of the message.
  3956. int32_t unwrappedKey = [aKey intValue];
  3957. double unwrappedValue = [aValue doubleValue];
  3958. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3959. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3960. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3961. // Write the fields.
  3962. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3963. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3964. }
  3965. }
  3966. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3967. forGPBGenericValueKey:(GPBGenericValue *)key {
  3968. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
  3969. }
  3970. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3971. [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
  3972. #pragma unused(stop)
  3973. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  3974. }];
  3975. }
  3976. - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
  3977. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3978. if (wrapped && value) {
  3979. *value = [wrapped doubleValue];
  3980. }
  3981. return (wrapped != NULL);
  3982. }
  3983. - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
  3984. if (otherDictionary) {
  3985. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3986. if (_autocreator) {
  3987. GPBAutocreatedDictionaryModified(_autocreator, self);
  3988. }
  3989. }
  3990. }
  3991. - (void)setDouble:(double)value forKey:(int32_t)key {
  3992. [_dictionary setObject:@(value) forKey:@(key)];
  3993. if (_autocreator) {
  3994. GPBAutocreatedDictionaryModified(_autocreator, self);
  3995. }
  3996. }
  3997. - (void)removeDoubleForKey:(int32_t)aKey {
  3998. [_dictionary removeObjectForKey:@(aKey)];
  3999. }
  4000. - (void)removeAll {
  4001. [_dictionary removeAllObjects];
  4002. }
  4003. @end
  4004. #pragma mark - Int32 -> Enum
  4005. @implementation GPBInt32EnumDictionary {
  4006. @package
  4007. NSMutableDictionary *_dictionary;
  4008. GPBEnumValidationFunc _validationFunc;
  4009. }
  4010. @synthesize validationFunc = _validationFunc;
  4011. - (instancetype)init {
  4012. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  4013. }
  4014. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  4015. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  4016. }
  4017. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  4018. rawValues:(const int32_t [])rawValues
  4019. forKeys:(const int32_t [])keys
  4020. count:(NSUInteger)count {
  4021. self = [super init];
  4022. if (self) {
  4023. _dictionary = [[NSMutableDictionary alloc] init];
  4024. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  4025. if (count && rawValues && keys) {
  4026. for (NSUInteger i = 0; i < count; ++i) {
  4027. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  4028. }
  4029. }
  4030. }
  4031. return self;
  4032. }
  4033. - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
  4034. self = [self initWithValidationFunction:dictionary.validationFunc
  4035. rawValues:NULL
  4036. forKeys:NULL
  4037. count:0];
  4038. if (self) {
  4039. if (dictionary) {
  4040. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4041. }
  4042. }
  4043. return self;
  4044. }
  4045. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  4046. capacity:(NSUInteger)numItems {
  4047. #pragma unused(numItems)
  4048. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  4049. }
  4050. - (void)dealloc {
  4051. NSAssert(!_autocreator,
  4052. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4053. [self class], _autocreator);
  4054. [_dictionary release];
  4055. [super dealloc];
  4056. }
  4057. - (instancetype)copyWithZone:(NSZone *)zone {
  4058. return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
  4059. }
  4060. - (BOOL)isEqual:(id)other {
  4061. if (self == other) {
  4062. return YES;
  4063. }
  4064. if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
  4065. return NO;
  4066. }
  4067. GPBInt32EnumDictionary *otherDictionary = other;
  4068. return [_dictionary isEqual:otherDictionary->_dictionary];
  4069. }
  4070. - (NSUInteger)hash {
  4071. return _dictionary.count;
  4072. }
  4073. - (NSString *)description {
  4074. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4075. }
  4076. - (NSUInteger)count {
  4077. return _dictionary.count;
  4078. }
  4079. - (void)enumerateKeysAndRawValuesUsingBlock:
  4080. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  4081. BOOL stop = NO;
  4082. NSDictionary *internal = _dictionary;
  4083. NSEnumerator *keys = [internal keyEnumerator];
  4084. NSNumber *aKey;
  4085. while ((aKey = [keys nextObject])) {
  4086. NSNumber *aValue = internal[aKey];
  4087. block([aKey intValue], [aValue intValue], &stop);
  4088. if (stop) {
  4089. break;
  4090. }
  4091. }
  4092. }
  4093. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4094. NSDictionary *internal = _dictionary;
  4095. NSUInteger count = internal.count;
  4096. if (count == 0) {
  4097. return 0;
  4098. }
  4099. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4100. GPBDataType keyDataType = field.mapKeyDataType;
  4101. size_t result = 0;
  4102. NSEnumerator *keys = [internal keyEnumerator];
  4103. NSNumber *aKey;
  4104. while ((aKey = [keys nextObject])) {
  4105. NSNumber *aValue = internal[aKey];
  4106. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  4107. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  4108. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4109. }
  4110. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4111. result += tagSize * count;
  4112. return result;
  4113. }
  4114. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4115. asField:(GPBFieldDescriptor *)field {
  4116. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4117. GPBDataType keyDataType = field.mapKeyDataType;
  4118. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4119. NSDictionary *internal = _dictionary;
  4120. NSEnumerator *keys = [internal keyEnumerator];
  4121. NSNumber *aKey;
  4122. while ((aKey = [keys nextObject])) {
  4123. NSNumber *aValue = internal[aKey];
  4124. [outputStream writeInt32NoTag:tag];
  4125. // Write the size of the message.
  4126. int32_t unwrappedKey = [aKey intValue];
  4127. int32_t unwrappedValue = [aValue intValue];
  4128. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4129. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4130. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4131. // Write the fields.
  4132. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4133. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4134. }
  4135. }
  4136. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  4137. forKey:(GPBGenericValue *)key
  4138. keyDataType:(GPBDataType)keyDataType {
  4139. size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
  4140. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  4141. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  4142. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  4143. WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
  4144. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  4145. [outputStream release];
  4146. return data;
  4147. }
  4148. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4149. forGPBGenericValueKey:(GPBGenericValue *)key {
  4150. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
  4151. }
  4152. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4153. [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
  4154. #pragma unused(stop)
  4155. block([NSString stringWithFormat:@"%d", key], @(value));
  4156. }];
  4157. }
  4158. - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
  4159. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4160. if (wrapped && value) {
  4161. int32_t result = [wrapped intValue];
  4162. if (!_validationFunc(result)) {
  4163. result = kGPBUnrecognizedEnumeratorValue;
  4164. }
  4165. *value = result;
  4166. }
  4167. return (wrapped != NULL);
  4168. }
  4169. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
  4170. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4171. if (wrapped && rawValue) {
  4172. *rawValue = [wrapped intValue];
  4173. }
  4174. return (wrapped != NULL);
  4175. }
  4176. - (void)enumerateKeysAndEnumsUsingBlock:
  4177. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  4178. GPBEnumValidationFunc func = _validationFunc;
  4179. BOOL stop = NO;
  4180. NSEnumerator *keys = [_dictionary keyEnumerator];
  4181. NSNumber *aKey;
  4182. while ((aKey = [keys nextObject])) {
  4183. NSNumber *aValue = _dictionary[aKey];
  4184. int32_t unwrapped = [aValue intValue];
  4185. if (!func(unwrapped)) {
  4186. unwrapped = kGPBUnrecognizedEnumeratorValue;
  4187. }
  4188. block([aKey intValue], unwrapped, &stop);
  4189. if (stop) {
  4190. break;
  4191. }
  4192. }
  4193. }
  4194. - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
  4195. if (otherDictionary) {
  4196. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4197. if (_autocreator) {
  4198. GPBAutocreatedDictionaryModified(_autocreator, self);
  4199. }
  4200. }
  4201. }
  4202. - (void)setRawValue:(int32_t)value forKey:(int32_t)key {
  4203. [_dictionary setObject:@(value) forKey:@(key)];
  4204. if (_autocreator) {
  4205. GPBAutocreatedDictionaryModified(_autocreator, self);
  4206. }
  4207. }
  4208. - (void)removeEnumForKey:(int32_t)aKey {
  4209. [_dictionary removeObjectForKey:@(aKey)];
  4210. }
  4211. - (void)removeAll {
  4212. [_dictionary removeAllObjects];
  4213. }
  4214. - (void)setEnum:(int32_t)value forKey:(int32_t)key {
  4215. if (!_validationFunc(value)) {
  4216. [NSException raise:NSInvalidArgumentException
  4217. format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
  4218. value];
  4219. }
  4220. [_dictionary setObject:@(value) forKey:@(key)];
  4221. if (_autocreator) {
  4222. GPBAutocreatedDictionaryModified(_autocreator, self);
  4223. }
  4224. }
  4225. @end
  4226. #pragma mark - Int32 -> Object
  4227. @implementation GPBInt32ObjectDictionary {
  4228. @package
  4229. NSMutableDictionary *_dictionary;
  4230. }
  4231. - (instancetype)init {
  4232. return [self initWithObjects:NULL forKeys:NULL count:0];
  4233. }
  4234. - (instancetype)initWithObjects:(const id [])objects
  4235. forKeys:(const int32_t [])keys
  4236. count:(NSUInteger)count {
  4237. self = [super init];
  4238. if (self) {
  4239. _dictionary = [[NSMutableDictionary alloc] init];
  4240. if (count && objects && keys) {
  4241. for (NSUInteger i = 0; i < count; ++i) {
  4242. if (!objects[i]) {
  4243. [NSException raise:NSInvalidArgumentException
  4244. format:@"Attempting to add nil object to a Dictionary"];
  4245. }
  4246. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  4247. }
  4248. }
  4249. }
  4250. return self;
  4251. }
  4252. - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
  4253. self = [self initWithObjects:NULL forKeys:NULL count:0];
  4254. if (self) {
  4255. if (dictionary) {
  4256. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4257. }
  4258. }
  4259. return self;
  4260. }
  4261. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4262. #pragma unused(numItems)
  4263. return [self initWithObjects:NULL forKeys:NULL count:0];
  4264. }
  4265. - (void)dealloc {
  4266. NSAssert(!_autocreator,
  4267. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4268. [self class], _autocreator);
  4269. [_dictionary release];
  4270. [super dealloc];
  4271. }
  4272. - (instancetype)copyWithZone:(NSZone *)zone {
  4273. return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  4274. }
  4275. - (BOOL)isEqual:(id)other {
  4276. if (self == other) {
  4277. return YES;
  4278. }
  4279. if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
  4280. return NO;
  4281. }
  4282. GPBInt32ObjectDictionary *otherDictionary = other;
  4283. return [_dictionary isEqual:otherDictionary->_dictionary];
  4284. }
  4285. - (NSUInteger)hash {
  4286. return _dictionary.count;
  4287. }
  4288. - (NSString *)description {
  4289. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4290. }
  4291. - (NSUInteger)count {
  4292. return _dictionary.count;
  4293. }
  4294. - (void)enumerateKeysAndObjectsUsingBlock:
  4295. (void (^)(int32_t key, id object, BOOL *stop))block {
  4296. BOOL stop = NO;
  4297. NSDictionary *internal = _dictionary;
  4298. NSEnumerator *keys = [internal keyEnumerator];
  4299. NSNumber *aKey;
  4300. while ((aKey = [keys nextObject])) {
  4301. id aObject = internal[aKey];
  4302. block([aKey intValue], aObject, &stop);
  4303. if (stop) {
  4304. break;
  4305. }
  4306. }
  4307. }
  4308. - (BOOL)isInitialized {
  4309. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  4310. if (!msg.initialized) {
  4311. return NO;
  4312. }
  4313. }
  4314. return YES;
  4315. }
  4316. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  4317. GPBInt32ObjectDictionary *newDict =
  4318. [[GPBInt32ObjectDictionary alloc] init];
  4319. NSEnumerator *keys = [_dictionary keyEnumerator];
  4320. id aKey;
  4321. NSMutableDictionary *internalDict = newDict->_dictionary;
  4322. while ((aKey = [keys nextObject])) {
  4323. GPBMessage *msg = _dictionary[aKey];
  4324. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  4325. [internalDict setObject:copiedMsg forKey:aKey];
  4326. [copiedMsg release];
  4327. }
  4328. return newDict;
  4329. }
  4330. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4331. NSDictionary *internal = _dictionary;
  4332. NSUInteger count = internal.count;
  4333. if (count == 0) {
  4334. return 0;
  4335. }
  4336. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4337. GPBDataType keyDataType = field.mapKeyDataType;
  4338. size_t result = 0;
  4339. NSEnumerator *keys = [internal keyEnumerator];
  4340. NSNumber *aKey;
  4341. while ((aKey = [keys nextObject])) {
  4342. id aObject = internal[aKey];
  4343. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  4344. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  4345. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4346. }
  4347. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4348. result += tagSize * count;
  4349. return result;
  4350. }
  4351. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4352. asField:(GPBFieldDescriptor *)field {
  4353. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4354. GPBDataType keyDataType = field.mapKeyDataType;
  4355. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4356. NSDictionary *internal = _dictionary;
  4357. NSEnumerator *keys = [internal keyEnumerator];
  4358. NSNumber *aKey;
  4359. while ((aKey = [keys nextObject])) {
  4360. id aObject = internal[aKey];
  4361. [outputStream writeInt32NoTag:tag];
  4362. // Write the size of the message.
  4363. int32_t unwrappedKey = [aKey intValue];
  4364. id unwrappedValue = aObject;
  4365. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4366. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4367. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4368. // Write the fields.
  4369. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4370. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4371. }
  4372. }
  4373. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4374. forGPBGenericValueKey:(GPBGenericValue *)key {
  4375. [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
  4376. }
  4377. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4378. [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
  4379. #pragma unused(stop)
  4380. block([NSString stringWithFormat:@"%d", key], object);
  4381. }];
  4382. }
  4383. - (id)objectForKey:(int32_t)key {
  4384. id result = [_dictionary objectForKey:@(key)];
  4385. return result;
  4386. }
  4387. - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
  4388. if (otherDictionary) {
  4389. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4390. if (_autocreator) {
  4391. GPBAutocreatedDictionaryModified(_autocreator, self);
  4392. }
  4393. }
  4394. }
  4395. - (void)setObject:(id)object forKey:(int32_t)key {
  4396. if (!object) {
  4397. [NSException raise:NSInvalidArgumentException
  4398. format:@"Attempting to add nil object to a Dictionary"];
  4399. }
  4400. [_dictionary setObject:object forKey:@(key)];
  4401. if (_autocreator) {
  4402. GPBAutocreatedDictionaryModified(_autocreator, self);
  4403. }
  4404. }
  4405. - (void)removeObjectForKey:(int32_t)aKey {
  4406. [_dictionary removeObjectForKey:@(aKey)];
  4407. }
  4408. - (void)removeAll {
  4409. [_dictionary removeAllObjects];
  4410. }
  4411. @end
  4412. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
  4413. // This block of code is generated, do not edit it directly.
  4414. #pragma mark - UInt64 -> UInt32
  4415. @implementation GPBUInt64UInt32Dictionary {
  4416. @package
  4417. NSMutableDictionary *_dictionary;
  4418. }
  4419. - (instancetype)init {
  4420. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  4421. }
  4422. - (instancetype)initWithUInt32s:(const uint32_t [])values
  4423. forKeys:(const uint64_t [])keys
  4424. count:(NSUInteger)count {
  4425. self = [super init];
  4426. if (self) {
  4427. _dictionary = [[NSMutableDictionary alloc] init];
  4428. if (count && values && keys) {
  4429. for (NSUInteger i = 0; i < count; ++i) {
  4430. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4431. }
  4432. }
  4433. }
  4434. return self;
  4435. }
  4436. - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
  4437. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  4438. if (self) {
  4439. if (dictionary) {
  4440. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4441. }
  4442. }
  4443. return self;
  4444. }
  4445. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4446. #pragma unused(numItems)
  4447. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  4448. }
  4449. - (void)dealloc {
  4450. NSAssert(!_autocreator,
  4451. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4452. [self class], _autocreator);
  4453. [_dictionary release];
  4454. [super dealloc];
  4455. }
  4456. - (instancetype)copyWithZone:(NSZone *)zone {
  4457. return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  4458. }
  4459. - (BOOL)isEqual:(id)other {
  4460. if (self == other) {
  4461. return YES;
  4462. }
  4463. if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
  4464. return NO;
  4465. }
  4466. GPBUInt64UInt32Dictionary *otherDictionary = other;
  4467. return [_dictionary isEqual:otherDictionary->_dictionary];
  4468. }
  4469. - (NSUInteger)hash {
  4470. return _dictionary.count;
  4471. }
  4472. - (NSString *)description {
  4473. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4474. }
  4475. - (NSUInteger)count {
  4476. return _dictionary.count;
  4477. }
  4478. - (void)enumerateKeysAndUInt32sUsingBlock:
  4479. (void (^)(uint64_t key, uint32_t value, BOOL *stop))block {
  4480. BOOL stop = NO;
  4481. NSDictionary *internal = _dictionary;
  4482. NSEnumerator *keys = [internal keyEnumerator];
  4483. NSNumber *aKey;
  4484. while ((aKey = [keys nextObject])) {
  4485. NSNumber *aValue = internal[aKey];
  4486. block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
  4487. if (stop) {
  4488. break;
  4489. }
  4490. }
  4491. }
  4492. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4493. NSDictionary *internal = _dictionary;
  4494. NSUInteger count = internal.count;
  4495. if (count == 0) {
  4496. return 0;
  4497. }
  4498. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4499. GPBDataType keyDataType = field.mapKeyDataType;
  4500. size_t result = 0;
  4501. NSEnumerator *keys = [internal keyEnumerator];
  4502. NSNumber *aKey;
  4503. while ((aKey = [keys nextObject])) {
  4504. NSNumber *aValue = internal[aKey];
  4505. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4506. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  4507. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4508. }
  4509. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4510. result += tagSize * count;
  4511. return result;
  4512. }
  4513. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4514. asField:(GPBFieldDescriptor *)field {
  4515. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4516. GPBDataType keyDataType = field.mapKeyDataType;
  4517. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4518. NSDictionary *internal = _dictionary;
  4519. NSEnumerator *keys = [internal keyEnumerator];
  4520. NSNumber *aKey;
  4521. while ((aKey = [keys nextObject])) {
  4522. NSNumber *aValue = internal[aKey];
  4523. [outputStream writeInt32NoTag:tag];
  4524. // Write the size of the message.
  4525. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4526. uint32_t unwrappedValue = [aValue unsignedIntValue];
  4527. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4528. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4529. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4530. // Write the fields.
  4531. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4532. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4533. }
  4534. }
  4535. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4536. forGPBGenericValueKey:(GPBGenericValue *)key {
  4537. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
  4538. }
  4539. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4540. [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
  4541. #pragma unused(stop)
  4542. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
  4543. }];
  4544. }
  4545. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
  4546. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4547. if (wrapped && value) {
  4548. *value = [wrapped unsignedIntValue];
  4549. }
  4550. return (wrapped != NULL);
  4551. }
  4552. - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
  4553. if (otherDictionary) {
  4554. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4555. if (_autocreator) {
  4556. GPBAutocreatedDictionaryModified(_autocreator, self);
  4557. }
  4558. }
  4559. }
  4560. - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
  4561. [_dictionary setObject:@(value) forKey:@(key)];
  4562. if (_autocreator) {
  4563. GPBAutocreatedDictionaryModified(_autocreator, self);
  4564. }
  4565. }
  4566. - (void)removeUInt32ForKey:(uint64_t)aKey {
  4567. [_dictionary removeObjectForKey:@(aKey)];
  4568. }
  4569. - (void)removeAll {
  4570. [_dictionary removeAllObjects];
  4571. }
  4572. @end
  4573. #pragma mark - UInt64 -> Int32
  4574. @implementation GPBUInt64Int32Dictionary {
  4575. @package
  4576. NSMutableDictionary *_dictionary;
  4577. }
  4578. - (instancetype)init {
  4579. return [self initWithInt32s:NULL forKeys:NULL count:0];
  4580. }
  4581. - (instancetype)initWithInt32s:(const int32_t [])values
  4582. forKeys:(const uint64_t [])keys
  4583. count:(NSUInteger)count {
  4584. self = [super init];
  4585. if (self) {
  4586. _dictionary = [[NSMutableDictionary alloc] init];
  4587. if (count && values && keys) {
  4588. for (NSUInteger i = 0; i < count; ++i) {
  4589. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4590. }
  4591. }
  4592. }
  4593. return self;
  4594. }
  4595. - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
  4596. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  4597. if (self) {
  4598. if (dictionary) {
  4599. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4600. }
  4601. }
  4602. return self;
  4603. }
  4604. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4605. #pragma unused(numItems)
  4606. return [self initWithInt32s:NULL forKeys:NULL count:0];
  4607. }
  4608. - (void)dealloc {
  4609. NSAssert(!_autocreator,
  4610. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4611. [self class], _autocreator);
  4612. [_dictionary release];
  4613. [super dealloc];
  4614. }
  4615. - (instancetype)copyWithZone:(NSZone *)zone {
  4616. return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  4617. }
  4618. - (BOOL)isEqual:(id)other {
  4619. if (self == other) {
  4620. return YES;
  4621. }
  4622. if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
  4623. return NO;
  4624. }
  4625. GPBUInt64Int32Dictionary *otherDictionary = other;
  4626. return [_dictionary isEqual:otherDictionary->_dictionary];
  4627. }
  4628. - (NSUInteger)hash {
  4629. return _dictionary.count;
  4630. }
  4631. - (NSString *)description {
  4632. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4633. }
  4634. - (NSUInteger)count {
  4635. return _dictionary.count;
  4636. }
  4637. - (void)enumerateKeysAndInt32sUsingBlock:
  4638. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  4639. BOOL stop = NO;
  4640. NSDictionary *internal = _dictionary;
  4641. NSEnumerator *keys = [internal keyEnumerator];
  4642. NSNumber *aKey;
  4643. while ((aKey = [keys nextObject])) {
  4644. NSNumber *aValue = internal[aKey];
  4645. block([aKey unsignedLongLongValue], [aValue intValue], &stop);
  4646. if (stop) {
  4647. break;
  4648. }
  4649. }
  4650. }
  4651. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4652. NSDictionary *internal = _dictionary;
  4653. NSUInteger count = internal.count;
  4654. if (count == 0) {
  4655. return 0;
  4656. }
  4657. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4658. GPBDataType keyDataType = field.mapKeyDataType;
  4659. size_t result = 0;
  4660. NSEnumerator *keys = [internal keyEnumerator];
  4661. NSNumber *aKey;
  4662. while ((aKey = [keys nextObject])) {
  4663. NSNumber *aValue = internal[aKey];
  4664. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4665. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  4666. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4667. }
  4668. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4669. result += tagSize * count;
  4670. return result;
  4671. }
  4672. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4673. asField:(GPBFieldDescriptor *)field {
  4674. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4675. GPBDataType keyDataType = field.mapKeyDataType;
  4676. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4677. NSDictionary *internal = _dictionary;
  4678. NSEnumerator *keys = [internal keyEnumerator];
  4679. NSNumber *aKey;
  4680. while ((aKey = [keys nextObject])) {
  4681. NSNumber *aValue = internal[aKey];
  4682. [outputStream writeInt32NoTag:tag];
  4683. // Write the size of the message.
  4684. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4685. int32_t unwrappedValue = [aValue intValue];
  4686. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4687. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4688. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4689. // Write the fields.
  4690. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4691. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4692. }
  4693. }
  4694. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4695. forGPBGenericValueKey:(GPBGenericValue *)key {
  4696. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
  4697. }
  4698. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4699. [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
  4700. #pragma unused(stop)
  4701. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
  4702. }];
  4703. }
  4704. - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
  4705. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4706. if (wrapped && value) {
  4707. *value = [wrapped intValue];
  4708. }
  4709. return (wrapped != NULL);
  4710. }
  4711. - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
  4712. if (otherDictionary) {
  4713. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4714. if (_autocreator) {
  4715. GPBAutocreatedDictionaryModified(_autocreator, self);
  4716. }
  4717. }
  4718. }
  4719. - (void)setInt32:(int32_t)value forKey:(uint64_t)key {
  4720. [_dictionary setObject:@(value) forKey:@(key)];
  4721. if (_autocreator) {
  4722. GPBAutocreatedDictionaryModified(_autocreator, self);
  4723. }
  4724. }
  4725. - (void)removeInt32ForKey:(uint64_t)aKey {
  4726. [_dictionary removeObjectForKey:@(aKey)];
  4727. }
  4728. - (void)removeAll {
  4729. [_dictionary removeAllObjects];
  4730. }
  4731. @end
  4732. #pragma mark - UInt64 -> UInt64
  4733. @implementation GPBUInt64UInt64Dictionary {
  4734. @package
  4735. NSMutableDictionary *_dictionary;
  4736. }
  4737. - (instancetype)init {
  4738. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  4739. }
  4740. - (instancetype)initWithUInt64s:(const uint64_t [])values
  4741. forKeys:(const uint64_t [])keys
  4742. count:(NSUInteger)count {
  4743. self = [super init];
  4744. if (self) {
  4745. _dictionary = [[NSMutableDictionary alloc] init];
  4746. if (count && values && keys) {
  4747. for (NSUInteger i = 0; i < count; ++i) {
  4748. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4749. }
  4750. }
  4751. }
  4752. return self;
  4753. }
  4754. - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
  4755. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  4756. if (self) {
  4757. if (dictionary) {
  4758. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4759. }
  4760. }
  4761. return self;
  4762. }
  4763. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4764. #pragma unused(numItems)
  4765. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  4766. }
  4767. - (void)dealloc {
  4768. NSAssert(!_autocreator,
  4769. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4770. [self class], _autocreator);
  4771. [_dictionary release];
  4772. [super dealloc];
  4773. }
  4774. - (instancetype)copyWithZone:(NSZone *)zone {
  4775. return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  4776. }
  4777. - (BOOL)isEqual:(id)other {
  4778. if (self == other) {
  4779. return YES;
  4780. }
  4781. if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
  4782. return NO;
  4783. }
  4784. GPBUInt64UInt64Dictionary *otherDictionary = other;
  4785. return [_dictionary isEqual:otherDictionary->_dictionary];
  4786. }
  4787. - (NSUInteger)hash {
  4788. return _dictionary.count;
  4789. }
  4790. - (NSString *)description {
  4791. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4792. }
  4793. - (NSUInteger)count {
  4794. return _dictionary.count;
  4795. }
  4796. - (void)enumerateKeysAndUInt64sUsingBlock:
  4797. (void (^)(uint64_t key, uint64_t value, BOOL *stop))block {
  4798. BOOL stop = NO;
  4799. NSDictionary *internal = _dictionary;
  4800. NSEnumerator *keys = [internal keyEnumerator];
  4801. NSNumber *aKey;
  4802. while ((aKey = [keys nextObject])) {
  4803. NSNumber *aValue = internal[aKey];
  4804. block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
  4805. if (stop) {
  4806. break;
  4807. }
  4808. }
  4809. }
  4810. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4811. NSDictionary *internal = _dictionary;
  4812. NSUInteger count = internal.count;
  4813. if (count == 0) {
  4814. return 0;
  4815. }
  4816. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4817. GPBDataType keyDataType = field.mapKeyDataType;
  4818. size_t result = 0;
  4819. NSEnumerator *keys = [internal keyEnumerator];
  4820. NSNumber *aKey;
  4821. while ((aKey = [keys nextObject])) {
  4822. NSNumber *aValue = internal[aKey];
  4823. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4824. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  4825. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4826. }
  4827. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4828. result += tagSize * count;
  4829. return result;
  4830. }
  4831. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4832. asField:(GPBFieldDescriptor *)field {
  4833. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4834. GPBDataType keyDataType = field.mapKeyDataType;
  4835. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4836. NSDictionary *internal = _dictionary;
  4837. NSEnumerator *keys = [internal keyEnumerator];
  4838. NSNumber *aKey;
  4839. while ((aKey = [keys nextObject])) {
  4840. NSNumber *aValue = internal[aKey];
  4841. [outputStream writeInt32NoTag:tag];
  4842. // Write the size of the message.
  4843. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4844. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  4845. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4846. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4847. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4848. // Write the fields.
  4849. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4850. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4851. }
  4852. }
  4853. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4854. forGPBGenericValueKey:(GPBGenericValue *)key {
  4855. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
  4856. }
  4857. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4858. [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
  4859. #pragma unused(stop)
  4860. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
  4861. }];
  4862. }
  4863. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
  4864. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4865. if (wrapped && value) {
  4866. *value = [wrapped unsignedLongLongValue];
  4867. }
  4868. return (wrapped != NULL);
  4869. }
  4870. - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
  4871. if (otherDictionary) {
  4872. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4873. if (_autocreator) {
  4874. GPBAutocreatedDictionaryModified(_autocreator, self);
  4875. }
  4876. }
  4877. }
  4878. - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
  4879. [_dictionary setObject:@(value) forKey:@(key)];
  4880. if (_autocreator) {
  4881. GPBAutocreatedDictionaryModified(_autocreator, self);
  4882. }
  4883. }
  4884. - (void)removeUInt64ForKey:(uint64_t)aKey {
  4885. [_dictionary removeObjectForKey:@(aKey)];
  4886. }
  4887. - (void)removeAll {
  4888. [_dictionary removeAllObjects];
  4889. }
  4890. @end
  4891. #pragma mark - UInt64 -> Int64
  4892. @implementation GPBUInt64Int64Dictionary {
  4893. @package
  4894. NSMutableDictionary *_dictionary;
  4895. }
  4896. - (instancetype)init {
  4897. return [self initWithInt64s:NULL forKeys:NULL count:0];
  4898. }
  4899. - (instancetype)initWithInt64s:(const int64_t [])values
  4900. forKeys:(const uint64_t [])keys
  4901. count:(NSUInteger)count {
  4902. self = [super init];
  4903. if (self) {
  4904. _dictionary = [[NSMutableDictionary alloc] init];
  4905. if (count && values && keys) {
  4906. for (NSUInteger i = 0; i < count; ++i) {
  4907. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4908. }
  4909. }
  4910. }
  4911. return self;
  4912. }
  4913. - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
  4914. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  4915. if (self) {
  4916. if (dictionary) {
  4917. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4918. }
  4919. }
  4920. return self;
  4921. }
  4922. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4923. #pragma unused(numItems)
  4924. return [self initWithInt64s:NULL forKeys:NULL count:0];
  4925. }
  4926. - (void)dealloc {
  4927. NSAssert(!_autocreator,
  4928. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4929. [self class], _autocreator);
  4930. [_dictionary release];
  4931. [super dealloc];
  4932. }
  4933. - (instancetype)copyWithZone:(NSZone *)zone {
  4934. return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  4935. }
  4936. - (BOOL)isEqual:(id)other {
  4937. if (self == other) {
  4938. return YES;
  4939. }
  4940. if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
  4941. return NO;
  4942. }
  4943. GPBUInt64Int64Dictionary *otherDictionary = other;
  4944. return [_dictionary isEqual:otherDictionary->_dictionary];
  4945. }
  4946. - (NSUInteger)hash {
  4947. return _dictionary.count;
  4948. }
  4949. - (NSString *)description {
  4950. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4951. }
  4952. - (NSUInteger)count {
  4953. return _dictionary.count;
  4954. }
  4955. - (void)enumerateKeysAndInt64sUsingBlock:
  4956. (void (^)(uint64_t key, int64_t value, BOOL *stop))block {
  4957. BOOL stop = NO;
  4958. NSDictionary *internal = _dictionary;
  4959. NSEnumerator *keys = [internal keyEnumerator];
  4960. NSNumber *aKey;
  4961. while ((aKey = [keys nextObject])) {
  4962. NSNumber *aValue = internal[aKey];
  4963. block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
  4964. if (stop) {
  4965. break;
  4966. }
  4967. }
  4968. }
  4969. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4970. NSDictionary *internal = _dictionary;
  4971. NSUInteger count = internal.count;
  4972. if (count == 0) {
  4973. return 0;
  4974. }
  4975. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4976. GPBDataType keyDataType = field.mapKeyDataType;
  4977. size_t result = 0;
  4978. NSEnumerator *keys = [internal keyEnumerator];
  4979. NSNumber *aKey;
  4980. while ((aKey = [keys nextObject])) {
  4981. NSNumber *aValue = internal[aKey];
  4982. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4983. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  4984. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4985. }
  4986. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4987. result += tagSize * count;
  4988. return result;
  4989. }
  4990. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4991. asField:(GPBFieldDescriptor *)field {
  4992. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4993. GPBDataType keyDataType = field.mapKeyDataType;
  4994. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4995. NSDictionary *internal = _dictionary;
  4996. NSEnumerator *keys = [internal keyEnumerator];
  4997. NSNumber *aKey;
  4998. while ((aKey = [keys nextObject])) {
  4999. NSNumber *aValue = internal[aKey];
  5000. [outputStream writeInt32NoTag:tag];
  5001. // Write the size of the message.
  5002. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5003. int64_t unwrappedValue = [aValue longLongValue];
  5004. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5005. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5006. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5007. // Write the fields.
  5008. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5009. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5010. }
  5011. }
  5012. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5013. forGPBGenericValueKey:(GPBGenericValue *)key {
  5014. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
  5015. }
  5016. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5017. [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
  5018. #pragma unused(stop)
  5019. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
  5020. }];
  5021. }
  5022. - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
  5023. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5024. if (wrapped && value) {
  5025. *value = [wrapped longLongValue];
  5026. }
  5027. return (wrapped != NULL);
  5028. }
  5029. - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
  5030. if (otherDictionary) {
  5031. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5032. if (_autocreator) {
  5033. GPBAutocreatedDictionaryModified(_autocreator, self);
  5034. }
  5035. }
  5036. }
  5037. - (void)setInt64:(int64_t)value forKey:(uint64_t)key {
  5038. [_dictionary setObject:@(value) forKey:@(key)];
  5039. if (_autocreator) {
  5040. GPBAutocreatedDictionaryModified(_autocreator, self);
  5041. }
  5042. }
  5043. - (void)removeInt64ForKey:(uint64_t)aKey {
  5044. [_dictionary removeObjectForKey:@(aKey)];
  5045. }
  5046. - (void)removeAll {
  5047. [_dictionary removeAllObjects];
  5048. }
  5049. @end
  5050. #pragma mark - UInt64 -> Bool
  5051. @implementation GPBUInt64BoolDictionary {
  5052. @package
  5053. NSMutableDictionary *_dictionary;
  5054. }
  5055. - (instancetype)init {
  5056. return [self initWithBools:NULL forKeys:NULL count:0];
  5057. }
  5058. - (instancetype)initWithBools:(const BOOL [])values
  5059. forKeys:(const uint64_t [])keys
  5060. count:(NSUInteger)count {
  5061. self = [super init];
  5062. if (self) {
  5063. _dictionary = [[NSMutableDictionary alloc] init];
  5064. if (count && values && keys) {
  5065. for (NSUInteger i = 0; i < count; ++i) {
  5066. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5067. }
  5068. }
  5069. }
  5070. return self;
  5071. }
  5072. - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
  5073. self = [self initWithBools:NULL forKeys:NULL count:0];
  5074. if (self) {
  5075. if (dictionary) {
  5076. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5077. }
  5078. }
  5079. return self;
  5080. }
  5081. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5082. #pragma unused(numItems)
  5083. return [self initWithBools:NULL forKeys:NULL count:0];
  5084. }
  5085. - (void)dealloc {
  5086. NSAssert(!_autocreator,
  5087. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5088. [self class], _autocreator);
  5089. [_dictionary release];
  5090. [super dealloc];
  5091. }
  5092. - (instancetype)copyWithZone:(NSZone *)zone {
  5093. return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
  5094. }
  5095. - (BOOL)isEqual:(id)other {
  5096. if (self == other) {
  5097. return YES;
  5098. }
  5099. if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
  5100. return NO;
  5101. }
  5102. GPBUInt64BoolDictionary *otherDictionary = other;
  5103. return [_dictionary isEqual:otherDictionary->_dictionary];
  5104. }
  5105. - (NSUInteger)hash {
  5106. return _dictionary.count;
  5107. }
  5108. - (NSString *)description {
  5109. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5110. }
  5111. - (NSUInteger)count {
  5112. return _dictionary.count;
  5113. }
  5114. - (void)enumerateKeysAndBoolsUsingBlock:
  5115. (void (^)(uint64_t key, BOOL value, BOOL *stop))block {
  5116. BOOL stop = NO;
  5117. NSDictionary *internal = _dictionary;
  5118. NSEnumerator *keys = [internal keyEnumerator];
  5119. NSNumber *aKey;
  5120. while ((aKey = [keys nextObject])) {
  5121. NSNumber *aValue = internal[aKey];
  5122. block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
  5123. if (stop) {
  5124. break;
  5125. }
  5126. }
  5127. }
  5128. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5129. NSDictionary *internal = _dictionary;
  5130. NSUInteger count = internal.count;
  5131. if (count == 0) {
  5132. return 0;
  5133. }
  5134. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5135. GPBDataType keyDataType = field.mapKeyDataType;
  5136. size_t result = 0;
  5137. NSEnumerator *keys = [internal keyEnumerator];
  5138. NSNumber *aKey;
  5139. while ((aKey = [keys nextObject])) {
  5140. NSNumber *aValue = internal[aKey];
  5141. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5142. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  5143. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5144. }
  5145. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5146. result += tagSize * count;
  5147. return result;
  5148. }
  5149. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5150. asField:(GPBFieldDescriptor *)field {
  5151. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5152. GPBDataType keyDataType = field.mapKeyDataType;
  5153. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5154. NSDictionary *internal = _dictionary;
  5155. NSEnumerator *keys = [internal keyEnumerator];
  5156. NSNumber *aKey;
  5157. while ((aKey = [keys nextObject])) {
  5158. NSNumber *aValue = internal[aKey];
  5159. [outputStream writeInt32NoTag:tag];
  5160. // Write the size of the message.
  5161. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5162. BOOL unwrappedValue = [aValue boolValue];
  5163. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5164. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5165. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5166. // Write the fields.
  5167. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5168. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5169. }
  5170. }
  5171. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5172. forGPBGenericValueKey:(GPBGenericValue *)key {
  5173. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
  5174. }
  5175. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5176. [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
  5177. #pragma unused(stop)
  5178. block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
  5179. }];
  5180. }
  5181. - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
  5182. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5183. if (wrapped && value) {
  5184. *value = [wrapped boolValue];
  5185. }
  5186. return (wrapped != NULL);
  5187. }
  5188. - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
  5189. if (otherDictionary) {
  5190. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5191. if (_autocreator) {
  5192. GPBAutocreatedDictionaryModified(_autocreator, self);
  5193. }
  5194. }
  5195. }
  5196. - (void)setBool:(BOOL)value forKey:(uint64_t)key {
  5197. [_dictionary setObject:@(value) forKey:@(key)];
  5198. if (_autocreator) {
  5199. GPBAutocreatedDictionaryModified(_autocreator, self);
  5200. }
  5201. }
  5202. - (void)removeBoolForKey:(uint64_t)aKey {
  5203. [_dictionary removeObjectForKey:@(aKey)];
  5204. }
  5205. - (void)removeAll {
  5206. [_dictionary removeAllObjects];
  5207. }
  5208. @end
  5209. #pragma mark - UInt64 -> Float
  5210. @implementation GPBUInt64FloatDictionary {
  5211. @package
  5212. NSMutableDictionary *_dictionary;
  5213. }
  5214. - (instancetype)init {
  5215. return [self initWithFloats:NULL forKeys:NULL count:0];
  5216. }
  5217. - (instancetype)initWithFloats:(const float [])values
  5218. forKeys:(const uint64_t [])keys
  5219. count:(NSUInteger)count {
  5220. self = [super init];
  5221. if (self) {
  5222. _dictionary = [[NSMutableDictionary alloc] init];
  5223. if (count && values && keys) {
  5224. for (NSUInteger i = 0; i < count; ++i) {
  5225. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5226. }
  5227. }
  5228. }
  5229. return self;
  5230. }
  5231. - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
  5232. self = [self initWithFloats:NULL forKeys:NULL count:0];
  5233. if (self) {
  5234. if (dictionary) {
  5235. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5236. }
  5237. }
  5238. return self;
  5239. }
  5240. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5241. #pragma unused(numItems)
  5242. return [self initWithFloats:NULL forKeys:NULL count:0];
  5243. }
  5244. - (void)dealloc {
  5245. NSAssert(!_autocreator,
  5246. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5247. [self class], _autocreator);
  5248. [_dictionary release];
  5249. [super dealloc];
  5250. }
  5251. - (instancetype)copyWithZone:(NSZone *)zone {
  5252. return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
  5253. }
  5254. - (BOOL)isEqual:(id)other {
  5255. if (self == other) {
  5256. return YES;
  5257. }
  5258. if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
  5259. return NO;
  5260. }
  5261. GPBUInt64FloatDictionary *otherDictionary = other;
  5262. return [_dictionary isEqual:otherDictionary->_dictionary];
  5263. }
  5264. - (NSUInteger)hash {
  5265. return _dictionary.count;
  5266. }
  5267. - (NSString *)description {
  5268. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5269. }
  5270. - (NSUInteger)count {
  5271. return _dictionary.count;
  5272. }
  5273. - (void)enumerateKeysAndFloatsUsingBlock:
  5274. (void (^)(uint64_t key, float value, BOOL *stop))block {
  5275. BOOL stop = NO;
  5276. NSDictionary *internal = _dictionary;
  5277. NSEnumerator *keys = [internal keyEnumerator];
  5278. NSNumber *aKey;
  5279. while ((aKey = [keys nextObject])) {
  5280. NSNumber *aValue = internal[aKey];
  5281. block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
  5282. if (stop) {
  5283. break;
  5284. }
  5285. }
  5286. }
  5287. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5288. NSDictionary *internal = _dictionary;
  5289. NSUInteger count = internal.count;
  5290. if (count == 0) {
  5291. return 0;
  5292. }
  5293. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5294. GPBDataType keyDataType = field.mapKeyDataType;
  5295. size_t result = 0;
  5296. NSEnumerator *keys = [internal keyEnumerator];
  5297. NSNumber *aKey;
  5298. while ((aKey = [keys nextObject])) {
  5299. NSNumber *aValue = internal[aKey];
  5300. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5301. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  5302. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5303. }
  5304. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5305. result += tagSize * count;
  5306. return result;
  5307. }
  5308. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5309. asField:(GPBFieldDescriptor *)field {
  5310. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5311. GPBDataType keyDataType = field.mapKeyDataType;
  5312. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5313. NSDictionary *internal = _dictionary;
  5314. NSEnumerator *keys = [internal keyEnumerator];
  5315. NSNumber *aKey;
  5316. while ((aKey = [keys nextObject])) {
  5317. NSNumber *aValue = internal[aKey];
  5318. [outputStream writeInt32NoTag:tag];
  5319. // Write the size of the message.
  5320. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5321. float unwrappedValue = [aValue floatValue];
  5322. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5323. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5324. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5325. // Write the fields.
  5326. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5327. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5328. }
  5329. }
  5330. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5331. forGPBGenericValueKey:(GPBGenericValue *)key {
  5332. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
  5333. }
  5334. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5335. [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
  5336. #pragma unused(stop)
  5337. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  5338. }];
  5339. }
  5340. - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
  5341. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5342. if (wrapped && value) {
  5343. *value = [wrapped floatValue];
  5344. }
  5345. return (wrapped != NULL);
  5346. }
  5347. - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
  5348. if (otherDictionary) {
  5349. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5350. if (_autocreator) {
  5351. GPBAutocreatedDictionaryModified(_autocreator, self);
  5352. }
  5353. }
  5354. }
  5355. - (void)setFloat:(float)value forKey:(uint64_t)key {
  5356. [_dictionary setObject:@(value) forKey:@(key)];
  5357. if (_autocreator) {
  5358. GPBAutocreatedDictionaryModified(_autocreator, self);
  5359. }
  5360. }
  5361. - (void)removeFloatForKey:(uint64_t)aKey {
  5362. [_dictionary removeObjectForKey:@(aKey)];
  5363. }
  5364. - (void)removeAll {
  5365. [_dictionary removeAllObjects];
  5366. }
  5367. @end
  5368. #pragma mark - UInt64 -> Double
  5369. @implementation GPBUInt64DoubleDictionary {
  5370. @package
  5371. NSMutableDictionary *_dictionary;
  5372. }
  5373. - (instancetype)init {
  5374. return [self initWithDoubles:NULL forKeys:NULL count:0];
  5375. }
  5376. - (instancetype)initWithDoubles:(const double [])values
  5377. forKeys:(const uint64_t [])keys
  5378. count:(NSUInteger)count {
  5379. self = [super init];
  5380. if (self) {
  5381. _dictionary = [[NSMutableDictionary alloc] init];
  5382. if (count && values && keys) {
  5383. for (NSUInteger i = 0; i < count; ++i) {
  5384. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5385. }
  5386. }
  5387. }
  5388. return self;
  5389. }
  5390. - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
  5391. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  5392. if (self) {
  5393. if (dictionary) {
  5394. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5395. }
  5396. }
  5397. return self;
  5398. }
  5399. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5400. #pragma unused(numItems)
  5401. return [self initWithDoubles:NULL forKeys:NULL count:0];
  5402. }
  5403. - (void)dealloc {
  5404. NSAssert(!_autocreator,
  5405. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5406. [self class], _autocreator);
  5407. [_dictionary release];
  5408. [super dealloc];
  5409. }
  5410. - (instancetype)copyWithZone:(NSZone *)zone {
  5411. return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  5412. }
  5413. - (BOOL)isEqual:(id)other {
  5414. if (self == other) {
  5415. return YES;
  5416. }
  5417. if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
  5418. return NO;
  5419. }
  5420. GPBUInt64DoubleDictionary *otherDictionary = other;
  5421. return [_dictionary isEqual:otherDictionary->_dictionary];
  5422. }
  5423. - (NSUInteger)hash {
  5424. return _dictionary.count;
  5425. }
  5426. - (NSString *)description {
  5427. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5428. }
  5429. - (NSUInteger)count {
  5430. return _dictionary.count;
  5431. }
  5432. - (void)enumerateKeysAndDoublesUsingBlock:
  5433. (void (^)(uint64_t key, double value, BOOL *stop))block {
  5434. BOOL stop = NO;
  5435. NSDictionary *internal = _dictionary;
  5436. NSEnumerator *keys = [internal keyEnumerator];
  5437. NSNumber *aKey;
  5438. while ((aKey = [keys nextObject])) {
  5439. NSNumber *aValue = internal[aKey];
  5440. block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
  5441. if (stop) {
  5442. break;
  5443. }
  5444. }
  5445. }
  5446. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5447. NSDictionary *internal = _dictionary;
  5448. NSUInteger count = internal.count;
  5449. if (count == 0) {
  5450. return 0;
  5451. }
  5452. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5453. GPBDataType keyDataType = field.mapKeyDataType;
  5454. size_t result = 0;
  5455. NSEnumerator *keys = [internal keyEnumerator];
  5456. NSNumber *aKey;
  5457. while ((aKey = [keys nextObject])) {
  5458. NSNumber *aValue = internal[aKey];
  5459. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5460. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  5461. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5462. }
  5463. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5464. result += tagSize * count;
  5465. return result;
  5466. }
  5467. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5468. asField:(GPBFieldDescriptor *)field {
  5469. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5470. GPBDataType keyDataType = field.mapKeyDataType;
  5471. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5472. NSDictionary *internal = _dictionary;
  5473. NSEnumerator *keys = [internal keyEnumerator];
  5474. NSNumber *aKey;
  5475. while ((aKey = [keys nextObject])) {
  5476. NSNumber *aValue = internal[aKey];
  5477. [outputStream writeInt32NoTag:tag];
  5478. // Write the size of the message.
  5479. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5480. double unwrappedValue = [aValue doubleValue];
  5481. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5482. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5483. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5484. // Write the fields.
  5485. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5486. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5487. }
  5488. }
  5489. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5490. forGPBGenericValueKey:(GPBGenericValue *)key {
  5491. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
  5492. }
  5493. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5494. [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
  5495. #pragma unused(stop)
  5496. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  5497. }];
  5498. }
  5499. - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
  5500. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5501. if (wrapped && value) {
  5502. *value = [wrapped doubleValue];
  5503. }
  5504. return (wrapped != NULL);
  5505. }
  5506. - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
  5507. if (otherDictionary) {
  5508. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5509. if (_autocreator) {
  5510. GPBAutocreatedDictionaryModified(_autocreator, self);
  5511. }
  5512. }
  5513. }
  5514. - (void)setDouble:(double)value forKey:(uint64_t)key {
  5515. [_dictionary setObject:@(value) forKey:@(key)];
  5516. if (_autocreator) {
  5517. GPBAutocreatedDictionaryModified(_autocreator, self);
  5518. }
  5519. }
  5520. - (void)removeDoubleForKey:(uint64_t)aKey {
  5521. [_dictionary removeObjectForKey:@(aKey)];
  5522. }
  5523. - (void)removeAll {
  5524. [_dictionary removeAllObjects];
  5525. }
  5526. @end
  5527. #pragma mark - UInt64 -> Enum
  5528. @implementation GPBUInt64EnumDictionary {
  5529. @package
  5530. NSMutableDictionary *_dictionary;
  5531. GPBEnumValidationFunc _validationFunc;
  5532. }
  5533. @synthesize validationFunc = _validationFunc;
  5534. - (instancetype)init {
  5535. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  5536. }
  5537. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  5538. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  5539. }
  5540. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  5541. rawValues:(const int32_t [])rawValues
  5542. forKeys:(const uint64_t [])keys
  5543. count:(NSUInteger)count {
  5544. self = [super init];
  5545. if (self) {
  5546. _dictionary = [[NSMutableDictionary alloc] init];
  5547. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  5548. if (count && rawValues && keys) {
  5549. for (NSUInteger i = 0; i < count; ++i) {
  5550. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  5551. }
  5552. }
  5553. }
  5554. return self;
  5555. }
  5556. - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
  5557. self = [self initWithValidationFunction:dictionary.validationFunc
  5558. rawValues:NULL
  5559. forKeys:NULL
  5560. count:0];
  5561. if (self) {
  5562. if (dictionary) {
  5563. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5564. }
  5565. }
  5566. return self;
  5567. }
  5568. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  5569. capacity:(NSUInteger)numItems {
  5570. #pragma unused(numItems)
  5571. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  5572. }
  5573. - (void)dealloc {
  5574. NSAssert(!_autocreator,
  5575. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5576. [self class], _autocreator);
  5577. [_dictionary release];
  5578. [super dealloc];
  5579. }
  5580. - (instancetype)copyWithZone:(NSZone *)zone {
  5581. return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
  5582. }
  5583. - (BOOL)isEqual:(id)other {
  5584. if (self == other) {
  5585. return YES;
  5586. }
  5587. if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
  5588. return NO;
  5589. }
  5590. GPBUInt64EnumDictionary *otherDictionary = other;
  5591. return [_dictionary isEqual:otherDictionary->_dictionary];
  5592. }
  5593. - (NSUInteger)hash {
  5594. return _dictionary.count;
  5595. }
  5596. - (NSString *)description {
  5597. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5598. }
  5599. - (NSUInteger)count {
  5600. return _dictionary.count;
  5601. }
  5602. - (void)enumerateKeysAndRawValuesUsingBlock:
  5603. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  5604. BOOL stop = NO;
  5605. NSDictionary *internal = _dictionary;
  5606. NSEnumerator *keys = [internal keyEnumerator];
  5607. NSNumber *aKey;
  5608. while ((aKey = [keys nextObject])) {
  5609. NSNumber *aValue = internal[aKey];
  5610. block([aKey unsignedLongLongValue], [aValue intValue], &stop);
  5611. if (stop) {
  5612. break;
  5613. }
  5614. }
  5615. }
  5616. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5617. NSDictionary *internal = _dictionary;
  5618. NSUInteger count = internal.count;
  5619. if (count == 0) {
  5620. return 0;
  5621. }
  5622. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5623. GPBDataType keyDataType = field.mapKeyDataType;
  5624. size_t result = 0;
  5625. NSEnumerator *keys = [internal keyEnumerator];
  5626. NSNumber *aKey;
  5627. while ((aKey = [keys nextObject])) {
  5628. NSNumber *aValue = internal[aKey];
  5629. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5630. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  5631. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5632. }
  5633. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5634. result += tagSize * count;
  5635. return result;
  5636. }
  5637. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5638. asField:(GPBFieldDescriptor *)field {
  5639. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5640. GPBDataType keyDataType = field.mapKeyDataType;
  5641. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5642. NSDictionary *internal = _dictionary;
  5643. NSEnumerator *keys = [internal keyEnumerator];
  5644. NSNumber *aKey;
  5645. while ((aKey = [keys nextObject])) {
  5646. NSNumber *aValue = internal[aKey];
  5647. [outputStream writeInt32NoTag:tag];
  5648. // Write the size of the message.
  5649. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5650. int32_t unwrappedValue = [aValue intValue];
  5651. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5652. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5653. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5654. // Write the fields.
  5655. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5656. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5657. }
  5658. }
  5659. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  5660. forKey:(GPBGenericValue *)key
  5661. keyDataType:(GPBDataType)keyDataType {
  5662. size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
  5663. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  5664. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  5665. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  5666. WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
  5667. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  5668. [outputStream release];
  5669. return data;
  5670. }
  5671. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5672. forGPBGenericValueKey:(GPBGenericValue *)key {
  5673. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
  5674. }
  5675. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5676. [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
  5677. #pragma unused(stop)
  5678. block([NSString stringWithFormat:@"%llu", key], @(value));
  5679. }];
  5680. }
  5681. - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
  5682. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5683. if (wrapped && value) {
  5684. int32_t result = [wrapped intValue];
  5685. if (!_validationFunc(result)) {
  5686. result = kGPBUnrecognizedEnumeratorValue;
  5687. }
  5688. *value = result;
  5689. }
  5690. return (wrapped != NULL);
  5691. }
  5692. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
  5693. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5694. if (wrapped && rawValue) {
  5695. *rawValue = [wrapped intValue];
  5696. }
  5697. return (wrapped != NULL);
  5698. }
  5699. - (void)enumerateKeysAndEnumsUsingBlock:
  5700. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  5701. GPBEnumValidationFunc func = _validationFunc;
  5702. BOOL stop = NO;
  5703. NSEnumerator *keys = [_dictionary keyEnumerator];
  5704. NSNumber *aKey;
  5705. while ((aKey = [keys nextObject])) {
  5706. NSNumber *aValue = _dictionary[aKey];
  5707. int32_t unwrapped = [aValue intValue];
  5708. if (!func(unwrapped)) {
  5709. unwrapped = kGPBUnrecognizedEnumeratorValue;
  5710. }
  5711. block([aKey unsignedLongLongValue], unwrapped, &stop);
  5712. if (stop) {
  5713. break;
  5714. }
  5715. }
  5716. }
  5717. - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
  5718. if (otherDictionary) {
  5719. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5720. if (_autocreator) {
  5721. GPBAutocreatedDictionaryModified(_autocreator, self);
  5722. }
  5723. }
  5724. }
  5725. - (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
  5726. [_dictionary setObject:@(value) forKey:@(key)];
  5727. if (_autocreator) {
  5728. GPBAutocreatedDictionaryModified(_autocreator, self);
  5729. }
  5730. }
  5731. - (void)removeEnumForKey:(uint64_t)aKey {
  5732. [_dictionary removeObjectForKey:@(aKey)];
  5733. }
  5734. - (void)removeAll {
  5735. [_dictionary removeAllObjects];
  5736. }
  5737. - (void)setEnum:(int32_t)value forKey:(uint64_t)key {
  5738. if (!_validationFunc(value)) {
  5739. [NSException raise:NSInvalidArgumentException
  5740. format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
  5741. value];
  5742. }
  5743. [_dictionary setObject:@(value) forKey:@(key)];
  5744. if (_autocreator) {
  5745. GPBAutocreatedDictionaryModified(_autocreator, self);
  5746. }
  5747. }
  5748. @end
  5749. #pragma mark - UInt64 -> Object
  5750. @implementation GPBUInt64ObjectDictionary {
  5751. @package
  5752. NSMutableDictionary *_dictionary;
  5753. }
  5754. - (instancetype)init {
  5755. return [self initWithObjects:NULL forKeys:NULL count:0];
  5756. }
  5757. - (instancetype)initWithObjects:(const id [])objects
  5758. forKeys:(const uint64_t [])keys
  5759. count:(NSUInteger)count {
  5760. self = [super init];
  5761. if (self) {
  5762. _dictionary = [[NSMutableDictionary alloc] init];
  5763. if (count && objects && keys) {
  5764. for (NSUInteger i = 0; i < count; ++i) {
  5765. if (!objects[i]) {
  5766. [NSException raise:NSInvalidArgumentException
  5767. format:@"Attempting to add nil object to a Dictionary"];
  5768. }
  5769. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  5770. }
  5771. }
  5772. }
  5773. return self;
  5774. }
  5775. - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
  5776. self = [self initWithObjects:NULL forKeys:NULL count:0];
  5777. if (self) {
  5778. if (dictionary) {
  5779. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5780. }
  5781. }
  5782. return self;
  5783. }
  5784. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5785. #pragma unused(numItems)
  5786. return [self initWithObjects:NULL forKeys:NULL count:0];
  5787. }
  5788. - (void)dealloc {
  5789. NSAssert(!_autocreator,
  5790. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5791. [self class], _autocreator);
  5792. [_dictionary release];
  5793. [super dealloc];
  5794. }
  5795. - (instancetype)copyWithZone:(NSZone *)zone {
  5796. return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  5797. }
  5798. - (BOOL)isEqual:(id)other {
  5799. if (self == other) {
  5800. return YES;
  5801. }
  5802. if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
  5803. return NO;
  5804. }
  5805. GPBUInt64ObjectDictionary *otherDictionary = other;
  5806. return [_dictionary isEqual:otherDictionary->_dictionary];
  5807. }
  5808. - (NSUInteger)hash {
  5809. return _dictionary.count;
  5810. }
  5811. - (NSString *)description {
  5812. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5813. }
  5814. - (NSUInteger)count {
  5815. return _dictionary.count;
  5816. }
  5817. - (void)enumerateKeysAndObjectsUsingBlock:
  5818. (void (^)(uint64_t key, id object, BOOL *stop))block {
  5819. BOOL stop = NO;
  5820. NSDictionary *internal = _dictionary;
  5821. NSEnumerator *keys = [internal keyEnumerator];
  5822. NSNumber *aKey;
  5823. while ((aKey = [keys nextObject])) {
  5824. id aObject = internal[aKey];
  5825. block([aKey unsignedLongLongValue], aObject, &stop);
  5826. if (stop) {
  5827. break;
  5828. }
  5829. }
  5830. }
  5831. - (BOOL)isInitialized {
  5832. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  5833. if (!msg.initialized) {
  5834. return NO;
  5835. }
  5836. }
  5837. return YES;
  5838. }
  5839. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  5840. GPBUInt64ObjectDictionary *newDict =
  5841. [[GPBUInt64ObjectDictionary alloc] init];
  5842. NSEnumerator *keys = [_dictionary keyEnumerator];
  5843. id aKey;
  5844. NSMutableDictionary *internalDict = newDict->_dictionary;
  5845. while ((aKey = [keys nextObject])) {
  5846. GPBMessage *msg = _dictionary[aKey];
  5847. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  5848. [internalDict setObject:copiedMsg forKey:aKey];
  5849. [copiedMsg release];
  5850. }
  5851. return newDict;
  5852. }
  5853. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5854. NSDictionary *internal = _dictionary;
  5855. NSUInteger count = internal.count;
  5856. if (count == 0) {
  5857. return 0;
  5858. }
  5859. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5860. GPBDataType keyDataType = field.mapKeyDataType;
  5861. size_t result = 0;
  5862. NSEnumerator *keys = [internal keyEnumerator];
  5863. NSNumber *aKey;
  5864. while ((aKey = [keys nextObject])) {
  5865. id aObject = internal[aKey];
  5866. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5867. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  5868. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5869. }
  5870. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5871. result += tagSize * count;
  5872. return result;
  5873. }
  5874. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5875. asField:(GPBFieldDescriptor *)field {
  5876. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5877. GPBDataType keyDataType = field.mapKeyDataType;
  5878. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5879. NSDictionary *internal = _dictionary;
  5880. NSEnumerator *keys = [internal keyEnumerator];
  5881. NSNumber *aKey;
  5882. while ((aKey = [keys nextObject])) {
  5883. id aObject = internal[aKey];
  5884. [outputStream writeInt32NoTag:tag];
  5885. // Write the size of the message.
  5886. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5887. id unwrappedValue = aObject;
  5888. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5889. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5890. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5891. // Write the fields.
  5892. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5893. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5894. }
  5895. }
  5896. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5897. forGPBGenericValueKey:(GPBGenericValue *)key {
  5898. [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
  5899. }
  5900. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5901. [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
  5902. #pragma unused(stop)
  5903. block([NSString stringWithFormat:@"%llu", key], object);
  5904. }];
  5905. }
  5906. - (id)objectForKey:(uint64_t)key {
  5907. id result = [_dictionary objectForKey:@(key)];
  5908. return result;
  5909. }
  5910. - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
  5911. if (otherDictionary) {
  5912. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5913. if (_autocreator) {
  5914. GPBAutocreatedDictionaryModified(_autocreator, self);
  5915. }
  5916. }
  5917. }
  5918. - (void)setObject:(id)object forKey:(uint64_t)key {
  5919. if (!object) {
  5920. [NSException raise:NSInvalidArgumentException
  5921. format:@"Attempting to add nil object to a Dictionary"];
  5922. }
  5923. [_dictionary setObject:object forKey:@(key)];
  5924. if (_autocreator) {
  5925. GPBAutocreatedDictionaryModified(_autocreator, self);
  5926. }
  5927. }
  5928. - (void)removeObjectForKey:(uint64_t)aKey {
  5929. [_dictionary removeObjectForKey:@(aKey)];
  5930. }
  5931. - (void)removeAll {
  5932. [_dictionary removeAllObjects];
  5933. }
  5934. @end
  5935. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
  5936. // This block of code is generated, do not edit it directly.
  5937. #pragma mark - Int64 -> UInt32
  5938. @implementation GPBInt64UInt32Dictionary {
  5939. @package
  5940. NSMutableDictionary *_dictionary;
  5941. }
  5942. - (instancetype)init {
  5943. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  5944. }
  5945. - (instancetype)initWithUInt32s:(const uint32_t [])values
  5946. forKeys:(const int64_t [])keys
  5947. count:(NSUInteger)count {
  5948. self = [super init];
  5949. if (self) {
  5950. _dictionary = [[NSMutableDictionary alloc] init];
  5951. if (count && values && keys) {
  5952. for (NSUInteger i = 0; i < count; ++i) {
  5953. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5954. }
  5955. }
  5956. }
  5957. return self;
  5958. }
  5959. - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
  5960. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  5961. if (self) {
  5962. if (dictionary) {
  5963. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5964. }
  5965. }
  5966. return self;
  5967. }
  5968. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5969. #pragma unused(numItems)
  5970. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  5971. }
  5972. - (void)dealloc {
  5973. NSAssert(!_autocreator,
  5974. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5975. [self class], _autocreator);
  5976. [_dictionary release];
  5977. [super dealloc];
  5978. }
  5979. - (instancetype)copyWithZone:(NSZone *)zone {
  5980. return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  5981. }
  5982. - (BOOL)isEqual:(id)other {
  5983. if (self == other) {
  5984. return YES;
  5985. }
  5986. if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
  5987. return NO;
  5988. }
  5989. GPBInt64UInt32Dictionary *otherDictionary = other;
  5990. return [_dictionary isEqual:otherDictionary->_dictionary];
  5991. }
  5992. - (NSUInteger)hash {
  5993. return _dictionary.count;
  5994. }
  5995. - (NSString *)description {
  5996. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5997. }
  5998. - (NSUInteger)count {
  5999. return _dictionary.count;
  6000. }
  6001. - (void)enumerateKeysAndUInt32sUsingBlock:
  6002. (void (^)(int64_t key, uint32_t value, BOOL *stop))block {
  6003. BOOL stop = NO;
  6004. NSDictionary *internal = _dictionary;
  6005. NSEnumerator *keys = [internal keyEnumerator];
  6006. NSNumber *aKey;
  6007. while ((aKey = [keys nextObject])) {
  6008. NSNumber *aValue = internal[aKey];
  6009. block([aKey longLongValue], [aValue unsignedIntValue], &stop);
  6010. if (stop) {
  6011. break;
  6012. }
  6013. }
  6014. }
  6015. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6016. NSDictionary *internal = _dictionary;
  6017. NSUInteger count = internal.count;
  6018. if (count == 0) {
  6019. return 0;
  6020. }
  6021. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6022. GPBDataType keyDataType = field.mapKeyDataType;
  6023. size_t result = 0;
  6024. NSEnumerator *keys = [internal keyEnumerator];
  6025. NSNumber *aKey;
  6026. while ((aKey = [keys nextObject])) {
  6027. NSNumber *aValue = internal[aKey];
  6028. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6029. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  6030. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6031. }
  6032. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6033. result += tagSize * count;
  6034. return result;
  6035. }
  6036. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6037. asField:(GPBFieldDescriptor *)field {
  6038. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6039. GPBDataType keyDataType = field.mapKeyDataType;
  6040. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6041. NSDictionary *internal = _dictionary;
  6042. NSEnumerator *keys = [internal keyEnumerator];
  6043. NSNumber *aKey;
  6044. while ((aKey = [keys nextObject])) {
  6045. NSNumber *aValue = internal[aKey];
  6046. [outputStream writeInt32NoTag:tag];
  6047. // Write the size of the message.
  6048. int64_t unwrappedKey = [aKey longLongValue];
  6049. uint32_t unwrappedValue = [aValue unsignedIntValue];
  6050. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6051. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6052. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6053. // Write the fields.
  6054. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6055. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6056. }
  6057. }
  6058. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6059. forGPBGenericValueKey:(GPBGenericValue *)key {
  6060. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
  6061. }
  6062. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6063. [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
  6064. #pragma unused(stop)
  6065. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
  6066. }];
  6067. }
  6068. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
  6069. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6070. if (wrapped && value) {
  6071. *value = [wrapped unsignedIntValue];
  6072. }
  6073. return (wrapped != NULL);
  6074. }
  6075. - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
  6076. if (otherDictionary) {
  6077. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6078. if (_autocreator) {
  6079. GPBAutocreatedDictionaryModified(_autocreator, self);
  6080. }
  6081. }
  6082. }
  6083. - (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
  6084. [_dictionary setObject:@(value) forKey:@(key)];
  6085. if (_autocreator) {
  6086. GPBAutocreatedDictionaryModified(_autocreator, self);
  6087. }
  6088. }
  6089. - (void)removeUInt32ForKey:(int64_t)aKey {
  6090. [_dictionary removeObjectForKey:@(aKey)];
  6091. }
  6092. - (void)removeAll {
  6093. [_dictionary removeAllObjects];
  6094. }
  6095. @end
  6096. #pragma mark - Int64 -> Int32
  6097. @implementation GPBInt64Int32Dictionary {
  6098. @package
  6099. NSMutableDictionary *_dictionary;
  6100. }
  6101. - (instancetype)init {
  6102. return [self initWithInt32s:NULL forKeys:NULL count:0];
  6103. }
  6104. - (instancetype)initWithInt32s:(const int32_t [])values
  6105. forKeys:(const int64_t [])keys
  6106. count:(NSUInteger)count {
  6107. self = [super init];
  6108. if (self) {
  6109. _dictionary = [[NSMutableDictionary alloc] init];
  6110. if (count && values && keys) {
  6111. for (NSUInteger i = 0; i < count; ++i) {
  6112. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6113. }
  6114. }
  6115. }
  6116. return self;
  6117. }
  6118. - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
  6119. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  6120. if (self) {
  6121. if (dictionary) {
  6122. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6123. }
  6124. }
  6125. return self;
  6126. }
  6127. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6128. #pragma unused(numItems)
  6129. return [self initWithInt32s:NULL forKeys:NULL count:0];
  6130. }
  6131. - (void)dealloc {
  6132. NSAssert(!_autocreator,
  6133. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6134. [self class], _autocreator);
  6135. [_dictionary release];
  6136. [super dealloc];
  6137. }
  6138. - (instancetype)copyWithZone:(NSZone *)zone {
  6139. return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  6140. }
  6141. - (BOOL)isEqual:(id)other {
  6142. if (self == other) {
  6143. return YES;
  6144. }
  6145. if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
  6146. return NO;
  6147. }
  6148. GPBInt64Int32Dictionary *otherDictionary = other;
  6149. return [_dictionary isEqual:otherDictionary->_dictionary];
  6150. }
  6151. - (NSUInteger)hash {
  6152. return _dictionary.count;
  6153. }
  6154. - (NSString *)description {
  6155. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6156. }
  6157. - (NSUInteger)count {
  6158. return _dictionary.count;
  6159. }
  6160. - (void)enumerateKeysAndInt32sUsingBlock:
  6161. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  6162. BOOL stop = NO;
  6163. NSDictionary *internal = _dictionary;
  6164. NSEnumerator *keys = [internal keyEnumerator];
  6165. NSNumber *aKey;
  6166. while ((aKey = [keys nextObject])) {
  6167. NSNumber *aValue = internal[aKey];
  6168. block([aKey longLongValue], [aValue intValue], &stop);
  6169. if (stop) {
  6170. break;
  6171. }
  6172. }
  6173. }
  6174. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6175. NSDictionary *internal = _dictionary;
  6176. NSUInteger count = internal.count;
  6177. if (count == 0) {
  6178. return 0;
  6179. }
  6180. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6181. GPBDataType keyDataType = field.mapKeyDataType;
  6182. size_t result = 0;
  6183. NSEnumerator *keys = [internal keyEnumerator];
  6184. NSNumber *aKey;
  6185. while ((aKey = [keys nextObject])) {
  6186. NSNumber *aValue = internal[aKey];
  6187. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6188. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  6189. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6190. }
  6191. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6192. result += tagSize * count;
  6193. return result;
  6194. }
  6195. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6196. asField:(GPBFieldDescriptor *)field {
  6197. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6198. GPBDataType keyDataType = field.mapKeyDataType;
  6199. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6200. NSDictionary *internal = _dictionary;
  6201. NSEnumerator *keys = [internal keyEnumerator];
  6202. NSNumber *aKey;
  6203. while ((aKey = [keys nextObject])) {
  6204. NSNumber *aValue = internal[aKey];
  6205. [outputStream writeInt32NoTag:tag];
  6206. // Write the size of the message.
  6207. int64_t unwrappedKey = [aKey longLongValue];
  6208. int32_t unwrappedValue = [aValue intValue];
  6209. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6210. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6211. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6212. // Write the fields.
  6213. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6214. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6215. }
  6216. }
  6217. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6218. forGPBGenericValueKey:(GPBGenericValue *)key {
  6219. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
  6220. }
  6221. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6222. [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
  6223. #pragma unused(stop)
  6224. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
  6225. }];
  6226. }
  6227. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
  6228. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6229. if (wrapped && value) {
  6230. *value = [wrapped intValue];
  6231. }
  6232. return (wrapped != NULL);
  6233. }
  6234. - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
  6235. if (otherDictionary) {
  6236. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6237. if (_autocreator) {
  6238. GPBAutocreatedDictionaryModified(_autocreator, self);
  6239. }
  6240. }
  6241. }
  6242. - (void)setInt32:(int32_t)value forKey:(int64_t)key {
  6243. [_dictionary setObject:@(value) forKey:@(key)];
  6244. if (_autocreator) {
  6245. GPBAutocreatedDictionaryModified(_autocreator, self);
  6246. }
  6247. }
  6248. - (void)removeInt32ForKey:(int64_t)aKey {
  6249. [_dictionary removeObjectForKey:@(aKey)];
  6250. }
  6251. - (void)removeAll {
  6252. [_dictionary removeAllObjects];
  6253. }
  6254. @end
  6255. #pragma mark - Int64 -> UInt64
  6256. @implementation GPBInt64UInt64Dictionary {
  6257. @package
  6258. NSMutableDictionary *_dictionary;
  6259. }
  6260. - (instancetype)init {
  6261. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  6262. }
  6263. - (instancetype)initWithUInt64s:(const uint64_t [])values
  6264. forKeys:(const int64_t [])keys
  6265. count:(NSUInteger)count {
  6266. self = [super init];
  6267. if (self) {
  6268. _dictionary = [[NSMutableDictionary alloc] init];
  6269. if (count && values && keys) {
  6270. for (NSUInteger i = 0; i < count; ++i) {
  6271. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6272. }
  6273. }
  6274. }
  6275. return self;
  6276. }
  6277. - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
  6278. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  6279. if (self) {
  6280. if (dictionary) {
  6281. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6282. }
  6283. }
  6284. return self;
  6285. }
  6286. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6287. #pragma unused(numItems)
  6288. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  6289. }
  6290. - (void)dealloc {
  6291. NSAssert(!_autocreator,
  6292. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6293. [self class], _autocreator);
  6294. [_dictionary release];
  6295. [super dealloc];
  6296. }
  6297. - (instancetype)copyWithZone:(NSZone *)zone {
  6298. return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  6299. }
  6300. - (BOOL)isEqual:(id)other {
  6301. if (self == other) {
  6302. return YES;
  6303. }
  6304. if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
  6305. return NO;
  6306. }
  6307. GPBInt64UInt64Dictionary *otherDictionary = other;
  6308. return [_dictionary isEqual:otherDictionary->_dictionary];
  6309. }
  6310. - (NSUInteger)hash {
  6311. return _dictionary.count;
  6312. }
  6313. - (NSString *)description {
  6314. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6315. }
  6316. - (NSUInteger)count {
  6317. return _dictionary.count;
  6318. }
  6319. - (void)enumerateKeysAndUInt64sUsingBlock:
  6320. (void (^)(int64_t key, uint64_t value, BOOL *stop))block {
  6321. BOOL stop = NO;
  6322. NSDictionary *internal = _dictionary;
  6323. NSEnumerator *keys = [internal keyEnumerator];
  6324. NSNumber *aKey;
  6325. while ((aKey = [keys nextObject])) {
  6326. NSNumber *aValue = internal[aKey];
  6327. block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
  6328. if (stop) {
  6329. break;
  6330. }
  6331. }
  6332. }
  6333. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6334. NSDictionary *internal = _dictionary;
  6335. NSUInteger count = internal.count;
  6336. if (count == 0) {
  6337. return 0;
  6338. }
  6339. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6340. GPBDataType keyDataType = field.mapKeyDataType;
  6341. size_t result = 0;
  6342. NSEnumerator *keys = [internal keyEnumerator];
  6343. NSNumber *aKey;
  6344. while ((aKey = [keys nextObject])) {
  6345. NSNumber *aValue = internal[aKey];
  6346. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6347. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  6348. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6349. }
  6350. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6351. result += tagSize * count;
  6352. return result;
  6353. }
  6354. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6355. asField:(GPBFieldDescriptor *)field {
  6356. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6357. GPBDataType keyDataType = field.mapKeyDataType;
  6358. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6359. NSDictionary *internal = _dictionary;
  6360. NSEnumerator *keys = [internal keyEnumerator];
  6361. NSNumber *aKey;
  6362. while ((aKey = [keys nextObject])) {
  6363. NSNumber *aValue = internal[aKey];
  6364. [outputStream writeInt32NoTag:tag];
  6365. // Write the size of the message.
  6366. int64_t unwrappedKey = [aKey longLongValue];
  6367. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  6368. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6369. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6370. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6371. // Write the fields.
  6372. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6373. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6374. }
  6375. }
  6376. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6377. forGPBGenericValueKey:(GPBGenericValue *)key {
  6378. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
  6379. }
  6380. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6381. [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
  6382. #pragma unused(stop)
  6383. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
  6384. }];
  6385. }
  6386. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
  6387. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6388. if (wrapped && value) {
  6389. *value = [wrapped unsignedLongLongValue];
  6390. }
  6391. return (wrapped != NULL);
  6392. }
  6393. - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
  6394. if (otherDictionary) {
  6395. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6396. if (_autocreator) {
  6397. GPBAutocreatedDictionaryModified(_autocreator, self);
  6398. }
  6399. }
  6400. }
  6401. - (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
  6402. [_dictionary setObject:@(value) forKey:@(key)];
  6403. if (_autocreator) {
  6404. GPBAutocreatedDictionaryModified(_autocreator, self);
  6405. }
  6406. }
  6407. - (void)removeUInt64ForKey:(int64_t)aKey {
  6408. [_dictionary removeObjectForKey:@(aKey)];
  6409. }
  6410. - (void)removeAll {
  6411. [_dictionary removeAllObjects];
  6412. }
  6413. @end
  6414. #pragma mark - Int64 -> Int64
  6415. @implementation GPBInt64Int64Dictionary {
  6416. @package
  6417. NSMutableDictionary *_dictionary;
  6418. }
  6419. - (instancetype)init {
  6420. return [self initWithInt64s:NULL forKeys:NULL count:0];
  6421. }
  6422. - (instancetype)initWithInt64s:(const int64_t [])values
  6423. forKeys:(const int64_t [])keys
  6424. count:(NSUInteger)count {
  6425. self = [super init];
  6426. if (self) {
  6427. _dictionary = [[NSMutableDictionary alloc] init];
  6428. if (count && values && keys) {
  6429. for (NSUInteger i = 0; i < count; ++i) {
  6430. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6431. }
  6432. }
  6433. }
  6434. return self;
  6435. }
  6436. - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
  6437. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  6438. if (self) {
  6439. if (dictionary) {
  6440. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6441. }
  6442. }
  6443. return self;
  6444. }
  6445. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6446. #pragma unused(numItems)
  6447. return [self initWithInt64s:NULL forKeys:NULL count:0];
  6448. }
  6449. - (void)dealloc {
  6450. NSAssert(!_autocreator,
  6451. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6452. [self class], _autocreator);
  6453. [_dictionary release];
  6454. [super dealloc];
  6455. }
  6456. - (instancetype)copyWithZone:(NSZone *)zone {
  6457. return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  6458. }
  6459. - (BOOL)isEqual:(id)other {
  6460. if (self == other) {
  6461. return YES;
  6462. }
  6463. if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
  6464. return NO;
  6465. }
  6466. GPBInt64Int64Dictionary *otherDictionary = other;
  6467. return [_dictionary isEqual:otherDictionary->_dictionary];
  6468. }
  6469. - (NSUInteger)hash {
  6470. return _dictionary.count;
  6471. }
  6472. - (NSString *)description {
  6473. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6474. }
  6475. - (NSUInteger)count {
  6476. return _dictionary.count;
  6477. }
  6478. - (void)enumerateKeysAndInt64sUsingBlock:
  6479. (void (^)(int64_t key, int64_t value, BOOL *stop))block {
  6480. BOOL stop = NO;
  6481. NSDictionary *internal = _dictionary;
  6482. NSEnumerator *keys = [internal keyEnumerator];
  6483. NSNumber *aKey;
  6484. while ((aKey = [keys nextObject])) {
  6485. NSNumber *aValue = internal[aKey];
  6486. block([aKey longLongValue], [aValue longLongValue], &stop);
  6487. if (stop) {
  6488. break;
  6489. }
  6490. }
  6491. }
  6492. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6493. NSDictionary *internal = _dictionary;
  6494. NSUInteger count = internal.count;
  6495. if (count == 0) {
  6496. return 0;
  6497. }
  6498. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6499. GPBDataType keyDataType = field.mapKeyDataType;
  6500. size_t result = 0;
  6501. NSEnumerator *keys = [internal keyEnumerator];
  6502. NSNumber *aKey;
  6503. while ((aKey = [keys nextObject])) {
  6504. NSNumber *aValue = internal[aKey];
  6505. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6506. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  6507. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6508. }
  6509. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6510. result += tagSize * count;
  6511. return result;
  6512. }
  6513. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6514. asField:(GPBFieldDescriptor *)field {
  6515. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6516. GPBDataType keyDataType = field.mapKeyDataType;
  6517. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6518. NSDictionary *internal = _dictionary;
  6519. NSEnumerator *keys = [internal keyEnumerator];
  6520. NSNumber *aKey;
  6521. while ((aKey = [keys nextObject])) {
  6522. NSNumber *aValue = internal[aKey];
  6523. [outputStream writeInt32NoTag:tag];
  6524. // Write the size of the message.
  6525. int64_t unwrappedKey = [aKey longLongValue];
  6526. int64_t unwrappedValue = [aValue longLongValue];
  6527. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6528. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6529. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6530. // Write the fields.
  6531. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6532. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6533. }
  6534. }
  6535. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6536. forGPBGenericValueKey:(GPBGenericValue *)key {
  6537. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
  6538. }
  6539. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6540. [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
  6541. #pragma unused(stop)
  6542. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
  6543. }];
  6544. }
  6545. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
  6546. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6547. if (wrapped && value) {
  6548. *value = [wrapped longLongValue];
  6549. }
  6550. return (wrapped != NULL);
  6551. }
  6552. - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
  6553. if (otherDictionary) {
  6554. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6555. if (_autocreator) {
  6556. GPBAutocreatedDictionaryModified(_autocreator, self);
  6557. }
  6558. }
  6559. }
  6560. - (void)setInt64:(int64_t)value forKey:(int64_t)key {
  6561. [_dictionary setObject:@(value) forKey:@(key)];
  6562. if (_autocreator) {
  6563. GPBAutocreatedDictionaryModified(_autocreator, self);
  6564. }
  6565. }
  6566. - (void)removeInt64ForKey:(int64_t)aKey {
  6567. [_dictionary removeObjectForKey:@(aKey)];
  6568. }
  6569. - (void)removeAll {
  6570. [_dictionary removeAllObjects];
  6571. }
  6572. @end
  6573. #pragma mark - Int64 -> Bool
  6574. @implementation GPBInt64BoolDictionary {
  6575. @package
  6576. NSMutableDictionary *_dictionary;
  6577. }
  6578. - (instancetype)init {
  6579. return [self initWithBools:NULL forKeys:NULL count:0];
  6580. }
  6581. - (instancetype)initWithBools:(const BOOL [])values
  6582. forKeys:(const int64_t [])keys
  6583. count:(NSUInteger)count {
  6584. self = [super init];
  6585. if (self) {
  6586. _dictionary = [[NSMutableDictionary alloc] init];
  6587. if (count && values && keys) {
  6588. for (NSUInteger i = 0; i < count; ++i) {
  6589. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6590. }
  6591. }
  6592. }
  6593. return self;
  6594. }
  6595. - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
  6596. self = [self initWithBools:NULL forKeys:NULL count:0];
  6597. if (self) {
  6598. if (dictionary) {
  6599. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6600. }
  6601. }
  6602. return self;
  6603. }
  6604. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6605. #pragma unused(numItems)
  6606. return [self initWithBools:NULL forKeys:NULL count:0];
  6607. }
  6608. - (void)dealloc {
  6609. NSAssert(!_autocreator,
  6610. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6611. [self class], _autocreator);
  6612. [_dictionary release];
  6613. [super dealloc];
  6614. }
  6615. - (instancetype)copyWithZone:(NSZone *)zone {
  6616. return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
  6617. }
  6618. - (BOOL)isEqual:(id)other {
  6619. if (self == other) {
  6620. return YES;
  6621. }
  6622. if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
  6623. return NO;
  6624. }
  6625. GPBInt64BoolDictionary *otherDictionary = other;
  6626. return [_dictionary isEqual:otherDictionary->_dictionary];
  6627. }
  6628. - (NSUInteger)hash {
  6629. return _dictionary.count;
  6630. }
  6631. - (NSString *)description {
  6632. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6633. }
  6634. - (NSUInteger)count {
  6635. return _dictionary.count;
  6636. }
  6637. - (void)enumerateKeysAndBoolsUsingBlock:
  6638. (void (^)(int64_t key, BOOL value, BOOL *stop))block {
  6639. BOOL stop = NO;
  6640. NSDictionary *internal = _dictionary;
  6641. NSEnumerator *keys = [internal keyEnumerator];
  6642. NSNumber *aKey;
  6643. while ((aKey = [keys nextObject])) {
  6644. NSNumber *aValue = internal[aKey];
  6645. block([aKey longLongValue], [aValue boolValue], &stop);
  6646. if (stop) {
  6647. break;
  6648. }
  6649. }
  6650. }
  6651. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6652. NSDictionary *internal = _dictionary;
  6653. NSUInteger count = internal.count;
  6654. if (count == 0) {
  6655. return 0;
  6656. }
  6657. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6658. GPBDataType keyDataType = field.mapKeyDataType;
  6659. size_t result = 0;
  6660. NSEnumerator *keys = [internal keyEnumerator];
  6661. NSNumber *aKey;
  6662. while ((aKey = [keys nextObject])) {
  6663. NSNumber *aValue = internal[aKey];
  6664. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6665. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  6666. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6667. }
  6668. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6669. result += tagSize * count;
  6670. return result;
  6671. }
  6672. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6673. asField:(GPBFieldDescriptor *)field {
  6674. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6675. GPBDataType keyDataType = field.mapKeyDataType;
  6676. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6677. NSDictionary *internal = _dictionary;
  6678. NSEnumerator *keys = [internal keyEnumerator];
  6679. NSNumber *aKey;
  6680. while ((aKey = [keys nextObject])) {
  6681. NSNumber *aValue = internal[aKey];
  6682. [outputStream writeInt32NoTag:tag];
  6683. // Write the size of the message.
  6684. int64_t unwrappedKey = [aKey longLongValue];
  6685. BOOL unwrappedValue = [aValue boolValue];
  6686. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6687. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6688. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6689. // Write the fields.
  6690. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6691. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6692. }
  6693. }
  6694. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6695. forGPBGenericValueKey:(GPBGenericValue *)key {
  6696. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
  6697. }
  6698. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6699. [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
  6700. #pragma unused(stop)
  6701. block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
  6702. }];
  6703. }
  6704. - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
  6705. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6706. if (wrapped && value) {
  6707. *value = [wrapped boolValue];
  6708. }
  6709. return (wrapped != NULL);
  6710. }
  6711. - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
  6712. if (otherDictionary) {
  6713. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6714. if (_autocreator) {
  6715. GPBAutocreatedDictionaryModified(_autocreator, self);
  6716. }
  6717. }
  6718. }
  6719. - (void)setBool:(BOOL)value forKey:(int64_t)key {
  6720. [_dictionary setObject:@(value) forKey:@(key)];
  6721. if (_autocreator) {
  6722. GPBAutocreatedDictionaryModified(_autocreator, self);
  6723. }
  6724. }
  6725. - (void)removeBoolForKey:(int64_t)aKey {
  6726. [_dictionary removeObjectForKey:@(aKey)];
  6727. }
  6728. - (void)removeAll {
  6729. [_dictionary removeAllObjects];
  6730. }
  6731. @end
  6732. #pragma mark - Int64 -> Float
  6733. @implementation GPBInt64FloatDictionary {
  6734. @package
  6735. NSMutableDictionary *_dictionary;
  6736. }
  6737. - (instancetype)init {
  6738. return [self initWithFloats:NULL forKeys:NULL count:0];
  6739. }
  6740. - (instancetype)initWithFloats:(const float [])values
  6741. forKeys:(const int64_t [])keys
  6742. count:(NSUInteger)count {
  6743. self = [super init];
  6744. if (self) {
  6745. _dictionary = [[NSMutableDictionary alloc] init];
  6746. if (count && values && keys) {
  6747. for (NSUInteger i = 0; i < count; ++i) {
  6748. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6749. }
  6750. }
  6751. }
  6752. return self;
  6753. }
  6754. - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
  6755. self = [self initWithFloats:NULL forKeys:NULL count:0];
  6756. if (self) {
  6757. if (dictionary) {
  6758. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6759. }
  6760. }
  6761. return self;
  6762. }
  6763. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6764. #pragma unused(numItems)
  6765. return [self initWithFloats:NULL forKeys:NULL count:0];
  6766. }
  6767. - (void)dealloc {
  6768. NSAssert(!_autocreator,
  6769. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6770. [self class], _autocreator);
  6771. [_dictionary release];
  6772. [super dealloc];
  6773. }
  6774. - (instancetype)copyWithZone:(NSZone *)zone {
  6775. return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
  6776. }
  6777. - (BOOL)isEqual:(id)other {
  6778. if (self == other) {
  6779. return YES;
  6780. }
  6781. if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
  6782. return NO;
  6783. }
  6784. GPBInt64FloatDictionary *otherDictionary = other;
  6785. return [_dictionary isEqual:otherDictionary->_dictionary];
  6786. }
  6787. - (NSUInteger)hash {
  6788. return _dictionary.count;
  6789. }
  6790. - (NSString *)description {
  6791. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6792. }
  6793. - (NSUInteger)count {
  6794. return _dictionary.count;
  6795. }
  6796. - (void)enumerateKeysAndFloatsUsingBlock:
  6797. (void (^)(int64_t key, float value, BOOL *stop))block {
  6798. BOOL stop = NO;
  6799. NSDictionary *internal = _dictionary;
  6800. NSEnumerator *keys = [internal keyEnumerator];
  6801. NSNumber *aKey;
  6802. while ((aKey = [keys nextObject])) {
  6803. NSNumber *aValue = internal[aKey];
  6804. block([aKey longLongValue], [aValue floatValue], &stop);
  6805. if (stop) {
  6806. break;
  6807. }
  6808. }
  6809. }
  6810. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6811. NSDictionary *internal = _dictionary;
  6812. NSUInteger count = internal.count;
  6813. if (count == 0) {
  6814. return 0;
  6815. }
  6816. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6817. GPBDataType keyDataType = field.mapKeyDataType;
  6818. size_t result = 0;
  6819. NSEnumerator *keys = [internal keyEnumerator];
  6820. NSNumber *aKey;
  6821. while ((aKey = [keys nextObject])) {
  6822. NSNumber *aValue = internal[aKey];
  6823. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6824. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  6825. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6826. }
  6827. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6828. result += tagSize * count;
  6829. return result;
  6830. }
  6831. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6832. asField:(GPBFieldDescriptor *)field {
  6833. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6834. GPBDataType keyDataType = field.mapKeyDataType;
  6835. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6836. NSDictionary *internal = _dictionary;
  6837. NSEnumerator *keys = [internal keyEnumerator];
  6838. NSNumber *aKey;
  6839. while ((aKey = [keys nextObject])) {
  6840. NSNumber *aValue = internal[aKey];
  6841. [outputStream writeInt32NoTag:tag];
  6842. // Write the size of the message.
  6843. int64_t unwrappedKey = [aKey longLongValue];
  6844. float unwrappedValue = [aValue floatValue];
  6845. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6846. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6847. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6848. // Write the fields.
  6849. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6850. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6851. }
  6852. }
  6853. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6854. forGPBGenericValueKey:(GPBGenericValue *)key {
  6855. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
  6856. }
  6857. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6858. [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
  6859. #pragma unused(stop)
  6860. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  6861. }];
  6862. }
  6863. - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
  6864. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6865. if (wrapped && value) {
  6866. *value = [wrapped floatValue];
  6867. }
  6868. return (wrapped != NULL);
  6869. }
  6870. - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
  6871. if (otherDictionary) {
  6872. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6873. if (_autocreator) {
  6874. GPBAutocreatedDictionaryModified(_autocreator, self);
  6875. }
  6876. }
  6877. }
  6878. - (void)setFloat:(float)value forKey:(int64_t)key {
  6879. [_dictionary setObject:@(value) forKey:@(key)];
  6880. if (_autocreator) {
  6881. GPBAutocreatedDictionaryModified(_autocreator, self);
  6882. }
  6883. }
  6884. - (void)removeFloatForKey:(int64_t)aKey {
  6885. [_dictionary removeObjectForKey:@(aKey)];
  6886. }
  6887. - (void)removeAll {
  6888. [_dictionary removeAllObjects];
  6889. }
  6890. @end
  6891. #pragma mark - Int64 -> Double
  6892. @implementation GPBInt64DoubleDictionary {
  6893. @package
  6894. NSMutableDictionary *_dictionary;
  6895. }
  6896. - (instancetype)init {
  6897. return [self initWithDoubles:NULL forKeys:NULL count:0];
  6898. }
  6899. - (instancetype)initWithDoubles:(const double [])values
  6900. forKeys:(const int64_t [])keys
  6901. count:(NSUInteger)count {
  6902. self = [super init];
  6903. if (self) {
  6904. _dictionary = [[NSMutableDictionary alloc] init];
  6905. if (count && values && keys) {
  6906. for (NSUInteger i = 0; i < count; ++i) {
  6907. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6908. }
  6909. }
  6910. }
  6911. return self;
  6912. }
  6913. - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
  6914. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  6915. if (self) {
  6916. if (dictionary) {
  6917. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6918. }
  6919. }
  6920. return self;
  6921. }
  6922. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6923. #pragma unused(numItems)
  6924. return [self initWithDoubles:NULL forKeys:NULL count:0];
  6925. }
  6926. - (void)dealloc {
  6927. NSAssert(!_autocreator,
  6928. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6929. [self class], _autocreator);
  6930. [_dictionary release];
  6931. [super dealloc];
  6932. }
  6933. - (instancetype)copyWithZone:(NSZone *)zone {
  6934. return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  6935. }
  6936. - (BOOL)isEqual:(id)other {
  6937. if (self == other) {
  6938. return YES;
  6939. }
  6940. if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
  6941. return NO;
  6942. }
  6943. GPBInt64DoubleDictionary *otherDictionary = other;
  6944. return [_dictionary isEqual:otherDictionary->_dictionary];
  6945. }
  6946. - (NSUInteger)hash {
  6947. return _dictionary.count;
  6948. }
  6949. - (NSString *)description {
  6950. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6951. }
  6952. - (NSUInteger)count {
  6953. return _dictionary.count;
  6954. }
  6955. - (void)enumerateKeysAndDoublesUsingBlock:
  6956. (void (^)(int64_t key, double value, BOOL *stop))block {
  6957. BOOL stop = NO;
  6958. NSDictionary *internal = _dictionary;
  6959. NSEnumerator *keys = [internal keyEnumerator];
  6960. NSNumber *aKey;
  6961. while ((aKey = [keys nextObject])) {
  6962. NSNumber *aValue = internal[aKey];
  6963. block([aKey longLongValue], [aValue doubleValue], &stop);
  6964. if (stop) {
  6965. break;
  6966. }
  6967. }
  6968. }
  6969. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6970. NSDictionary *internal = _dictionary;
  6971. NSUInteger count = internal.count;
  6972. if (count == 0) {
  6973. return 0;
  6974. }
  6975. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6976. GPBDataType keyDataType = field.mapKeyDataType;
  6977. size_t result = 0;
  6978. NSEnumerator *keys = [internal keyEnumerator];
  6979. NSNumber *aKey;
  6980. while ((aKey = [keys nextObject])) {
  6981. NSNumber *aValue = internal[aKey];
  6982. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6983. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  6984. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6985. }
  6986. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6987. result += tagSize * count;
  6988. return result;
  6989. }
  6990. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6991. asField:(GPBFieldDescriptor *)field {
  6992. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6993. GPBDataType keyDataType = field.mapKeyDataType;
  6994. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6995. NSDictionary *internal = _dictionary;
  6996. NSEnumerator *keys = [internal keyEnumerator];
  6997. NSNumber *aKey;
  6998. while ((aKey = [keys nextObject])) {
  6999. NSNumber *aValue = internal[aKey];
  7000. [outputStream writeInt32NoTag:tag];
  7001. // Write the size of the message.
  7002. int64_t unwrappedKey = [aKey longLongValue];
  7003. double unwrappedValue = [aValue doubleValue];
  7004. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7005. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7006. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7007. // Write the fields.
  7008. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7009. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7010. }
  7011. }
  7012. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7013. forGPBGenericValueKey:(GPBGenericValue *)key {
  7014. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
  7015. }
  7016. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7017. [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
  7018. #pragma unused(stop)
  7019. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  7020. }];
  7021. }
  7022. - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
  7023. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7024. if (wrapped && value) {
  7025. *value = [wrapped doubleValue];
  7026. }
  7027. return (wrapped != NULL);
  7028. }
  7029. - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
  7030. if (otherDictionary) {
  7031. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7032. if (_autocreator) {
  7033. GPBAutocreatedDictionaryModified(_autocreator, self);
  7034. }
  7035. }
  7036. }
  7037. - (void)setDouble:(double)value forKey:(int64_t)key {
  7038. [_dictionary setObject:@(value) forKey:@(key)];
  7039. if (_autocreator) {
  7040. GPBAutocreatedDictionaryModified(_autocreator, self);
  7041. }
  7042. }
  7043. - (void)removeDoubleForKey:(int64_t)aKey {
  7044. [_dictionary removeObjectForKey:@(aKey)];
  7045. }
  7046. - (void)removeAll {
  7047. [_dictionary removeAllObjects];
  7048. }
  7049. @end
  7050. #pragma mark - Int64 -> Enum
  7051. @implementation GPBInt64EnumDictionary {
  7052. @package
  7053. NSMutableDictionary *_dictionary;
  7054. GPBEnumValidationFunc _validationFunc;
  7055. }
  7056. @synthesize validationFunc = _validationFunc;
  7057. - (instancetype)init {
  7058. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  7059. }
  7060. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  7061. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  7062. }
  7063. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  7064. rawValues:(const int32_t [])rawValues
  7065. forKeys:(const int64_t [])keys
  7066. count:(NSUInteger)count {
  7067. self = [super init];
  7068. if (self) {
  7069. _dictionary = [[NSMutableDictionary alloc] init];
  7070. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  7071. if (count && rawValues && keys) {
  7072. for (NSUInteger i = 0; i < count; ++i) {
  7073. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  7074. }
  7075. }
  7076. }
  7077. return self;
  7078. }
  7079. - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
  7080. self = [self initWithValidationFunction:dictionary.validationFunc
  7081. rawValues:NULL
  7082. forKeys:NULL
  7083. count:0];
  7084. if (self) {
  7085. if (dictionary) {
  7086. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7087. }
  7088. }
  7089. return self;
  7090. }
  7091. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  7092. capacity:(NSUInteger)numItems {
  7093. #pragma unused(numItems)
  7094. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  7095. }
  7096. - (void)dealloc {
  7097. NSAssert(!_autocreator,
  7098. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7099. [self class], _autocreator);
  7100. [_dictionary release];
  7101. [super dealloc];
  7102. }
  7103. - (instancetype)copyWithZone:(NSZone *)zone {
  7104. return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
  7105. }
  7106. - (BOOL)isEqual:(id)other {
  7107. if (self == other) {
  7108. return YES;
  7109. }
  7110. if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
  7111. return NO;
  7112. }
  7113. GPBInt64EnumDictionary *otherDictionary = other;
  7114. return [_dictionary isEqual:otherDictionary->_dictionary];
  7115. }
  7116. - (NSUInteger)hash {
  7117. return _dictionary.count;
  7118. }
  7119. - (NSString *)description {
  7120. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7121. }
  7122. - (NSUInteger)count {
  7123. return _dictionary.count;
  7124. }
  7125. - (void)enumerateKeysAndRawValuesUsingBlock:
  7126. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  7127. BOOL stop = NO;
  7128. NSDictionary *internal = _dictionary;
  7129. NSEnumerator *keys = [internal keyEnumerator];
  7130. NSNumber *aKey;
  7131. while ((aKey = [keys nextObject])) {
  7132. NSNumber *aValue = internal[aKey];
  7133. block([aKey longLongValue], [aValue intValue], &stop);
  7134. if (stop) {
  7135. break;
  7136. }
  7137. }
  7138. }
  7139. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7140. NSDictionary *internal = _dictionary;
  7141. NSUInteger count = internal.count;
  7142. if (count == 0) {
  7143. return 0;
  7144. }
  7145. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7146. GPBDataType keyDataType = field.mapKeyDataType;
  7147. size_t result = 0;
  7148. NSEnumerator *keys = [internal keyEnumerator];
  7149. NSNumber *aKey;
  7150. while ((aKey = [keys nextObject])) {
  7151. NSNumber *aValue = internal[aKey];
  7152. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  7153. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  7154. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7155. }
  7156. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7157. result += tagSize * count;
  7158. return result;
  7159. }
  7160. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7161. asField:(GPBFieldDescriptor *)field {
  7162. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7163. GPBDataType keyDataType = field.mapKeyDataType;
  7164. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7165. NSDictionary *internal = _dictionary;
  7166. NSEnumerator *keys = [internal keyEnumerator];
  7167. NSNumber *aKey;
  7168. while ((aKey = [keys nextObject])) {
  7169. NSNumber *aValue = internal[aKey];
  7170. [outputStream writeInt32NoTag:tag];
  7171. // Write the size of the message.
  7172. int64_t unwrappedKey = [aKey longLongValue];
  7173. int32_t unwrappedValue = [aValue intValue];
  7174. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7175. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7176. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7177. // Write the fields.
  7178. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7179. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7180. }
  7181. }
  7182. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  7183. forKey:(GPBGenericValue *)key
  7184. keyDataType:(GPBDataType)keyDataType {
  7185. size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
  7186. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  7187. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  7188. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  7189. WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
  7190. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  7191. [outputStream release];
  7192. return data;
  7193. }
  7194. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7195. forGPBGenericValueKey:(GPBGenericValue *)key {
  7196. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
  7197. }
  7198. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7199. [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
  7200. #pragma unused(stop)
  7201. block([NSString stringWithFormat:@"%lld", key], @(value));
  7202. }];
  7203. }
  7204. - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
  7205. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7206. if (wrapped && value) {
  7207. int32_t result = [wrapped intValue];
  7208. if (!_validationFunc(result)) {
  7209. result = kGPBUnrecognizedEnumeratorValue;
  7210. }
  7211. *value = result;
  7212. }
  7213. return (wrapped != NULL);
  7214. }
  7215. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
  7216. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7217. if (wrapped && rawValue) {
  7218. *rawValue = [wrapped intValue];
  7219. }
  7220. return (wrapped != NULL);
  7221. }
  7222. - (void)enumerateKeysAndEnumsUsingBlock:
  7223. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  7224. GPBEnumValidationFunc func = _validationFunc;
  7225. BOOL stop = NO;
  7226. NSEnumerator *keys = [_dictionary keyEnumerator];
  7227. NSNumber *aKey;
  7228. while ((aKey = [keys nextObject])) {
  7229. NSNumber *aValue = _dictionary[aKey];
  7230. int32_t unwrapped = [aValue intValue];
  7231. if (!func(unwrapped)) {
  7232. unwrapped = kGPBUnrecognizedEnumeratorValue;
  7233. }
  7234. block([aKey longLongValue], unwrapped, &stop);
  7235. if (stop) {
  7236. break;
  7237. }
  7238. }
  7239. }
  7240. - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
  7241. if (otherDictionary) {
  7242. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7243. if (_autocreator) {
  7244. GPBAutocreatedDictionaryModified(_autocreator, self);
  7245. }
  7246. }
  7247. }
  7248. - (void)setRawValue:(int32_t)value forKey:(int64_t)key {
  7249. [_dictionary setObject:@(value) forKey:@(key)];
  7250. if (_autocreator) {
  7251. GPBAutocreatedDictionaryModified(_autocreator, self);
  7252. }
  7253. }
  7254. - (void)removeEnumForKey:(int64_t)aKey {
  7255. [_dictionary removeObjectForKey:@(aKey)];
  7256. }
  7257. - (void)removeAll {
  7258. [_dictionary removeAllObjects];
  7259. }
  7260. - (void)setEnum:(int32_t)value forKey:(int64_t)key {
  7261. if (!_validationFunc(value)) {
  7262. [NSException raise:NSInvalidArgumentException
  7263. format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
  7264. value];
  7265. }
  7266. [_dictionary setObject:@(value) forKey:@(key)];
  7267. if (_autocreator) {
  7268. GPBAutocreatedDictionaryModified(_autocreator, self);
  7269. }
  7270. }
  7271. @end
  7272. #pragma mark - Int64 -> Object
  7273. @implementation GPBInt64ObjectDictionary {
  7274. @package
  7275. NSMutableDictionary *_dictionary;
  7276. }
  7277. - (instancetype)init {
  7278. return [self initWithObjects:NULL forKeys:NULL count:0];
  7279. }
  7280. - (instancetype)initWithObjects:(const id [])objects
  7281. forKeys:(const int64_t [])keys
  7282. count:(NSUInteger)count {
  7283. self = [super init];
  7284. if (self) {
  7285. _dictionary = [[NSMutableDictionary alloc] init];
  7286. if (count && objects && keys) {
  7287. for (NSUInteger i = 0; i < count; ++i) {
  7288. if (!objects[i]) {
  7289. [NSException raise:NSInvalidArgumentException
  7290. format:@"Attempting to add nil object to a Dictionary"];
  7291. }
  7292. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  7293. }
  7294. }
  7295. }
  7296. return self;
  7297. }
  7298. - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
  7299. self = [self initWithObjects:NULL forKeys:NULL count:0];
  7300. if (self) {
  7301. if (dictionary) {
  7302. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7303. }
  7304. }
  7305. return self;
  7306. }
  7307. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7308. #pragma unused(numItems)
  7309. return [self initWithObjects:NULL forKeys:NULL count:0];
  7310. }
  7311. - (void)dealloc {
  7312. NSAssert(!_autocreator,
  7313. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7314. [self class], _autocreator);
  7315. [_dictionary release];
  7316. [super dealloc];
  7317. }
  7318. - (instancetype)copyWithZone:(NSZone *)zone {
  7319. return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  7320. }
  7321. - (BOOL)isEqual:(id)other {
  7322. if (self == other) {
  7323. return YES;
  7324. }
  7325. if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
  7326. return NO;
  7327. }
  7328. GPBInt64ObjectDictionary *otherDictionary = other;
  7329. return [_dictionary isEqual:otherDictionary->_dictionary];
  7330. }
  7331. - (NSUInteger)hash {
  7332. return _dictionary.count;
  7333. }
  7334. - (NSString *)description {
  7335. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7336. }
  7337. - (NSUInteger)count {
  7338. return _dictionary.count;
  7339. }
  7340. - (void)enumerateKeysAndObjectsUsingBlock:
  7341. (void (^)(int64_t key, id object, BOOL *stop))block {
  7342. BOOL stop = NO;
  7343. NSDictionary *internal = _dictionary;
  7344. NSEnumerator *keys = [internal keyEnumerator];
  7345. NSNumber *aKey;
  7346. while ((aKey = [keys nextObject])) {
  7347. id aObject = internal[aKey];
  7348. block([aKey longLongValue], aObject, &stop);
  7349. if (stop) {
  7350. break;
  7351. }
  7352. }
  7353. }
  7354. - (BOOL)isInitialized {
  7355. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  7356. if (!msg.initialized) {
  7357. return NO;
  7358. }
  7359. }
  7360. return YES;
  7361. }
  7362. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  7363. GPBInt64ObjectDictionary *newDict =
  7364. [[GPBInt64ObjectDictionary alloc] init];
  7365. NSEnumerator *keys = [_dictionary keyEnumerator];
  7366. id aKey;
  7367. NSMutableDictionary *internalDict = newDict->_dictionary;
  7368. while ((aKey = [keys nextObject])) {
  7369. GPBMessage *msg = _dictionary[aKey];
  7370. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  7371. [internalDict setObject:copiedMsg forKey:aKey];
  7372. [copiedMsg release];
  7373. }
  7374. return newDict;
  7375. }
  7376. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7377. NSDictionary *internal = _dictionary;
  7378. NSUInteger count = internal.count;
  7379. if (count == 0) {
  7380. return 0;
  7381. }
  7382. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7383. GPBDataType keyDataType = field.mapKeyDataType;
  7384. size_t result = 0;
  7385. NSEnumerator *keys = [internal keyEnumerator];
  7386. NSNumber *aKey;
  7387. while ((aKey = [keys nextObject])) {
  7388. id aObject = internal[aKey];
  7389. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  7390. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  7391. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7392. }
  7393. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7394. result += tagSize * count;
  7395. return result;
  7396. }
  7397. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7398. asField:(GPBFieldDescriptor *)field {
  7399. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7400. GPBDataType keyDataType = field.mapKeyDataType;
  7401. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7402. NSDictionary *internal = _dictionary;
  7403. NSEnumerator *keys = [internal keyEnumerator];
  7404. NSNumber *aKey;
  7405. while ((aKey = [keys nextObject])) {
  7406. id aObject = internal[aKey];
  7407. [outputStream writeInt32NoTag:tag];
  7408. // Write the size of the message.
  7409. int64_t unwrappedKey = [aKey longLongValue];
  7410. id unwrappedValue = aObject;
  7411. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7412. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7413. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7414. // Write the fields.
  7415. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7416. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7417. }
  7418. }
  7419. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7420. forGPBGenericValueKey:(GPBGenericValue *)key {
  7421. [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
  7422. }
  7423. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7424. [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
  7425. #pragma unused(stop)
  7426. block([NSString stringWithFormat:@"%lld", key], object);
  7427. }];
  7428. }
  7429. - (id)objectForKey:(int64_t)key {
  7430. id result = [_dictionary objectForKey:@(key)];
  7431. return result;
  7432. }
  7433. - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
  7434. if (otherDictionary) {
  7435. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7436. if (_autocreator) {
  7437. GPBAutocreatedDictionaryModified(_autocreator, self);
  7438. }
  7439. }
  7440. }
  7441. - (void)setObject:(id)object forKey:(int64_t)key {
  7442. if (!object) {
  7443. [NSException raise:NSInvalidArgumentException
  7444. format:@"Attempting to add nil object to a Dictionary"];
  7445. }
  7446. [_dictionary setObject:object forKey:@(key)];
  7447. if (_autocreator) {
  7448. GPBAutocreatedDictionaryModified(_autocreator, self);
  7449. }
  7450. }
  7451. - (void)removeObjectForKey:(int64_t)aKey {
  7452. [_dictionary removeObjectForKey:@(aKey)];
  7453. }
  7454. - (void)removeAll {
  7455. [_dictionary removeAllObjects];
  7456. }
  7457. @end
  7458. //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
  7459. // This block of code is generated, do not edit it directly.
  7460. #pragma mark - String -> UInt32
  7461. @implementation GPBStringUInt32Dictionary {
  7462. @package
  7463. NSMutableDictionary *_dictionary;
  7464. }
  7465. - (instancetype)init {
  7466. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  7467. }
  7468. - (instancetype)initWithUInt32s:(const uint32_t [])values
  7469. forKeys:(const NSString * [])keys
  7470. count:(NSUInteger)count {
  7471. self = [super init];
  7472. if (self) {
  7473. _dictionary = [[NSMutableDictionary alloc] init];
  7474. if (count && values && keys) {
  7475. for (NSUInteger i = 0; i < count; ++i) {
  7476. if (!keys[i]) {
  7477. [NSException raise:NSInvalidArgumentException
  7478. format:@"Attempting to add nil key to a Dictionary"];
  7479. }
  7480. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7481. }
  7482. }
  7483. }
  7484. return self;
  7485. }
  7486. - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
  7487. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  7488. if (self) {
  7489. if (dictionary) {
  7490. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7491. }
  7492. }
  7493. return self;
  7494. }
  7495. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7496. #pragma unused(numItems)
  7497. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  7498. }
  7499. - (void)dealloc {
  7500. NSAssert(!_autocreator,
  7501. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7502. [self class], _autocreator);
  7503. [_dictionary release];
  7504. [super dealloc];
  7505. }
  7506. - (instancetype)copyWithZone:(NSZone *)zone {
  7507. return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  7508. }
  7509. - (BOOL)isEqual:(id)other {
  7510. if (self == other) {
  7511. return YES;
  7512. }
  7513. if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
  7514. return NO;
  7515. }
  7516. GPBStringUInt32Dictionary *otherDictionary = other;
  7517. return [_dictionary isEqual:otherDictionary->_dictionary];
  7518. }
  7519. - (NSUInteger)hash {
  7520. return _dictionary.count;
  7521. }
  7522. - (NSString *)description {
  7523. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7524. }
  7525. - (NSUInteger)count {
  7526. return _dictionary.count;
  7527. }
  7528. - (void)enumerateKeysAndUInt32sUsingBlock:
  7529. (void (^)(NSString *key, uint32_t value, BOOL *stop))block {
  7530. BOOL stop = NO;
  7531. NSDictionary *internal = _dictionary;
  7532. NSEnumerator *keys = [internal keyEnumerator];
  7533. NSString *aKey;
  7534. while ((aKey = [keys nextObject])) {
  7535. NSNumber *aValue = internal[aKey];
  7536. block(aKey, [aValue unsignedIntValue], &stop);
  7537. if (stop) {
  7538. break;
  7539. }
  7540. }
  7541. }
  7542. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7543. NSDictionary *internal = _dictionary;
  7544. NSUInteger count = internal.count;
  7545. if (count == 0) {
  7546. return 0;
  7547. }
  7548. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7549. GPBDataType keyDataType = field.mapKeyDataType;
  7550. size_t result = 0;
  7551. NSEnumerator *keys = [internal keyEnumerator];
  7552. NSString *aKey;
  7553. while ((aKey = [keys nextObject])) {
  7554. NSNumber *aValue = internal[aKey];
  7555. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7556. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  7557. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7558. }
  7559. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7560. result += tagSize * count;
  7561. return result;
  7562. }
  7563. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7564. asField:(GPBFieldDescriptor *)field {
  7565. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7566. GPBDataType keyDataType = field.mapKeyDataType;
  7567. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7568. NSDictionary *internal = _dictionary;
  7569. NSEnumerator *keys = [internal keyEnumerator];
  7570. NSString *aKey;
  7571. while ((aKey = [keys nextObject])) {
  7572. NSNumber *aValue = internal[aKey];
  7573. [outputStream writeInt32NoTag:tag];
  7574. // Write the size of the message.
  7575. NSString *unwrappedKey = aKey;
  7576. uint32_t unwrappedValue = [aValue unsignedIntValue];
  7577. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7578. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7579. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7580. // Write the fields.
  7581. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7582. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7583. }
  7584. }
  7585. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7586. forGPBGenericValueKey:(GPBGenericValue *)key {
  7587. [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
  7588. }
  7589. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7590. [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
  7591. #pragma unused(stop)
  7592. block(key, [NSString stringWithFormat:@"%u", value]);
  7593. }];
  7594. }
  7595. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
  7596. NSNumber *wrapped = [_dictionary objectForKey:key];
  7597. if (wrapped && value) {
  7598. *value = [wrapped unsignedIntValue];
  7599. }
  7600. return (wrapped != NULL);
  7601. }
  7602. - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
  7603. if (otherDictionary) {
  7604. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7605. if (_autocreator) {
  7606. GPBAutocreatedDictionaryModified(_autocreator, self);
  7607. }
  7608. }
  7609. }
  7610. - (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
  7611. if (!key) {
  7612. [NSException raise:NSInvalidArgumentException
  7613. format:@"Attempting to add nil key to a Dictionary"];
  7614. }
  7615. [_dictionary setObject:@(value) forKey:key];
  7616. if (_autocreator) {
  7617. GPBAutocreatedDictionaryModified(_autocreator, self);
  7618. }
  7619. }
  7620. - (void)removeUInt32ForKey:(NSString *)aKey {
  7621. [_dictionary removeObjectForKey:aKey];
  7622. }
  7623. - (void)removeAll {
  7624. [_dictionary removeAllObjects];
  7625. }
  7626. @end
  7627. #pragma mark - String -> Int32
  7628. @implementation GPBStringInt32Dictionary {
  7629. @package
  7630. NSMutableDictionary *_dictionary;
  7631. }
  7632. - (instancetype)init {
  7633. return [self initWithInt32s:NULL forKeys:NULL count:0];
  7634. }
  7635. - (instancetype)initWithInt32s:(const int32_t [])values
  7636. forKeys:(const NSString * [])keys
  7637. count:(NSUInteger)count {
  7638. self = [super init];
  7639. if (self) {
  7640. _dictionary = [[NSMutableDictionary alloc] init];
  7641. if (count && values && keys) {
  7642. for (NSUInteger i = 0; i < count; ++i) {
  7643. if (!keys[i]) {
  7644. [NSException raise:NSInvalidArgumentException
  7645. format:@"Attempting to add nil key to a Dictionary"];
  7646. }
  7647. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7648. }
  7649. }
  7650. }
  7651. return self;
  7652. }
  7653. - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
  7654. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  7655. if (self) {
  7656. if (dictionary) {
  7657. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7658. }
  7659. }
  7660. return self;
  7661. }
  7662. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7663. #pragma unused(numItems)
  7664. return [self initWithInt32s:NULL forKeys:NULL count:0];
  7665. }
  7666. - (void)dealloc {
  7667. NSAssert(!_autocreator,
  7668. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7669. [self class], _autocreator);
  7670. [_dictionary release];
  7671. [super dealloc];
  7672. }
  7673. - (instancetype)copyWithZone:(NSZone *)zone {
  7674. return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  7675. }
  7676. - (BOOL)isEqual:(id)other {
  7677. if (self == other) {
  7678. return YES;
  7679. }
  7680. if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
  7681. return NO;
  7682. }
  7683. GPBStringInt32Dictionary *otherDictionary = other;
  7684. return [_dictionary isEqual:otherDictionary->_dictionary];
  7685. }
  7686. - (NSUInteger)hash {
  7687. return _dictionary.count;
  7688. }
  7689. - (NSString *)description {
  7690. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7691. }
  7692. - (NSUInteger)count {
  7693. return _dictionary.count;
  7694. }
  7695. - (void)enumerateKeysAndInt32sUsingBlock:
  7696. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  7697. BOOL stop = NO;
  7698. NSDictionary *internal = _dictionary;
  7699. NSEnumerator *keys = [internal keyEnumerator];
  7700. NSString *aKey;
  7701. while ((aKey = [keys nextObject])) {
  7702. NSNumber *aValue = internal[aKey];
  7703. block(aKey, [aValue intValue], &stop);
  7704. if (stop) {
  7705. break;
  7706. }
  7707. }
  7708. }
  7709. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7710. NSDictionary *internal = _dictionary;
  7711. NSUInteger count = internal.count;
  7712. if (count == 0) {
  7713. return 0;
  7714. }
  7715. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7716. GPBDataType keyDataType = field.mapKeyDataType;
  7717. size_t result = 0;
  7718. NSEnumerator *keys = [internal keyEnumerator];
  7719. NSString *aKey;
  7720. while ((aKey = [keys nextObject])) {
  7721. NSNumber *aValue = internal[aKey];
  7722. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7723. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  7724. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7725. }
  7726. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7727. result += tagSize * count;
  7728. return result;
  7729. }
  7730. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7731. asField:(GPBFieldDescriptor *)field {
  7732. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7733. GPBDataType keyDataType = field.mapKeyDataType;
  7734. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7735. NSDictionary *internal = _dictionary;
  7736. NSEnumerator *keys = [internal keyEnumerator];
  7737. NSString *aKey;
  7738. while ((aKey = [keys nextObject])) {
  7739. NSNumber *aValue = internal[aKey];
  7740. [outputStream writeInt32NoTag:tag];
  7741. // Write the size of the message.
  7742. NSString *unwrappedKey = aKey;
  7743. int32_t unwrappedValue = [aValue intValue];
  7744. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7745. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7746. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7747. // Write the fields.
  7748. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7749. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7750. }
  7751. }
  7752. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7753. forGPBGenericValueKey:(GPBGenericValue *)key {
  7754. [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
  7755. }
  7756. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7757. [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
  7758. #pragma unused(stop)
  7759. block(key, [NSString stringWithFormat:@"%d", value]);
  7760. }];
  7761. }
  7762. - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
  7763. NSNumber *wrapped = [_dictionary objectForKey:key];
  7764. if (wrapped && value) {
  7765. *value = [wrapped intValue];
  7766. }
  7767. return (wrapped != NULL);
  7768. }
  7769. - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
  7770. if (otherDictionary) {
  7771. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7772. if (_autocreator) {
  7773. GPBAutocreatedDictionaryModified(_autocreator, self);
  7774. }
  7775. }
  7776. }
  7777. - (void)setInt32:(int32_t)value forKey:(NSString *)key {
  7778. if (!key) {
  7779. [NSException raise:NSInvalidArgumentException
  7780. format:@"Attempting to add nil key to a Dictionary"];
  7781. }
  7782. [_dictionary setObject:@(value) forKey:key];
  7783. if (_autocreator) {
  7784. GPBAutocreatedDictionaryModified(_autocreator, self);
  7785. }
  7786. }
  7787. - (void)removeInt32ForKey:(NSString *)aKey {
  7788. [_dictionary removeObjectForKey:aKey];
  7789. }
  7790. - (void)removeAll {
  7791. [_dictionary removeAllObjects];
  7792. }
  7793. @end
  7794. #pragma mark - String -> UInt64
  7795. @implementation GPBStringUInt64Dictionary {
  7796. @package
  7797. NSMutableDictionary *_dictionary;
  7798. }
  7799. - (instancetype)init {
  7800. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  7801. }
  7802. - (instancetype)initWithUInt64s:(const uint64_t [])values
  7803. forKeys:(const NSString * [])keys
  7804. count:(NSUInteger)count {
  7805. self = [super init];
  7806. if (self) {
  7807. _dictionary = [[NSMutableDictionary alloc] init];
  7808. if (count && values && keys) {
  7809. for (NSUInteger i = 0; i < count; ++i) {
  7810. if (!keys[i]) {
  7811. [NSException raise:NSInvalidArgumentException
  7812. format:@"Attempting to add nil key to a Dictionary"];
  7813. }
  7814. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7815. }
  7816. }
  7817. }
  7818. return self;
  7819. }
  7820. - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
  7821. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  7822. if (self) {
  7823. if (dictionary) {
  7824. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7825. }
  7826. }
  7827. return self;
  7828. }
  7829. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7830. #pragma unused(numItems)
  7831. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  7832. }
  7833. - (void)dealloc {
  7834. NSAssert(!_autocreator,
  7835. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7836. [self class], _autocreator);
  7837. [_dictionary release];
  7838. [super dealloc];
  7839. }
  7840. - (instancetype)copyWithZone:(NSZone *)zone {
  7841. return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  7842. }
  7843. - (BOOL)isEqual:(id)other {
  7844. if (self == other) {
  7845. return YES;
  7846. }
  7847. if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
  7848. return NO;
  7849. }
  7850. GPBStringUInt64Dictionary *otherDictionary = other;
  7851. return [_dictionary isEqual:otherDictionary->_dictionary];
  7852. }
  7853. - (NSUInteger)hash {
  7854. return _dictionary.count;
  7855. }
  7856. - (NSString *)description {
  7857. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7858. }
  7859. - (NSUInteger)count {
  7860. return _dictionary.count;
  7861. }
  7862. - (void)enumerateKeysAndUInt64sUsingBlock:
  7863. (void (^)(NSString *key, uint64_t value, BOOL *stop))block {
  7864. BOOL stop = NO;
  7865. NSDictionary *internal = _dictionary;
  7866. NSEnumerator *keys = [internal keyEnumerator];
  7867. NSString *aKey;
  7868. while ((aKey = [keys nextObject])) {
  7869. NSNumber *aValue = internal[aKey];
  7870. block(aKey, [aValue unsignedLongLongValue], &stop);
  7871. if (stop) {
  7872. break;
  7873. }
  7874. }
  7875. }
  7876. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7877. NSDictionary *internal = _dictionary;
  7878. NSUInteger count = internal.count;
  7879. if (count == 0) {
  7880. return 0;
  7881. }
  7882. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7883. GPBDataType keyDataType = field.mapKeyDataType;
  7884. size_t result = 0;
  7885. NSEnumerator *keys = [internal keyEnumerator];
  7886. NSString *aKey;
  7887. while ((aKey = [keys nextObject])) {
  7888. NSNumber *aValue = internal[aKey];
  7889. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7890. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  7891. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7892. }
  7893. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7894. result += tagSize * count;
  7895. return result;
  7896. }
  7897. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7898. asField:(GPBFieldDescriptor *)field {
  7899. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7900. GPBDataType keyDataType = field.mapKeyDataType;
  7901. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7902. NSDictionary *internal = _dictionary;
  7903. NSEnumerator *keys = [internal keyEnumerator];
  7904. NSString *aKey;
  7905. while ((aKey = [keys nextObject])) {
  7906. NSNumber *aValue = internal[aKey];
  7907. [outputStream writeInt32NoTag:tag];
  7908. // Write the size of the message.
  7909. NSString *unwrappedKey = aKey;
  7910. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  7911. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7912. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7913. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7914. // Write the fields.
  7915. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7916. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7917. }
  7918. }
  7919. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7920. forGPBGenericValueKey:(GPBGenericValue *)key {
  7921. [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
  7922. }
  7923. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7924. [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
  7925. #pragma unused(stop)
  7926. block(key, [NSString stringWithFormat:@"%llu", value]);
  7927. }];
  7928. }
  7929. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
  7930. NSNumber *wrapped = [_dictionary objectForKey:key];
  7931. if (wrapped && value) {
  7932. *value = [wrapped unsignedLongLongValue];
  7933. }
  7934. return (wrapped != NULL);
  7935. }
  7936. - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
  7937. if (otherDictionary) {
  7938. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7939. if (_autocreator) {
  7940. GPBAutocreatedDictionaryModified(_autocreator, self);
  7941. }
  7942. }
  7943. }
  7944. - (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
  7945. if (!key) {
  7946. [NSException raise:NSInvalidArgumentException
  7947. format:@"Attempting to add nil key to a Dictionary"];
  7948. }
  7949. [_dictionary setObject:@(value) forKey:key];
  7950. if (_autocreator) {
  7951. GPBAutocreatedDictionaryModified(_autocreator, self);
  7952. }
  7953. }
  7954. - (void)removeUInt64ForKey:(NSString *)aKey {
  7955. [_dictionary removeObjectForKey:aKey];
  7956. }
  7957. - (void)removeAll {
  7958. [_dictionary removeAllObjects];
  7959. }
  7960. @end
  7961. #pragma mark - String -> Int64
  7962. @implementation GPBStringInt64Dictionary {
  7963. @package
  7964. NSMutableDictionary *_dictionary;
  7965. }
  7966. - (instancetype)init {
  7967. return [self initWithInt64s:NULL forKeys:NULL count:0];
  7968. }
  7969. - (instancetype)initWithInt64s:(const int64_t [])values
  7970. forKeys:(const NSString * [])keys
  7971. count:(NSUInteger)count {
  7972. self = [super init];
  7973. if (self) {
  7974. _dictionary = [[NSMutableDictionary alloc] init];
  7975. if (count && values && keys) {
  7976. for (NSUInteger i = 0; i < count; ++i) {
  7977. if (!keys[i]) {
  7978. [NSException raise:NSInvalidArgumentException
  7979. format:@"Attempting to add nil key to a Dictionary"];
  7980. }
  7981. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7982. }
  7983. }
  7984. }
  7985. return self;
  7986. }
  7987. - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
  7988. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  7989. if (self) {
  7990. if (dictionary) {
  7991. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7992. }
  7993. }
  7994. return self;
  7995. }
  7996. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7997. #pragma unused(numItems)
  7998. return [self initWithInt64s:NULL forKeys:NULL count:0];
  7999. }
  8000. - (void)dealloc {
  8001. NSAssert(!_autocreator,
  8002. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8003. [self class], _autocreator);
  8004. [_dictionary release];
  8005. [super dealloc];
  8006. }
  8007. - (instancetype)copyWithZone:(NSZone *)zone {
  8008. return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  8009. }
  8010. - (BOOL)isEqual:(id)other {
  8011. if (self == other) {
  8012. return YES;
  8013. }
  8014. if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
  8015. return NO;
  8016. }
  8017. GPBStringInt64Dictionary *otherDictionary = other;
  8018. return [_dictionary isEqual:otherDictionary->_dictionary];
  8019. }
  8020. - (NSUInteger)hash {
  8021. return _dictionary.count;
  8022. }
  8023. - (NSString *)description {
  8024. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8025. }
  8026. - (NSUInteger)count {
  8027. return _dictionary.count;
  8028. }
  8029. - (void)enumerateKeysAndInt64sUsingBlock:
  8030. (void (^)(NSString *key, int64_t value, BOOL *stop))block {
  8031. BOOL stop = NO;
  8032. NSDictionary *internal = _dictionary;
  8033. NSEnumerator *keys = [internal keyEnumerator];
  8034. NSString *aKey;
  8035. while ((aKey = [keys nextObject])) {
  8036. NSNumber *aValue = internal[aKey];
  8037. block(aKey, [aValue longLongValue], &stop);
  8038. if (stop) {
  8039. break;
  8040. }
  8041. }
  8042. }
  8043. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8044. NSDictionary *internal = _dictionary;
  8045. NSUInteger count = internal.count;
  8046. if (count == 0) {
  8047. return 0;
  8048. }
  8049. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8050. GPBDataType keyDataType = field.mapKeyDataType;
  8051. size_t result = 0;
  8052. NSEnumerator *keys = [internal keyEnumerator];
  8053. NSString *aKey;
  8054. while ((aKey = [keys nextObject])) {
  8055. NSNumber *aValue = internal[aKey];
  8056. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8057. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  8058. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8059. }
  8060. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8061. result += tagSize * count;
  8062. return result;
  8063. }
  8064. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8065. asField:(GPBFieldDescriptor *)field {
  8066. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8067. GPBDataType keyDataType = field.mapKeyDataType;
  8068. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8069. NSDictionary *internal = _dictionary;
  8070. NSEnumerator *keys = [internal keyEnumerator];
  8071. NSString *aKey;
  8072. while ((aKey = [keys nextObject])) {
  8073. NSNumber *aValue = internal[aKey];
  8074. [outputStream writeInt32NoTag:tag];
  8075. // Write the size of the message.
  8076. NSString *unwrappedKey = aKey;
  8077. int64_t unwrappedValue = [aValue longLongValue];
  8078. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8079. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8080. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8081. // Write the fields.
  8082. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8083. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8084. }
  8085. }
  8086. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8087. forGPBGenericValueKey:(GPBGenericValue *)key {
  8088. [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
  8089. }
  8090. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8091. [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
  8092. #pragma unused(stop)
  8093. block(key, [NSString stringWithFormat:@"%lld", value]);
  8094. }];
  8095. }
  8096. - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
  8097. NSNumber *wrapped = [_dictionary objectForKey:key];
  8098. if (wrapped && value) {
  8099. *value = [wrapped longLongValue];
  8100. }
  8101. return (wrapped != NULL);
  8102. }
  8103. - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
  8104. if (otherDictionary) {
  8105. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8106. if (_autocreator) {
  8107. GPBAutocreatedDictionaryModified(_autocreator, self);
  8108. }
  8109. }
  8110. }
  8111. - (void)setInt64:(int64_t)value forKey:(NSString *)key {
  8112. if (!key) {
  8113. [NSException raise:NSInvalidArgumentException
  8114. format:@"Attempting to add nil key to a Dictionary"];
  8115. }
  8116. [_dictionary setObject:@(value) forKey:key];
  8117. if (_autocreator) {
  8118. GPBAutocreatedDictionaryModified(_autocreator, self);
  8119. }
  8120. }
  8121. - (void)removeInt64ForKey:(NSString *)aKey {
  8122. [_dictionary removeObjectForKey:aKey];
  8123. }
  8124. - (void)removeAll {
  8125. [_dictionary removeAllObjects];
  8126. }
  8127. @end
  8128. #pragma mark - String -> Bool
  8129. @implementation GPBStringBoolDictionary {
  8130. @package
  8131. NSMutableDictionary *_dictionary;
  8132. }
  8133. - (instancetype)init {
  8134. return [self initWithBools:NULL forKeys:NULL count:0];
  8135. }
  8136. - (instancetype)initWithBools:(const BOOL [])values
  8137. forKeys:(const NSString * [])keys
  8138. count:(NSUInteger)count {
  8139. self = [super init];
  8140. if (self) {
  8141. _dictionary = [[NSMutableDictionary alloc] init];
  8142. if (count && values && keys) {
  8143. for (NSUInteger i = 0; i < count; ++i) {
  8144. if (!keys[i]) {
  8145. [NSException raise:NSInvalidArgumentException
  8146. format:@"Attempting to add nil key to a Dictionary"];
  8147. }
  8148. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8149. }
  8150. }
  8151. }
  8152. return self;
  8153. }
  8154. - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
  8155. self = [self initWithBools:NULL forKeys:NULL count:0];
  8156. if (self) {
  8157. if (dictionary) {
  8158. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8159. }
  8160. }
  8161. return self;
  8162. }
  8163. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8164. #pragma unused(numItems)
  8165. return [self initWithBools:NULL forKeys:NULL count:0];
  8166. }
  8167. - (void)dealloc {
  8168. NSAssert(!_autocreator,
  8169. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8170. [self class], _autocreator);
  8171. [_dictionary release];
  8172. [super dealloc];
  8173. }
  8174. - (instancetype)copyWithZone:(NSZone *)zone {
  8175. return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
  8176. }
  8177. - (BOOL)isEqual:(id)other {
  8178. if (self == other) {
  8179. return YES;
  8180. }
  8181. if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
  8182. return NO;
  8183. }
  8184. GPBStringBoolDictionary *otherDictionary = other;
  8185. return [_dictionary isEqual:otherDictionary->_dictionary];
  8186. }
  8187. - (NSUInteger)hash {
  8188. return _dictionary.count;
  8189. }
  8190. - (NSString *)description {
  8191. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8192. }
  8193. - (NSUInteger)count {
  8194. return _dictionary.count;
  8195. }
  8196. - (void)enumerateKeysAndBoolsUsingBlock:
  8197. (void (^)(NSString *key, BOOL value, BOOL *stop))block {
  8198. BOOL stop = NO;
  8199. NSDictionary *internal = _dictionary;
  8200. NSEnumerator *keys = [internal keyEnumerator];
  8201. NSString *aKey;
  8202. while ((aKey = [keys nextObject])) {
  8203. NSNumber *aValue = internal[aKey];
  8204. block(aKey, [aValue boolValue], &stop);
  8205. if (stop) {
  8206. break;
  8207. }
  8208. }
  8209. }
  8210. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8211. NSDictionary *internal = _dictionary;
  8212. NSUInteger count = internal.count;
  8213. if (count == 0) {
  8214. return 0;
  8215. }
  8216. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8217. GPBDataType keyDataType = field.mapKeyDataType;
  8218. size_t result = 0;
  8219. NSEnumerator *keys = [internal keyEnumerator];
  8220. NSString *aKey;
  8221. while ((aKey = [keys nextObject])) {
  8222. NSNumber *aValue = internal[aKey];
  8223. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8224. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  8225. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8226. }
  8227. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8228. result += tagSize * count;
  8229. return result;
  8230. }
  8231. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8232. asField:(GPBFieldDescriptor *)field {
  8233. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8234. GPBDataType keyDataType = field.mapKeyDataType;
  8235. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8236. NSDictionary *internal = _dictionary;
  8237. NSEnumerator *keys = [internal keyEnumerator];
  8238. NSString *aKey;
  8239. while ((aKey = [keys nextObject])) {
  8240. NSNumber *aValue = internal[aKey];
  8241. [outputStream writeInt32NoTag:tag];
  8242. // Write the size of the message.
  8243. NSString *unwrappedKey = aKey;
  8244. BOOL unwrappedValue = [aValue boolValue];
  8245. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8246. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8247. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8248. // Write the fields.
  8249. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8250. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8251. }
  8252. }
  8253. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8254. forGPBGenericValueKey:(GPBGenericValue *)key {
  8255. [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
  8256. }
  8257. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8258. [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
  8259. #pragma unused(stop)
  8260. block(key, (value ? @"true" : @"false"));
  8261. }];
  8262. }
  8263. - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
  8264. NSNumber *wrapped = [_dictionary objectForKey:key];
  8265. if (wrapped && value) {
  8266. *value = [wrapped boolValue];
  8267. }
  8268. return (wrapped != NULL);
  8269. }
  8270. - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
  8271. if (otherDictionary) {
  8272. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8273. if (_autocreator) {
  8274. GPBAutocreatedDictionaryModified(_autocreator, self);
  8275. }
  8276. }
  8277. }
  8278. - (void)setBool:(BOOL)value forKey:(NSString *)key {
  8279. if (!key) {
  8280. [NSException raise:NSInvalidArgumentException
  8281. format:@"Attempting to add nil key to a Dictionary"];
  8282. }
  8283. [_dictionary setObject:@(value) forKey:key];
  8284. if (_autocreator) {
  8285. GPBAutocreatedDictionaryModified(_autocreator, self);
  8286. }
  8287. }
  8288. - (void)removeBoolForKey:(NSString *)aKey {
  8289. [_dictionary removeObjectForKey:aKey];
  8290. }
  8291. - (void)removeAll {
  8292. [_dictionary removeAllObjects];
  8293. }
  8294. @end
  8295. #pragma mark - String -> Float
  8296. @implementation GPBStringFloatDictionary {
  8297. @package
  8298. NSMutableDictionary *_dictionary;
  8299. }
  8300. - (instancetype)init {
  8301. return [self initWithFloats:NULL forKeys:NULL count:0];
  8302. }
  8303. - (instancetype)initWithFloats:(const float [])values
  8304. forKeys:(const NSString * [])keys
  8305. count:(NSUInteger)count {
  8306. self = [super init];
  8307. if (self) {
  8308. _dictionary = [[NSMutableDictionary alloc] init];
  8309. if (count && values && keys) {
  8310. for (NSUInteger i = 0; i < count; ++i) {
  8311. if (!keys[i]) {
  8312. [NSException raise:NSInvalidArgumentException
  8313. format:@"Attempting to add nil key to a Dictionary"];
  8314. }
  8315. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8316. }
  8317. }
  8318. }
  8319. return self;
  8320. }
  8321. - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
  8322. self = [self initWithFloats:NULL forKeys:NULL count:0];
  8323. if (self) {
  8324. if (dictionary) {
  8325. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8326. }
  8327. }
  8328. return self;
  8329. }
  8330. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8331. #pragma unused(numItems)
  8332. return [self initWithFloats:NULL forKeys:NULL count:0];
  8333. }
  8334. - (void)dealloc {
  8335. NSAssert(!_autocreator,
  8336. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8337. [self class], _autocreator);
  8338. [_dictionary release];
  8339. [super dealloc];
  8340. }
  8341. - (instancetype)copyWithZone:(NSZone *)zone {
  8342. return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
  8343. }
  8344. - (BOOL)isEqual:(id)other {
  8345. if (self == other) {
  8346. return YES;
  8347. }
  8348. if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
  8349. return NO;
  8350. }
  8351. GPBStringFloatDictionary *otherDictionary = other;
  8352. return [_dictionary isEqual:otherDictionary->_dictionary];
  8353. }
  8354. - (NSUInteger)hash {
  8355. return _dictionary.count;
  8356. }
  8357. - (NSString *)description {
  8358. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8359. }
  8360. - (NSUInteger)count {
  8361. return _dictionary.count;
  8362. }
  8363. - (void)enumerateKeysAndFloatsUsingBlock:
  8364. (void (^)(NSString *key, float value, BOOL *stop))block {
  8365. BOOL stop = NO;
  8366. NSDictionary *internal = _dictionary;
  8367. NSEnumerator *keys = [internal keyEnumerator];
  8368. NSString *aKey;
  8369. while ((aKey = [keys nextObject])) {
  8370. NSNumber *aValue = internal[aKey];
  8371. block(aKey, [aValue floatValue], &stop);
  8372. if (stop) {
  8373. break;
  8374. }
  8375. }
  8376. }
  8377. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8378. NSDictionary *internal = _dictionary;
  8379. NSUInteger count = internal.count;
  8380. if (count == 0) {
  8381. return 0;
  8382. }
  8383. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8384. GPBDataType keyDataType = field.mapKeyDataType;
  8385. size_t result = 0;
  8386. NSEnumerator *keys = [internal keyEnumerator];
  8387. NSString *aKey;
  8388. while ((aKey = [keys nextObject])) {
  8389. NSNumber *aValue = internal[aKey];
  8390. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8391. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  8392. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8393. }
  8394. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8395. result += tagSize * count;
  8396. return result;
  8397. }
  8398. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8399. asField:(GPBFieldDescriptor *)field {
  8400. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8401. GPBDataType keyDataType = field.mapKeyDataType;
  8402. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8403. NSDictionary *internal = _dictionary;
  8404. NSEnumerator *keys = [internal keyEnumerator];
  8405. NSString *aKey;
  8406. while ((aKey = [keys nextObject])) {
  8407. NSNumber *aValue = internal[aKey];
  8408. [outputStream writeInt32NoTag:tag];
  8409. // Write the size of the message.
  8410. NSString *unwrappedKey = aKey;
  8411. float unwrappedValue = [aValue floatValue];
  8412. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8413. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8414. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8415. // Write the fields.
  8416. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8417. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8418. }
  8419. }
  8420. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8421. forGPBGenericValueKey:(GPBGenericValue *)key {
  8422. [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
  8423. }
  8424. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8425. [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
  8426. #pragma unused(stop)
  8427. block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  8428. }];
  8429. }
  8430. - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
  8431. NSNumber *wrapped = [_dictionary objectForKey:key];
  8432. if (wrapped && value) {
  8433. *value = [wrapped floatValue];
  8434. }
  8435. return (wrapped != NULL);
  8436. }
  8437. - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
  8438. if (otherDictionary) {
  8439. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8440. if (_autocreator) {
  8441. GPBAutocreatedDictionaryModified(_autocreator, self);
  8442. }
  8443. }
  8444. }
  8445. - (void)setFloat:(float)value forKey:(NSString *)key {
  8446. if (!key) {
  8447. [NSException raise:NSInvalidArgumentException
  8448. format:@"Attempting to add nil key to a Dictionary"];
  8449. }
  8450. [_dictionary setObject:@(value) forKey:key];
  8451. if (_autocreator) {
  8452. GPBAutocreatedDictionaryModified(_autocreator, self);
  8453. }
  8454. }
  8455. - (void)removeFloatForKey:(NSString *)aKey {
  8456. [_dictionary removeObjectForKey:aKey];
  8457. }
  8458. - (void)removeAll {
  8459. [_dictionary removeAllObjects];
  8460. }
  8461. @end
  8462. #pragma mark - String -> Double
  8463. @implementation GPBStringDoubleDictionary {
  8464. @package
  8465. NSMutableDictionary *_dictionary;
  8466. }
  8467. - (instancetype)init {
  8468. return [self initWithDoubles:NULL forKeys:NULL count:0];
  8469. }
  8470. - (instancetype)initWithDoubles:(const double [])values
  8471. forKeys:(const NSString * [])keys
  8472. count:(NSUInteger)count {
  8473. self = [super init];
  8474. if (self) {
  8475. _dictionary = [[NSMutableDictionary alloc] init];
  8476. if (count && values && keys) {
  8477. for (NSUInteger i = 0; i < count; ++i) {
  8478. if (!keys[i]) {
  8479. [NSException raise:NSInvalidArgumentException
  8480. format:@"Attempting to add nil key to a Dictionary"];
  8481. }
  8482. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8483. }
  8484. }
  8485. }
  8486. return self;
  8487. }
  8488. - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
  8489. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  8490. if (self) {
  8491. if (dictionary) {
  8492. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8493. }
  8494. }
  8495. return self;
  8496. }
  8497. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8498. #pragma unused(numItems)
  8499. return [self initWithDoubles:NULL forKeys:NULL count:0];
  8500. }
  8501. - (void)dealloc {
  8502. NSAssert(!_autocreator,
  8503. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8504. [self class], _autocreator);
  8505. [_dictionary release];
  8506. [super dealloc];
  8507. }
  8508. - (instancetype)copyWithZone:(NSZone *)zone {
  8509. return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
  8510. }
  8511. - (BOOL)isEqual:(id)other {
  8512. if (self == other) {
  8513. return YES;
  8514. }
  8515. if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
  8516. return NO;
  8517. }
  8518. GPBStringDoubleDictionary *otherDictionary = other;
  8519. return [_dictionary isEqual:otherDictionary->_dictionary];
  8520. }
  8521. - (NSUInteger)hash {
  8522. return _dictionary.count;
  8523. }
  8524. - (NSString *)description {
  8525. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8526. }
  8527. - (NSUInteger)count {
  8528. return _dictionary.count;
  8529. }
  8530. - (void)enumerateKeysAndDoublesUsingBlock:
  8531. (void (^)(NSString *key, double value, BOOL *stop))block {
  8532. BOOL stop = NO;
  8533. NSDictionary *internal = _dictionary;
  8534. NSEnumerator *keys = [internal keyEnumerator];
  8535. NSString *aKey;
  8536. while ((aKey = [keys nextObject])) {
  8537. NSNumber *aValue = internal[aKey];
  8538. block(aKey, [aValue doubleValue], &stop);
  8539. if (stop) {
  8540. break;
  8541. }
  8542. }
  8543. }
  8544. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8545. NSDictionary *internal = _dictionary;
  8546. NSUInteger count = internal.count;
  8547. if (count == 0) {
  8548. return 0;
  8549. }
  8550. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8551. GPBDataType keyDataType = field.mapKeyDataType;
  8552. size_t result = 0;
  8553. NSEnumerator *keys = [internal keyEnumerator];
  8554. NSString *aKey;
  8555. while ((aKey = [keys nextObject])) {
  8556. NSNumber *aValue = internal[aKey];
  8557. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8558. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  8559. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8560. }
  8561. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8562. result += tagSize * count;
  8563. return result;
  8564. }
  8565. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8566. asField:(GPBFieldDescriptor *)field {
  8567. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8568. GPBDataType keyDataType = field.mapKeyDataType;
  8569. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8570. NSDictionary *internal = _dictionary;
  8571. NSEnumerator *keys = [internal keyEnumerator];
  8572. NSString *aKey;
  8573. while ((aKey = [keys nextObject])) {
  8574. NSNumber *aValue = internal[aKey];
  8575. [outputStream writeInt32NoTag:tag];
  8576. // Write the size of the message.
  8577. NSString *unwrappedKey = aKey;
  8578. double unwrappedValue = [aValue doubleValue];
  8579. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8580. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8581. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8582. // Write the fields.
  8583. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8584. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8585. }
  8586. }
  8587. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8588. forGPBGenericValueKey:(GPBGenericValue *)key {
  8589. [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
  8590. }
  8591. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8592. [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
  8593. #pragma unused(stop)
  8594. block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  8595. }];
  8596. }
  8597. - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
  8598. NSNumber *wrapped = [_dictionary objectForKey:key];
  8599. if (wrapped && value) {
  8600. *value = [wrapped doubleValue];
  8601. }
  8602. return (wrapped != NULL);
  8603. }
  8604. - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
  8605. if (otherDictionary) {
  8606. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8607. if (_autocreator) {
  8608. GPBAutocreatedDictionaryModified(_autocreator, self);
  8609. }
  8610. }
  8611. }
  8612. - (void)setDouble:(double)value forKey:(NSString *)key {
  8613. if (!key) {
  8614. [NSException raise:NSInvalidArgumentException
  8615. format:@"Attempting to add nil key to a Dictionary"];
  8616. }
  8617. [_dictionary setObject:@(value) forKey:key];
  8618. if (_autocreator) {
  8619. GPBAutocreatedDictionaryModified(_autocreator, self);
  8620. }
  8621. }
  8622. - (void)removeDoubleForKey:(NSString *)aKey {
  8623. [_dictionary removeObjectForKey:aKey];
  8624. }
  8625. - (void)removeAll {
  8626. [_dictionary removeAllObjects];
  8627. }
  8628. @end
  8629. #pragma mark - String -> Enum
  8630. @implementation GPBStringEnumDictionary {
  8631. @package
  8632. NSMutableDictionary *_dictionary;
  8633. GPBEnumValidationFunc _validationFunc;
  8634. }
  8635. @synthesize validationFunc = _validationFunc;
  8636. - (instancetype)init {
  8637. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  8638. }
  8639. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  8640. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  8641. }
  8642. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  8643. rawValues:(const int32_t [])rawValues
  8644. forKeys:(const NSString * [])keys
  8645. count:(NSUInteger)count {
  8646. self = [super init];
  8647. if (self) {
  8648. _dictionary = [[NSMutableDictionary alloc] init];
  8649. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  8650. if (count && rawValues && keys) {
  8651. for (NSUInteger i = 0; i < count; ++i) {
  8652. if (!keys[i]) {
  8653. [NSException raise:NSInvalidArgumentException
  8654. format:@"Attempting to add nil key to a Dictionary"];
  8655. }
  8656. [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
  8657. }
  8658. }
  8659. }
  8660. return self;
  8661. }
  8662. - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
  8663. self = [self initWithValidationFunction:dictionary.validationFunc
  8664. rawValues:NULL
  8665. forKeys:NULL
  8666. count:0];
  8667. if (self) {
  8668. if (dictionary) {
  8669. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8670. }
  8671. }
  8672. return self;
  8673. }
  8674. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  8675. capacity:(NSUInteger)numItems {
  8676. #pragma unused(numItems)
  8677. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  8678. }
  8679. - (void)dealloc {
  8680. NSAssert(!_autocreator,
  8681. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8682. [self class], _autocreator);
  8683. [_dictionary release];
  8684. [super dealloc];
  8685. }
  8686. - (instancetype)copyWithZone:(NSZone *)zone {
  8687. return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
  8688. }
  8689. - (BOOL)isEqual:(id)other {
  8690. if (self == other) {
  8691. return YES;
  8692. }
  8693. if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
  8694. return NO;
  8695. }
  8696. GPBStringEnumDictionary *otherDictionary = other;
  8697. return [_dictionary isEqual:otherDictionary->_dictionary];
  8698. }
  8699. - (NSUInteger)hash {
  8700. return _dictionary.count;
  8701. }
  8702. - (NSString *)description {
  8703. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8704. }
  8705. - (NSUInteger)count {
  8706. return _dictionary.count;
  8707. }
  8708. - (void)enumerateKeysAndRawValuesUsingBlock:
  8709. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  8710. BOOL stop = NO;
  8711. NSDictionary *internal = _dictionary;
  8712. NSEnumerator *keys = [internal keyEnumerator];
  8713. NSString *aKey;
  8714. while ((aKey = [keys nextObject])) {
  8715. NSNumber *aValue = internal[aKey];
  8716. block(aKey, [aValue intValue], &stop);
  8717. if (stop) {
  8718. break;
  8719. }
  8720. }
  8721. }
  8722. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8723. NSDictionary *internal = _dictionary;
  8724. NSUInteger count = internal.count;
  8725. if (count == 0) {
  8726. return 0;
  8727. }
  8728. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8729. GPBDataType keyDataType = field.mapKeyDataType;
  8730. size_t result = 0;
  8731. NSEnumerator *keys = [internal keyEnumerator];
  8732. NSString *aKey;
  8733. while ((aKey = [keys nextObject])) {
  8734. NSNumber *aValue = internal[aKey];
  8735. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8736. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  8737. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8738. }
  8739. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8740. result += tagSize * count;
  8741. return result;
  8742. }
  8743. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8744. asField:(GPBFieldDescriptor *)field {
  8745. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8746. GPBDataType keyDataType = field.mapKeyDataType;
  8747. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8748. NSDictionary *internal = _dictionary;
  8749. NSEnumerator *keys = [internal keyEnumerator];
  8750. NSString *aKey;
  8751. while ((aKey = [keys nextObject])) {
  8752. NSNumber *aValue = internal[aKey];
  8753. [outputStream writeInt32NoTag:tag];
  8754. // Write the size of the message.
  8755. NSString *unwrappedKey = aKey;
  8756. int32_t unwrappedValue = [aValue intValue];
  8757. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8758. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8759. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8760. // Write the fields.
  8761. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8762. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8763. }
  8764. }
  8765. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  8766. forKey:(GPBGenericValue *)key
  8767. keyDataType:(GPBDataType)keyDataType {
  8768. size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
  8769. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  8770. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  8771. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  8772. WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
  8773. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  8774. [outputStream release];
  8775. return data;
  8776. }
  8777. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8778. forGPBGenericValueKey:(GPBGenericValue *)key {
  8779. [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
  8780. }
  8781. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8782. [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
  8783. #pragma unused(stop)
  8784. block(key, @(value));
  8785. }];
  8786. }
  8787. - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
  8788. NSNumber *wrapped = [_dictionary objectForKey:key];
  8789. if (wrapped && value) {
  8790. int32_t result = [wrapped intValue];
  8791. if (!_validationFunc(result)) {
  8792. result = kGPBUnrecognizedEnumeratorValue;
  8793. }
  8794. *value = result;
  8795. }
  8796. return (wrapped != NULL);
  8797. }
  8798. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
  8799. NSNumber *wrapped = [_dictionary objectForKey:key];
  8800. if (wrapped && rawValue) {
  8801. *rawValue = [wrapped intValue];
  8802. }
  8803. return (wrapped != NULL);
  8804. }
  8805. - (void)enumerateKeysAndEnumsUsingBlock:
  8806. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  8807. GPBEnumValidationFunc func = _validationFunc;
  8808. BOOL stop = NO;
  8809. NSEnumerator *keys = [_dictionary keyEnumerator];
  8810. NSString *aKey;
  8811. while ((aKey = [keys nextObject])) {
  8812. NSNumber *aValue = _dictionary[aKey];
  8813. int32_t unwrapped = [aValue intValue];
  8814. if (!func(unwrapped)) {
  8815. unwrapped = kGPBUnrecognizedEnumeratorValue;
  8816. }
  8817. block(aKey, unwrapped, &stop);
  8818. if (stop) {
  8819. break;
  8820. }
  8821. }
  8822. }
  8823. - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
  8824. if (otherDictionary) {
  8825. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8826. if (_autocreator) {
  8827. GPBAutocreatedDictionaryModified(_autocreator, self);
  8828. }
  8829. }
  8830. }
  8831. - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
  8832. if (!key) {
  8833. [NSException raise:NSInvalidArgumentException
  8834. format:@"Attempting to add nil key to a Dictionary"];
  8835. }
  8836. [_dictionary setObject:@(value) forKey:key];
  8837. if (_autocreator) {
  8838. GPBAutocreatedDictionaryModified(_autocreator, self);
  8839. }
  8840. }
  8841. - (void)removeEnumForKey:(NSString *)aKey {
  8842. [_dictionary removeObjectForKey:aKey];
  8843. }
  8844. - (void)removeAll {
  8845. [_dictionary removeAllObjects];
  8846. }
  8847. - (void)setEnum:(int32_t)value forKey:(NSString *)key {
  8848. if (!key) {
  8849. [NSException raise:NSInvalidArgumentException
  8850. format:@"Attempting to add nil key to a Dictionary"];
  8851. }
  8852. if (!_validationFunc(value)) {
  8853. [NSException raise:NSInvalidArgumentException
  8854. format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
  8855. value];
  8856. }
  8857. [_dictionary setObject:@(value) forKey:key];
  8858. if (_autocreator) {
  8859. GPBAutocreatedDictionaryModified(_autocreator, self);
  8860. }
  8861. }
  8862. @end
  8863. //%PDDM-EXPAND-END (5 expansions)
  8864. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
  8865. // This block of code is generated, do not edit it directly.
  8866. #pragma mark - Bool -> UInt32
  8867. @implementation GPBBoolUInt32Dictionary {
  8868. @package
  8869. uint32_t _values[2];
  8870. BOOL _valueSet[2];
  8871. }
  8872. - (instancetype)init {
  8873. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  8874. }
  8875. - (instancetype)initWithUInt32s:(const uint32_t [])values
  8876. forKeys:(const BOOL [])keys
  8877. count:(NSUInteger)count {
  8878. self = [super init];
  8879. if (self) {
  8880. for (NSUInteger i = 0; i < count; ++i) {
  8881. int idx = keys[i] ? 1 : 0;
  8882. _values[idx] = values[i];
  8883. _valueSet[idx] = YES;
  8884. }
  8885. }
  8886. return self;
  8887. }
  8888. - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
  8889. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  8890. if (self) {
  8891. if (dictionary) {
  8892. for (int i = 0; i < 2; ++i) {
  8893. if (dictionary->_valueSet[i]) {
  8894. _values[i] = dictionary->_values[i];
  8895. _valueSet[i] = YES;
  8896. }
  8897. }
  8898. }
  8899. }
  8900. return self;
  8901. }
  8902. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8903. #pragma unused(numItems)
  8904. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  8905. }
  8906. #if !defined(NS_BLOCK_ASSERTIONS)
  8907. - (void)dealloc {
  8908. NSAssert(!_autocreator,
  8909. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8910. [self class], _autocreator);
  8911. [super dealloc];
  8912. }
  8913. #endif // !defined(NS_BLOCK_ASSERTIONS)
  8914. - (instancetype)copyWithZone:(NSZone *)zone {
  8915. return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  8916. }
  8917. - (BOOL)isEqual:(id)other {
  8918. if (self == other) {
  8919. return YES;
  8920. }
  8921. if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
  8922. return NO;
  8923. }
  8924. GPBBoolUInt32Dictionary *otherDictionary = other;
  8925. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  8926. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  8927. return NO;
  8928. }
  8929. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  8930. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  8931. return NO;
  8932. }
  8933. return YES;
  8934. }
  8935. - (NSUInteger)hash {
  8936. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  8937. }
  8938. - (NSString *)description {
  8939. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  8940. if (_valueSet[0]) {
  8941. [result appendFormat:@"NO: %u", _values[0]];
  8942. }
  8943. if (_valueSet[1]) {
  8944. [result appendFormat:@"YES: %u", _values[1]];
  8945. }
  8946. [result appendString:@" }"];
  8947. return result;
  8948. }
  8949. - (NSUInteger)count {
  8950. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  8951. }
  8952. - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
  8953. int idx = (key ? 1 : 0);
  8954. if (_valueSet[idx]) {
  8955. if (value) {
  8956. *value = _values[idx];
  8957. }
  8958. return YES;
  8959. }
  8960. return NO;
  8961. }
  8962. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8963. forGPBGenericValueKey:(GPBGenericValue *)key {
  8964. int idx = (key->valueBool ? 1 : 0);
  8965. _values[idx] = value->valueUInt32;
  8966. _valueSet[idx] = YES;
  8967. }
  8968. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8969. if (_valueSet[0]) {
  8970. block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
  8971. }
  8972. if (_valueSet[1]) {
  8973. block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
  8974. }
  8975. }
  8976. - (void)enumerateKeysAndUInt32sUsingBlock:
  8977. (void (^)(BOOL key, uint32_t value, BOOL *stop))block {
  8978. BOOL stop = NO;
  8979. if (_valueSet[0]) {
  8980. block(NO, _values[0], &stop);
  8981. }
  8982. if (!stop && _valueSet[1]) {
  8983. block(YES, _values[1], &stop);
  8984. }
  8985. }
  8986. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8987. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8988. NSUInteger count = 0;
  8989. size_t result = 0;
  8990. for (int i = 0; i < 2; ++i) {
  8991. if (_valueSet[i]) {
  8992. ++count;
  8993. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  8994. msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  8995. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8996. }
  8997. }
  8998. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8999. result += tagSize * count;
  9000. return result;
  9001. }
  9002. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9003. asField:(GPBFieldDescriptor *)field {
  9004. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9005. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9006. for (int i = 0; i < 2; ++i) {
  9007. if (_valueSet[i]) {
  9008. // Write the tag.
  9009. [outputStream writeInt32NoTag:tag];
  9010. // Write the size of the message.
  9011. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9012. msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9013. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9014. // Write the fields.
  9015. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9016. WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9017. }
  9018. }
  9019. }
  9020. - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
  9021. if (otherDictionary) {
  9022. for (int i = 0; i < 2; ++i) {
  9023. if (otherDictionary->_valueSet[i]) {
  9024. _valueSet[i] = YES;
  9025. _values[i] = otherDictionary->_values[i];
  9026. }
  9027. }
  9028. if (_autocreator) {
  9029. GPBAutocreatedDictionaryModified(_autocreator, self);
  9030. }
  9031. }
  9032. }
  9033. - (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
  9034. int idx = (key ? 1 : 0);
  9035. _values[idx] = value;
  9036. _valueSet[idx] = YES;
  9037. if (_autocreator) {
  9038. GPBAutocreatedDictionaryModified(_autocreator, self);
  9039. }
  9040. }
  9041. - (void)removeUInt32ForKey:(BOOL)aKey {
  9042. _valueSet[aKey ? 1 : 0] = NO;
  9043. }
  9044. - (void)removeAll {
  9045. _valueSet[0] = NO;
  9046. _valueSet[1] = NO;
  9047. }
  9048. @end
  9049. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
  9050. // This block of code is generated, do not edit it directly.
  9051. #pragma mark - Bool -> Int32
  9052. @implementation GPBBoolInt32Dictionary {
  9053. @package
  9054. int32_t _values[2];
  9055. BOOL _valueSet[2];
  9056. }
  9057. - (instancetype)init {
  9058. return [self initWithInt32s:NULL forKeys:NULL count:0];
  9059. }
  9060. - (instancetype)initWithInt32s:(const int32_t [])values
  9061. forKeys:(const BOOL [])keys
  9062. count:(NSUInteger)count {
  9063. self = [super init];
  9064. if (self) {
  9065. for (NSUInteger i = 0; i < count; ++i) {
  9066. int idx = keys[i] ? 1 : 0;
  9067. _values[idx] = values[i];
  9068. _valueSet[idx] = YES;
  9069. }
  9070. }
  9071. return self;
  9072. }
  9073. - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
  9074. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  9075. if (self) {
  9076. if (dictionary) {
  9077. for (int i = 0; i < 2; ++i) {
  9078. if (dictionary->_valueSet[i]) {
  9079. _values[i] = dictionary->_values[i];
  9080. _valueSet[i] = YES;
  9081. }
  9082. }
  9083. }
  9084. }
  9085. return self;
  9086. }
  9087. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9088. #pragma unused(numItems)
  9089. return [self initWithInt32s:NULL forKeys:NULL count:0];
  9090. }
  9091. #if !defined(NS_BLOCK_ASSERTIONS)
  9092. - (void)dealloc {
  9093. NSAssert(!_autocreator,
  9094. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9095. [self class], _autocreator);
  9096. [super dealloc];
  9097. }
  9098. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9099. - (instancetype)copyWithZone:(NSZone *)zone {
  9100. return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  9101. }
  9102. - (BOOL)isEqual:(id)other {
  9103. if (self == other) {
  9104. return YES;
  9105. }
  9106. if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
  9107. return NO;
  9108. }
  9109. GPBBoolInt32Dictionary *otherDictionary = other;
  9110. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9111. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9112. return NO;
  9113. }
  9114. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9115. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9116. return NO;
  9117. }
  9118. return YES;
  9119. }
  9120. - (NSUInteger)hash {
  9121. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9122. }
  9123. - (NSString *)description {
  9124. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9125. if (_valueSet[0]) {
  9126. [result appendFormat:@"NO: %d", _values[0]];
  9127. }
  9128. if (_valueSet[1]) {
  9129. [result appendFormat:@"YES: %d", _values[1]];
  9130. }
  9131. [result appendString:@" }"];
  9132. return result;
  9133. }
  9134. - (NSUInteger)count {
  9135. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9136. }
  9137. - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
  9138. int idx = (key ? 1 : 0);
  9139. if (_valueSet[idx]) {
  9140. if (value) {
  9141. *value = _values[idx];
  9142. }
  9143. return YES;
  9144. }
  9145. return NO;
  9146. }
  9147. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9148. forGPBGenericValueKey:(GPBGenericValue *)key {
  9149. int idx = (key->valueBool ? 1 : 0);
  9150. _values[idx] = value->valueInt32;
  9151. _valueSet[idx] = YES;
  9152. }
  9153. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9154. if (_valueSet[0]) {
  9155. block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
  9156. }
  9157. if (_valueSet[1]) {
  9158. block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
  9159. }
  9160. }
  9161. - (void)enumerateKeysAndInt32sUsingBlock:
  9162. (void (^)(BOOL key, int32_t value, BOOL *stop))block {
  9163. BOOL stop = NO;
  9164. if (_valueSet[0]) {
  9165. block(NO, _values[0], &stop);
  9166. }
  9167. if (!stop && _valueSet[1]) {
  9168. block(YES, _values[1], &stop);
  9169. }
  9170. }
  9171. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9172. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9173. NSUInteger count = 0;
  9174. size_t result = 0;
  9175. for (int i = 0; i < 2; ++i) {
  9176. if (_valueSet[i]) {
  9177. ++count;
  9178. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9179. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9180. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9181. }
  9182. }
  9183. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9184. result += tagSize * count;
  9185. return result;
  9186. }
  9187. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9188. asField:(GPBFieldDescriptor *)field {
  9189. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9190. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9191. for (int i = 0; i < 2; ++i) {
  9192. if (_valueSet[i]) {
  9193. // Write the tag.
  9194. [outputStream writeInt32NoTag:tag];
  9195. // Write the size of the message.
  9196. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9197. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9198. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9199. // Write the fields.
  9200. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9201. WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9202. }
  9203. }
  9204. }
  9205. - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
  9206. if (otherDictionary) {
  9207. for (int i = 0; i < 2; ++i) {
  9208. if (otherDictionary->_valueSet[i]) {
  9209. _valueSet[i] = YES;
  9210. _values[i] = otherDictionary->_values[i];
  9211. }
  9212. }
  9213. if (_autocreator) {
  9214. GPBAutocreatedDictionaryModified(_autocreator, self);
  9215. }
  9216. }
  9217. }
  9218. - (void)setInt32:(int32_t)value forKey:(BOOL)key {
  9219. int idx = (key ? 1 : 0);
  9220. _values[idx] = value;
  9221. _valueSet[idx] = YES;
  9222. if (_autocreator) {
  9223. GPBAutocreatedDictionaryModified(_autocreator, self);
  9224. }
  9225. }
  9226. - (void)removeInt32ForKey:(BOOL)aKey {
  9227. _valueSet[aKey ? 1 : 0] = NO;
  9228. }
  9229. - (void)removeAll {
  9230. _valueSet[0] = NO;
  9231. _valueSet[1] = NO;
  9232. }
  9233. @end
  9234. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
  9235. // This block of code is generated, do not edit it directly.
  9236. #pragma mark - Bool -> UInt64
  9237. @implementation GPBBoolUInt64Dictionary {
  9238. @package
  9239. uint64_t _values[2];
  9240. BOOL _valueSet[2];
  9241. }
  9242. - (instancetype)init {
  9243. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  9244. }
  9245. - (instancetype)initWithUInt64s:(const uint64_t [])values
  9246. forKeys:(const BOOL [])keys
  9247. count:(NSUInteger)count {
  9248. self = [super init];
  9249. if (self) {
  9250. for (NSUInteger i = 0; i < count; ++i) {
  9251. int idx = keys[i] ? 1 : 0;
  9252. _values[idx] = values[i];
  9253. _valueSet[idx] = YES;
  9254. }
  9255. }
  9256. return self;
  9257. }
  9258. - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
  9259. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  9260. if (self) {
  9261. if (dictionary) {
  9262. for (int i = 0; i < 2; ++i) {
  9263. if (dictionary->_valueSet[i]) {
  9264. _values[i] = dictionary->_values[i];
  9265. _valueSet[i] = YES;
  9266. }
  9267. }
  9268. }
  9269. }
  9270. return self;
  9271. }
  9272. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9273. #pragma unused(numItems)
  9274. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  9275. }
  9276. #if !defined(NS_BLOCK_ASSERTIONS)
  9277. - (void)dealloc {
  9278. NSAssert(!_autocreator,
  9279. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9280. [self class], _autocreator);
  9281. [super dealloc];
  9282. }
  9283. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9284. - (instancetype)copyWithZone:(NSZone *)zone {
  9285. return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  9286. }
  9287. - (BOOL)isEqual:(id)other {
  9288. if (self == other) {
  9289. return YES;
  9290. }
  9291. if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
  9292. return NO;
  9293. }
  9294. GPBBoolUInt64Dictionary *otherDictionary = other;
  9295. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9296. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9297. return NO;
  9298. }
  9299. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9300. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9301. return NO;
  9302. }
  9303. return YES;
  9304. }
  9305. - (NSUInteger)hash {
  9306. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9307. }
  9308. - (NSString *)description {
  9309. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9310. if (_valueSet[0]) {
  9311. [result appendFormat:@"NO: %llu", _values[0]];
  9312. }
  9313. if (_valueSet[1]) {
  9314. [result appendFormat:@"YES: %llu", _values[1]];
  9315. }
  9316. [result appendString:@" }"];
  9317. return result;
  9318. }
  9319. - (NSUInteger)count {
  9320. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9321. }
  9322. - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
  9323. int idx = (key ? 1 : 0);
  9324. if (_valueSet[idx]) {
  9325. if (value) {
  9326. *value = _values[idx];
  9327. }
  9328. return YES;
  9329. }
  9330. return NO;
  9331. }
  9332. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9333. forGPBGenericValueKey:(GPBGenericValue *)key {
  9334. int idx = (key->valueBool ? 1 : 0);
  9335. _values[idx] = value->valueUInt64;
  9336. _valueSet[idx] = YES;
  9337. }
  9338. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9339. if (_valueSet[0]) {
  9340. block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
  9341. }
  9342. if (_valueSet[1]) {
  9343. block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
  9344. }
  9345. }
  9346. - (void)enumerateKeysAndUInt64sUsingBlock:
  9347. (void (^)(BOOL key, uint64_t value, BOOL *stop))block {
  9348. BOOL stop = NO;
  9349. if (_valueSet[0]) {
  9350. block(NO, _values[0], &stop);
  9351. }
  9352. if (!stop && _valueSet[1]) {
  9353. block(YES, _values[1], &stop);
  9354. }
  9355. }
  9356. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9357. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9358. NSUInteger count = 0;
  9359. size_t result = 0;
  9360. for (int i = 0; i < 2; ++i) {
  9361. if (_valueSet[i]) {
  9362. ++count;
  9363. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9364. msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9365. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9366. }
  9367. }
  9368. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9369. result += tagSize * count;
  9370. return result;
  9371. }
  9372. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9373. asField:(GPBFieldDescriptor *)field {
  9374. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9375. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9376. for (int i = 0; i < 2; ++i) {
  9377. if (_valueSet[i]) {
  9378. // Write the tag.
  9379. [outputStream writeInt32NoTag:tag];
  9380. // Write the size of the message.
  9381. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9382. msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9383. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9384. // Write the fields.
  9385. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9386. WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9387. }
  9388. }
  9389. }
  9390. - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
  9391. if (otherDictionary) {
  9392. for (int i = 0; i < 2; ++i) {
  9393. if (otherDictionary->_valueSet[i]) {
  9394. _valueSet[i] = YES;
  9395. _values[i] = otherDictionary->_values[i];
  9396. }
  9397. }
  9398. if (_autocreator) {
  9399. GPBAutocreatedDictionaryModified(_autocreator, self);
  9400. }
  9401. }
  9402. }
  9403. - (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
  9404. int idx = (key ? 1 : 0);
  9405. _values[idx] = value;
  9406. _valueSet[idx] = YES;
  9407. if (_autocreator) {
  9408. GPBAutocreatedDictionaryModified(_autocreator, self);
  9409. }
  9410. }
  9411. - (void)removeUInt64ForKey:(BOOL)aKey {
  9412. _valueSet[aKey ? 1 : 0] = NO;
  9413. }
  9414. - (void)removeAll {
  9415. _valueSet[0] = NO;
  9416. _valueSet[1] = NO;
  9417. }
  9418. @end
  9419. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
  9420. // This block of code is generated, do not edit it directly.
  9421. #pragma mark - Bool -> Int64
  9422. @implementation GPBBoolInt64Dictionary {
  9423. @package
  9424. int64_t _values[2];
  9425. BOOL _valueSet[2];
  9426. }
  9427. - (instancetype)init {
  9428. return [self initWithInt64s:NULL forKeys:NULL count:0];
  9429. }
  9430. - (instancetype)initWithInt64s:(const int64_t [])values
  9431. forKeys:(const BOOL [])keys
  9432. count:(NSUInteger)count {
  9433. self = [super init];
  9434. if (self) {
  9435. for (NSUInteger i = 0; i < count; ++i) {
  9436. int idx = keys[i] ? 1 : 0;
  9437. _values[idx] = values[i];
  9438. _valueSet[idx] = YES;
  9439. }
  9440. }
  9441. return self;
  9442. }
  9443. - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
  9444. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  9445. if (self) {
  9446. if (dictionary) {
  9447. for (int i = 0; i < 2; ++i) {
  9448. if (dictionary->_valueSet[i]) {
  9449. _values[i] = dictionary->_values[i];
  9450. _valueSet[i] = YES;
  9451. }
  9452. }
  9453. }
  9454. }
  9455. return self;
  9456. }
  9457. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9458. #pragma unused(numItems)
  9459. return [self initWithInt64s:NULL forKeys:NULL count:0];
  9460. }
  9461. #if !defined(NS_BLOCK_ASSERTIONS)
  9462. - (void)dealloc {
  9463. NSAssert(!_autocreator,
  9464. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9465. [self class], _autocreator);
  9466. [super dealloc];
  9467. }
  9468. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9469. - (instancetype)copyWithZone:(NSZone *)zone {
  9470. return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  9471. }
  9472. - (BOOL)isEqual:(id)other {
  9473. if (self == other) {
  9474. return YES;
  9475. }
  9476. if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
  9477. return NO;
  9478. }
  9479. GPBBoolInt64Dictionary *otherDictionary = other;
  9480. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9481. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9482. return NO;
  9483. }
  9484. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9485. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9486. return NO;
  9487. }
  9488. return YES;
  9489. }
  9490. - (NSUInteger)hash {
  9491. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9492. }
  9493. - (NSString *)description {
  9494. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9495. if (_valueSet[0]) {
  9496. [result appendFormat:@"NO: %lld", _values[0]];
  9497. }
  9498. if (_valueSet[1]) {
  9499. [result appendFormat:@"YES: %lld", _values[1]];
  9500. }
  9501. [result appendString:@" }"];
  9502. return result;
  9503. }
  9504. - (NSUInteger)count {
  9505. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9506. }
  9507. - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
  9508. int idx = (key ? 1 : 0);
  9509. if (_valueSet[idx]) {
  9510. if (value) {
  9511. *value = _values[idx];
  9512. }
  9513. return YES;
  9514. }
  9515. return NO;
  9516. }
  9517. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9518. forGPBGenericValueKey:(GPBGenericValue *)key {
  9519. int idx = (key->valueBool ? 1 : 0);
  9520. _values[idx] = value->valueInt64;
  9521. _valueSet[idx] = YES;
  9522. }
  9523. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9524. if (_valueSet[0]) {
  9525. block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
  9526. }
  9527. if (_valueSet[1]) {
  9528. block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
  9529. }
  9530. }
  9531. - (void)enumerateKeysAndInt64sUsingBlock:
  9532. (void (^)(BOOL key, int64_t value, BOOL *stop))block {
  9533. BOOL stop = NO;
  9534. if (_valueSet[0]) {
  9535. block(NO, _values[0], &stop);
  9536. }
  9537. if (!stop && _valueSet[1]) {
  9538. block(YES, _values[1], &stop);
  9539. }
  9540. }
  9541. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9542. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9543. NSUInteger count = 0;
  9544. size_t result = 0;
  9545. for (int i = 0; i < 2; ++i) {
  9546. if (_valueSet[i]) {
  9547. ++count;
  9548. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9549. msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9550. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9551. }
  9552. }
  9553. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9554. result += tagSize * count;
  9555. return result;
  9556. }
  9557. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9558. asField:(GPBFieldDescriptor *)field {
  9559. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9560. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9561. for (int i = 0; i < 2; ++i) {
  9562. if (_valueSet[i]) {
  9563. // Write the tag.
  9564. [outputStream writeInt32NoTag:tag];
  9565. // Write the size of the message.
  9566. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9567. msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9568. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9569. // Write the fields.
  9570. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9571. WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9572. }
  9573. }
  9574. }
  9575. - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
  9576. if (otherDictionary) {
  9577. for (int i = 0; i < 2; ++i) {
  9578. if (otherDictionary->_valueSet[i]) {
  9579. _valueSet[i] = YES;
  9580. _values[i] = otherDictionary->_values[i];
  9581. }
  9582. }
  9583. if (_autocreator) {
  9584. GPBAutocreatedDictionaryModified(_autocreator, self);
  9585. }
  9586. }
  9587. }
  9588. - (void)setInt64:(int64_t)value forKey:(BOOL)key {
  9589. int idx = (key ? 1 : 0);
  9590. _values[idx] = value;
  9591. _valueSet[idx] = YES;
  9592. if (_autocreator) {
  9593. GPBAutocreatedDictionaryModified(_autocreator, self);
  9594. }
  9595. }
  9596. - (void)removeInt64ForKey:(BOOL)aKey {
  9597. _valueSet[aKey ? 1 : 0] = NO;
  9598. }
  9599. - (void)removeAll {
  9600. _valueSet[0] = NO;
  9601. _valueSet[1] = NO;
  9602. }
  9603. @end
  9604. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
  9605. // This block of code is generated, do not edit it directly.
  9606. #pragma mark - Bool -> Bool
  9607. @implementation GPBBoolBoolDictionary {
  9608. @package
  9609. BOOL _values[2];
  9610. BOOL _valueSet[2];
  9611. }
  9612. - (instancetype)init {
  9613. return [self initWithBools:NULL forKeys:NULL count:0];
  9614. }
  9615. - (instancetype)initWithBools:(const BOOL [])values
  9616. forKeys:(const BOOL [])keys
  9617. count:(NSUInteger)count {
  9618. self = [super init];
  9619. if (self) {
  9620. for (NSUInteger i = 0; i < count; ++i) {
  9621. int idx = keys[i] ? 1 : 0;
  9622. _values[idx] = values[i];
  9623. _valueSet[idx] = YES;
  9624. }
  9625. }
  9626. return self;
  9627. }
  9628. - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
  9629. self = [self initWithBools:NULL forKeys:NULL count:0];
  9630. if (self) {
  9631. if (dictionary) {
  9632. for (int i = 0; i < 2; ++i) {
  9633. if (dictionary->_valueSet[i]) {
  9634. _values[i] = dictionary->_values[i];
  9635. _valueSet[i] = YES;
  9636. }
  9637. }
  9638. }
  9639. }
  9640. return self;
  9641. }
  9642. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9643. #pragma unused(numItems)
  9644. return [self initWithBools:NULL forKeys:NULL count:0];
  9645. }
  9646. #if !defined(NS_BLOCK_ASSERTIONS)
  9647. - (void)dealloc {
  9648. NSAssert(!_autocreator,
  9649. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9650. [self class], _autocreator);
  9651. [super dealloc];
  9652. }
  9653. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9654. - (instancetype)copyWithZone:(NSZone *)zone {
  9655. return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
  9656. }
  9657. - (BOOL)isEqual:(id)other {
  9658. if (self == other) {
  9659. return YES;
  9660. }
  9661. if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
  9662. return NO;
  9663. }
  9664. GPBBoolBoolDictionary *otherDictionary = other;
  9665. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9666. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9667. return NO;
  9668. }
  9669. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9670. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9671. return NO;
  9672. }
  9673. return YES;
  9674. }
  9675. - (NSUInteger)hash {
  9676. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9677. }
  9678. - (NSString *)description {
  9679. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9680. if (_valueSet[0]) {
  9681. [result appendFormat:@"NO: %d", _values[0]];
  9682. }
  9683. if (_valueSet[1]) {
  9684. [result appendFormat:@"YES: %d", _values[1]];
  9685. }
  9686. [result appendString:@" }"];
  9687. return result;
  9688. }
  9689. - (NSUInteger)count {
  9690. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9691. }
  9692. - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
  9693. int idx = (key ? 1 : 0);
  9694. if (_valueSet[idx]) {
  9695. if (value) {
  9696. *value = _values[idx];
  9697. }
  9698. return YES;
  9699. }
  9700. return NO;
  9701. }
  9702. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9703. forGPBGenericValueKey:(GPBGenericValue *)key {
  9704. int idx = (key->valueBool ? 1 : 0);
  9705. _values[idx] = value->valueBool;
  9706. _valueSet[idx] = YES;
  9707. }
  9708. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9709. if (_valueSet[0]) {
  9710. block(@"false", (_values[0] ? @"true" : @"false"));
  9711. }
  9712. if (_valueSet[1]) {
  9713. block(@"true", (_values[1] ? @"true" : @"false"));
  9714. }
  9715. }
  9716. - (void)enumerateKeysAndBoolsUsingBlock:
  9717. (void (^)(BOOL key, BOOL value, BOOL *stop))block {
  9718. BOOL stop = NO;
  9719. if (_valueSet[0]) {
  9720. block(NO, _values[0], &stop);
  9721. }
  9722. if (!stop && _valueSet[1]) {
  9723. block(YES, _values[1], &stop);
  9724. }
  9725. }
  9726. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9727. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9728. NSUInteger count = 0;
  9729. size_t result = 0;
  9730. for (int i = 0; i < 2; ++i) {
  9731. if (_valueSet[i]) {
  9732. ++count;
  9733. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9734. msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9735. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9736. }
  9737. }
  9738. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9739. result += tagSize * count;
  9740. return result;
  9741. }
  9742. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9743. asField:(GPBFieldDescriptor *)field {
  9744. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9745. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9746. for (int i = 0; i < 2; ++i) {
  9747. if (_valueSet[i]) {
  9748. // Write the tag.
  9749. [outputStream writeInt32NoTag:tag];
  9750. // Write the size of the message.
  9751. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9752. msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9753. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9754. // Write the fields.
  9755. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9756. WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9757. }
  9758. }
  9759. }
  9760. - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
  9761. if (otherDictionary) {
  9762. for (int i = 0; i < 2; ++i) {
  9763. if (otherDictionary->_valueSet[i]) {
  9764. _valueSet[i] = YES;
  9765. _values[i] = otherDictionary->_values[i];
  9766. }
  9767. }
  9768. if (_autocreator) {
  9769. GPBAutocreatedDictionaryModified(_autocreator, self);
  9770. }
  9771. }
  9772. }
  9773. - (void)setBool:(BOOL)value forKey:(BOOL)key {
  9774. int idx = (key ? 1 : 0);
  9775. _values[idx] = value;
  9776. _valueSet[idx] = YES;
  9777. if (_autocreator) {
  9778. GPBAutocreatedDictionaryModified(_autocreator, self);
  9779. }
  9780. }
  9781. - (void)removeBoolForKey:(BOOL)aKey {
  9782. _valueSet[aKey ? 1 : 0] = NO;
  9783. }
  9784. - (void)removeAll {
  9785. _valueSet[0] = NO;
  9786. _valueSet[1] = NO;
  9787. }
  9788. @end
  9789. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
  9790. // This block of code is generated, do not edit it directly.
  9791. #pragma mark - Bool -> Float
  9792. @implementation GPBBoolFloatDictionary {
  9793. @package
  9794. float _values[2];
  9795. BOOL _valueSet[2];
  9796. }
  9797. - (instancetype)init {
  9798. return [self initWithFloats:NULL forKeys:NULL count:0];
  9799. }
  9800. - (instancetype)initWithFloats:(const float [])values
  9801. forKeys:(const BOOL [])keys
  9802. count:(NSUInteger)count {
  9803. self = [super init];
  9804. if (self) {
  9805. for (NSUInteger i = 0; i < count; ++i) {
  9806. int idx = keys[i] ? 1 : 0;
  9807. _values[idx] = values[i];
  9808. _valueSet[idx] = YES;
  9809. }
  9810. }
  9811. return self;
  9812. }
  9813. - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
  9814. self = [self initWithFloats:NULL forKeys:NULL count:0];
  9815. if (self) {
  9816. if (dictionary) {
  9817. for (int i = 0; i < 2; ++i) {
  9818. if (dictionary->_valueSet[i]) {
  9819. _values[i] = dictionary->_values[i];
  9820. _valueSet[i] = YES;
  9821. }
  9822. }
  9823. }
  9824. }
  9825. return self;
  9826. }
  9827. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9828. #pragma unused(numItems)
  9829. return [self initWithFloats:NULL forKeys:NULL count:0];
  9830. }
  9831. #if !defined(NS_BLOCK_ASSERTIONS)
  9832. - (void)dealloc {
  9833. NSAssert(!_autocreator,
  9834. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9835. [self class], _autocreator);
  9836. [super dealloc];
  9837. }
  9838. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9839. - (instancetype)copyWithZone:(NSZone *)zone {
  9840. return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
  9841. }
  9842. - (BOOL)isEqual:(id)other {
  9843. if (self == other) {
  9844. return YES;
  9845. }
  9846. if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
  9847. return NO;
  9848. }
  9849. GPBBoolFloatDictionary *otherDictionary = other;
  9850. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9851. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9852. return NO;
  9853. }
  9854. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9855. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9856. return NO;
  9857. }
  9858. return YES;
  9859. }
  9860. - (NSUInteger)hash {
  9861. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9862. }
  9863. - (NSString *)description {
  9864. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9865. if (_valueSet[0]) {
  9866. [result appendFormat:@"NO: %f", _values[0]];
  9867. }
  9868. if (_valueSet[1]) {
  9869. [result appendFormat:@"YES: %f", _values[1]];
  9870. }
  9871. [result appendString:@" }"];
  9872. return result;
  9873. }
  9874. - (NSUInteger)count {
  9875. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9876. }
  9877. - (BOOL)getFloat:(float *)value forKey:(BOOL)key {
  9878. int idx = (key ? 1 : 0);
  9879. if (_valueSet[idx]) {
  9880. if (value) {
  9881. *value = _values[idx];
  9882. }
  9883. return YES;
  9884. }
  9885. return NO;
  9886. }
  9887. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9888. forGPBGenericValueKey:(GPBGenericValue *)key {
  9889. int idx = (key->valueBool ? 1 : 0);
  9890. _values[idx] = value->valueFloat;
  9891. _valueSet[idx] = YES;
  9892. }
  9893. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9894. if (_valueSet[0]) {
  9895. block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
  9896. }
  9897. if (_valueSet[1]) {
  9898. block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
  9899. }
  9900. }
  9901. - (void)enumerateKeysAndFloatsUsingBlock:
  9902. (void (^)(BOOL key, float value, BOOL *stop))block {
  9903. BOOL stop = NO;
  9904. if (_valueSet[0]) {
  9905. block(NO, _values[0], &stop);
  9906. }
  9907. if (!stop && _valueSet[1]) {
  9908. block(YES, _values[1], &stop);
  9909. }
  9910. }
  9911. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9912. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9913. NSUInteger count = 0;
  9914. size_t result = 0;
  9915. for (int i = 0; i < 2; ++i) {
  9916. if (_valueSet[i]) {
  9917. ++count;
  9918. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9919. msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9920. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9921. }
  9922. }
  9923. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9924. result += tagSize * count;
  9925. return result;
  9926. }
  9927. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9928. asField:(GPBFieldDescriptor *)field {
  9929. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9930. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9931. for (int i = 0; i < 2; ++i) {
  9932. if (_valueSet[i]) {
  9933. // Write the tag.
  9934. [outputStream writeInt32NoTag:tag];
  9935. // Write the size of the message.
  9936. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9937. msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9938. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9939. // Write the fields.
  9940. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9941. WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9942. }
  9943. }
  9944. }
  9945. - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
  9946. if (otherDictionary) {
  9947. for (int i = 0; i < 2; ++i) {
  9948. if (otherDictionary->_valueSet[i]) {
  9949. _valueSet[i] = YES;
  9950. _values[i] = otherDictionary->_values[i];
  9951. }
  9952. }
  9953. if (_autocreator) {
  9954. GPBAutocreatedDictionaryModified(_autocreator, self);
  9955. }
  9956. }
  9957. }
  9958. - (void)setFloat:(float)value forKey:(BOOL)key {
  9959. int idx = (key ? 1 : 0);
  9960. _values[idx] = value;
  9961. _valueSet[idx] = YES;
  9962. if (_autocreator) {
  9963. GPBAutocreatedDictionaryModified(_autocreator, self);
  9964. }
  9965. }
  9966. - (void)removeFloatForKey:(BOOL)aKey {
  9967. _valueSet[aKey ? 1 : 0] = NO;
  9968. }
  9969. - (void)removeAll {
  9970. _valueSet[0] = NO;
  9971. _valueSet[1] = NO;
  9972. }
  9973. @end
  9974. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
  9975. // This block of code is generated, do not edit it directly.
  9976. #pragma mark - Bool -> Double
  9977. @implementation GPBBoolDoubleDictionary {
  9978. @package
  9979. double _values[2];
  9980. BOOL _valueSet[2];
  9981. }
  9982. - (instancetype)init {
  9983. return [self initWithDoubles:NULL forKeys:NULL count:0];
  9984. }
  9985. - (instancetype)initWithDoubles:(const double [])values
  9986. forKeys:(const BOOL [])keys
  9987. count:(NSUInteger)count {
  9988. self = [super init];
  9989. if (self) {
  9990. for (NSUInteger i = 0; i < count; ++i) {
  9991. int idx = keys[i] ? 1 : 0;
  9992. _values[idx] = values[i];
  9993. _valueSet[idx] = YES;
  9994. }
  9995. }
  9996. return self;
  9997. }
  9998. - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
  9999. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  10000. if (self) {
  10001. if (dictionary) {
  10002. for (int i = 0; i < 2; ++i) {
  10003. if (dictionary->_valueSet[i]) {
  10004. _values[i] = dictionary->_values[i];
  10005. _valueSet[i] = YES;
  10006. }
  10007. }
  10008. }
  10009. }
  10010. return self;
  10011. }
  10012. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  10013. #pragma unused(numItems)
  10014. return [self initWithDoubles:NULL forKeys:NULL count:0];
  10015. }
  10016. #if !defined(NS_BLOCK_ASSERTIONS)
  10017. - (void)dealloc {
  10018. NSAssert(!_autocreator,
  10019. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10020. [self class], _autocreator);
  10021. [super dealloc];
  10022. }
  10023. #endif // !defined(NS_BLOCK_ASSERTIONS)
  10024. - (instancetype)copyWithZone:(NSZone *)zone {
  10025. return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
  10026. }
  10027. - (BOOL)isEqual:(id)other {
  10028. if (self == other) {
  10029. return YES;
  10030. }
  10031. if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
  10032. return NO;
  10033. }
  10034. GPBBoolDoubleDictionary *otherDictionary = other;
  10035. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  10036. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  10037. return NO;
  10038. }
  10039. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  10040. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  10041. return NO;
  10042. }
  10043. return YES;
  10044. }
  10045. - (NSUInteger)hash {
  10046. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10047. }
  10048. - (NSString *)description {
  10049. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10050. if (_valueSet[0]) {
  10051. [result appendFormat:@"NO: %lf", _values[0]];
  10052. }
  10053. if (_valueSet[1]) {
  10054. [result appendFormat:@"YES: %lf", _values[1]];
  10055. }
  10056. [result appendString:@" }"];
  10057. return result;
  10058. }
  10059. - (NSUInteger)count {
  10060. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10061. }
  10062. - (BOOL)getDouble:(double *)value forKey:(BOOL)key {
  10063. int idx = (key ? 1 : 0);
  10064. if (_valueSet[idx]) {
  10065. if (value) {
  10066. *value = _values[idx];
  10067. }
  10068. return YES;
  10069. }
  10070. return NO;
  10071. }
  10072. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10073. forGPBGenericValueKey:(GPBGenericValue *)key {
  10074. int idx = (key->valueBool ? 1 : 0);
  10075. _values[idx] = value->valueDouble;
  10076. _valueSet[idx] = YES;
  10077. }
  10078. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10079. if (_valueSet[0]) {
  10080. block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
  10081. }
  10082. if (_valueSet[1]) {
  10083. block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
  10084. }
  10085. }
  10086. - (void)enumerateKeysAndDoublesUsingBlock:
  10087. (void (^)(BOOL key, double value, BOOL *stop))block {
  10088. BOOL stop = NO;
  10089. if (_valueSet[0]) {
  10090. block(NO, _values[0], &stop);
  10091. }
  10092. if (!stop && _valueSet[1]) {
  10093. block(YES, _values[1], &stop);
  10094. }
  10095. }
  10096. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10097. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10098. NSUInteger count = 0;
  10099. size_t result = 0;
  10100. for (int i = 0; i < 2; ++i) {
  10101. if (_valueSet[i]) {
  10102. ++count;
  10103. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10104. msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10105. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10106. }
  10107. }
  10108. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10109. result += tagSize * count;
  10110. return result;
  10111. }
  10112. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10113. asField:(GPBFieldDescriptor *)field {
  10114. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10115. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10116. for (int i = 0; i < 2; ++i) {
  10117. if (_valueSet[i]) {
  10118. // Write the tag.
  10119. [outputStream writeInt32NoTag:tag];
  10120. // Write the size of the message.
  10121. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10122. msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10123. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10124. // Write the fields.
  10125. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10126. WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10127. }
  10128. }
  10129. }
  10130. - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
  10131. if (otherDictionary) {
  10132. for (int i = 0; i < 2; ++i) {
  10133. if (otherDictionary->_valueSet[i]) {
  10134. _valueSet[i] = YES;
  10135. _values[i] = otherDictionary->_values[i];
  10136. }
  10137. }
  10138. if (_autocreator) {
  10139. GPBAutocreatedDictionaryModified(_autocreator, self);
  10140. }
  10141. }
  10142. }
  10143. - (void)setDouble:(double)value forKey:(BOOL)key {
  10144. int idx = (key ? 1 : 0);
  10145. _values[idx] = value;
  10146. _valueSet[idx] = YES;
  10147. if (_autocreator) {
  10148. GPBAutocreatedDictionaryModified(_autocreator, self);
  10149. }
  10150. }
  10151. - (void)removeDoubleForKey:(BOOL)aKey {
  10152. _valueSet[aKey ? 1 : 0] = NO;
  10153. }
  10154. - (void)removeAll {
  10155. _valueSet[0] = NO;
  10156. _valueSet[1] = NO;
  10157. }
  10158. @end
  10159. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
  10160. // This block of code is generated, do not edit it directly.
  10161. #pragma mark - Bool -> Object
  10162. @implementation GPBBoolObjectDictionary {
  10163. @package
  10164. id _values[2];
  10165. }
  10166. - (instancetype)init {
  10167. return [self initWithObjects:NULL forKeys:NULL count:0];
  10168. }
  10169. - (instancetype)initWithObjects:(const id [])objects
  10170. forKeys:(const BOOL [])keys
  10171. count:(NSUInteger)count {
  10172. self = [super init];
  10173. if (self) {
  10174. for (NSUInteger i = 0; i < count; ++i) {
  10175. if (!objects[i]) {
  10176. [NSException raise:NSInvalidArgumentException
  10177. format:@"Attempting to add nil object to a Dictionary"];
  10178. }
  10179. int idx = keys[i] ? 1 : 0;
  10180. [_values[idx] release];
  10181. _values[idx] = (id)[objects[i] retain];
  10182. }
  10183. }
  10184. return self;
  10185. }
  10186. - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
  10187. self = [self initWithObjects:NULL forKeys:NULL count:0];
  10188. if (self) {
  10189. if (dictionary) {
  10190. _values[0] = [dictionary->_values[0] retain];
  10191. _values[1] = [dictionary->_values[1] retain];
  10192. }
  10193. }
  10194. return self;
  10195. }
  10196. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  10197. #pragma unused(numItems)
  10198. return [self initWithObjects:NULL forKeys:NULL count:0];
  10199. }
  10200. - (void)dealloc {
  10201. NSAssert(!_autocreator,
  10202. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10203. [self class], _autocreator);
  10204. [_values[0] release];
  10205. [_values[1] release];
  10206. [super dealloc];
  10207. }
  10208. - (instancetype)copyWithZone:(NSZone *)zone {
  10209. return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
  10210. }
  10211. - (BOOL)isEqual:(id)other {
  10212. if (self == other) {
  10213. return YES;
  10214. }
  10215. if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
  10216. return NO;
  10217. }
  10218. GPBBoolObjectDictionary *otherDictionary = other;
  10219. if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
  10220. ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
  10221. return NO;
  10222. }
  10223. if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
  10224. ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
  10225. return NO;
  10226. }
  10227. return YES;
  10228. }
  10229. - (NSUInteger)hash {
  10230. return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
  10231. }
  10232. - (NSString *)description {
  10233. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10234. if ((_values[0] != nil)) {
  10235. [result appendFormat:@"NO: %@", _values[0]];
  10236. }
  10237. if ((_values[1] != nil)) {
  10238. [result appendFormat:@"YES: %@", _values[1]];
  10239. }
  10240. [result appendString:@" }"];
  10241. return result;
  10242. }
  10243. - (NSUInteger)count {
  10244. return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
  10245. }
  10246. - (id)objectForKey:(BOOL)key {
  10247. return _values[key ? 1 : 0];
  10248. }
  10249. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10250. forGPBGenericValueKey:(GPBGenericValue *)key {
  10251. int idx = (key->valueBool ? 1 : 0);
  10252. [_values[idx] release];
  10253. _values[idx] = [value->valueString retain];
  10254. }
  10255. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10256. if (_values[0] != nil) {
  10257. block(@"false", _values[0]);
  10258. }
  10259. if ((_values[1] != nil)) {
  10260. block(@"true", _values[1]);
  10261. }
  10262. }
  10263. - (void)enumerateKeysAndObjectsUsingBlock:
  10264. (void (^)(BOOL key, id object, BOOL *stop))block {
  10265. BOOL stop = NO;
  10266. if (_values[0] != nil) {
  10267. block(NO, _values[0], &stop);
  10268. }
  10269. if (!stop && (_values[1] != nil)) {
  10270. block(YES, _values[1], &stop);
  10271. }
  10272. }
  10273. - (BOOL)isInitialized {
  10274. if (_values[0] && ![_values[0] isInitialized]) {
  10275. return NO;
  10276. }
  10277. if (_values[1] && ![_values[1] isInitialized]) {
  10278. return NO;
  10279. }
  10280. return YES;
  10281. }
  10282. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  10283. GPBBoolObjectDictionary *newDict =
  10284. [[GPBBoolObjectDictionary alloc] init];
  10285. for (int i = 0; i < 2; ++i) {
  10286. if (_values[i] != nil) {
  10287. newDict->_values[i] = [_values[i] copyWithZone:zone];
  10288. }
  10289. }
  10290. return newDict;
  10291. }
  10292. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10293. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10294. NSUInteger count = 0;
  10295. size_t result = 0;
  10296. for (int i = 0; i < 2; ++i) {
  10297. if (_values[i] != nil) {
  10298. ++count;
  10299. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10300. msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10301. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10302. }
  10303. }
  10304. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10305. result += tagSize * count;
  10306. return result;
  10307. }
  10308. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10309. asField:(GPBFieldDescriptor *)field {
  10310. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10311. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10312. for (int i = 0; i < 2; ++i) {
  10313. if (_values[i] != nil) {
  10314. // Write the tag.
  10315. [outputStream writeInt32NoTag:tag];
  10316. // Write the size of the message.
  10317. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10318. msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10319. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10320. // Write the fields.
  10321. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10322. WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10323. }
  10324. }
  10325. }
  10326. - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
  10327. if (otherDictionary) {
  10328. for (int i = 0; i < 2; ++i) {
  10329. if (otherDictionary->_values[i] != nil) {
  10330. [_values[i] release];
  10331. _values[i] = [otherDictionary->_values[i] retain];
  10332. }
  10333. }
  10334. if (_autocreator) {
  10335. GPBAutocreatedDictionaryModified(_autocreator, self);
  10336. }
  10337. }
  10338. }
  10339. - (void)setObject:(id)object forKey:(BOOL)key {
  10340. if (!object) {
  10341. [NSException raise:NSInvalidArgumentException
  10342. format:@"Attempting to add nil object to a Dictionary"];
  10343. }
  10344. int idx = (key ? 1 : 0);
  10345. [_values[idx] release];
  10346. _values[idx] = [object retain];
  10347. if (_autocreator) {
  10348. GPBAutocreatedDictionaryModified(_autocreator, self);
  10349. }
  10350. }
  10351. - (void)removeObjectForKey:(BOOL)aKey {
  10352. int idx = (aKey ? 1 : 0);
  10353. [_values[idx] release];
  10354. _values[idx] = nil;
  10355. }
  10356. - (void)removeAll {
  10357. for (int i = 0; i < 2; ++i) {
  10358. [_values[i] release];
  10359. _values[i] = nil;
  10360. }
  10361. }
  10362. @end
  10363. //%PDDM-EXPAND-END (8 expansions)
  10364. #pragma mark - Bool -> Enum
  10365. @implementation GPBBoolEnumDictionary {
  10366. @package
  10367. GPBEnumValidationFunc _validationFunc;
  10368. int32_t _values[2];
  10369. BOOL _valueSet[2];
  10370. }
  10371. @synthesize validationFunc = _validationFunc;
  10372. - (instancetype)init {
  10373. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  10374. }
  10375. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  10376. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  10377. }
  10378. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  10379. rawValues:(const int32_t [])rawValues
  10380. forKeys:(const BOOL [])keys
  10381. count:(NSUInteger)count {
  10382. self = [super init];
  10383. if (self) {
  10384. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  10385. for (NSUInteger i = 0; i < count; ++i) {
  10386. int idx = keys[i] ? 1 : 0;
  10387. _values[idx] = rawValues[i];
  10388. _valueSet[idx] = YES;
  10389. }
  10390. }
  10391. return self;
  10392. }
  10393. - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
  10394. self = [self initWithValidationFunction:dictionary.validationFunc
  10395. rawValues:NULL
  10396. forKeys:NULL
  10397. count:0];
  10398. if (self) {
  10399. if (dictionary) {
  10400. for (int i = 0; i < 2; ++i) {
  10401. if (dictionary->_valueSet[i]) {
  10402. _values[i] = dictionary->_values[i];
  10403. _valueSet[i] = YES;
  10404. }
  10405. }
  10406. }
  10407. }
  10408. return self;
  10409. }
  10410. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  10411. capacity:(NSUInteger)numItems {
  10412. #pragma unused(numItems)
  10413. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  10414. }
  10415. #if !defined(NS_BLOCK_ASSERTIONS)
  10416. - (void)dealloc {
  10417. NSAssert(!_autocreator,
  10418. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10419. [self class], _autocreator);
  10420. [super dealloc];
  10421. }
  10422. #endif // !defined(NS_BLOCK_ASSERTIONS)
  10423. - (instancetype)copyWithZone:(NSZone *)zone {
  10424. return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
  10425. }
  10426. - (BOOL)isEqual:(id)other {
  10427. if (self == other) {
  10428. return YES;
  10429. }
  10430. if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
  10431. return NO;
  10432. }
  10433. GPBBoolEnumDictionary *otherDictionary = other;
  10434. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  10435. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  10436. return NO;
  10437. }
  10438. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  10439. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  10440. return NO;
  10441. }
  10442. return YES;
  10443. }
  10444. - (NSUInteger)hash {
  10445. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10446. }
  10447. - (NSString *)description {
  10448. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10449. if (_valueSet[0]) {
  10450. [result appendFormat:@"NO: %d", _values[0]];
  10451. }
  10452. if (_valueSet[1]) {
  10453. [result appendFormat:@"YES: %d", _values[1]];
  10454. }
  10455. [result appendString:@" }"];
  10456. return result;
  10457. }
  10458. - (NSUInteger)count {
  10459. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10460. }
  10461. - (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
  10462. int idx = (key ? 1 : 0);
  10463. if (_valueSet[idx]) {
  10464. if (value) {
  10465. int32_t result = _values[idx];
  10466. if (!_validationFunc(result)) {
  10467. result = kGPBUnrecognizedEnumeratorValue;
  10468. }
  10469. *value = result;
  10470. }
  10471. return YES;
  10472. }
  10473. return NO;
  10474. }
  10475. - (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
  10476. int idx = (key ? 1 : 0);
  10477. if (_valueSet[idx]) {
  10478. if (rawValue) {
  10479. *rawValue = _values[idx];
  10480. }
  10481. return YES;
  10482. }
  10483. return NO;
  10484. }
  10485. - (void)enumerateKeysAndRawValuesUsingBlock:
  10486. (void (^)(BOOL key, int32_t value, BOOL *stop))block {
  10487. BOOL stop = NO;
  10488. if (_valueSet[0]) {
  10489. block(NO, _values[0], &stop);
  10490. }
  10491. if (!stop && _valueSet[1]) {
  10492. block(YES, _values[1], &stop);
  10493. }
  10494. }
  10495. - (void)enumerateKeysAndEnumsUsingBlock:
  10496. (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block {
  10497. BOOL stop = NO;
  10498. GPBEnumValidationFunc func = _validationFunc;
  10499. int32_t validatedValue;
  10500. if (_valueSet[0]) {
  10501. validatedValue = _values[0];
  10502. if (!func(validatedValue)) {
  10503. validatedValue = kGPBUnrecognizedEnumeratorValue;
  10504. }
  10505. block(NO, validatedValue, &stop);
  10506. }
  10507. if (!stop && _valueSet[1]) {
  10508. validatedValue = _values[1];
  10509. if (!func(validatedValue)) {
  10510. validatedValue = kGPBUnrecognizedEnumeratorValue;
  10511. }
  10512. block(YES, validatedValue, &stop);
  10513. }
  10514. }
  10515. //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
  10516. // This block of code is generated, do not edit it directly.
  10517. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  10518. forKey:(GPBGenericValue *)key
  10519. keyDataType:(GPBDataType)keyDataType {
  10520. size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
  10521. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  10522. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  10523. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  10524. WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
  10525. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  10526. [outputStream release];
  10527. return data;
  10528. }
  10529. //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
  10530. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10531. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10532. NSUInteger count = 0;
  10533. size_t result = 0;
  10534. for (int i = 0; i < 2; ++i) {
  10535. if (_valueSet[i]) {
  10536. ++count;
  10537. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10538. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10539. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10540. }
  10541. }
  10542. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10543. result += tagSize * count;
  10544. return result;
  10545. }
  10546. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10547. asField:(GPBFieldDescriptor *)field {
  10548. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10549. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10550. for (int i = 0; i < 2; ++i) {
  10551. if (_valueSet[i]) {
  10552. // Write the tag.
  10553. [outputStream writeInt32NoTag:tag];
  10554. // Write the size of the message.
  10555. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10556. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10557. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10558. // Write the fields.
  10559. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10560. WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10561. }
  10562. }
  10563. }
  10564. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10565. if (_valueSet[0]) {
  10566. block(@"false", @(_values[0]));
  10567. }
  10568. if (_valueSet[1]) {
  10569. block(@"true", @(_values[1]));
  10570. }
  10571. }
  10572. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10573. forGPBGenericValueKey:(GPBGenericValue *)key {
  10574. int idx = (key->valueBool ? 1 : 0);
  10575. _values[idx] = value->valueInt32;
  10576. _valueSet[idx] = YES;
  10577. }
  10578. - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
  10579. if (otherDictionary) {
  10580. for (int i = 0; i < 2; ++i) {
  10581. if (otherDictionary->_valueSet[i]) {
  10582. _valueSet[i] = YES;
  10583. _values[i] = otherDictionary->_values[i];
  10584. }
  10585. }
  10586. if (_autocreator) {
  10587. GPBAutocreatedDictionaryModified(_autocreator, self);
  10588. }
  10589. }
  10590. }
  10591. - (void)setEnum:(int32_t)value forKey:(BOOL)key {
  10592. if (!_validationFunc(value)) {
  10593. [NSException raise:NSInvalidArgumentException
  10594. format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
  10595. value];
  10596. }
  10597. int idx = (key ? 1 : 0);
  10598. _values[idx] = value;
  10599. _valueSet[idx] = YES;
  10600. if (_autocreator) {
  10601. GPBAutocreatedDictionaryModified(_autocreator, self);
  10602. }
  10603. }
  10604. - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
  10605. int idx = (key ? 1 : 0);
  10606. _values[idx] = rawValue;
  10607. _valueSet[idx] = YES;
  10608. if (_autocreator) {
  10609. GPBAutocreatedDictionaryModified(_autocreator, self);
  10610. }
  10611. }
  10612. - (void)removeEnumForKey:(BOOL)aKey {
  10613. _valueSet[aKey ? 1 : 0] = NO;
  10614. }
  10615. - (void)removeAll {
  10616. _valueSet[0] = NO;
  10617. _valueSet[1] = NO;
  10618. }
  10619. @end
  10620. #pragma mark - NSDictionary Subclass
  10621. @implementation GPBAutocreatedDictionary {
  10622. NSMutableDictionary *_dictionary;
  10623. }
  10624. - (void)dealloc {
  10625. NSAssert(!_autocreator,
  10626. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10627. [self class], _autocreator);
  10628. [_dictionary release];
  10629. [super dealloc];
  10630. }
  10631. #pragma mark Required NSDictionary overrides
  10632. - (instancetype)initWithObjects:(const id [])objects
  10633. forKeys:(const id<NSCopying> [])keys
  10634. count:(NSUInteger)count {
  10635. self = [super init];
  10636. if (self) {
  10637. _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
  10638. forKeys:keys
  10639. count:count];
  10640. }
  10641. return self;
  10642. }
  10643. - (NSUInteger)count {
  10644. return [_dictionary count];
  10645. }
  10646. - (id)objectForKey:(id)aKey {
  10647. return [_dictionary objectForKey:aKey];
  10648. }
  10649. - (NSEnumerator *)keyEnumerator {
  10650. if (_dictionary == nil) {
  10651. _dictionary = [[NSMutableDictionary alloc] init];
  10652. }
  10653. return [_dictionary keyEnumerator];
  10654. }
  10655. #pragma mark Required NSMutableDictionary overrides
  10656. // Only need to call GPBAutocreatedDictionaryModified() when adding things
  10657. // since we only autocreate empty dictionaries.
  10658. - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
  10659. if (_dictionary == nil) {
  10660. _dictionary = [[NSMutableDictionary alloc] init];
  10661. }
  10662. [_dictionary setObject:anObject forKey:aKey];
  10663. if (_autocreator) {
  10664. GPBAutocreatedDictionaryModified(_autocreator, self);
  10665. }
  10666. }
  10667. - (void)removeObjectForKey:(id)aKey {
  10668. [_dictionary removeObjectForKey:aKey];
  10669. }
  10670. #pragma mark Extra things hooked
  10671. - (id)copyWithZone:(NSZone *)zone {
  10672. if (_dictionary == nil) {
  10673. return [[NSMutableDictionary allocWithZone:zone] init];
  10674. }
  10675. return [_dictionary copyWithZone:zone];
  10676. }
  10677. - (id)mutableCopyWithZone:(NSZone *)zone {
  10678. if (_dictionary == nil) {
  10679. return [[NSMutableDictionary allocWithZone:zone] init];
  10680. }
  10681. return [_dictionary mutableCopyWithZone:zone];
  10682. }
  10683. // Not really needed, but subscripting is likely common enough it doesn't hurt
  10684. // to ensure it goes directly to the real NSMutableDictionary.
  10685. - (id)objectForKeyedSubscript:(id)key {
  10686. return [_dictionary objectForKeyedSubscript:key];
  10687. }
  10688. // Not really needed, but subscripting is likely common enough it doesn't hurt
  10689. // to ensure it goes directly to the real NSMutableDictionary.
  10690. - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
  10691. if (_dictionary == nil) {
  10692. _dictionary = [[NSMutableDictionary alloc] init];
  10693. }
  10694. [_dictionary setObject:obj forKeyedSubscript:key];
  10695. if (_autocreator) {
  10696. GPBAutocreatedDictionaryModified(_autocreator, self);
  10697. }
  10698. }
  10699. - (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key,
  10700. id obj,
  10701. BOOL *stop))block {
  10702. [_dictionary enumerateKeysAndObjectsUsingBlock:block];
  10703. }
  10704. - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
  10705. usingBlock:(void (NS_NOESCAPE ^)(id key,
  10706. id obj,
  10707. BOOL *stop))block {
  10708. [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
  10709. }
  10710. @end
  10711. #pragma clang diagnostic pop