GPBDictionary.m 374 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125
  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. }else {
  2723. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  2724. }
  2725. }
  2726. }
  2727. }
  2728. return self;
  2729. }
  2730. - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
  2731. self = [self initWithObjects:NULL forKeys:NULL count:0];
  2732. if (self) {
  2733. if (dictionary) {
  2734. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2735. }
  2736. }
  2737. return self;
  2738. }
  2739. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2740. #pragma unused(numItems)
  2741. return [self initWithObjects:NULL forKeys:NULL count:0];
  2742. }
  2743. - (void)dealloc {
  2744. NSAssert(!_autocreator,
  2745. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2746. [self class], _autocreator);
  2747. [_dictionary release];
  2748. [super dealloc];
  2749. }
  2750. - (instancetype)copyWithZone:(NSZone *)zone {
  2751. return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  2752. }
  2753. - (BOOL)isEqual:(id)other {
  2754. if (self == other) {
  2755. return YES;
  2756. }
  2757. if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
  2758. return NO;
  2759. }
  2760. GPBUInt32ObjectDictionary *otherDictionary = other;
  2761. return [_dictionary isEqual:otherDictionary->_dictionary];
  2762. }
  2763. - (NSUInteger)hash {
  2764. return _dictionary.count;
  2765. }
  2766. - (NSString *)description {
  2767. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2768. }
  2769. - (NSUInteger)count {
  2770. return _dictionary.count;
  2771. }
  2772. - (void)enumerateKeysAndObjectsUsingBlock:
  2773. (void (^)(uint32_t key, id object, BOOL *stop))block {
  2774. BOOL stop = NO;
  2775. NSDictionary *internal = _dictionary;
  2776. NSEnumerator *keys = [internal keyEnumerator];
  2777. NSNumber *aKey;
  2778. while ((aKey = [keys nextObject])) {
  2779. id aObject = internal[aKey];
  2780. block([aKey unsignedIntValue], aObject, &stop);
  2781. if (stop) {
  2782. break;
  2783. }
  2784. }
  2785. }
  2786. - (BOOL)isInitialized {
  2787. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  2788. if (!msg.initialized) {
  2789. return NO;
  2790. }
  2791. }
  2792. return YES;
  2793. }
  2794. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  2795. GPBUInt32ObjectDictionary *newDict =
  2796. [[GPBUInt32ObjectDictionary alloc] init];
  2797. NSEnumerator *keys = [_dictionary keyEnumerator];
  2798. id aKey;
  2799. NSMutableDictionary *internalDict = newDict->_dictionary;
  2800. while ((aKey = [keys nextObject])) {
  2801. GPBMessage *msg = _dictionary[aKey];
  2802. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  2803. [internalDict setObject:copiedMsg forKey:aKey];
  2804. [copiedMsg release];
  2805. }
  2806. return newDict;
  2807. }
  2808. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2809. NSDictionary *internal = _dictionary;
  2810. NSUInteger count = internal.count;
  2811. if (count == 0) {
  2812. return 0;
  2813. }
  2814. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2815. GPBDataType keyDataType = field.mapKeyDataType;
  2816. size_t result = 0;
  2817. NSEnumerator *keys = [internal keyEnumerator];
  2818. NSNumber *aKey;
  2819. while ((aKey = [keys nextObject])) {
  2820. id aObject = internal[aKey];
  2821. size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
  2822. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  2823. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2824. }
  2825. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2826. result += tagSize * count;
  2827. return result;
  2828. }
  2829. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2830. asField:(GPBFieldDescriptor *)field {
  2831. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2832. GPBDataType keyDataType = field.mapKeyDataType;
  2833. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2834. NSDictionary *internal = _dictionary;
  2835. NSEnumerator *keys = [internal keyEnumerator];
  2836. NSNumber *aKey;
  2837. while ((aKey = [keys nextObject])) {
  2838. id aObject = internal[aKey];
  2839. [outputStream writeInt32NoTag:tag];
  2840. // Write the size of the message.
  2841. uint32_t unwrappedKey = [aKey unsignedIntValue];
  2842. id unwrappedValue = aObject;
  2843. size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2844. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  2845. [outputStream writeInt32NoTag:(int32_t)msgSize];
  2846. // Write the fields.
  2847. WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  2848. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  2849. }
  2850. }
  2851. - (void)setGPBGenericValue:(GPBGenericValue *)value
  2852. forGPBGenericValueKey:(GPBGenericValue *)key {
  2853. [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
  2854. }
  2855. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  2856. [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
  2857. #pragma unused(stop)
  2858. block([NSString stringWithFormat:@"%u", key], object);
  2859. }];
  2860. }
  2861. - (id)objectForKey:(uint32_t)key {
  2862. id result = [_dictionary objectForKey:@(key)];
  2863. return result;
  2864. }
  2865. - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
  2866. if (otherDictionary) {
  2867. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  2868. if (_autocreator) {
  2869. GPBAutocreatedDictionaryModified(_autocreator, self);
  2870. }
  2871. }
  2872. }
  2873. - (void)setObject:(id)object forKey:(uint32_t)key {
  2874. if (!object) {
  2875. [NSException raise:NSInvalidArgumentException
  2876. format:@"Attempting to add nil object to a Dictionary"];
  2877. }
  2878. [_dictionary setObject:object forKey:@(key)];
  2879. if (_autocreator) {
  2880. GPBAutocreatedDictionaryModified(_autocreator, self);
  2881. }
  2882. }
  2883. - (void)removeObjectForKey:(uint32_t)aKey {
  2884. [_dictionary removeObjectForKey:@(aKey)];
  2885. }
  2886. - (void)removeAll {
  2887. [_dictionary removeAllObjects];
  2888. }
  2889. @end
  2890. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
  2891. // This block of code is generated, do not edit it directly.
  2892. #pragma mark - Int32 -> UInt32
  2893. @implementation GPBInt32UInt32Dictionary {
  2894. @package
  2895. NSMutableDictionary *_dictionary;
  2896. }
  2897. - (instancetype)init {
  2898. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  2899. }
  2900. - (instancetype)initWithUInt32s:(const uint32_t [])values
  2901. forKeys:(const int32_t [])keys
  2902. count:(NSUInteger)count {
  2903. self = [super init];
  2904. if (self) {
  2905. _dictionary = [[NSMutableDictionary alloc] init];
  2906. if (count && values && keys) {
  2907. for (NSUInteger i = 0; i < count; ++i) {
  2908. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  2909. }
  2910. }
  2911. }
  2912. return self;
  2913. }
  2914. - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
  2915. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  2916. if (self) {
  2917. if (dictionary) {
  2918. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  2919. }
  2920. }
  2921. return self;
  2922. }
  2923. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  2924. #pragma unused(numItems)
  2925. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  2926. }
  2927. - (void)dealloc {
  2928. NSAssert(!_autocreator,
  2929. @"%@: Autocreator must be cleared before release, autocreator: %@",
  2930. [self class], _autocreator);
  2931. [_dictionary release];
  2932. [super dealloc];
  2933. }
  2934. - (instancetype)copyWithZone:(NSZone *)zone {
  2935. return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  2936. }
  2937. - (BOOL)isEqual:(id)other {
  2938. if (self == other) {
  2939. return YES;
  2940. }
  2941. if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
  2942. return NO;
  2943. }
  2944. GPBInt32UInt32Dictionary *otherDictionary = other;
  2945. return [_dictionary isEqual:otherDictionary->_dictionary];
  2946. }
  2947. - (NSUInteger)hash {
  2948. return _dictionary.count;
  2949. }
  2950. - (NSString *)description {
  2951. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  2952. }
  2953. - (NSUInteger)count {
  2954. return _dictionary.count;
  2955. }
  2956. - (void)enumerateKeysAndUInt32sUsingBlock:
  2957. (void (^)(int32_t key, uint32_t value, BOOL *stop))block {
  2958. BOOL stop = NO;
  2959. NSDictionary *internal = _dictionary;
  2960. NSEnumerator *keys = [internal keyEnumerator];
  2961. NSNumber *aKey;
  2962. while ((aKey = [keys nextObject])) {
  2963. NSNumber *aValue = internal[aKey];
  2964. block([aKey intValue], [aValue unsignedIntValue], &stop);
  2965. if (stop) {
  2966. break;
  2967. }
  2968. }
  2969. }
  2970. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  2971. NSDictionary *internal = _dictionary;
  2972. NSUInteger count = internal.count;
  2973. if (count == 0) {
  2974. return 0;
  2975. }
  2976. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2977. GPBDataType keyDataType = field.mapKeyDataType;
  2978. size_t result = 0;
  2979. NSEnumerator *keys = [internal keyEnumerator];
  2980. NSNumber *aKey;
  2981. while ((aKey = [keys nextObject])) {
  2982. NSNumber *aValue = internal[aKey];
  2983. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  2984. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  2985. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  2986. }
  2987. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  2988. result += tagSize * count;
  2989. return result;
  2990. }
  2991. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  2992. asField:(GPBFieldDescriptor *)field {
  2993. GPBDataType valueDataType = GPBGetFieldDataType(field);
  2994. GPBDataType keyDataType = field.mapKeyDataType;
  2995. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  2996. NSDictionary *internal = _dictionary;
  2997. NSEnumerator *keys = [internal keyEnumerator];
  2998. NSNumber *aKey;
  2999. while ((aKey = [keys nextObject])) {
  3000. NSNumber *aValue = internal[aKey];
  3001. [outputStream writeInt32NoTag:tag];
  3002. // Write the size of the message.
  3003. int32_t unwrappedKey = [aKey intValue];
  3004. uint32_t unwrappedValue = [aValue unsignedIntValue];
  3005. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3006. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3007. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3008. // Write the fields.
  3009. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3010. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3011. }
  3012. }
  3013. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3014. forGPBGenericValueKey:(GPBGenericValue *)key {
  3015. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
  3016. }
  3017. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3018. [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
  3019. #pragma unused(stop)
  3020. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
  3021. }];
  3022. }
  3023. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
  3024. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3025. if (wrapped && value) {
  3026. *value = [wrapped unsignedIntValue];
  3027. }
  3028. return (wrapped != NULL);
  3029. }
  3030. - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
  3031. if (otherDictionary) {
  3032. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3033. if (_autocreator) {
  3034. GPBAutocreatedDictionaryModified(_autocreator, self);
  3035. }
  3036. }
  3037. }
  3038. - (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
  3039. [_dictionary setObject:@(value) forKey:@(key)];
  3040. if (_autocreator) {
  3041. GPBAutocreatedDictionaryModified(_autocreator, self);
  3042. }
  3043. }
  3044. - (void)removeUInt32ForKey:(int32_t)aKey {
  3045. [_dictionary removeObjectForKey:@(aKey)];
  3046. }
  3047. - (void)removeAll {
  3048. [_dictionary removeAllObjects];
  3049. }
  3050. @end
  3051. #pragma mark - Int32 -> Int32
  3052. @implementation GPBInt32Int32Dictionary {
  3053. @package
  3054. NSMutableDictionary *_dictionary;
  3055. }
  3056. - (instancetype)init {
  3057. return [self initWithInt32s:NULL forKeys:NULL count:0];
  3058. }
  3059. - (instancetype)initWithInt32s:(const int32_t [])values
  3060. forKeys:(const int32_t [])keys
  3061. count:(NSUInteger)count {
  3062. self = [super init];
  3063. if (self) {
  3064. _dictionary = [[NSMutableDictionary alloc] init];
  3065. if (count && values && keys) {
  3066. for (NSUInteger i = 0; i < count; ++i) {
  3067. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3068. }
  3069. }
  3070. }
  3071. return self;
  3072. }
  3073. - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
  3074. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  3075. if (self) {
  3076. if (dictionary) {
  3077. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3078. }
  3079. }
  3080. return self;
  3081. }
  3082. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3083. #pragma unused(numItems)
  3084. return [self initWithInt32s:NULL forKeys:NULL count:0];
  3085. }
  3086. - (void)dealloc {
  3087. NSAssert(!_autocreator,
  3088. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3089. [self class], _autocreator);
  3090. [_dictionary release];
  3091. [super dealloc];
  3092. }
  3093. - (instancetype)copyWithZone:(NSZone *)zone {
  3094. return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  3095. }
  3096. - (BOOL)isEqual:(id)other {
  3097. if (self == other) {
  3098. return YES;
  3099. }
  3100. if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
  3101. return NO;
  3102. }
  3103. GPBInt32Int32Dictionary *otherDictionary = other;
  3104. return [_dictionary isEqual:otherDictionary->_dictionary];
  3105. }
  3106. - (NSUInteger)hash {
  3107. return _dictionary.count;
  3108. }
  3109. - (NSString *)description {
  3110. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3111. }
  3112. - (NSUInteger)count {
  3113. return _dictionary.count;
  3114. }
  3115. - (void)enumerateKeysAndInt32sUsingBlock:
  3116. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  3117. BOOL stop = NO;
  3118. NSDictionary *internal = _dictionary;
  3119. NSEnumerator *keys = [internal keyEnumerator];
  3120. NSNumber *aKey;
  3121. while ((aKey = [keys nextObject])) {
  3122. NSNumber *aValue = internal[aKey];
  3123. block([aKey intValue], [aValue intValue], &stop);
  3124. if (stop) {
  3125. break;
  3126. }
  3127. }
  3128. }
  3129. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3130. NSDictionary *internal = _dictionary;
  3131. NSUInteger count = internal.count;
  3132. if (count == 0) {
  3133. return 0;
  3134. }
  3135. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3136. GPBDataType keyDataType = field.mapKeyDataType;
  3137. size_t result = 0;
  3138. NSEnumerator *keys = [internal keyEnumerator];
  3139. NSNumber *aKey;
  3140. while ((aKey = [keys nextObject])) {
  3141. NSNumber *aValue = internal[aKey];
  3142. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3143. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  3144. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3145. }
  3146. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3147. result += tagSize * count;
  3148. return result;
  3149. }
  3150. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3151. asField:(GPBFieldDescriptor *)field {
  3152. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3153. GPBDataType keyDataType = field.mapKeyDataType;
  3154. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3155. NSDictionary *internal = _dictionary;
  3156. NSEnumerator *keys = [internal keyEnumerator];
  3157. NSNumber *aKey;
  3158. while ((aKey = [keys nextObject])) {
  3159. NSNumber *aValue = internal[aKey];
  3160. [outputStream writeInt32NoTag:tag];
  3161. // Write the size of the message.
  3162. int32_t unwrappedKey = [aKey intValue];
  3163. int32_t unwrappedValue = [aValue intValue];
  3164. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3165. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3166. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3167. // Write the fields.
  3168. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3169. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3170. }
  3171. }
  3172. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3173. forGPBGenericValueKey:(GPBGenericValue *)key {
  3174. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
  3175. }
  3176. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3177. [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
  3178. #pragma unused(stop)
  3179. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
  3180. }];
  3181. }
  3182. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
  3183. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3184. if (wrapped && value) {
  3185. *value = [wrapped intValue];
  3186. }
  3187. return (wrapped != NULL);
  3188. }
  3189. - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
  3190. if (otherDictionary) {
  3191. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3192. if (_autocreator) {
  3193. GPBAutocreatedDictionaryModified(_autocreator, self);
  3194. }
  3195. }
  3196. }
  3197. - (void)setInt32:(int32_t)value forKey:(int32_t)key {
  3198. [_dictionary setObject:@(value) forKey:@(key)];
  3199. if (_autocreator) {
  3200. GPBAutocreatedDictionaryModified(_autocreator, self);
  3201. }
  3202. }
  3203. - (void)removeInt32ForKey:(int32_t)aKey {
  3204. [_dictionary removeObjectForKey:@(aKey)];
  3205. }
  3206. - (void)removeAll {
  3207. [_dictionary removeAllObjects];
  3208. }
  3209. @end
  3210. #pragma mark - Int32 -> UInt64
  3211. @implementation GPBInt32UInt64Dictionary {
  3212. @package
  3213. NSMutableDictionary *_dictionary;
  3214. }
  3215. - (instancetype)init {
  3216. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  3217. }
  3218. - (instancetype)initWithUInt64s:(const uint64_t [])values
  3219. forKeys:(const int32_t [])keys
  3220. count:(NSUInteger)count {
  3221. self = [super init];
  3222. if (self) {
  3223. _dictionary = [[NSMutableDictionary alloc] init];
  3224. if (count && values && keys) {
  3225. for (NSUInteger i = 0; i < count; ++i) {
  3226. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3227. }
  3228. }
  3229. }
  3230. return self;
  3231. }
  3232. - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
  3233. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  3234. if (self) {
  3235. if (dictionary) {
  3236. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3237. }
  3238. }
  3239. return self;
  3240. }
  3241. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3242. #pragma unused(numItems)
  3243. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  3244. }
  3245. - (void)dealloc {
  3246. NSAssert(!_autocreator,
  3247. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3248. [self class], _autocreator);
  3249. [_dictionary release];
  3250. [super dealloc];
  3251. }
  3252. - (instancetype)copyWithZone:(NSZone *)zone {
  3253. return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  3254. }
  3255. - (BOOL)isEqual:(id)other {
  3256. if (self == other) {
  3257. return YES;
  3258. }
  3259. if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
  3260. return NO;
  3261. }
  3262. GPBInt32UInt64Dictionary *otherDictionary = other;
  3263. return [_dictionary isEqual:otherDictionary->_dictionary];
  3264. }
  3265. - (NSUInteger)hash {
  3266. return _dictionary.count;
  3267. }
  3268. - (NSString *)description {
  3269. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3270. }
  3271. - (NSUInteger)count {
  3272. return _dictionary.count;
  3273. }
  3274. - (void)enumerateKeysAndUInt64sUsingBlock:
  3275. (void (^)(int32_t key, uint64_t value, BOOL *stop))block {
  3276. BOOL stop = NO;
  3277. NSDictionary *internal = _dictionary;
  3278. NSEnumerator *keys = [internal keyEnumerator];
  3279. NSNumber *aKey;
  3280. while ((aKey = [keys nextObject])) {
  3281. NSNumber *aValue = internal[aKey];
  3282. block([aKey intValue], [aValue unsignedLongLongValue], &stop);
  3283. if (stop) {
  3284. break;
  3285. }
  3286. }
  3287. }
  3288. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3289. NSDictionary *internal = _dictionary;
  3290. NSUInteger count = internal.count;
  3291. if (count == 0) {
  3292. return 0;
  3293. }
  3294. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3295. GPBDataType keyDataType = field.mapKeyDataType;
  3296. size_t result = 0;
  3297. NSEnumerator *keys = [internal keyEnumerator];
  3298. NSNumber *aKey;
  3299. while ((aKey = [keys nextObject])) {
  3300. NSNumber *aValue = internal[aKey];
  3301. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3302. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  3303. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3304. }
  3305. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3306. result += tagSize * count;
  3307. return result;
  3308. }
  3309. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3310. asField:(GPBFieldDescriptor *)field {
  3311. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3312. GPBDataType keyDataType = field.mapKeyDataType;
  3313. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3314. NSDictionary *internal = _dictionary;
  3315. NSEnumerator *keys = [internal keyEnumerator];
  3316. NSNumber *aKey;
  3317. while ((aKey = [keys nextObject])) {
  3318. NSNumber *aValue = internal[aKey];
  3319. [outputStream writeInt32NoTag:tag];
  3320. // Write the size of the message.
  3321. int32_t unwrappedKey = [aKey intValue];
  3322. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  3323. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3324. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3325. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3326. // Write the fields.
  3327. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3328. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3329. }
  3330. }
  3331. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3332. forGPBGenericValueKey:(GPBGenericValue *)key {
  3333. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
  3334. }
  3335. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3336. [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
  3337. #pragma unused(stop)
  3338. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
  3339. }];
  3340. }
  3341. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
  3342. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3343. if (wrapped && value) {
  3344. *value = [wrapped unsignedLongLongValue];
  3345. }
  3346. return (wrapped != NULL);
  3347. }
  3348. - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
  3349. if (otherDictionary) {
  3350. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3351. if (_autocreator) {
  3352. GPBAutocreatedDictionaryModified(_autocreator, self);
  3353. }
  3354. }
  3355. }
  3356. - (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
  3357. [_dictionary setObject:@(value) forKey:@(key)];
  3358. if (_autocreator) {
  3359. GPBAutocreatedDictionaryModified(_autocreator, self);
  3360. }
  3361. }
  3362. - (void)removeUInt64ForKey:(int32_t)aKey {
  3363. [_dictionary removeObjectForKey:@(aKey)];
  3364. }
  3365. - (void)removeAll {
  3366. [_dictionary removeAllObjects];
  3367. }
  3368. @end
  3369. #pragma mark - Int32 -> Int64
  3370. @implementation GPBInt32Int64Dictionary {
  3371. @package
  3372. NSMutableDictionary *_dictionary;
  3373. }
  3374. - (instancetype)init {
  3375. return [self initWithInt64s:NULL forKeys:NULL count:0];
  3376. }
  3377. - (instancetype)initWithInt64s:(const int64_t [])values
  3378. forKeys:(const int32_t [])keys
  3379. count:(NSUInteger)count {
  3380. self = [super init];
  3381. if (self) {
  3382. _dictionary = [[NSMutableDictionary alloc] init];
  3383. if (count && values && keys) {
  3384. for (NSUInteger i = 0; i < count; ++i) {
  3385. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3386. }
  3387. }
  3388. }
  3389. return self;
  3390. }
  3391. - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
  3392. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  3393. if (self) {
  3394. if (dictionary) {
  3395. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3396. }
  3397. }
  3398. return self;
  3399. }
  3400. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3401. #pragma unused(numItems)
  3402. return [self initWithInt64s:NULL forKeys:NULL count:0];
  3403. }
  3404. - (void)dealloc {
  3405. NSAssert(!_autocreator,
  3406. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3407. [self class], _autocreator);
  3408. [_dictionary release];
  3409. [super dealloc];
  3410. }
  3411. - (instancetype)copyWithZone:(NSZone *)zone {
  3412. return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  3413. }
  3414. - (BOOL)isEqual:(id)other {
  3415. if (self == other) {
  3416. return YES;
  3417. }
  3418. if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
  3419. return NO;
  3420. }
  3421. GPBInt32Int64Dictionary *otherDictionary = other;
  3422. return [_dictionary isEqual:otherDictionary->_dictionary];
  3423. }
  3424. - (NSUInteger)hash {
  3425. return _dictionary.count;
  3426. }
  3427. - (NSString *)description {
  3428. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3429. }
  3430. - (NSUInteger)count {
  3431. return _dictionary.count;
  3432. }
  3433. - (void)enumerateKeysAndInt64sUsingBlock:
  3434. (void (^)(int32_t key, int64_t value, BOOL *stop))block {
  3435. BOOL stop = NO;
  3436. NSDictionary *internal = _dictionary;
  3437. NSEnumerator *keys = [internal keyEnumerator];
  3438. NSNumber *aKey;
  3439. while ((aKey = [keys nextObject])) {
  3440. NSNumber *aValue = internal[aKey];
  3441. block([aKey intValue], [aValue longLongValue], &stop);
  3442. if (stop) {
  3443. break;
  3444. }
  3445. }
  3446. }
  3447. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3448. NSDictionary *internal = _dictionary;
  3449. NSUInteger count = internal.count;
  3450. if (count == 0) {
  3451. return 0;
  3452. }
  3453. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3454. GPBDataType keyDataType = field.mapKeyDataType;
  3455. size_t result = 0;
  3456. NSEnumerator *keys = [internal keyEnumerator];
  3457. NSNumber *aKey;
  3458. while ((aKey = [keys nextObject])) {
  3459. NSNumber *aValue = internal[aKey];
  3460. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3461. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  3462. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3463. }
  3464. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3465. result += tagSize * count;
  3466. return result;
  3467. }
  3468. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3469. asField:(GPBFieldDescriptor *)field {
  3470. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3471. GPBDataType keyDataType = field.mapKeyDataType;
  3472. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3473. NSDictionary *internal = _dictionary;
  3474. NSEnumerator *keys = [internal keyEnumerator];
  3475. NSNumber *aKey;
  3476. while ((aKey = [keys nextObject])) {
  3477. NSNumber *aValue = internal[aKey];
  3478. [outputStream writeInt32NoTag:tag];
  3479. // Write the size of the message.
  3480. int32_t unwrappedKey = [aKey intValue];
  3481. int64_t unwrappedValue = [aValue longLongValue];
  3482. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3483. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3484. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3485. // Write the fields.
  3486. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3487. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3488. }
  3489. }
  3490. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3491. forGPBGenericValueKey:(GPBGenericValue *)key {
  3492. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
  3493. }
  3494. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3495. [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
  3496. #pragma unused(stop)
  3497. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
  3498. }];
  3499. }
  3500. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
  3501. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3502. if (wrapped && value) {
  3503. *value = [wrapped longLongValue];
  3504. }
  3505. return (wrapped != NULL);
  3506. }
  3507. - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
  3508. if (otherDictionary) {
  3509. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3510. if (_autocreator) {
  3511. GPBAutocreatedDictionaryModified(_autocreator, self);
  3512. }
  3513. }
  3514. }
  3515. - (void)setInt64:(int64_t)value forKey:(int32_t)key {
  3516. [_dictionary setObject:@(value) forKey:@(key)];
  3517. if (_autocreator) {
  3518. GPBAutocreatedDictionaryModified(_autocreator, self);
  3519. }
  3520. }
  3521. - (void)removeInt64ForKey:(int32_t)aKey {
  3522. [_dictionary removeObjectForKey:@(aKey)];
  3523. }
  3524. - (void)removeAll {
  3525. [_dictionary removeAllObjects];
  3526. }
  3527. @end
  3528. #pragma mark - Int32 -> Bool
  3529. @implementation GPBInt32BoolDictionary {
  3530. @package
  3531. NSMutableDictionary *_dictionary;
  3532. }
  3533. - (instancetype)init {
  3534. return [self initWithBools:NULL forKeys:NULL count:0];
  3535. }
  3536. - (instancetype)initWithBools:(const BOOL [])values
  3537. forKeys:(const int32_t [])keys
  3538. count:(NSUInteger)count {
  3539. self = [super init];
  3540. if (self) {
  3541. _dictionary = [[NSMutableDictionary alloc] init];
  3542. if (count && values && keys) {
  3543. for (NSUInteger i = 0; i < count; ++i) {
  3544. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3545. }
  3546. }
  3547. }
  3548. return self;
  3549. }
  3550. - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
  3551. self = [self initWithBools:NULL forKeys:NULL count:0];
  3552. if (self) {
  3553. if (dictionary) {
  3554. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3555. }
  3556. }
  3557. return self;
  3558. }
  3559. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3560. #pragma unused(numItems)
  3561. return [self initWithBools:NULL forKeys:NULL count:0];
  3562. }
  3563. - (void)dealloc {
  3564. NSAssert(!_autocreator,
  3565. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3566. [self class], _autocreator);
  3567. [_dictionary release];
  3568. [super dealloc];
  3569. }
  3570. - (instancetype)copyWithZone:(NSZone *)zone {
  3571. return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
  3572. }
  3573. - (BOOL)isEqual:(id)other {
  3574. if (self == other) {
  3575. return YES;
  3576. }
  3577. if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
  3578. return NO;
  3579. }
  3580. GPBInt32BoolDictionary *otherDictionary = other;
  3581. return [_dictionary isEqual:otherDictionary->_dictionary];
  3582. }
  3583. - (NSUInteger)hash {
  3584. return _dictionary.count;
  3585. }
  3586. - (NSString *)description {
  3587. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3588. }
  3589. - (NSUInteger)count {
  3590. return _dictionary.count;
  3591. }
  3592. - (void)enumerateKeysAndBoolsUsingBlock:
  3593. (void (^)(int32_t key, BOOL value, BOOL *stop))block {
  3594. BOOL stop = NO;
  3595. NSDictionary *internal = _dictionary;
  3596. NSEnumerator *keys = [internal keyEnumerator];
  3597. NSNumber *aKey;
  3598. while ((aKey = [keys nextObject])) {
  3599. NSNumber *aValue = internal[aKey];
  3600. block([aKey intValue], [aValue boolValue], &stop);
  3601. if (stop) {
  3602. break;
  3603. }
  3604. }
  3605. }
  3606. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3607. NSDictionary *internal = _dictionary;
  3608. NSUInteger count = internal.count;
  3609. if (count == 0) {
  3610. return 0;
  3611. }
  3612. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3613. GPBDataType keyDataType = field.mapKeyDataType;
  3614. size_t result = 0;
  3615. NSEnumerator *keys = [internal keyEnumerator];
  3616. NSNumber *aKey;
  3617. while ((aKey = [keys nextObject])) {
  3618. NSNumber *aValue = internal[aKey];
  3619. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3620. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  3621. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3622. }
  3623. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3624. result += tagSize * count;
  3625. return result;
  3626. }
  3627. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3628. asField:(GPBFieldDescriptor *)field {
  3629. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3630. GPBDataType keyDataType = field.mapKeyDataType;
  3631. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3632. NSDictionary *internal = _dictionary;
  3633. NSEnumerator *keys = [internal keyEnumerator];
  3634. NSNumber *aKey;
  3635. while ((aKey = [keys nextObject])) {
  3636. NSNumber *aValue = internal[aKey];
  3637. [outputStream writeInt32NoTag:tag];
  3638. // Write the size of the message.
  3639. int32_t unwrappedKey = [aKey intValue];
  3640. BOOL unwrappedValue = [aValue boolValue];
  3641. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3642. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3643. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3644. // Write the fields.
  3645. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3646. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3647. }
  3648. }
  3649. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3650. forGPBGenericValueKey:(GPBGenericValue *)key {
  3651. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
  3652. }
  3653. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3654. [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
  3655. #pragma unused(stop)
  3656. block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
  3657. }];
  3658. }
  3659. - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
  3660. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3661. if (wrapped && value) {
  3662. *value = [wrapped boolValue];
  3663. }
  3664. return (wrapped != NULL);
  3665. }
  3666. - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
  3667. if (otherDictionary) {
  3668. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3669. if (_autocreator) {
  3670. GPBAutocreatedDictionaryModified(_autocreator, self);
  3671. }
  3672. }
  3673. }
  3674. - (void)setBool:(BOOL)value forKey:(int32_t)key {
  3675. [_dictionary setObject:@(value) forKey:@(key)];
  3676. if (_autocreator) {
  3677. GPBAutocreatedDictionaryModified(_autocreator, self);
  3678. }
  3679. }
  3680. - (void)removeBoolForKey:(int32_t)aKey {
  3681. [_dictionary removeObjectForKey:@(aKey)];
  3682. }
  3683. - (void)removeAll {
  3684. [_dictionary removeAllObjects];
  3685. }
  3686. @end
  3687. #pragma mark - Int32 -> Float
  3688. @implementation GPBInt32FloatDictionary {
  3689. @package
  3690. NSMutableDictionary *_dictionary;
  3691. }
  3692. - (instancetype)init {
  3693. return [self initWithFloats:NULL forKeys:NULL count:0];
  3694. }
  3695. - (instancetype)initWithFloats:(const float [])values
  3696. forKeys:(const int32_t [])keys
  3697. count:(NSUInteger)count {
  3698. self = [super init];
  3699. if (self) {
  3700. _dictionary = [[NSMutableDictionary alloc] init];
  3701. if (count && values && keys) {
  3702. for (NSUInteger i = 0; i < count; ++i) {
  3703. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3704. }
  3705. }
  3706. }
  3707. return self;
  3708. }
  3709. - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
  3710. self = [self initWithFloats:NULL forKeys:NULL count:0];
  3711. if (self) {
  3712. if (dictionary) {
  3713. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3714. }
  3715. }
  3716. return self;
  3717. }
  3718. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3719. #pragma unused(numItems)
  3720. return [self initWithFloats:NULL forKeys:NULL count:0];
  3721. }
  3722. - (void)dealloc {
  3723. NSAssert(!_autocreator,
  3724. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3725. [self class], _autocreator);
  3726. [_dictionary release];
  3727. [super dealloc];
  3728. }
  3729. - (instancetype)copyWithZone:(NSZone *)zone {
  3730. return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
  3731. }
  3732. - (BOOL)isEqual:(id)other {
  3733. if (self == other) {
  3734. return YES;
  3735. }
  3736. if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
  3737. return NO;
  3738. }
  3739. GPBInt32FloatDictionary *otherDictionary = other;
  3740. return [_dictionary isEqual:otherDictionary->_dictionary];
  3741. }
  3742. - (NSUInteger)hash {
  3743. return _dictionary.count;
  3744. }
  3745. - (NSString *)description {
  3746. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3747. }
  3748. - (NSUInteger)count {
  3749. return _dictionary.count;
  3750. }
  3751. - (void)enumerateKeysAndFloatsUsingBlock:
  3752. (void (^)(int32_t key, float value, BOOL *stop))block {
  3753. BOOL stop = NO;
  3754. NSDictionary *internal = _dictionary;
  3755. NSEnumerator *keys = [internal keyEnumerator];
  3756. NSNumber *aKey;
  3757. while ((aKey = [keys nextObject])) {
  3758. NSNumber *aValue = internal[aKey];
  3759. block([aKey intValue], [aValue floatValue], &stop);
  3760. if (stop) {
  3761. break;
  3762. }
  3763. }
  3764. }
  3765. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3766. NSDictionary *internal = _dictionary;
  3767. NSUInteger count = internal.count;
  3768. if (count == 0) {
  3769. return 0;
  3770. }
  3771. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3772. GPBDataType keyDataType = field.mapKeyDataType;
  3773. size_t result = 0;
  3774. NSEnumerator *keys = [internal keyEnumerator];
  3775. NSNumber *aKey;
  3776. while ((aKey = [keys nextObject])) {
  3777. NSNumber *aValue = internal[aKey];
  3778. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3779. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  3780. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3781. }
  3782. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3783. result += tagSize * count;
  3784. return result;
  3785. }
  3786. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3787. asField:(GPBFieldDescriptor *)field {
  3788. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3789. GPBDataType keyDataType = field.mapKeyDataType;
  3790. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3791. NSDictionary *internal = _dictionary;
  3792. NSEnumerator *keys = [internal keyEnumerator];
  3793. NSNumber *aKey;
  3794. while ((aKey = [keys nextObject])) {
  3795. NSNumber *aValue = internal[aKey];
  3796. [outputStream writeInt32NoTag:tag];
  3797. // Write the size of the message.
  3798. int32_t unwrappedKey = [aKey intValue];
  3799. float unwrappedValue = [aValue floatValue];
  3800. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3801. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3802. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3803. // Write the fields.
  3804. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3805. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3806. }
  3807. }
  3808. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3809. forGPBGenericValueKey:(GPBGenericValue *)key {
  3810. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
  3811. }
  3812. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3813. [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
  3814. #pragma unused(stop)
  3815. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  3816. }];
  3817. }
  3818. - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
  3819. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3820. if (wrapped && value) {
  3821. *value = [wrapped floatValue];
  3822. }
  3823. return (wrapped != NULL);
  3824. }
  3825. - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
  3826. if (otherDictionary) {
  3827. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3828. if (_autocreator) {
  3829. GPBAutocreatedDictionaryModified(_autocreator, self);
  3830. }
  3831. }
  3832. }
  3833. - (void)setFloat:(float)value forKey:(int32_t)key {
  3834. [_dictionary setObject:@(value) forKey:@(key)];
  3835. if (_autocreator) {
  3836. GPBAutocreatedDictionaryModified(_autocreator, self);
  3837. }
  3838. }
  3839. - (void)removeFloatForKey:(int32_t)aKey {
  3840. [_dictionary removeObjectForKey:@(aKey)];
  3841. }
  3842. - (void)removeAll {
  3843. [_dictionary removeAllObjects];
  3844. }
  3845. @end
  3846. #pragma mark - Int32 -> Double
  3847. @implementation GPBInt32DoubleDictionary {
  3848. @package
  3849. NSMutableDictionary *_dictionary;
  3850. }
  3851. - (instancetype)init {
  3852. return [self initWithDoubles:NULL forKeys:NULL count:0];
  3853. }
  3854. - (instancetype)initWithDoubles:(const double [])values
  3855. forKeys:(const int32_t [])keys
  3856. count:(NSUInteger)count {
  3857. self = [super init];
  3858. if (self) {
  3859. _dictionary = [[NSMutableDictionary alloc] init];
  3860. if (count && values && keys) {
  3861. for (NSUInteger i = 0; i < count; ++i) {
  3862. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  3863. }
  3864. }
  3865. }
  3866. return self;
  3867. }
  3868. - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
  3869. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  3870. if (self) {
  3871. if (dictionary) {
  3872. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  3873. }
  3874. }
  3875. return self;
  3876. }
  3877. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  3878. #pragma unused(numItems)
  3879. return [self initWithDoubles:NULL forKeys:NULL count:0];
  3880. }
  3881. - (void)dealloc {
  3882. NSAssert(!_autocreator,
  3883. @"%@: Autocreator must be cleared before release, autocreator: %@",
  3884. [self class], _autocreator);
  3885. [_dictionary release];
  3886. [super dealloc];
  3887. }
  3888. - (instancetype)copyWithZone:(NSZone *)zone {
  3889. return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  3890. }
  3891. - (BOOL)isEqual:(id)other {
  3892. if (self == other) {
  3893. return YES;
  3894. }
  3895. if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
  3896. return NO;
  3897. }
  3898. GPBInt32DoubleDictionary *otherDictionary = other;
  3899. return [_dictionary isEqual:otherDictionary->_dictionary];
  3900. }
  3901. - (NSUInteger)hash {
  3902. return _dictionary.count;
  3903. }
  3904. - (NSString *)description {
  3905. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  3906. }
  3907. - (NSUInteger)count {
  3908. return _dictionary.count;
  3909. }
  3910. - (void)enumerateKeysAndDoublesUsingBlock:
  3911. (void (^)(int32_t key, double value, BOOL *stop))block {
  3912. BOOL stop = NO;
  3913. NSDictionary *internal = _dictionary;
  3914. NSEnumerator *keys = [internal keyEnumerator];
  3915. NSNumber *aKey;
  3916. while ((aKey = [keys nextObject])) {
  3917. NSNumber *aValue = internal[aKey];
  3918. block([aKey intValue], [aValue doubleValue], &stop);
  3919. if (stop) {
  3920. break;
  3921. }
  3922. }
  3923. }
  3924. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  3925. NSDictionary *internal = _dictionary;
  3926. NSUInteger count = internal.count;
  3927. if (count == 0) {
  3928. return 0;
  3929. }
  3930. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3931. GPBDataType keyDataType = field.mapKeyDataType;
  3932. size_t result = 0;
  3933. NSEnumerator *keys = [internal keyEnumerator];
  3934. NSNumber *aKey;
  3935. while ((aKey = [keys nextObject])) {
  3936. NSNumber *aValue = internal[aKey];
  3937. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  3938. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  3939. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  3940. }
  3941. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  3942. result += tagSize * count;
  3943. return result;
  3944. }
  3945. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  3946. asField:(GPBFieldDescriptor *)field {
  3947. GPBDataType valueDataType = GPBGetFieldDataType(field);
  3948. GPBDataType keyDataType = field.mapKeyDataType;
  3949. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  3950. NSDictionary *internal = _dictionary;
  3951. NSEnumerator *keys = [internal keyEnumerator];
  3952. NSNumber *aKey;
  3953. while ((aKey = [keys nextObject])) {
  3954. NSNumber *aValue = internal[aKey];
  3955. [outputStream writeInt32NoTag:tag];
  3956. // Write the size of the message.
  3957. int32_t unwrappedKey = [aKey intValue];
  3958. double unwrappedValue = [aValue doubleValue];
  3959. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3960. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  3961. [outputStream writeInt32NoTag:(int32_t)msgSize];
  3962. // Write the fields.
  3963. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  3964. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  3965. }
  3966. }
  3967. - (void)setGPBGenericValue:(GPBGenericValue *)value
  3968. forGPBGenericValueKey:(GPBGenericValue *)key {
  3969. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
  3970. }
  3971. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  3972. [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
  3973. #pragma unused(stop)
  3974. block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  3975. }];
  3976. }
  3977. - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
  3978. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  3979. if (wrapped && value) {
  3980. *value = [wrapped doubleValue];
  3981. }
  3982. return (wrapped != NULL);
  3983. }
  3984. - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
  3985. if (otherDictionary) {
  3986. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  3987. if (_autocreator) {
  3988. GPBAutocreatedDictionaryModified(_autocreator, self);
  3989. }
  3990. }
  3991. }
  3992. - (void)setDouble:(double)value forKey:(int32_t)key {
  3993. [_dictionary setObject:@(value) forKey:@(key)];
  3994. if (_autocreator) {
  3995. GPBAutocreatedDictionaryModified(_autocreator, self);
  3996. }
  3997. }
  3998. - (void)removeDoubleForKey:(int32_t)aKey {
  3999. [_dictionary removeObjectForKey:@(aKey)];
  4000. }
  4001. - (void)removeAll {
  4002. [_dictionary removeAllObjects];
  4003. }
  4004. @end
  4005. #pragma mark - Int32 -> Enum
  4006. @implementation GPBInt32EnumDictionary {
  4007. @package
  4008. NSMutableDictionary *_dictionary;
  4009. GPBEnumValidationFunc _validationFunc;
  4010. }
  4011. @synthesize validationFunc = _validationFunc;
  4012. - (instancetype)init {
  4013. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  4014. }
  4015. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  4016. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  4017. }
  4018. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  4019. rawValues:(const int32_t [])rawValues
  4020. forKeys:(const int32_t [])keys
  4021. count:(NSUInteger)count {
  4022. self = [super init];
  4023. if (self) {
  4024. _dictionary = [[NSMutableDictionary alloc] init];
  4025. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  4026. if (count && rawValues && keys) {
  4027. for (NSUInteger i = 0; i < count; ++i) {
  4028. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  4029. }
  4030. }
  4031. }
  4032. return self;
  4033. }
  4034. - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
  4035. self = [self initWithValidationFunction:dictionary.validationFunc
  4036. rawValues:NULL
  4037. forKeys:NULL
  4038. count:0];
  4039. if (self) {
  4040. if (dictionary) {
  4041. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4042. }
  4043. }
  4044. return self;
  4045. }
  4046. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  4047. capacity:(NSUInteger)numItems {
  4048. #pragma unused(numItems)
  4049. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  4050. }
  4051. - (void)dealloc {
  4052. NSAssert(!_autocreator,
  4053. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4054. [self class], _autocreator);
  4055. [_dictionary release];
  4056. [super dealloc];
  4057. }
  4058. - (instancetype)copyWithZone:(NSZone *)zone {
  4059. return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
  4060. }
  4061. - (BOOL)isEqual:(id)other {
  4062. if (self == other) {
  4063. return YES;
  4064. }
  4065. if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
  4066. return NO;
  4067. }
  4068. GPBInt32EnumDictionary *otherDictionary = other;
  4069. return [_dictionary isEqual:otherDictionary->_dictionary];
  4070. }
  4071. - (NSUInteger)hash {
  4072. return _dictionary.count;
  4073. }
  4074. - (NSString *)description {
  4075. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4076. }
  4077. - (NSUInteger)count {
  4078. return _dictionary.count;
  4079. }
  4080. - (void)enumerateKeysAndRawValuesUsingBlock:
  4081. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  4082. BOOL stop = NO;
  4083. NSDictionary *internal = _dictionary;
  4084. NSEnumerator *keys = [internal keyEnumerator];
  4085. NSNumber *aKey;
  4086. while ((aKey = [keys nextObject])) {
  4087. NSNumber *aValue = internal[aKey];
  4088. block([aKey intValue], [aValue intValue], &stop);
  4089. if (stop) {
  4090. break;
  4091. }
  4092. }
  4093. }
  4094. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4095. NSDictionary *internal = _dictionary;
  4096. NSUInteger count = internal.count;
  4097. if (count == 0) {
  4098. return 0;
  4099. }
  4100. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4101. GPBDataType keyDataType = field.mapKeyDataType;
  4102. size_t result = 0;
  4103. NSEnumerator *keys = [internal keyEnumerator];
  4104. NSNumber *aKey;
  4105. while ((aKey = [keys nextObject])) {
  4106. NSNumber *aValue = internal[aKey];
  4107. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  4108. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  4109. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4110. }
  4111. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4112. result += tagSize * count;
  4113. return result;
  4114. }
  4115. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4116. asField:(GPBFieldDescriptor *)field {
  4117. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4118. GPBDataType keyDataType = field.mapKeyDataType;
  4119. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4120. NSDictionary *internal = _dictionary;
  4121. NSEnumerator *keys = [internal keyEnumerator];
  4122. NSNumber *aKey;
  4123. while ((aKey = [keys nextObject])) {
  4124. NSNumber *aValue = internal[aKey];
  4125. [outputStream writeInt32NoTag:tag];
  4126. // Write the size of the message.
  4127. int32_t unwrappedKey = [aKey intValue];
  4128. int32_t unwrappedValue = [aValue intValue];
  4129. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4130. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4131. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4132. // Write the fields.
  4133. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4134. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4135. }
  4136. }
  4137. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  4138. forKey:(GPBGenericValue *)key
  4139. keyDataType:(GPBDataType)keyDataType {
  4140. size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
  4141. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  4142. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  4143. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  4144. WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
  4145. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  4146. [outputStream release];
  4147. return data;
  4148. }
  4149. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4150. forGPBGenericValueKey:(GPBGenericValue *)key {
  4151. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
  4152. }
  4153. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4154. [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
  4155. #pragma unused(stop)
  4156. block([NSString stringWithFormat:@"%d", key], @(value));
  4157. }];
  4158. }
  4159. - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
  4160. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4161. if (wrapped && value) {
  4162. int32_t result = [wrapped intValue];
  4163. if (!_validationFunc(result)) {
  4164. result = kGPBUnrecognizedEnumeratorValue;
  4165. }
  4166. *value = result;
  4167. }
  4168. return (wrapped != NULL);
  4169. }
  4170. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
  4171. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4172. if (wrapped && rawValue) {
  4173. *rawValue = [wrapped intValue];
  4174. }
  4175. return (wrapped != NULL);
  4176. }
  4177. - (void)enumerateKeysAndEnumsUsingBlock:
  4178. (void (^)(int32_t key, int32_t value, BOOL *stop))block {
  4179. GPBEnumValidationFunc func = _validationFunc;
  4180. BOOL stop = NO;
  4181. NSEnumerator *keys = [_dictionary keyEnumerator];
  4182. NSNumber *aKey;
  4183. while ((aKey = [keys nextObject])) {
  4184. NSNumber *aValue = _dictionary[aKey];
  4185. int32_t unwrapped = [aValue intValue];
  4186. if (!func(unwrapped)) {
  4187. unwrapped = kGPBUnrecognizedEnumeratorValue;
  4188. }
  4189. block([aKey intValue], unwrapped, &stop);
  4190. if (stop) {
  4191. break;
  4192. }
  4193. }
  4194. }
  4195. - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
  4196. if (otherDictionary) {
  4197. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4198. if (_autocreator) {
  4199. GPBAutocreatedDictionaryModified(_autocreator, self);
  4200. }
  4201. }
  4202. }
  4203. - (void)setRawValue:(int32_t)value forKey:(int32_t)key {
  4204. [_dictionary setObject:@(value) forKey:@(key)];
  4205. if (_autocreator) {
  4206. GPBAutocreatedDictionaryModified(_autocreator, self);
  4207. }
  4208. }
  4209. - (void)removeEnumForKey:(int32_t)aKey {
  4210. [_dictionary removeObjectForKey:@(aKey)];
  4211. }
  4212. - (void)removeAll {
  4213. [_dictionary removeAllObjects];
  4214. }
  4215. - (void)setEnum:(int32_t)value forKey:(int32_t)key {
  4216. if (!_validationFunc(value)) {
  4217. [NSException raise:NSInvalidArgumentException
  4218. format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
  4219. value];
  4220. }
  4221. [_dictionary setObject:@(value) forKey:@(key)];
  4222. if (_autocreator) {
  4223. GPBAutocreatedDictionaryModified(_autocreator, self);
  4224. }
  4225. }
  4226. @end
  4227. #pragma mark - Int32 -> Object
  4228. @implementation GPBInt32ObjectDictionary {
  4229. @package
  4230. NSMutableDictionary *_dictionary;
  4231. }
  4232. - (instancetype)init {
  4233. return [self initWithObjects:NULL forKeys:NULL count:0];
  4234. }
  4235. - (instancetype)initWithObjects:(const id [])objects
  4236. forKeys:(const int32_t [])keys
  4237. count:(NSUInteger)count {
  4238. self = [super init];
  4239. if (self) {
  4240. _dictionary = [[NSMutableDictionary alloc] init];
  4241. if (count && objects && keys) {
  4242. for (NSUInteger i = 0; i < count; ++i) {
  4243. if (!objects[i]) {
  4244. [NSException raise:NSInvalidArgumentException
  4245. format:@"Attempting to add nil object to a Dictionary"];
  4246. }else {
  4247. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  4248. }
  4249. }
  4250. }
  4251. }
  4252. return self;
  4253. }
  4254. - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
  4255. self = [self initWithObjects:NULL forKeys:NULL count:0];
  4256. if (self) {
  4257. if (dictionary) {
  4258. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4259. }
  4260. }
  4261. return self;
  4262. }
  4263. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4264. #pragma unused(numItems)
  4265. return [self initWithObjects:NULL forKeys:NULL count:0];
  4266. }
  4267. - (void)dealloc {
  4268. NSAssert(!_autocreator,
  4269. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4270. [self class], _autocreator);
  4271. [_dictionary release];
  4272. [super dealloc];
  4273. }
  4274. - (instancetype)copyWithZone:(NSZone *)zone {
  4275. return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  4276. }
  4277. - (BOOL)isEqual:(id)other {
  4278. if (self == other) {
  4279. return YES;
  4280. }
  4281. if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
  4282. return NO;
  4283. }
  4284. GPBInt32ObjectDictionary *otherDictionary = other;
  4285. return [_dictionary isEqual:otherDictionary->_dictionary];
  4286. }
  4287. - (NSUInteger)hash {
  4288. return _dictionary.count;
  4289. }
  4290. - (NSString *)description {
  4291. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4292. }
  4293. - (NSUInteger)count {
  4294. return _dictionary.count;
  4295. }
  4296. - (void)enumerateKeysAndObjectsUsingBlock:
  4297. (void (^)(int32_t key, id object, BOOL *stop))block {
  4298. BOOL stop = NO;
  4299. NSDictionary *internal = _dictionary;
  4300. NSEnumerator *keys = [internal keyEnumerator];
  4301. NSNumber *aKey;
  4302. while ((aKey = [keys nextObject])) {
  4303. id aObject = internal[aKey];
  4304. block([aKey intValue], aObject, &stop);
  4305. if (stop) {
  4306. break;
  4307. }
  4308. }
  4309. }
  4310. - (BOOL)isInitialized {
  4311. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  4312. if (!msg.initialized) {
  4313. return NO;
  4314. }
  4315. }
  4316. return YES;
  4317. }
  4318. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  4319. GPBInt32ObjectDictionary *newDict =
  4320. [[GPBInt32ObjectDictionary alloc] init];
  4321. NSEnumerator *keys = [_dictionary keyEnumerator];
  4322. id aKey;
  4323. NSMutableDictionary *internalDict = newDict->_dictionary;
  4324. while ((aKey = [keys nextObject])) {
  4325. GPBMessage *msg = _dictionary[aKey];
  4326. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  4327. [internalDict setObject:copiedMsg forKey:aKey];
  4328. [copiedMsg release];
  4329. }
  4330. return newDict;
  4331. }
  4332. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4333. NSDictionary *internal = _dictionary;
  4334. NSUInteger count = internal.count;
  4335. if (count == 0) {
  4336. return 0;
  4337. }
  4338. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4339. GPBDataType keyDataType = field.mapKeyDataType;
  4340. size_t result = 0;
  4341. NSEnumerator *keys = [internal keyEnumerator];
  4342. NSNumber *aKey;
  4343. while ((aKey = [keys nextObject])) {
  4344. id aObject = internal[aKey];
  4345. size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
  4346. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  4347. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4348. }
  4349. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4350. result += tagSize * count;
  4351. return result;
  4352. }
  4353. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4354. asField:(GPBFieldDescriptor *)field {
  4355. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4356. GPBDataType keyDataType = field.mapKeyDataType;
  4357. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4358. NSDictionary *internal = _dictionary;
  4359. NSEnumerator *keys = [internal keyEnumerator];
  4360. NSNumber *aKey;
  4361. while ((aKey = [keys nextObject])) {
  4362. id aObject = internal[aKey];
  4363. [outputStream writeInt32NoTag:tag];
  4364. // Write the size of the message.
  4365. int32_t unwrappedKey = [aKey intValue];
  4366. id unwrappedValue = aObject;
  4367. size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4368. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4369. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4370. // Write the fields.
  4371. WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4372. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4373. }
  4374. }
  4375. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4376. forGPBGenericValueKey:(GPBGenericValue *)key {
  4377. [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
  4378. }
  4379. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4380. [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
  4381. #pragma unused(stop)
  4382. block([NSString stringWithFormat:@"%d", key], object);
  4383. }];
  4384. }
  4385. - (id)objectForKey:(int32_t)key {
  4386. id result = [_dictionary objectForKey:@(key)];
  4387. return result;
  4388. }
  4389. - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
  4390. if (otherDictionary) {
  4391. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4392. if (_autocreator) {
  4393. GPBAutocreatedDictionaryModified(_autocreator, self);
  4394. }
  4395. }
  4396. }
  4397. - (void)setObject:(id)object forKey:(int32_t)key {
  4398. if (!object) {
  4399. [NSException raise:NSInvalidArgumentException
  4400. format:@"Attempting to add nil object to a Dictionary"];
  4401. }
  4402. [_dictionary setObject:object forKey:@(key)];
  4403. if (_autocreator) {
  4404. GPBAutocreatedDictionaryModified(_autocreator, self);
  4405. }
  4406. }
  4407. - (void)removeObjectForKey:(int32_t)aKey {
  4408. [_dictionary removeObjectForKey:@(aKey)];
  4409. }
  4410. - (void)removeAll {
  4411. [_dictionary removeAllObjects];
  4412. }
  4413. @end
  4414. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
  4415. // This block of code is generated, do not edit it directly.
  4416. #pragma mark - UInt64 -> UInt32
  4417. @implementation GPBUInt64UInt32Dictionary {
  4418. @package
  4419. NSMutableDictionary *_dictionary;
  4420. }
  4421. - (instancetype)init {
  4422. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  4423. }
  4424. - (instancetype)initWithUInt32s:(const uint32_t [])values
  4425. forKeys:(const uint64_t [])keys
  4426. count:(NSUInteger)count {
  4427. self = [super init];
  4428. if (self) {
  4429. _dictionary = [[NSMutableDictionary alloc] init];
  4430. if (count && values && keys) {
  4431. for (NSUInteger i = 0; i < count; ++i) {
  4432. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4433. }
  4434. }
  4435. }
  4436. return self;
  4437. }
  4438. - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
  4439. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  4440. if (self) {
  4441. if (dictionary) {
  4442. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4443. }
  4444. }
  4445. return self;
  4446. }
  4447. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4448. #pragma unused(numItems)
  4449. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  4450. }
  4451. - (void)dealloc {
  4452. NSAssert(!_autocreator,
  4453. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4454. [self class], _autocreator);
  4455. [_dictionary release];
  4456. [super dealloc];
  4457. }
  4458. - (instancetype)copyWithZone:(NSZone *)zone {
  4459. return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  4460. }
  4461. - (BOOL)isEqual:(id)other {
  4462. if (self == other) {
  4463. return YES;
  4464. }
  4465. if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
  4466. return NO;
  4467. }
  4468. GPBUInt64UInt32Dictionary *otherDictionary = other;
  4469. return [_dictionary isEqual:otherDictionary->_dictionary];
  4470. }
  4471. - (NSUInteger)hash {
  4472. return _dictionary.count;
  4473. }
  4474. - (NSString *)description {
  4475. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4476. }
  4477. - (NSUInteger)count {
  4478. return _dictionary.count;
  4479. }
  4480. - (void)enumerateKeysAndUInt32sUsingBlock:
  4481. (void (^)(uint64_t key, uint32_t value, BOOL *stop))block {
  4482. BOOL stop = NO;
  4483. NSDictionary *internal = _dictionary;
  4484. NSEnumerator *keys = [internal keyEnumerator];
  4485. NSNumber *aKey;
  4486. while ((aKey = [keys nextObject])) {
  4487. NSNumber *aValue = internal[aKey];
  4488. block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
  4489. if (stop) {
  4490. break;
  4491. }
  4492. }
  4493. }
  4494. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4495. NSDictionary *internal = _dictionary;
  4496. NSUInteger count = internal.count;
  4497. if (count == 0) {
  4498. return 0;
  4499. }
  4500. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4501. GPBDataType keyDataType = field.mapKeyDataType;
  4502. size_t result = 0;
  4503. NSEnumerator *keys = [internal keyEnumerator];
  4504. NSNumber *aKey;
  4505. while ((aKey = [keys nextObject])) {
  4506. NSNumber *aValue = internal[aKey];
  4507. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4508. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  4509. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4510. }
  4511. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4512. result += tagSize * count;
  4513. return result;
  4514. }
  4515. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4516. asField:(GPBFieldDescriptor *)field {
  4517. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4518. GPBDataType keyDataType = field.mapKeyDataType;
  4519. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4520. NSDictionary *internal = _dictionary;
  4521. NSEnumerator *keys = [internal keyEnumerator];
  4522. NSNumber *aKey;
  4523. while ((aKey = [keys nextObject])) {
  4524. NSNumber *aValue = internal[aKey];
  4525. [outputStream writeInt32NoTag:tag];
  4526. // Write the size of the message.
  4527. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4528. uint32_t unwrappedValue = [aValue unsignedIntValue];
  4529. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4530. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4531. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4532. // Write the fields.
  4533. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4534. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4535. }
  4536. }
  4537. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4538. forGPBGenericValueKey:(GPBGenericValue *)key {
  4539. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
  4540. }
  4541. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4542. [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
  4543. #pragma unused(stop)
  4544. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
  4545. }];
  4546. }
  4547. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
  4548. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4549. if (wrapped && value) {
  4550. *value = [wrapped unsignedIntValue];
  4551. }
  4552. return (wrapped != NULL);
  4553. }
  4554. - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
  4555. if (otherDictionary) {
  4556. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4557. if (_autocreator) {
  4558. GPBAutocreatedDictionaryModified(_autocreator, self);
  4559. }
  4560. }
  4561. }
  4562. - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
  4563. [_dictionary setObject:@(value) forKey:@(key)];
  4564. if (_autocreator) {
  4565. GPBAutocreatedDictionaryModified(_autocreator, self);
  4566. }
  4567. }
  4568. - (void)removeUInt32ForKey:(uint64_t)aKey {
  4569. [_dictionary removeObjectForKey:@(aKey)];
  4570. }
  4571. - (void)removeAll {
  4572. [_dictionary removeAllObjects];
  4573. }
  4574. @end
  4575. #pragma mark - UInt64 -> Int32
  4576. @implementation GPBUInt64Int32Dictionary {
  4577. @package
  4578. NSMutableDictionary *_dictionary;
  4579. }
  4580. - (instancetype)init {
  4581. return [self initWithInt32s:NULL forKeys:NULL count:0];
  4582. }
  4583. - (instancetype)initWithInt32s:(const int32_t [])values
  4584. forKeys:(const uint64_t [])keys
  4585. count:(NSUInteger)count {
  4586. self = [super init];
  4587. if (self) {
  4588. _dictionary = [[NSMutableDictionary alloc] init];
  4589. if (count && values && keys) {
  4590. for (NSUInteger i = 0; i < count; ++i) {
  4591. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4592. }
  4593. }
  4594. }
  4595. return self;
  4596. }
  4597. - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
  4598. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  4599. if (self) {
  4600. if (dictionary) {
  4601. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4602. }
  4603. }
  4604. return self;
  4605. }
  4606. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4607. #pragma unused(numItems)
  4608. return [self initWithInt32s:NULL forKeys:NULL count:0];
  4609. }
  4610. - (void)dealloc {
  4611. NSAssert(!_autocreator,
  4612. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4613. [self class], _autocreator);
  4614. [_dictionary release];
  4615. [super dealloc];
  4616. }
  4617. - (instancetype)copyWithZone:(NSZone *)zone {
  4618. return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  4619. }
  4620. - (BOOL)isEqual:(id)other {
  4621. if (self == other) {
  4622. return YES;
  4623. }
  4624. if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
  4625. return NO;
  4626. }
  4627. GPBUInt64Int32Dictionary *otherDictionary = other;
  4628. return [_dictionary isEqual:otherDictionary->_dictionary];
  4629. }
  4630. - (NSUInteger)hash {
  4631. return _dictionary.count;
  4632. }
  4633. - (NSString *)description {
  4634. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4635. }
  4636. - (NSUInteger)count {
  4637. return _dictionary.count;
  4638. }
  4639. - (void)enumerateKeysAndInt32sUsingBlock:
  4640. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  4641. BOOL stop = NO;
  4642. NSDictionary *internal = _dictionary;
  4643. NSEnumerator *keys = [internal keyEnumerator];
  4644. NSNumber *aKey;
  4645. while ((aKey = [keys nextObject])) {
  4646. NSNumber *aValue = internal[aKey];
  4647. block([aKey unsignedLongLongValue], [aValue intValue], &stop);
  4648. if (stop) {
  4649. break;
  4650. }
  4651. }
  4652. }
  4653. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4654. NSDictionary *internal = _dictionary;
  4655. NSUInteger count = internal.count;
  4656. if (count == 0) {
  4657. return 0;
  4658. }
  4659. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4660. GPBDataType keyDataType = field.mapKeyDataType;
  4661. size_t result = 0;
  4662. NSEnumerator *keys = [internal keyEnumerator];
  4663. NSNumber *aKey;
  4664. while ((aKey = [keys nextObject])) {
  4665. NSNumber *aValue = internal[aKey];
  4666. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4667. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  4668. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4669. }
  4670. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4671. result += tagSize * count;
  4672. return result;
  4673. }
  4674. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4675. asField:(GPBFieldDescriptor *)field {
  4676. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4677. GPBDataType keyDataType = field.mapKeyDataType;
  4678. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4679. NSDictionary *internal = _dictionary;
  4680. NSEnumerator *keys = [internal keyEnumerator];
  4681. NSNumber *aKey;
  4682. while ((aKey = [keys nextObject])) {
  4683. NSNumber *aValue = internal[aKey];
  4684. [outputStream writeInt32NoTag:tag];
  4685. // Write the size of the message.
  4686. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4687. int32_t unwrappedValue = [aValue intValue];
  4688. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4689. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4690. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4691. // Write the fields.
  4692. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4693. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4694. }
  4695. }
  4696. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4697. forGPBGenericValueKey:(GPBGenericValue *)key {
  4698. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
  4699. }
  4700. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4701. [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
  4702. #pragma unused(stop)
  4703. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
  4704. }];
  4705. }
  4706. - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
  4707. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4708. if (wrapped && value) {
  4709. *value = [wrapped intValue];
  4710. }
  4711. return (wrapped != NULL);
  4712. }
  4713. - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
  4714. if (otherDictionary) {
  4715. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4716. if (_autocreator) {
  4717. GPBAutocreatedDictionaryModified(_autocreator, self);
  4718. }
  4719. }
  4720. }
  4721. - (void)setInt32:(int32_t)value forKey:(uint64_t)key {
  4722. [_dictionary setObject:@(value) forKey:@(key)];
  4723. if (_autocreator) {
  4724. GPBAutocreatedDictionaryModified(_autocreator, self);
  4725. }
  4726. }
  4727. - (void)removeInt32ForKey:(uint64_t)aKey {
  4728. [_dictionary removeObjectForKey:@(aKey)];
  4729. }
  4730. - (void)removeAll {
  4731. [_dictionary removeAllObjects];
  4732. }
  4733. @end
  4734. #pragma mark - UInt64 -> UInt64
  4735. @implementation GPBUInt64UInt64Dictionary {
  4736. @package
  4737. NSMutableDictionary *_dictionary;
  4738. }
  4739. - (instancetype)init {
  4740. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  4741. }
  4742. - (instancetype)initWithUInt64s:(const uint64_t [])values
  4743. forKeys:(const uint64_t [])keys
  4744. count:(NSUInteger)count {
  4745. self = [super init];
  4746. if (self) {
  4747. _dictionary = [[NSMutableDictionary alloc] init];
  4748. if (count && values && keys) {
  4749. for (NSUInteger i = 0; i < count; ++i) {
  4750. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4751. }
  4752. }
  4753. }
  4754. return self;
  4755. }
  4756. - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
  4757. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  4758. if (self) {
  4759. if (dictionary) {
  4760. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4761. }
  4762. }
  4763. return self;
  4764. }
  4765. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4766. #pragma unused(numItems)
  4767. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  4768. }
  4769. - (void)dealloc {
  4770. NSAssert(!_autocreator,
  4771. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4772. [self class], _autocreator);
  4773. [_dictionary release];
  4774. [super dealloc];
  4775. }
  4776. - (instancetype)copyWithZone:(NSZone *)zone {
  4777. return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  4778. }
  4779. - (BOOL)isEqual:(id)other {
  4780. if (self == other) {
  4781. return YES;
  4782. }
  4783. if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
  4784. return NO;
  4785. }
  4786. GPBUInt64UInt64Dictionary *otherDictionary = other;
  4787. return [_dictionary isEqual:otherDictionary->_dictionary];
  4788. }
  4789. - (NSUInteger)hash {
  4790. return _dictionary.count;
  4791. }
  4792. - (NSString *)description {
  4793. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4794. }
  4795. - (NSUInteger)count {
  4796. return _dictionary.count;
  4797. }
  4798. - (void)enumerateKeysAndUInt64sUsingBlock:
  4799. (void (^)(uint64_t key, uint64_t value, BOOL *stop))block {
  4800. BOOL stop = NO;
  4801. NSDictionary *internal = _dictionary;
  4802. NSEnumerator *keys = [internal keyEnumerator];
  4803. NSNumber *aKey;
  4804. while ((aKey = [keys nextObject])) {
  4805. NSNumber *aValue = internal[aKey];
  4806. block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
  4807. if (stop) {
  4808. break;
  4809. }
  4810. }
  4811. }
  4812. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4813. NSDictionary *internal = _dictionary;
  4814. NSUInteger count = internal.count;
  4815. if (count == 0) {
  4816. return 0;
  4817. }
  4818. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4819. GPBDataType keyDataType = field.mapKeyDataType;
  4820. size_t result = 0;
  4821. NSEnumerator *keys = [internal keyEnumerator];
  4822. NSNumber *aKey;
  4823. while ((aKey = [keys nextObject])) {
  4824. NSNumber *aValue = internal[aKey];
  4825. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4826. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  4827. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4828. }
  4829. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4830. result += tagSize * count;
  4831. return result;
  4832. }
  4833. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4834. asField:(GPBFieldDescriptor *)field {
  4835. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4836. GPBDataType keyDataType = field.mapKeyDataType;
  4837. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4838. NSDictionary *internal = _dictionary;
  4839. NSEnumerator *keys = [internal keyEnumerator];
  4840. NSNumber *aKey;
  4841. while ((aKey = [keys nextObject])) {
  4842. NSNumber *aValue = internal[aKey];
  4843. [outputStream writeInt32NoTag:tag];
  4844. // Write the size of the message.
  4845. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  4846. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  4847. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4848. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  4849. [outputStream writeInt32NoTag:(int32_t)msgSize];
  4850. // Write the fields.
  4851. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  4852. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  4853. }
  4854. }
  4855. - (void)setGPBGenericValue:(GPBGenericValue *)value
  4856. forGPBGenericValueKey:(GPBGenericValue *)key {
  4857. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
  4858. }
  4859. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  4860. [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
  4861. #pragma unused(stop)
  4862. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
  4863. }];
  4864. }
  4865. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
  4866. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  4867. if (wrapped && value) {
  4868. *value = [wrapped unsignedLongLongValue];
  4869. }
  4870. return (wrapped != NULL);
  4871. }
  4872. - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
  4873. if (otherDictionary) {
  4874. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  4875. if (_autocreator) {
  4876. GPBAutocreatedDictionaryModified(_autocreator, self);
  4877. }
  4878. }
  4879. }
  4880. - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
  4881. [_dictionary setObject:@(value) forKey:@(key)];
  4882. if (_autocreator) {
  4883. GPBAutocreatedDictionaryModified(_autocreator, self);
  4884. }
  4885. }
  4886. - (void)removeUInt64ForKey:(uint64_t)aKey {
  4887. [_dictionary removeObjectForKey:@(aKey)];
  4888. }
  4889. - (void)removeAll {
  4890. [_dictionary removeAllObjects];
  4891. }
  4892. @end
  4893. #pragma mark - UInt64 -> Int64
  4894. @implementation GPBUInt64Int64Dictionary {
  4895. @package
  4896. NSMutableDictionary *_dictionary;
  4897. }
  4898. - (instancetype)init {
  4899. return [self initWithInt64s:NULL forKeys:NULL count:0];
  4900. }
  4901. - (instancetype)initWithInt64s:(const int64_t [])values
  4902. forKeys:(const uint64_t [])keys
  4903. count:(NSUInteger)count {
  4904. self = [super init];
  4905. if (self) {
  4906. _dictionary = [[NSMutableDictionary alloc] init];
  4907. if (count && values && keys) {
  4908. for (NSUInteger i = 0; i < count; ++i) {
  4909. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  4910. }
  4911. }
  4912. }
  4913. return self;
  4914. }
  4915. - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
  4916. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  4917. if (self) {
  4918. if (dictionary) {
  4919. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  4920. }
  4921. }
  4922. return self;
  4923. }
  4924. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  4925. #pragma unused(numItems)
  4926. return [self initWithInt64s:NULL forKeys:NULL count:0];
  4927. }
  4928. - (void)dealloc {
  4929. NSAssert(!_autocreator,
  4930. @"%@: Autocreator must be cleared before release, autocreator: %@",
  4931. [self class], _autocreator);
  4932. [_dictionary release];
  4933. [super dealloc];
  4934. }
  4935. - (instancetype)copyWithZone:(NSZone *)zone {
  4936. return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  4937. }
  4938. - (BOOL)isEqual:(id)other {
  4939. if (self == other) {
  4940. return YES;
  4941. }
  4942. if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
  4943. return NO;
  4944. }
  4945. GPBUInt64Int64Dictionary *otherDictionary = other;
  4946. return [_dictionary isEqual:otherDictionary->_dictionary];
  4947. }
  4948. - (NSUInteger)hash {
  4949. return _dictionary.count;
  4950. }
  4951. - (NSString *)description {
  4952. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  4953. }
  4954. - (NSUInteger)count {
  4955. return _dictionary.count;
  4956. }
  4957. - (void)enumerateKeysAndInt64sUsingBlock:
  4958. (void (^)(uint64_t key, int64_t value, BOOL *stop))block {
  4959. BOOL stop = NO;
  4960. NSDictionary *internal = _dictionary;
  4961. NSEnumerator *keys = [internal keyEnumerator];
  4962. NSNumber *aKey;
  4963. while ((aKey = [keys nextObject])) {
  4964. NSNumber *aValue = internal[aKey];
  4965. block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
  4966. if (stop) {
  4967. break;
  4968. }
  4969. }
  4970. }
  4971. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  4972. NSDictionary *internal = _dictionary;
  4973. NSUInteger count = internal.count;
  4974. if (count == 0) {
  4975. return 0;
  4976. }
  4977. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4978. GPBDataType keyDataType = field.mapKeyDataType;
  4979. size_t result = 0;
  4980. NSEnumerator *keys = [internal keyEnumerator];
  4981. NSNumber *aKey;
  4982. while ((aKey = [keys nextObject])) {
  4983. NSNumber *aValue = internal[aKey];
  4984. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  4985. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  4986. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  4987. }
  4988. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  4989. result += tagSize * count;
  4990. return result;
  4991. }
  4992. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  4993. asField:(GPBFieldDescriptor *)field {
  4994. GPBDataType valueDataType = GPBGetFieldDataType(field);
  4995. GPBDataType keyDataType = field.mapKeyDataType;
  4996. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  4997. NSDictionary *internal = _dictionary;
  4998. NSEnumerator *keys = [internal keyEnumerator];
  4999. NSNumber *aKey;
  5000. while ((aKey = [keys nextObject])) {
  5001. NSNumber *aValue = internal[aKey];
  5002. [outputStream writeInt32NoTag:tag];
  5003. // Write the size of the message.
  5004. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5005. int64_t unwrappedValue = [aValue longLongValue];
  5006. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5007. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5008. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5009. // Write the fields.
  5010. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5011. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5012. }
  5013. }
  5014. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5015. forGPBGenericValueKey:(GPBGenericValue *)key {
  5016. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
  5017. }
  5018. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5019. [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
  5020. #pragma unused(stop)
  5021. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
  5022. }];
  5023. }
  5024. - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
  5025. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5026. if (wrapped && value) {
  5027. *value = [wrapped longLongValue];
  5028. }
  5029. return (wrapped != NULL);
  5030. }
  5031. - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
  5032. if (otherDictionary) {
  5033. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5034. if (_autocreator) {
  5035. GPBAutocreatedDictionaryModified(_autocreator, self);
  5036. }
  5037. }
  5038. }
  5039. - (void)setInt64:(int64_t)value forKey:(uint64_t)key {
  5040. [_dictionary setObject:@(value) forKey:@(key)];
  5041. if (_autocreator) {
  5042. GPBAutocreatedDictionaryModified(_autocreator, self);
  5043. }
  5044. }
  5045. - (void)removeInt64ForKey:(uint64_t)aKey {
  5046. [_dictionary removeObjectForKey:@(aKey)];
  5047. }
  5048. - (void)removeAll {
  5049. [_dictionary removeAllObjects];
  5050. }
  5051. @end
  5052. #pragma mark - UInt64 -> Bool
  5053. @implementation GPBUInt64BoolDictionary {
  5054. @package
  5055. NSMutableDictionary *_dictionary;
  5056. }
  5057. - (instancetype)init {
  5058. return [self initWithBools:NULL forKeys:NULL count:0];
  5059. }
  5060. - (instancetype)initWithBools:(const BOOL [])values
  5061. forKeys:(const uint64_t [])keys
  5062. count:(NSUInteger)count {
  5063. self = [super init];
  5064. if (self) {
  5065. _dictionary = [[NSMutableDictionary alloc] init];
  5066. if (count && values && keys) {
  5067. for (NSUInteger i = 0; i < count; ++i) {
  5068. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5069. }
  5070. }
  5071. }
  5072. return self;
  5073. }
  5074. - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
  5075. self = [self initWithBools:NULL forKeys:NULL count:0];
  5076. if (self) {
  5077. if (dictionary) {
  5078. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5079. }
  5080. }
  5081. return self;
  5082. }
  5083. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5084. #pragma unused(numItems)
  5085. return [self initWithBools:NULL forKeys:NULL count:0];
  5086. }
  5087. - (void)dealloc {
  5088. NSAssert(!_autocreator,
  5089. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5090. [self class], _autocreator);
  5091. [_dictionary release];
  5092. [super dealloc];
  5093. }
  5094. - (instancetype)copyWithZone:(NSZone *)zone {
  5095. return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
  5096. }
  5097. - (BOOL)isEqual:(id)other {
  5098. if (self == other) {
  5099. return YES;
  5100. }
  5101. if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
  5102. return NO;
  5103. }
  5104. GPBUInt64BoolDictionary *otherDictionary = other;
  5105. return [_dictionary isEqual:otherDictionary->_dictionary];
  5106. }
  5107. - (NSUInteger)hash {
  5108. return _dictionary.count;
  5109. }
  5110. - (NSString *)description {
  5111. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5112. }
  5113. - (NSUInteger)count {
  5114. return _dictionary.count;
  5115. }
  5116. - (void)enumerateKeysAndBoolsUsingBlock:
  5117. (void (^)(uint64_t key, BOOL value, BOOL *stop))block {
  5118. BOOL stop = NO;
  5119. NSDictionary *internal = _dictionary;
  5120. NSEnumerator *keys = [internal keyEnumerator];
  5121. NSNumber *aKey;
  5122. while ((aKey = [keys nextObject])) {
  5123. NSNumber *aValue = internal[aKey];
  5124. block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
  5125. if (stop) {
  5126. break;
  5127. }
  5128. }
  5129. }
  5130. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5131. NSDictionary *internal = _dictionary;
  5132. NSUInteger count = internal.count;
  5133. if (count == 0) {
  5134. return 0;
  5135. }
  5136. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5137. GPBDataType keyDataType = field.mapKeyDataType;
  5138. size_t result = 0;
  5139. NSEnumerator *keys = [internal keyEnumerator];
  5140. NSNumber *aKey;
  5141. while ((aKey = [keys nextObject])) {
  5142. NSNumber *aValue = internal[aKey];
  5143. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5144. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  5145. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5146. }
  5147. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5148. result += tagSize * count;
  5149. return result;
  5150. }
  5151. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5152. asField:(GPBFieldDescriptor *)field {
  5153. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5154. GPBDataType keyDataType = field.mapKeyDataType;
  5155. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5156. NSDictionary *internal = _dictionary;
  5157. NSEnumerator *keys = [internal keyEnumerator];
  5158. NSNumber *aKey;
  5159. while ((aKey = [keys nextObject])) {
  5160. NSNumber *aValue = internal[aKey];
  5161. [outputStream writeInt32NoTag:tag];
  5162. // Write the size of the message.
  5163. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5164. BOOL unwrappedValue = [aValue boolValue];
  5165. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5166. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5167. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5168. // Write the fields.
  5169. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5170. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5171. }
  5172. }
  5173. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5174. forGPBGenericValueKey:(GPBGenericValue *)key {
  5175. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
  5176. }
  5177. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5178. [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
  5179. #pragma unused(stop)
  5180. block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
  5181. }];
  5182. }
  5183. - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
  5184. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5185. if (wrapped && value) {
  5186. *value = [wrapped boolValue];
  5187. }
  5188. return (wrapped != NULL);
  5189. }
  5190. - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
  5191. if (otherDictionary) {
  5192. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5193. if (_autocreator) {
  5194. GPBAutocreatedDictionaryModified(_autocreator, self);
  5195. }
  5196. }
  5197. }
  5198. - (void)setBool:(BOOL)value forKey:(uint64_t)key {
  5199. [_dictionary setObject:@(value) forKey:@(key)];
  5200. if (_autocreator) {
  5201. GPBAutocreatedDictionaryModified(_autocreator, self);
  5202. }
  5203. }
  5204. - (void)removeBoolForKey:(uint64_t)aKey {
  5205. [_dictionary removeObjectForKey:@(aKey)];
  5206. }
  5207. - (void)removeAll {
  5208. [_dictionary removeAllObjects];
  5209. }
  5210. @end
  5211. #pragma mark - UInt64 -> Float
  5212. @implementation GPBUInt64FloatDictionary {
  5213. @package
  5214. NSMutableDictionary *_dictionary;
  5215. }
  5216. - (instancetype)init {
  5217. return [self initWithFloats:NULL forKeys:NULL count:0];
  5218. }
  5219. - (instancetype)initWithFloats:(const float [])values
  5220. forKeys:(const uint64_t [])keys
  5221. count:(NSUInteger)count {
  5222. self = [super init];
  5223. if (self) {
  5224. _dictionary = [[NSMutableDictionary alloc] init];
  5225. if (count && values && keys) {
  5226. for (NSUInteger i = 0; i < count; ++i) {
  5227. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5228. }
  5229. }
  5230. }
  5231. return self;
  5232. }
  5233. - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
  5234. self = [self initWithFloats:NULL forKeys:NULL count:0];
  5235. if (self) {
  5236. if (dictionary) {
  5237. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5238. }
  5239. }
  5240. return self;
  5241. }
  5242. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5243. #pragma unused(numItems)
  5244. return [self initWithFloats:NULL forKeys:NULL count:0];
  5245. }
  5246. - (void)dealloc {
  5247. NSAssert(!_autocreator,
  5248. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5249. [self class], _autocreator);
  5250. [_dictionary release];
  5251. [super dealloc];
  5252. }
  5253. - (instancetype)copyWithZone:(NSZone *)zone {
  5254. return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
  5255. }
  5256. - (BOOL)isEqual:(id)other {
  5257. if (self == other) {
  5258. return YES;
  5259. }
  5260. if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
  5261. return NO;
  5262. }
  5263. GPBUInt64FloatDictionary *otherDictionary = other;
  5264. return [_dictionary isEqual:otherDictionary->_dictionary];
  5265. }
  5266. - (NSUInteger)hash {
  5267. return _dictionary.count;
  5268. }
  5269. - (NSString *)description {
  5270. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5271. }
  5272. - (NSUInteger)count {
  5273. return _dictionary.count;
  5274. }
  5275. - (void)enumerateKeysAndFloatsUsingBlock:
  5276. (void (^)(uint64_t key, float value, BOOL *stop))block {
  5277. BOOL stop = NO;
  5278. NSDictionary *internal = _dictionary;
  5279. NSEnumerator *keys = [internal keyEnumerator];
  5280. NSNumber *aKey;
  5281. while ((aKey = [keys nextObject])) {
  5282. NSNumber *aValue = internal[aKey];
  5283. block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
  5284. if (stop) {
  5285. break;
  5286. }
  5287. }
  5288. }
  5289. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5290. NSDictionary *internal = _dictionary;
  5291. NSUInteger count = internal.count;
  5292. if (count == 0) {
  5293. return 0;
  5294. }
  5295. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5296. GPBDataType keyDataType = field.mapKeyDataType;
  5297. size_t result = 0;
  5298. NSEnumerator *keys = [internal keyEnumerator];
  5299. NSNumber *aKey;
  5300. while ((aKey = [keys nextObject])) {
  5301. NSNumber *aValue = internal[aKey];
  5302. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5303. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  5304. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5305. }
  5306. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5307. result += tagSize * count;
  5308. return result;
  5309. }
  5310. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5311. asField:(GPBFieldDescriptor *)field {
  5312. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5313. GPBDataType keyDataType = field.mapKeyDataType;
  5314. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5315. NSDictionary *internal = _dictionary;
  5316. NSEnumerator *keys = [internal keyEnumerator];
  5317. NSNumber *aKey;
  5318. while ((aKey = [keys nextObject])) {
  5319. NSNumber *aValue = internal[aKey];
  5320. [outputStream writeInt32NoTag:tag];
  5321. // Write the size of the message.
  5322. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5323. float unwrappedValue = [aValue floatValue];
  5324. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5325. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5326. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5327. // Write the fields.
  5328. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5329. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5330. }
  5331. }
  5332. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5333. forGPBGenericValueKey:(GPBGenericValue *)key {
  5334. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
  5335. }
  5336. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5337. [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
  5338. #pragma unused(stop)
  5339. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  5340. }];
  5341. }
  5342. - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
  5343. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5344. if (wrapped && value) {
  5345. *value = [wrapped floatValue];
  5346. }
  5347. return (wrapped != NULL);
  5348. }
  5349. - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
  5350. if (otherDictionary) {
  5351. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5352. if (_autocreator) {
  5353. GPBAutocreatedDictionaryModified(_autocreator, self);
  5354. }
  5355. }
  5356. }
  5357. - (void)setFloat:(float)value forKey:(uint64_t)key {
  5358. [_dictionary setObject:@(value) forKey:@(key)];
  5359. if (_autocreator) {
  5360. GPBAutocreatedDictionaryModified(_autocreator, self);
  5361. }
  5362. }
  5363. - (void)removeFloatForKey:(uint64_t)aKey {
  5364. [_dictionary removeObjectForKey:@(aKey)];
  5365. }
  5366. - (void)removeAll {
  5367. [_dictionary removeAllObjects];
  5368. }
  5369. @end
  5370. #pragma mark - UInt64 -> Double
  5371. @implementation GPBUInt64DoubleDictionary {
  5372. @package
  5373. NSMutableDictionary *_dictionary;
  5374. }
  5375. - (instancetype)init {
  5376. return [self initWithDoubles:NULL forKeys:NULL count:0];
  5377. }
  5378. - (instancetype)initWithDoubles:(const double [])values
  5379. forKeys:(const uint64_t [])keys
  5380. count:(NSUInteger)count {
  5381. self = [super init];
  5382. if (self) {
  5383. _dictionary = [[NSMutableDictionary alloc] init];
  5384. if (count && values && keys) {
  5385. for (NSUInteger i = 0; i < count; ++i) {
  5386. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5387. }
  5388. }
  5389. }
  5390. return self;
  5391. }
  5392. - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
  5393. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  5394. if (self) {
  5395. if (dictionary) {
  5396. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5397. }
  5398. }
  5399. return self;
  5400. }
  5401. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5402. #pragma unused(numItems)
  5403. return [self initWithDoubles:NULL forKeys:NULL count:0];
  5404. }
  5405. - (void)dealloc {
  5406. NSAssert(!_autocreator,
  5407. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5408. [self class], _autocreator);
  5409. [_dictionary release];
  5410. [super dealloc];
  5411. }
  5412. - (instancetype)copyWithZone:(NSZone *)zone {
  5413. return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  5414. }
  5415. - (BOOL)isEqual:(id)other {
  5416. if (self == other) {
  5417. return YES;
  5418. }
  5419. if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
  5420. return NO;
  5421. }
  5422. GPBUInt64DoubleDictionary *otherDictionary = other;
  5423. return [_dictionary isEqual:otherDictionary->_dictionary];
  5424. }
  5425. - (NSUInteger)hash {
  5426. return _dictionary.count;
  5427. }
  5428. - (NSString *)description {
  5429. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5430. }
  5431. - (NSUInteger)count {
  5432. return _dictionary.count;
  5433. }
  5434. - (void)enumerateKeysAndDoublesUsingBlock:
  5435. (void (^)(uint64_t key, double value, BOOL *stop))block {
  5436. BOOL stop = NO;
  5437. NSDictionary *internal = _dictionary;
  5438. NSEnumerator *keys = [internal keyEnumerator];
  5439. NSNumber *aKey;
  5440. while ((aKey = [keys nextObject])) {
  5441. NSNumber *aValue = internal[aKey];
  5442. block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
  5443. if (stop) {
  5444. break;
  5445. }
  5446. }
  5447. }
  5448. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5449. NSDictionary *internal = _dictionary;
  5450. NSUInteger count = internal.count;
  5451. if (count == 0) {
  5452. return 0;
  5453. }
  5454. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5455. GPBDataType keyDataType = field.mapKeyDataType;
  5456. size_t result = 0;
  5457. NSEnumerator *keys = [internal keyEnumerator];
  5458. NSNumber *aKey;
  5459. while ((aKey = [keys nextObject])) {
  5460. NSNumber *aValue = internal[aKey];
  5461. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5462. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  5463. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5464. }
  5465. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5466. result += tagSize * count;
  5467. return result;
  5468. }
  5469. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5470. asField:(GPBFieldDescriptor *)field {
  5471. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5472. GPBDataType keyDataType = field.mapKeyDataType;
  5473. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5474. NSDictionary *internal = _dictionary;
  5475. NSEnumerator *keys = [internal keyEnumerator];
  5476. NSNumber *aKey;
  5477. while ((aKey = [keys nextObject])) {
  5478. NSNumber *aValue = internal[aKey];
  5479. [outputStream writeInt32NoTag:tag];
  5480. // Write the size of the message.
  5481. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5482. double unwrappedValue = [aValue doubleValue];
  5483. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5484. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5485. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5486. // Write the fields.
  5487. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5488. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5489. }
  5490. }
  5491. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5492. forGPBGenericValueKey:(GPBGenericValue *)key {
  5493. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
  5494. }
  5495. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5496. [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
  5497. #pragma unused(stop)
  5498. block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  5499. }];
  5500. }
  5501. - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
  5502. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5503. if (wrapped && value) {
  5504. *value = [wrapped doubleValue];
  5505. }
  5506. return (wrapped != NULL);
  5507. }
  5508. - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
  5509. if (otherDictionary) {
  5510. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5511. if (_autocreator) {
  5512. GPBAutocreatedDictionaryModified(_autocreator, self);
  5513. }
  5514. }
  5515. }
  5516. - (void)setDouble:(double)value forKey:(uint64_t)key {
  5517. [_dictionary setObject:@(value) forKey:@(key)];
  5518. if (_autocreator) {
  5519. GPBAutocreatedDictionaryModified(_autocreator, self);
  5520. }
  5521. }
  5522. - (void)removeDoubleForKey:(uint64_t)aKey {
  5523. [_dictionary removeObjectForKey:@(aKey)];
  5524. }
  5525. - (void)removeAll {
  5526. [_dictionary removeAllObjects];
  5527. }
  5528. @end
  5529. #pragma mark - UInt64 -> Enum
  5530. @implementation GPBUInt64EnumDictionary {
  5531. @package
  5532. NSMutableDictionary *_dictionary;
  5533. GPBEnumValidationFunc _validationFunc;
  5534. }
  5535. @synthesize validationFunc = _validationFunc;
  5536. - (instancetype)init {
  5537. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  5538. }
  5539. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  5540. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  5541. }
  5542. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  5543. rawValues:(const int32_t [])rawValues
  5544. forKeys:(const uint64_t [])keys
  5545. count:(NSUInteger)count {
  5546. self = [super init];
  5547. if (self) {
  5548. _dictionary = [[NSMutableDictionary alloc] init];
  5549. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  5550. if (count && rawValues && keys) {
  5551. for (NSUInteger i = 0; i < count; ++i) {
  5552. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  5553. }
  5554. }
  5555. }
  5556. return self;
  5557. }
  5558. - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
  5559. self = [self initWithValidationFunction:dictionary.validationFunc
  5560. rawValues:NULL
  5561. forKeys:NULL
  5562. count:0];
  5563. if (self) {
  5564. if (dictionary) {
  5565. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5566. }
  5567. }
  5568. return self;
  5569. }
  5570. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  5571. capacity:(NSUInteger)numItems {
  5572. #pragma unused(numItems)
  5573. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  5574. }
  5575. - (void)dealloc {
  5576. NSAssert(!_autocreator,
  5577. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5578. [self class], _autocreator);
  5579. [_dictionary release];
  5580. [super dealloc];
  5581. }
  5582. - (instancetype)copyWithZone:(NSZone *)zone {
  5583. return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
  5584. }
  5585. - (BOOL)isEqual:(id)other {
  5586. if (self == other) {
  5587. return YES;
  5588. }
  5589. if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
  5590. return NO;
  5591. }
  5592. GPBUInt64EnumDictionary *otherDictionary = other;
  5593. return [_dictionary isEqual:otherDictionary->_dictionary];
  5594. }
  5595. - (NSUInteger)hash {
  5596. return _dictionary.count;
  5597. }
  5598. - (NSString *)description {
  5599. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5600. }
  5601. - (NSUInteger)count {
  5602. return _dictionary.count;
  5603. }
  5604. - (void)enumerateKeysAndRawValuesUsingBlock:
  5605. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  5606. BOOL stop = NO;
  5607. NSDictionary *internal = _dictionary;
  5608. NSEnumerator *keys = [internal keyEnumerator];
  5609. NSNumber *aKey;
  5610. while ((aKey = [keys nextObject])) {
  5611. NSNumber *aValue = internal[aKey];
  5612. block([aKey unsignedLongLongValue], [aValue intValue], &stop);
  5613. if (stop) {
  5614. break;
  5615. }
  5616. }
  5617. }
  5618. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5619. NSDictionary *internal = _dictionary;
  5620. NSUInteger count = internal.count;
  5621. if (count == 0) {
  5622. return 0;
  5623. }
  5624. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5625. GPBDataType keyDataType = field.mapKeyDataType;
  5626. size_t result = 0;
  5627. NSEnumerator *keys = [internal keyEnumerator];
  5628. NSNumber *aKey;
  5629. while ((aKey = [keys nextObject])) {
  5630. NSNumber *aValue = internal[aKey];
  5631. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5632. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  5633. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5634. }
  5635. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5636. result += tagSize * count;
  5637. return result;
  5638. }
  5639. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5640. asField:(GPBFieldDescriptor *)field {
  5641. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5642. GPBDataType keyDataType = field.mapKeyDataType;
  5643. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5644. NSDictionary *internal = _dictionary;
  5645. NSEnumerator *keys = [internal keyEnumerator];
  5646. NSNumber *aKey;
  5647. while ((aKey = [keys nextObject])) {
  5648. NSNumber *aValue = internal[aKey];
  5649. [outputStream writeInt32NoTag:tag];
  5650. // Write the size of the message.
  5651. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5652. int32_t unwrappedValue = [aValue intValue];
  5653. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5654. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5655. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5656. // Write the fields.
  5657. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5658. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5659. }
  5660. }
  5661. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  5662. forKey:(GPBGenericValue *)key
  5663. keyDataType:(GPBDataType)keyDataType {
  5664. size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
  5665. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  5666. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  5667. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  5668. WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
  5669. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  5670. [outputStream release];
  5671. return data;
  5672. }
  5673. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5674. forGPBGenericValueKey:(GPBGenericValue *)key {
  5675. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
  5676. }
  5677. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5678. [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
  5679. #pragma unused(stop)
  5680. block([NSString stringWithFormat:@"%llu", key], @(value));
  5681. }];
  5682. }
  5683. - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
  5684. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5685. if (wrapped && value) {
  5686. int32_t result = [wrapped intValue];
  5687. if (!_validationFunc(result)) {
  5688. result = kGPBUnrecognizedEnumeratorValue;
  5689. }
  5690. *value = result;
  5691. }
  5692. return (wrapped != NULL);
  5693. }
  5694. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
  5695. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  5696. if (wrapped && rawValue) {
  5697. *rawValue = [wrapped intValue];
  5698. }
  5699. return (wrapped != NULL);
  5700. }
  5701. - (void)enumerateKeysAndEnumsUsingBlock:
  5702. (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
  5703. GPBEnumValidationFunc func = _validationFunc;
  5704. BOOL stop = NO;
  5705. NSEnumerator *keys = [_dictionary keyEnumerator];
  5706. NSNumber *aKey;
  5707. while ((aKey = [keys nextObject])) {
  5708. NSNumber *aValue = _dictionary[aKey];
  5709. int32_t unwrapped = [aValue intValue];
  5710. if (!func(unwrapped)) {
  5711. unwrapped = kGPBUnrecognizedEnumeratorValue;
  5712. }
  5713. block([aKey unsignedLongLongValue], unwrapped, &stop);
  5714. if (stop) {
  5715. break;
  5716. }
  5717. }
  5718. }
  5719. - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
  5720. if (otherDictionary) {
  5721. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5722. if (_autocreator) {
  5723. GPBAutocreatedDictionaryModified(_autocreator, self);
  5724. }
  5725. }
  5726. }
  5727. - (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
  5728. [_dictionary setObject:@(value) forKey:@(key)];
  5729. if (_autocreator) {
  5730. GPBAutocreatedDictionaryModified(_autocreator, self);
  5731. }
  5732. }
  5733. - (void)removeEnumForKey:(uint64_t)aKey {
  5734. [_dictionary removeObjectForKey:@(aKey)];
  5735. }
  5736. - (void)removeAll {
  5737. [_dictionary removeAllObjects];
  5738. }
  5739. - (void)setEnum:(int32_t)value forKey:(uint64_t)key {
  5740. if (!_validationFunc(value)) {
  5741. [NSException raise:NSInvalidArgumentException
  5742. format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
  5743. value];
  5744. }
  5745. [_dictionary setObject:@(value) forKey:@(key)];
  5746. if (_autocreator) {
  5747. GPBAutocreatedDictionaryModified(_autocreator, self);
  5748. }
  5749. }
  5750. @end
  5751. #pragma mark - UInt64 -> Object
  5752. @implementation GPBUInt64ObjectDictionary {
  5753. @package
  5754. NSMutableDictionary *_dictionary;
  5755. }
  5756. - (instancetype)init {
  5757. return [self initWithObjects:NULL forKeys:NULL count:0];
  5758. }
  5759. - (instancetype)initWithObjects:(const id [])objects
  5760. forKeys:(const uint64_t [])keys
  5761. count:(NSUInteger)count {
  5762. self = [super init];
  5763. if (self) {
  5764. _dictionary = [[NSMutableDictionary alloc] init];
  5765. if (count && objects && keys) {
  5766. for (NSUInteger i = 0; i < count; ++i) {
  5767. if (!objects[i]) {
  5768. [NSException raise:NSInvalidArgumentException
  5769. format:@"Attempting to add nil object to a Dictionary"];
  5770. }else {
  5771. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  5772. }
  5773. }
  5774. }
  5775. }
  5776. return self;
  5777. }
  5778. - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
  5779. self = [self initWithObjects:NULL forKeys:NULL count:0];
  5780. if (self) {
  5781. if (dictionary) {
  5782. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5783. }
  5784. }
  5785. return self;
  5786. }
  5787. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5788. #pragma unused(numItems)
  5789. return [self initWithObjects:NULL forKeys:NULL count:0];
  5790. }
  5791. - (void)dealloc {
  5792. NSAssert(!_autocreator,
  5793. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5794. [self class], _autocreator);
  5795. [_dictionary release];
  5796. [super dealloc];
  5797. }
  5798. - (instancetype)copyWithZone:(NSZone *)zone {
  5799. return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  5800. }
  5801. - (BOOL)isEqual:(id)other {
  5802. if (self == other) {
  5803. return YES;
  5804. }
  5805. if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
  5806. return NO;
  5807. }
  5808. GPBUInt64ObjectDictionary *otherDictionary = other;
  5809. return [_dictionary isEqual:otherDictionary->_dictionary];
  5810. }
  5811. - (NSUInteger)hash {
  5812. return _dictionary.count;
  5813. }
  5814. - (NSString *)description {
  5815. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  5816. }
  5817. - (NSUInteger)count {
  5818. return _dictionary.count;
  5819. }
  5820. - (void)enumerateKeysAndObjectsUsingBlock:
  5821. (void (^)(uint64_t key, id object, BOOL *stop))block {
  5822. BOOL stop = NO;
  5823. NSDictionary *internal = _dictionary;
  5824. NSEnumerator *keys = [internal keyEnumerator];
  5825. NSNumber *aKey;
  5826. while ((aKey = [keys nextObject])) {
  5827. id aObject = internal[aKey];
  5828. block([aKey unsignedLongLongValue], aObject, &stop);
  5829. if (stop) {
  5830. break;
  5831. }
  5832. }
  5833. }
  5834. - (BOOL)isInitialized {
  5835. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  5836. if (!msg.initialized) {
  5837. return NO;
  5838. }
  5839. }
  5840. return YES;
  5841. }
  5842. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  5843. GPBUInt64ObjectDictionary *newDict =
  5844. [[GPBUInt64ObjectDictionary alloc] init];
  5845. NSEnumerator *keys = [_dictionary keyEnumerator];
  5846. id aKey;
  5847. NSMutableDictionary *internalDict = newDict->_dictionary;
  5848. while ((aKey = [keys nextObject])) {
  5849. GPBMessage *msg = _dictionary[aKey];
  5850. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  5851. [internalDict setObject:copiedMsg forKey:aKey];
  5852. [copiedMsg release];
  5853. }
  5854. return newDict;
  5855. }
  5856. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  5857. NSDictionary *internal = _dictionary;
  5858. NSUInteger count = internal.count;
  5859. if (count == 0) {
  5860. return 0;
  5861. }
  5862. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5863. GPBDataType keyDataType = field.mapKeyDataType;
  5864. size_t result = 0;
  5865. NSEnumerator *keys = [internal keyEnumerator];
  5866. NSNumber *aKey;
  5867. while ((aKey = [keys nextObject])) {
  5868. id aObject = internal[aKey];
  5869. size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
  5870. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  5871. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  5872. }
  5873. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  5874. result += tagSize * count;
  5875. return result;
  5876. }
  5877. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  5878. asField:(GPBFieldDescriptor *)field {
  5879. GPBDataType valueDataType = GPBGetFieldDataType(field);
  5880. GPBDataType keyDataType = field.mapKeyDataType;
  5881. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  5882. NSDictionary *internal = _dictionary;
  5883. NSEnumerator *keys = [internal keyEnumerator];
  5884. NSNumber *aKey;
  5885. while ((aKey = [keys nextObject])) {
  5886. id aObject = internal[aKey];
  5887. [outputStream writeInt32NoTag:tag];
  5888. // Write the size of the message.
  5889. uint64_t unwrappedKey = [aKey unsignedLongLongValue];
  5890. id unwrappedValue = aObject;
  5891. size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5892. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  5893. [outputStream writeInt32NoTag:(int32_t)msgSize];
  5894. // Write the fields.
  5895. WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  5896. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  5897. }
  5898. }
  5899. - (void)setGPBGenericValue:(GPBGenericValue *)value
  5900. forGPBGenericValueKey:(GPBGenericValue *)key {
  5901. [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
  5902. }
  5903. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  5904. [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
  5905. #pragma unused(stop)
  5906. block([NSString stringWithFormat:@"%llu", key], object);
  5907. }];
  5908. }
  5909. - (id)objectForKey:(uint64_t)key {
  5910. id result = [_dictionary objectForKey:@(key)];
  5911. return result;
  5912. }
  5913. - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
  5914. if (otherDictionary) {
  5915. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  5916. if (_autocreator) {
  5917. GPBAutocreatedDictionaryModified(_autocreator, self);
  5918. }
  5919. }
  5920. }
  5921. - (void)setObject:(id)object forKey:(uint64_t)key {
  5922. if (!object) {
  5923. [NSException raise:NSInvalidArgumentException
  5924. format:@"Attempting to add nil object to a Dictionary"];
  5925. }
  5926. [_dictionary setObject:object forKey:@(key)];
  5927. if (_autocreator) {
  5928. GPBAutocreatedDictionaryModified(_autocreator, self);
  5929. }
  5930. }
  5931. - (void)removeObjectForKey:(uint64_t)aKey {
  5932. [_dictionary removeObjectForKey:@(aKey)];
  5933. }
  5934. - (void)removeAll {
  5935. [_dictionary removeAllObjects];
  5936. }
  5937. @end
  5938. //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
  5939. // This block of code is generated, do not edit it directly.
  5940. #pragma mark - Int64 -> UInt32
  5941. @implementation GPBInt64UInt32Dictionary {
  5942. @package
  5943. NSMutableDictionary *_dictionary;
  5944. }
  5945. - (instancetype)init {
  5946. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  5947. }
  5948. - (instancetype)initWithUInt32s:(const uint32_t [])values
  5949. forKeys:(const int64_t [])keys
  5950. count:(NSUInteger)count {
  5951. self = [super init];
  5952. if (self) {
  5953. _dictionary = [[NSMutableDictionary alloc] init];
  5954. if (count && values && keys) {
  5955. for (NSUInteger i = 0; i < count; ++i) {
  5956. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  5957. }
  5958. }
  5959. }
  5960. return self;
  5961. }
  5962. - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
  5963. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  5964. if (self) {
  5965. if (dictionary) {
  5966. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  5967. }
  5968. }
  5969. return self;
  5970. }
  5971. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  5972. #pragma unused(numItems)
  5973. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  5974. }
  5975. - (void)dealloc {
  5976. NSAssert(!_autocreator,
  5977. @"%@: Autocreator must be cleared before release, autocreator: %@",
  5978. [self class], _autocreator);
  5979. [_dictionary release];
  5980. [super dealloc];
  5981. }
  5982. - (instancetype)copyWithZone:(NSZone *)zone {
  5983. return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  5984. }
  5985. - (BOOL)isEqual:(id)other {
  5986. if (self == other) {
  5987. return YES;
  5988. }
  5989. if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
  5990. return NO;
  5991. }
  5992. GPBInt64UInt32Dictionary *otherDictionary = other;
  5993. return [_dictionary isEqual:otherDictionary->_dictionary];
  5994. }
  5995. - (NSUInteger)hash {
  5996. return _dictionary.count;
  5997. }
  5998. - (NSString *)description {
  5999. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6000. }
  6001. - (NSUInteger)count {
  6002. return _dictionary.count;
  6003. }
  6004. - (void)enumerateKeysAndUInt32sUsingBlock:
  6005. (void (^)(int64_t key, uint32_t value, BOOL *stop))block {
  6006. BOOL stop = NO;
  6007. NSDictionary *internal = _dictionary;
  6008. NSEnumerator *keys = [internal keyEnumerator];
  6009. NSNumber *aKey;
  6010. while ((aKey = [keys nextObject])) {
  6011. NSNumber *aValue = internal[aKey];
  6012. block([aKey longLongValue], [aValue unsignedIntValue], &stop);
  6013. if (stop) {
  6014. break;
  6015. }
  6016. }
  6017. }
  6018. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6019. NSDictionary *internal = _dictionary;
  6020. NSUInteger count = internal.count;
  6021. if (count == 0) {
  6022. return 0;
  6023. }
  6024. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6025. GPBDataType keyDataType = field.mapKeyDataType;
  6026. size_t result = 0;
  6027. NSEnumerator *keys = [internal keyEnumerator];
  6028. NSNumber *aKey;
  6029. while ((aKey = [keys nextObject])) {
  6030. NSNumber *aValue = internal[aKey];
  6031. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6032. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  6033. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6034. }
  6035. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6036. result += tagSize * count;
  6037. return result;
  6038. }
  6039. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6040. asField:(GPBFieldDescriptor *)field {
  6041. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6042. GPBDataType keyDataType = field.mapKeyDataType;
  6043. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6044. NSDictionary *internal = _dictionary;
  6045. NSEnumerator *keys = [internal keyEnumerator];
  6046. NSNumber *aKey;
  6047. while ((aKey = [keys nextObject])) {
  6048. NSNumber *aValue = internal[aKey];
  6049. [outputStream writeInt32NoTag:tag];
  6050. // Write the size of the message.
  6051. int64_t unwrappedKey = [aKey longLongValue];
  6052. uint32_t unwrappedValue = [aValue unsignedIntValue];
  6053. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6054. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6055. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6056. // Write the fields.
  6057. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6058. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6059. }
  6060. }
  6061. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6062. forGPBGenericValueKey:(GPBGenericValue *)key {
  6063. [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
  6064. }
  6065. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6066. [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
  6067. #pragma unused(stop)
  6068. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
  6069. }];
  6070. }
  6071. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
  6072. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6073. if (wrapped && value) {
  6074. *value = [wrapped unsignedIntValue];
  6075. }
  6076. return (wrapped != NULL);
  6077. }
  6078. - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
  6079. if (otherDictionary) {
  6080. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6081. if (_autocreator) {
  6082. GPBAutocreatedDictionaryModified(_autocreator, self);
  6083. }
  6084. }
  6085. }
  6086. - (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
  6087. [_dictionary setObject:@(value) forKey:@(key)];
  6088. if (_autocreator) {
  6089. GPBAutocreatedDictionaryModified(_autocreator, self);
  6090. }
  6091. }
  6092. - (void)removeUInt32ForKey:(int64_t)aKey {
  6093. [_dictionary removeObjectForKey:@(aKey)];
  6094. }
  6095. - (void)removeAll {
  6096. [_dictionary removeAllObjects];
  6097. }
  6098. @end
  6099. #pragma mark - Int64 -> Int32
  6100. @implementation GPBInt64Int32Dictionary {
  6101. @package
  6102. NSMutableDictionary *_dictionary;
  6103. }
  6104. - (instancetype)init {
  6105. return [self initWithInt32s:NULL forKeys:NULL count:0];
  6106. }
  6107. - (instancetype)initWithInt32s:(const int32_t [])values
  6108. forKeys:(const int64_t [])keys
  6109. count:(NSUInteger)count {
  6110. self = [super init];
  6111. if (self) {
  6112. _dictionary = [[NSMutableDictionary alloc] init];
  6113. if (count && values && keys) {
  6114. for (NSUInteger i = 0; i < count; ++i) {
  6115. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6116. }
  6117. }
  6118. }
  6119. return self;
  6120. }
  6121. - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
  6122. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  6123. if (self) {
  6124. if (dictionary) {
  6125. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6126. }
  6127. }
  6128. return self;
  6129. }
  6130. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6131. #pragma unused(numItems)
  6132. return [self initWithInt32s:NULL forKeys:NULL count:0];
  6133. }
  6134. - (void)dealloc {
  6135. NSAssert(!_autocreator,
  6136. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6137. [self class], _autocreator);
  6138. [_dictionary release];
  6139. [super dealloc];
  6140. }
  6141. - (instancetype)copyWithZone:(NSZone *)zone {
  6142. return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
  6143. }
  6144. - (BOOL)isEqual:(id)other {
  6145. if (self == other) {
  6146. return YES;
  6147. }
  6148. if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
  6149. return NO;
  6150. }
  6151. GPBInt64Int32Dictionary *otherDictionary = other;
  6152. return [_dictionary isEqual:otherDictionary->_dictionary];
  6153. }
  6154. - (NSUInteger)hash {
  6155. return _dictionary.count;
  6156. }
  6157. - (NSString *)description {
  6158. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6159. }
  6160. - (NSUInteger)count {
  6161. return _dictionary.count;
  6162. }
  6163. - (void)enumerateKeysAndInt32sUsingBlock:
  6164. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  6165. BOOL stop = NO;
  6166. NSDictionary *internal = _dictionary;
  6167. NSEnumerator *keys = [internal keyEnumerator];
  6168. NSNumber *aKey;
  6169. while ((aKey = [keys nextObject])) {
  6170. NSNumber *aValue = internal[aKey];
  6171. block([aKey longLongValue], [aValue intValue], &stop);
  6172. if (stop) {
  6173. break;
  6174. }
  6175. }
  6176. }
  6177. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6178. NSDictionary *internal = _dictionary;
  6179. NSUInteger count = internal.count;
  6180. if (count == 0) {
  6181. return 0;
  6182. }
  6183. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6184. GPBDataType keyDataType = field.mapKeyDataType;
  6185. size_t result = 0;
  6186. NSEnumerator *keys = [internal keyEnumerator];
  6187. NSNumber *aKey;
  6188. while ((aKey = [keys nextObject])) {
  6189. NSNumber *aValue = internal[aKey];
  6190. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6191. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  6192. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6193. }
  6194. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6195. result += tagSize * count;
  6196. return result;
  6197. }
  6198. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6199. asField:(GPBFieldDescriptor *)field {
  6200. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6201. GPBDataType keyDataType = field.mapKeyDataType;
  6202. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6203. NSDictionary *internal = _dictionary;
  6204. NSEnumerator *keys = [internal keyEnumerator];
  6205. NSNumber *aKey;
  6206. while ((aKey = [keys nextObject])) {
  6207. NSNumber *aValue = internal[aKey];
  6208. [outputStream writeInt32NoTag:tag];
  6209. // Write the size of the message.
  6210. int64_t unwrappedKey = [aKey longLongValue];
  6211. int32_t unwrappedValue = [aValue intValue];
  6212. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6213. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6214. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6215. // Write the fields.
  6216. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6217. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6218. }
  6219. }
  6220. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6221. forGPBGenericValueKey:(GPBGenericValue *)key {
  6222. [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
  6223. }
  6224. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6225. [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
  6226. #pragma unused(stop)
  6227. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
  6228. }];
  6229. }
  6230. - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
  6231. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6232. if (wrapped && value) {
  6233. *value = [wrapped intValue];
  6234. }
  6235. return (wrapped != NULL);
  6236. }
  6237. - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
  6238. if (otherDictionary) {
  6239. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6240. if (_autocreator) {
  6241. GPBAutocreatedDictionaryModified(_autocreator, self);
  6242. }
  6243. }
  6244. }
  6245. - (void)setInt32:(int32_t)value forKey:(int64_t)key {
  6246. [_dictionary setObject:@(value) forKey:@(key)];
  6247. if (_autocreator) {
  6248. GPBAutocreatedDictionaryModified(_autocreator, self);
  6249. }
  6250. }
  6251. - (void)removeInt32ForKey:(int64_t)aKey {
  6252. [_dictionary removeObjectForKey:@(aKey)];
  6253. }
  6254. - (void)removeAll {
  6255. [_dictionary removeAllObjects];
  6256. }
  6257. @end
  6258. #pragma mark - Int64 -> UInt64
  6259. @implementation GPBInt64UInt64Dictionary {
  6260. @package
  6261. NSMutableDictionary *_dictionary;
  6262. }
  6263. - (instancetype)init {
  6264. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  6265. }
  6266. - (instancetype)initWithUInt64s:(const uint64_t [])values
  6267. forKeys:(const int64_t [])keys
  6268. count:(NSUInteger)count {
  6269. self = [super init];
  6270. if (self) {
  6271. _dictionary = [[NSMutableDictionary alloc] init];
  6272. if (count && values && keys) {
  6273. for (NSUInteger i = 0; i < count; ++i) {
  6274. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6275. }
  6276. }
  6277. }
  6278. return self;
  6279. }
  6280. - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
  6281. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  6282. if (self) {
  6283. if (dictionary) {
  6284. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6285. }
  6286. }
  6287. return self;
  6288. }
  6289. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6290. #pragma unused(numItems)
  6291. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  6292. }
  6293. - (void)dealloc {
  6294. NSAssert(!_autocreator,
  6295. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6296. [self class], _autocreator);
  6297. [_dictionary release];
  6298. [super dealloc];
  6299. }
  6300. - (instancetype)copyWithZone:(NSZone *)zone {
  6301. return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  6302. }
  6303. - (BOOL)isEqual:(id)other {
  6304. if (self == other) {
  6305. return YES;
  6306. }
  6307. if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
  6308. return NO;
  6309. }
  6310. GPBInt64UInt64Dictionary *otherDictionary = other;
  6311. return [_dictionary isEqual:otherDictionary->_dictionary];
  6312. }
  6313. - (NSUInteger)hash {
  6314. return _dictionary.count;
  6315. }
  6316. - (NSString *)description {
  6317. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6318. }
  6319. - (NSUInteger)count {
  6320. return _dictionary.count;
  6321. }
  6322. - (void)enumerateKeysAndUInt64sUsingBlock:
  6323. (void (^)(int64_t key, uint64_t value, BOOL *stop))block {
  6324. BOOL stop = NO;
  6325. NSDictionary *internal = _dictionary;
  6326. NSEnumerator *keys = [internal keyEnumerator];
  6327. NSNumber *aKey;
  6328. while ((aKey = [keys nextObject])) {
  6329. NSNumber *aValue = internal[aKey];
  6330. block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
  6331. if (stop) {
  6332. break;
  6333. }
  6334. }
  6335. }
  6336. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6337. NSDictionary *internal = _dictionary;
  6338. NSUInteger count = internal.count;
  6339. if (count == 0) {
  6340. return 0;
  6341. }
  6342. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6343. GPBDataType keyDataType = field.mapKeyDataType;
  6344. size_t result = 0;
  6345. NSEnumerator *keys = [internal keyEnumerator];
  6346. NSNumber *aKey;
  6347. while ((aKey = [keys nextObject])) {
  6348. NSNumber *aValue = internal[aKey];
  6349. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6350. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  6351. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6352. }
  6353. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6354. result += tagSize * count;
  6355. return result;
  6356. }
  6357. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6358. asField:(GPBFieldDescriptor *)field {
  6359. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6360. GPBDataType keyDataType = field.mapKeyDataType;
  6361. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6362. NSDictionary *internal = _dictionary;
  6363. NSEnumerator *keys = [internal keyEnumerator];
  6364. NSNumber *aKey;
  6365. while ((aKey = [keys nextObject])) {
  6366. NSNumber *aValue = internal[aKey];
  6367. [outputStream writeInt32NoTag:tag];
  6368. // Write the size of the message.
  6369. int64_t unwrappedKey = [aKey longLongValue];
  6370. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  6371. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6372. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6373. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6374. // Write the fields.
  6375. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6376. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6377. }
  6378. }
  6379. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6380. forGPBGenericValueKey:(GPBGenericValue *)key {
  6381. [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
  6382. }
  6383. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6384. [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
  6385. #pragma unused(stop)
  6386. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
  6387. }];
  6388. }
  6389. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
  6390. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6391. if (wrapped && value) {
  6392. *value = [wrapped unsignedLongLongValue];
  6393. }
  6394. return (wrapped != NULL);
  6395. }
  6396. - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
  6397. if (otherDictionary) {
  6398. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6399. if (_autocreator) {
  6400. GPBAutocreatedDictionaryModified(_autocreator, self);
  6401. }
  6402. }
  6403. }
  6404. - (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
  6405. [_dictionary setObject:@(value) forKey:@(key)];
  6406. if (_autocreator) {
  6407. GPBAutocreatedDictionaryModified(_autocreator, self);
  6408. }
  6409. }
  6410. - (void)removeUInt64ForKey:(int64_t)aKey {
  6411. [_dictionary removeObjectForKey:@(aKey)];
  6412. }
  6413. - (void)removeAll {
  6414. [_dictionary removeAllObjects];
  6415. }
  6416. @end
  6417. #pragma mark - Int64 -> Int64
  6418. @implementation GPBInt64Int64Dictionary {
  6419. @package
  6420. NSMutableDictionary *_dictionary;
  6421. }
  6422. - (instancetype)init {
  6423. return [self initWithInt64s:NULL forKeys:NULL count:0];
  6424. }
  6425. - (instancetype)initWithInt64s:(const int64_t [])values
  6426. forKeys:(const int64_t [])keys
  6427. count:(NSUInteger)count {
  6428. self = [super init];
  6429. if (self) {
  6430. _dictionary = [[NSMutableDictionary alloc] init];
  6431. if (count && values && keys) {
  6432. for (NSUInteger i = 0; i < count; ++i) {
  6433. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6434. }
  6435. }
  6436. }
  6437. return self;
  6438. }
  6439. - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
  6440. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  6441. if (self) {
  6442. if (dictionary) {
  6443. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6444. }
  6445. }
  6446. return self;
  6447. }
  6448. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6449. #pragma unused(numItems)
  6450. return [self initWithInt64s:NULL forKeys:NULL count:0];
  6451. }
  6452. - (void)dealloc {
  6453. NSAssert(!_autocreator,
  6454. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6455. [self class], _autocreator);
  6456. [_dictionary release];
  6457. [super dealloc];
  6458. }
  6459. - (instancetype)copyWithZone:(NSZone *)zone {
  6460. return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
  6461. }
  6462. - (BOOL)isEqual:(id)other {
  6463. if (self == other) {
  6464. return YES;
  6465. }
  6466. if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
  6467. return NO;
  6468. }
  6469. GPBInt64Int64Dictionary *otherDictionary = other;
  6470. return [_dictionary isEqual:otherDictionary->_dictionary];
  6471. }
  6472. - (NSUInteger)hash {
  6473. return _dictionary.count;
  6474. }
  6475. - (NSString *)description {
  6476. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6477. }
  6478. - (NSUInteger)count {
  6479. return _dictionary.count;
  6480. }
  6481. - (void)enumerateKeysAndInt64sUsingBlock:
  6482. (void (^)(int64_t key, int64_t value, BOOL *stop))block {
  6483. BOOL stop = NO;
  6484. NSDictionary *internal = _dictionary;
  6485. NSEnumerator *keys = [internal keyEnumerator];
  6486. NSNumber *aKey;
  6487. while ((aKey = [keys nextObject])) {
  6488. NSNumber *aValue = internal[aKey];
  6489. block([aKey longLongValue], [aValue longLongValue], &stop);
  6490. if (stop) {
  6491. break;
  6492. }
  6493. }
  6494. }
  6495. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6496. NSDictionary *internal = _dictionary;
  6497. NSUInteger count = internal.count;
  6498. if (count == 0) {
  6499. return 0;
  6500. }
  6501. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6502. GPBDataType keyDataType = field.mapKeyDataType;
  6503. size_t result = 0;
  6504. NSEnumerator *keys = [internal keyEnumerator];
  6505. NSNumber *aKey;
  6506. while ((aKey = [keys nextObject])) {
  6507. NSNumber *aValue = internal[aKey];
  6508. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6509. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  6510. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6511. }
  6512. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6513. result += tagSize * count;
  6514. return result;
  6515. }
  6516. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6517. asField:(GPBFieldDescriptor *)field {
  6518. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6519. GPBDataType keyDataType = field.mapKeyDataType;
  6520. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6521. NSDictionary *internal = _dictionary;
  6522. NSEnumerator *keys = [internal keyEnumerator];
  6523. NSNumber *aKey;
  6524. while ((aKey = [keys nextObject])) {
  6525. NSNumber *aValue = internal[aKey];
  6526. [outputStream writeInt32NoTag:tag];
  6527. // Write the size of the message.
  6528. int64_t unwrappedKey = [aKey longLongValue];
  6529. int64_t unwrappedValue = [aValue longLongValue];
  6530. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6531. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6532. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6533. // Write the fields.
  6534. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6535. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6536. }
  6537. }
  6538. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6539. forGPBGenericValueKey:(GPBGenericValue *)key {
  6540. [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
  6541. }
  6542. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6543. [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
  6544. #pragma unused(stop)
  6545. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
  6546. }];
  6547. }
  6548. - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
  6549. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6550. if (wrapped && value) {
  6551. *value = [wrapped longLongValue];
  6552. }
  6553. return (wrapped != NULL);
  6554. }
  6555. - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
  6556. if (otherDictionary) {
  6557. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6558. if (_autocreator) {
  6559. GPBAutocreatedDictionaryModified(_autocreator, self);
  6560. }
  6561. }
  6562. }
  6563. - (void)setInt64:(int64_t)value forKey:(int64_t)key {
  6564. [_dictionary setObject:@(value) forKey:@(key)];
  6565. if (_autocreator) {
  6566. GPBAutocreatedDictionaryModified(_autocreator, self);
  6567. }
  6568. }
  6569. - (void)removeInt64ForKey:(int64_t)aKey {
  6570. [_dictionary removeObjectForKey:@(aKey)];
  6571. }
  6572. - (void)removeAll {
  6573. [_dictionary removeAllObjects];
  6574. }
  6575. @end
  6576. #pragma mark - Int64 -> Bool
  6577. @implementation GPBInt64BoolDictionary {
  6578. @package
  6579. NSMutableDictionary *_dictionary;
  6580. }
  6581. - (instancetype)init {
  6582. return [self initWithBools:NULL forKeys:NULL count:0];
  6583. }
  6584. - (instancetype)initWithBools:(const BOOL [])values
  6585. forKeys:(const int64_t [])keys
  6586. count:(NSUInteger)count {
  6587. self = [super init];
  6588. if (self) {
  6589. _dictionary = [[NSMutableDictionary alloc] init];
  6590. if (count && values && keys) {
  6591. for (NSUInteger i = 0; i < count; ++i) {
  6592. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6593. }
  6594. }
  6595. }
  6596. return self;
  6597. }
  6598. - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
  6599. self = [self initWithBools:NULL forKeys:NULL count:0];
  6600. if (self) {
  6601. if (dictionary) {
  6602. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6603. }
  6604. }
  6605. return self;
  6606. }
  6607. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6608. #pragma unused(numItems)
  6609. return [self initWithBools:NULL forKeys:NULL count:0];
  6610. }
  6611. - (void)dealloc {
  6612. NSAssert(!_autocreator,
  6613. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6614. [self class], _autocreator);
  6615. [_dictionary release];
  6616. [super dealloc];
  6617. }
  6618. - (instancetype)copyWithZone:(NSZone *)zone {
  6619. return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
  6620. }
  6621. - (BOOL)isEqual:(id)other {
  6622. if (self == other) {
  6623. return YES;
  6624. }
  6625. if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
  6626. return NO;
  6627. }
  6628. GPBInt64BoolDictionary *otherDictionary = other;
  6629. return [_dictionary isEqual:otherDictionary->_dictionary];
  6630. }
  6631. - (NSUInteger)hash {
  6632. return _dictionary.count;
  6633. }
  6634. - (NSString *)description {
  6635. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6636. }
  6637. - (NSUInteger)count {
  6638. return _dictionary.count;
  6639. }
  6640. - (void)enumerateKeysAndBoolsUsingBlock:
  6641. (void (^)(int64_t key, BOOL value, BOOL *stop))block {
  6642. BOOL stop = NO;
  6643. NSDictionary *internal = _dictionary;
  6644. NSEnumerator *keys = [internal keyEnumerator];
  6645. NSNumber *aKey;
  6646. while ((aKey = [keys nextObject])) {
  6647. NSNumber *aValue = internal[aKey];
  6648. block([aKey longLongValue], [aValue boolValue], &stop);
  6649. if (stop) {
  6650. break;
  6651. }
  6652. }
  6653. }
  6654. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6655. NSDictionary *internal = _dictionary;
  6656. NSUInteger count = internal.count;
  6657. if (count == 0) {
  6658. return 0;
  6659. }
  6660. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6661. GPBDataType keyDataType = field.mapKeyDataType;
  6662. size_t result = 0;
  6663. NSEnumerator *keys = [internal keyEnumerator];
  6664. NSNumber *aKey;
  6665. while ((aKey = [keys nextObject])) {
  6666. NSNumber *aValue = internal[aKey];
  6667. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6668. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  6669. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6670. }
  6671. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6672. result += tagSize * count;
  6673. return result;
  6674. }
  6675. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6676. asField:(GPBFieldDescriptor *)field {
  6677. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6678. GPBDataType keyDataType = field.mapKeyDataType;
  6679. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6680. NSDictionary *internal = _dictionary;
  6681. NSEnumerator *keys = [internal keyEnumerator];
  6682. NSNumber *aKey;
  6683. while ((aKey = [keys nextObject])) {
  6684. NSNumber *aValue = internal[aKey];
  6685. [outputStream writeInt32NoTag:tag];
  6686. // Write the size of the message.
  6687. int64_t unwrappedKey = [aKey longLongValue];
  6688. BOOL unwrappedValue = [aValue boolValue];
  6689. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6690. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6691. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6692. // Write the fields.
  6693. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6694. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6695. }
  6696. }
  6697. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6698. forGPBGenericValueKey:(GPBGenericValue *)key {
  6699. [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
  6700. }
  6701. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6702. [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
  6703. #pragma unused(stop)
  6704. block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
  6705. }];
  6706. }
  6707. - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
  6708. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6709. if (wrapped && value) {
  6710. *value = [wrapped boolValue];
  6711. }
  6712. return (wrapped != NULL);
  6713. }
  6714. - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
  6715. if (otherDictionary) {
  6716. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6717. if (_autocreator) {
  6718. GPBAutocreatedDictionaryModified(_autocreator, self);
  6719. }
  6720. }
  6721. }
  6722. - (void)setBool:(BOOL)value forKey:(int64_t)key {
  6723. [_dictionary setObject:@(value) forKey:@(key)];
  6724. if (_autocreator) {
  6725. GPBAutocreatedDictionaryModified(_autocreator, self);
  6726. }
  6727. }
  6728. - (void)removeBoolForKey:(int64_t)aKey {
  6729. [_dictionary removeObjectForKey:@(aKey)];
  6730. }
  6731. - (void)removeAll {
  6732. [_dictionary removeAllObjects];
  6733. }
  6734. @end
  6735. #pragma mark - Int64 -> Float
  6736. @implementation GPBInt64FloatDictionary {
  6737. @package
  6738. NSMutableDictionary *_dictionary;
  6739. }
  6740. - (instancetype)init {
  6741. return [self initWithFloats:NULL forKeys:NULL count:0];
  6742. }
  6743. - (instancetype)initWithFloats:(const float [])values
  6744. forKeys:(const int64_t [])keys
  6745. count:(NSUInteger)count {
  6746. self = [super init];
  6747. if (self) {
  6748. _dictionary = [[NSMutableDictionary alloc] init];
  6749. if (count && values && keys) {
  6750. for (NSUInteger i = 0; i < count; ++i) {
  6751. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6752. }
  6753. }
  6754. }
  6755. return self;
  6756. }
  6757. - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
  6758. self = [self initWithFloats:NULL forKeys:NULL count:0];
  6759. if (self) {
  6760. if (dictionary) {
  6761. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6762. }
  6763. }
  6764. return self;
  6765. }
  6766. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6767. #pragma unused(numItems)
  6768. return [self initWithFloats:NULL forKeys:NULL count:0];
  6769. }
  6770. - (void)dealloc {
  6771. NSAssert(!_autocreator,
  6772. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6773. [self class], _autocreator);
  6774. [_dictionary release];
  6775. [super dealloc];
  6776. }
  6777. - (instancetype)copyWithZone:(NSZone *)zone {
  6778. return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
  6779. }
  6780. - (BOOL)isEqual:(id)other {
  6781. if (self == other) {
  6782. return YES;
  6783. }
  6784. if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
  6785. return NO;
  6786. }
  6787. GPBInt64FloatDictionary *otherDictionary = other;
  6788. return [_dictionary isEqual:otherDictionary->_dictionary];
  6789. }
  6790. - (NSUInteger)hash {
  6791. return _dictionary.count;
  6792. }
  6793. - (NSString *)description {
  6794. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6795. }
  6796. - (NSUInteger)count {
  6797. return _dictionary.count;
  6798. }
  6799. - (void)enumerateKeysAndFloatsUsingBlock:
  6800. (void (^)(int64_t key, float value, BOOL *stop))block {
  6801. BOOL stop = NO;
  6802. NSDictionary *internal = _dictionary;
  6803. NSEnumerator *keys = [internal keyEnumerator];
  6804. NSNumber *aKey;
  6805. while ((aKey = [keys nextObject])) {
  6806. NSNumber *aValue = internal[aKey];
  6807. block([aKey longLongValue], [aValue floatValue], &stop);
  6808. if (stop) {
  6809. break;
  6810. }
  6811. }
  6812. }
  6813. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6814. NSDictionary *internal = _dictionary;
  6815. NSUInteger count = internal.count;
  6816. if (count == 0) {
  6817. return 0;
  6818. }
  6819. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6820. GPBDataType keyDataType = field.mapKeyDataType;
  6821. size_t result = 0;
  6822. NSEnumerator *keys = [internal keyEnumerator];
  6823. NSNumber *aKey;
  6824. while ((aKey = [keys nextObject])) {
  6825. NSNumber *aValue = internal[aKey];
  6826. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6827. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  6828. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6829. }
  6830. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6831. result += tagSize * count;
  6832. return result;
  6833. }
  6834. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6835. asField:(GPBFieldDescriptor *)field {
  6836. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6837. GPBDataType keyDataType = field.mapKeyDataType;
  6838. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6839. NSDictionary *internal = _dictionary;
  6840. NSEnumerator *keys = [internal keyEnumerator];
  6841. NSNumber *aKey;
  6842. while ((aKey = [keys nextObject])) {
  6843. NSNumber *aValue = internal[aKey];
  6844. [outputStream writeInt32NoTag:tag];
  6845. // Write the size of the message.
  6846. int64_t unwrappedKey = [aKey longLongValue];
  6847. float unwrappedValue = [aValue floatValue];
  6848. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6849. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  6850. [outputStream writeInt32NoTag:(int32_t)msgSize];
  6851. // Write the fields.
  6852. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  6853. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  6854. }
  6855. }
  6856. - (void)setGPBGenericValue:(GPBGenericValue *)value
  6857. forGPBGenericValueKey:(GPBGenericValue *)key {
  6858. [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
  6859. }
  6860. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  6861. [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
  6862. #pragma unused(stop)
  6863. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  6864. }];
  6865. }
  6866. - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
  6867. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  6868. if (wrapped && value) {
  6869. *value = [wrapped floatValue];
  6870. }
  6871. return (wrapped != NULL);
  6872. }
  6873. - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
  6874. if (otherDictionary) {
  6875. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  6876. if (_autocreator) {
  6877. GPBAutocreatedDictionaryModified(_autocreator, self);
  6878. }
  6879. }
  6880. }
  6881. - (void)setFloat:(float)value forKey:(int64_t)key {
  6882. [_dictionary setObject:@(value) forKey:@(key)];
  6883. if (_autocreator) {
  6884. GPBAutocreatedDictionaryModified(_autocreator, self);
  6885. }
  6886. }
  6887. - (void)removeFloatForKey:(int64_t)aKey {
  6888. [_dictionary removeObjectForKey:@(aKey)];
  6889. }
  6890. - (void)removeAll {
  6891. [_dictionary removeAllObjects];
  6892. }
  6893. @end
  6894. #pragma mark - Int64 -> Double
  6895. @implementation GPBInt64DoubleDictionary {
  6896. @package
  6897. NSMutableDictionary *_dictionary;
  6898. }
  6899. - (instancetype)init {
  6900. return [self initWithDoubles:NULL forKeys:NULL count:0];
  6901. }
  6902. - (instancetype)initWithDoubles:(const double [])values
  6903. forKeys:(const int64_t [])keys
  6904. count:(NSUInteger)count {
  6905. self = [super init];
  6906. if (self) {
  6907. _dictionary = [[NSMutableDictionary alloc] init];
  6908. if (count && values && keys) {
  6909. for (NSUInteger i = 0; i < count; ++i) {
  6910. [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
  6911. }
  6912. }
  6913. }
  6914. return self;
  6915. }
  6916. - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
  6917. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  6918. if (self) {
  6919. if (dictionary) {
  6920. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  6921. }
  6922. }
  6923. return self;
  6924. }
  6925. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  6926. #pragma unused(numItems)
  6927. return [self initWithDoubles:NULL forKeys:NULL count:0];
  6928. }
  6929. - (void)dealloc {
  6930. NSAssert(!_autocreator,
  6931. @"%@: Autocreator must be cleared before release, autocreator: %@",
  6932. [self class], _autocreator);
  6933. [_dictionary release];
  6934. [super dealloc];
  6935. }
  6936. - (instancetype)copyWithZone:(NSZone *)zone {
  6937. return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
  6938. }
  6939. - (BOOL)isEqual:(id)other {
  6940. if (self == other) {
  6941. return YES;
  6942. }
  6943. if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
  6944. return NO;
  6945. }
  6946. GPBInt64DoubleDictionary *otherDictionary = other;
  6947. return [_dictionary isEqual:otherDictionary->_dictionary];
  6948. }
  6949. - (NSUInteger)hash {
  6950. return _dictionary.count;
  6951. }
  6952. - (NSString *)description {
  6953. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  6954. }
  6955. - (NSUInteger)count {
  6956. return _dictionary.count;
  6957. }
  6958. - (void)enumerateKeysAndDoublesUsingBlock:
  6959. (void (^)(int64_t key, double value, BOOL *stop))block {
  6960. BOOL stop = NO;
  6961. NSDictionary *internal = _dictionary;
  6962. NSEnumerator *keys = [internal keyEnumerator];
  6963. NSNumber *aKey;
  6964. while ((aKey = [keys nextObject])) {
  6965. NSNumber *aValue = internal[aKey];
  6966. block([aKey longLongValue], [aValue doubleValue], &stop);
  6967. if (stop) {
  6968. break;
  6969. }
  6970. }
  6971. }
  6972. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  6973. NSDictionary *internal = _dictionary;
  6974. NSUInteger count = internal.count;
  6975. if (count == 0) {
  6976. return 0;
  6977. }
  6978. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6979. GPBDataType keyDataType = field.mapKeyDataType;
  6980. size_t result = 0;
  6981. NSEnumerator *keys = [internal keyEnumerator];
  6982. NSNumber *aKey;
  6983. while ((aKey = [keys nextObject])) {
  6984. NSNumber *aValue = internal[aKey];
  6985. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  6986. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  6987. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  6988. }
  6989. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  6990. result += tagSize * count;
  6991. return result;
  6992. }
  6993. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  6994. asField:(GPBFieldDescriptor *)field {
  6995. GPBDataType valueDataType = GPBGetFieldDataType(field);
  6996. GPBDataType keyDataType = field.mapKeyDataType;
  6997. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  6998. NSDictionary *internal = _dictionary;
  6999. NSEnumerator *keys = [internal keyEnumerator];
  7000. NSNumber *aKey;
  7001. while ((aKey = [keys nextObject])) {
  7002. NSNumber *aValue = internal[aKey];
  7003. [outputStream writeInt32NoTag:tag];
  7004. // Write the size of the message.
  7005. int64_t unwrappedKey = [aKey longLongValue];
  7006. double unwrappedValue = [aValue doubleValue];
  7007. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7008. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7009. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7010. // Write the fields.
  7011. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7012. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7013. }
  7014. }
  7015. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7016. forGPBGenericValueKey:(GPBGenericValue *)key {
  7017. [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
  7018. }
  7019. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7020. [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
  7021. #pragma unused(stop)
  7022. block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  7023. }];
  7024. }
  7025. - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
  7026. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7027. if (wrapped && value) {
  7028. *value = [wrapped doubleValue];
  7029. }
  7030. return (wrapped != NULL);
  7031. }
  7032. - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
  7033. if (otherDictionary) {
  7034. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7035. if (_autocreator) {
  7036. GPBAutocreatedDictionaryModified(_autocreator, self);
  7037. }
  7038. }
  7039. }
  7040. - (void)setDouble:(double)value forKey:(int64_t)key {
  7041. [_dictionary setObject:@(value) forKey:@(key)];
  7042. if (_autocreator) {
  7043. GPBAutocreatedDictionaryModified(_autocreator, self);
  7044. }
  7045. }
  7046. - (void)removeDoubleForKey:(int64_t)aKey {
  7047. [_dictionary removeObjectForKey:@(aKey)];
  7048. }
  7049. - (void)removeAll {
  7050. [_dictionary removeAllObjects];
  7051. }
  7052. @end
  7053. #pragma mark - Int64 -> Enum
  7054. @implementation GPBInt64EnumDictionary {
  7055. @package
  7056. NSMutableDictionary *_dictionary;
  7057. GPBEnumValidationFunc _validationFunc;
  7058. }
  7059. @synthesize validationFunc = _validationFunc;
  7060. - (instancetype)init {
  7061. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  7062. }
  7063. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  7064. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  7065. }
  7066. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  7067. rawValues:(const int32_t [])rawValues
  7068. forKeys:(const int64_t [])keys
  7069. count:(NSUInteger)count {
  7070. self = [super init];
  7071. if (self) {
  7072. _dictionary = [[NSMutableDictionary alloc] init];
  7073. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  7074. if (count && rawValues && keys) {
  7075. for (NSUInteger i = 0; i < count; ++i) {
  7076. [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
  7077. }
  7078. }
  7079. }
  7080. return self;
  7081. }
  7082. - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
  7083. self = [self initWithValidationFunction:dictionary.validationFunc
  7084. rawValues:NULL
  7085. forKeys:NULL
  7086. count:0];
  7087. if (self) {
  7088. if (dictionary) {
  7089. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7090. }
  7091. }
  7092. return self;
  7093. }
  7094. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  7095. capacity:(NSUInteger)numItems {
  7096. #pragma unused(numItems)
  7097. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  7098. }
  7099. - (void)dealloc {
  7100. NSAssert(!_autocreator,
  7101. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7102. [self class], _autocreator);
  7103. [_dictionary release];
  7104. [super dealloc];
  7105. }
  7106. - (instancetype)copyWithZone:(NSZone *)zone {
  7107. return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
  7108. }
  7109. - (BOOL)isEqual:(id)other {
  7110. if (self == other) {
  7111. return YES;
  7112. }
  7113. if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
  7114. return NO;
  7115. }
  7116. GPBInt64EnumDictionary *otherDictionary = other;
  7117. return [_dictionary isEqual:otherDictionary->_dictionary];
  7118. }
  7119. - (NSUInteger)hash {
  7120. return _dictionary.count;
  7121. }
  7122. - (NSString *)description {
  7123. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7124. }
  7125. - (NSUInteger)count {
  7126. return _dictionary.count;
  7127. }
  7128. - (void)enumerateKeysAndRawValuesUsingBlock:
  7129. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  7130. BOOL stop = NO;
  7131. NSDictionary *internal = _dictionary;
  7132. NSEnumerator *keys = [internal keyEnumerator];
  7133. NSNumber *aKey;
  7134. while ((aKey = [keys nextObject])) {
  7135. NSNumber *aValue = internal[aKey];
  7136. block([aKey longLongValue], [aValue intValue], &stop);
  7137. if (stop) {
  7138. break;
  7139. }
  7140. }
  7141. }
  7142. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7143. NSDictionary *internal = _dictionary;
  7144. NSUInteger count = internal.count;
  7145. if (count == 0) {
  7146. return 0;
  7147. }
  7148. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7149. GPBDataType keyDataType = field.mapKeyDataType;
  7150. size_t result = 0;
  7151. NSEnumerator *keys = [internal keyEnumerator];
  7152. NSNumber *aKey;
  7153. while ((aKey = [keys nextObject])) {
  7154. NSNumber *aValue = internal[aKey];
  7155. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  7156. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  7157. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7158. }
  7159. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7160. result += tagSize * count;
  7161. return result;
  7162. }
  7163. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7164. asField:(GPBFieldDescriptor *)field {
  7165. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7166. GPBDataType keyDataType = field.mapKeyDataType;
  7167. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7168. NSDictionary *internal = _dictionary;
  7169. NSEnumerator *keys = [internal keyEnumerator];
  7170. NSNumber *aKey;
  7171. while ((aKey = [keys nextObject])) {
  7172. NSNumber *aValue = internal[aKey];
  7173. [outputStream writeInt32NoTag:tag];
  7174. // Write the size of the message.
  7175. int64_t unwrappedKey = [aKey longLongValue];
  7176. int32_t unwrappedValue = [aValue intValue];
  7177. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7178. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7179. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7180. // Write the fields.
  7181. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7182. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7183. }
  7184. }
  7185. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  7186. forKey:(GPBGenericValue *)key
  7187. keyDataType:(GPBDataType)keyDataType {
  7188. size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
  7189. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  7190. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  7191. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  7192. WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
  7193. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  7194. [outputStream release];
  7195. return data;
  7196. }
  7197. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7198. forGPBGenericValueKey:(GPBGenericValue *)key {
  7199. [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
  7200. }
  7201. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7202. [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
  7203. #pragma unused(stop)
  7204. block([NSString stringWithFormat:@"%lld", key], @(value));
  7205. }];
  7206. }
  7207. - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
  7208. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7209. if (wrapped && value) {
  7210. int32_t result = [wrapped intValue];
  7211. if (!_validationFunc(result)) {
  7212. result = kGPBUnrecognizedEnumeratorValue;
  7213. }
  7214. *value = result;
  7215. }
  7216. return (wrapped != NULL);
  7217. }
  7218. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
  7219. NSNumber *wrapped = [_dictionary objectForKey:@(key)];
  7220. if (wrapped && rawValue) {
  7221. *rawValue = [wrapped intValue];
  7222. }
  7223. return (wrapped != NULL);
  7224. }
  7225. - (void)enumerateKeysAndEnumsUsingBlock:
  7226. (void (^)(int64_t key, int32_t value, BOOL *stop))block {
  7227. GPBEnumValidationFunc func = _validationFunc;
  7228. BOOL stop = NO;
  7229. NSEnumerator *keys = [_dictionary keyEnumerator];
  7230. NSNumber *aKey;
  7231. while ((aKey = [keys nextObject])) {
  7232. NSNumber *aValue = _dictionary[aKey];
  7233. int32_t unwrapped = [aValue intValue];
  7234. if (!func(unwrapped)) {
  7235. unwrapped = kGPBUnrecognizedEnumeratorValue;
  7236. }
  7237. block([aKey longLongValue], unwrapped, &stop);
  7238. if (stop) {
  7239. break;
  7240. }
  7241. }
  7242. }
  7243. - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
  7244. if (otherDictionary) {
  7245. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7246. if (_autocreator) {
  7247. GPBAutocreatedDictionaryModified(_autocreator, self);
  7248. }
  7249. }
  7250. }
  7251. - (void)setRawValue:(int32_t)value forKey:(int64_t)key {
  7252. [_dictionary setObject:@(value) forKey:@(key)];
  7253. if (_autocreator) {
  7254. GPBAutocreatedDictionaryModified(_autocreator, self);
  7255. }
  7256. }
  7257. - (void)removeEnumForKey:(int64_t)aKey {
  7258. [_dictionary removeObjectForKey:@(aKey)];
  7259. }
  7260. - (void)removeAll {
  7261. [_dictionary removeAllObjects];
  7262. }
  7263. - (void)setEnum:(int32_t)value forKey:(int64_t)key {
  7264. if (!_validationFunc(value)) {
  7265. [NSException raise:NSInvalidArgumentException
  7266. format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
  7267. value];
  7268. }
  7269. [_dictionary setObject:@(value) forKey:@(key)];
  7270. if (_autocreator) {
  7271. GPBAutocreatedDictionaryModified(_autocreator, self);
  7272. }
  7273. }
  7274. @end
  7275. #pragma mark - Int64 -> Object
  7276. @implementation GPBInt64ObjectDictionary {
  7277. @package
  7278. NSMutableDictionary *_dictionary;
  7279. }
  7280. - (instancetype)init {
  7281. return [self initWithObjects:NULL forKeys:NULL count:0];
  7282. }
  7283. - (instancetype)initWithObjects:(const id [])objects
  7284. forKeys:(const int64_t [])keys
  7285. count:(NSUInteger)count {
  7286. self = [super init];
  7287. if (self) {
  7288. _dictionary = [[NSMutableDictionary alloc] init];
  7289. if (count && objects && keys) {
  7290. for (NSUInteger i = 0; i < count; ++i) {
  7291. if (!objects[i]) {
  7292. [NSException raise:NSInvalidArgumentException
  7293. format:@"Attempting to add nil object to a Dictionary"];
  7294. }else {
  7295. [_dictionary setObject:objects[i] forKey:@(keys[i])];
  7296. }
  7297. }
  7298. }
  7299. }
  7300. return self;
  7301. }
  7302. - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
  7303. self = [self initWithObjects:NULL forKeys:NULL count:0];
  7304. if (self) {
  7305. if (dictionary) {
  7306. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7307. }
  7308. }
  7309. return self;
  7310. }
  7311. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7312. #pragma unused(numItems)
  7313. return [self initWithObjects:NULL forKeys:NULL count:0];
  7314. }
  7315. - (void)dealloc {
  7316. NSAssert(!_autocreator,
  7317. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7318. [self class], _autocreator);
  7319. [_dictionary release];
  7320. [super dealloc];
  7321. }
  7322. - (instancetype)copyWithZone:(NSZone *)zone {
  7323. return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
  7324. }
  7325. - (BOOL)isEqual:(id)other {
  7326. if (self == other) {
  7327. return YES;
  7328. }
  7329. if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
  7330. return NO;
  7331. }
  7332. GPBInt64ObjectDictionary *otherDictionary = other;
  7333. return [_dictionary isEqual:otherDictionary->_dictionary];
  7334. }
  7335. - (NSUInteger)hash {
  7336. return _dictionary.count;
  7337. }
  7338. - (NSString *)description {
  7339. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7340. }
  7341. - (NSUInteger)count {
  7342. return _dictionary.count;
  7343. }
  7344. - (void)enumerateKeysAndObjectsUsingBlock:
  7345. (void (^)(int64_t key, id object, BOOL *stop))block {
  7346. BOOL stop = NO;
  7347. NSDictionary *internal = _dictionary;
  7348. NSEnumerator *keys = [internal keyEnumerator];
  7349. NSNumber *aKey;
  7350. while ((aKey = [keys nextObject])) {
  7351. id aObject = internal[aKey];
  7352. block([aKey longLongValue], aObject, &stop);
  7353. if (stop) {
  7354. break;
  7355. }
  7356. }
  7357. }
  7358. - (BOOL)isInitialized {
  7359. for (GPBMessage *msg in [_dictionary objectEnumerator]) {
  7360. if (!msg.initialized) {
  7361. return NO;
  7362. }
  7363. }
  7364. return YES;
  7365. }
  7366. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  7367. GPBInt64ObjectDictionary *newDict =
  7368. [[GPBInt64ObjectDictionary alloc] init];
  7369. NSEnumerator *keys = [_dictionary keyEnumerator];
  7370. id aKey;
  7371. NSMutableDictionary *internalDict = newDict->_dictionary;
  7372. while ((aKey = [keys nextObject])) {
  7373. GPBMessage *msg = _dictionary[aKey];
  7374. GPBMessage *copiedMsg = [msg copyWithZone:zone];
  7375. [internalDict setObject:copiedMsg forKey:aKey];
  7376. [copiedMsg release];
  7377. }
  7378. return newDict;
  7379. }
  7380. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7381. NSDictionary *internal = _dictionary;
  7382. NSUInteger count = internal.count;
  7383. if (count == 0) {
  7384. return 0;
  7385. }
  7386. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7387. GPBDataType keyDataType = field.mapKeyDataType;
  7388. size_t result = 0;
  7389. NSEnumerator *keys = [internal keyEnumerator];
  7390. NSNumber *aKey;
  7391. while ((aKey = [keys nextObject])) {
  7392. id aObject = internal[aKey];
  7393. size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
  7394. msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
  7395. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7396. }
  7397. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7398. result += tagSize * count;
  7399. return result;
  7400. }
  7401. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7402. asField:(GPBFieldDescriptor *)field {
  7403. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7404. GPBDataType keyDataType = field.mapKeyDataType;
  7405. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7406. NSDictionary *internal = _dictionary;
  7407. NSEnumerator *keys = [internal keyEnumerator];
  7408. NSNumber *aKey;
  7409. while ((aKey = [keys nextObject])) {
  7410. id aObject = internal[aKey];
  7411. [outputStream writeInt32NoTag:tag];
  7412. // Write the size of the message.
  7413. int64_t unwrappedKey = [aKey longLongValue];
  7414. id unwrappedValue = aObject;
  7415. size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7416. msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7417. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7418. // Write the fields.
  7419. WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7420. WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7421. }
  7422. }
  7423. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7424. forGPBGenericValueKey:(GPBGenericValue *)key {
  7425. [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
  7426. }
  7427. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7428. [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
  7429. #pragma unused(stop)
  7430. block([NSString stringWithFormat:@"%lld", key], object);
  7431. }];
  7432. }
  7433. - (id)objectForKey:(int64_t)key {
  7434. id result = [_dictionary objectForKey:@(key)];
  7435. return result;
  7436. }
  7437. - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
  7438. if (otherDictionary) {
  7439. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7440. if (_autocreator) {
  7441. GPBAutocreatedDictionaryModified(_autocreator, self);
  7442. }
  7443. }
  7444. }
  7445. - (void)setObject:(id)object forKey:(int64_t)key {
  7446. if (!object) {
  7447. [NSException raise:NSInvalidArgumentException
  7448. format:@"Attempting to add nil object to a Dictionary"];
  7449. }
  7450. [_dictionary setObject:object forKey:@(key)];
  7451. if (_autocreator) {
  7452. GPBAutocreatedDictionaryModified(_autocreator, self);
  7453. }
  7454. }
  7455. - (void)removeObjectForKey:(int64_t)aKey {
  7456. [_dictionary removeObjectForKey:@(aKey)];
  7457. }
  7458. - (void)removeAll {
  7459. [_dictionary removeAllObjects];
  7460. }
  7461. @end
  7462. //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
  7463. // This block of code is generated, do not edit it directly.
  7464. #pragma mark - String -> UInt32
  7465. @implementation GPBStringUInt32Dictionary {
  7466. @package
  7467. NSMutableDictionary *_dictionary;
  7468. }
  7469. - (instancetype)init {
  7470. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  7471. }
  7472. - (instancetype)initWithUInt32s:(const uint32_t [])values
  7473. forKeys:(const NSString * [])keys
  7474. count:(NSUInteger)count {
  7475. self = [super init];
  7476. if (self) {
  7477. _dictionary = [[NSMutableDictionary alloc] init];
  7478. if (count && values && keys) {
  7479. for (NSUInteger i = 0; i < count; ++i) {
  7480. if (!keys[i]) {
  7481. [NSException raise:NSInvalidArgumentException
  7482. format:@"Attempting to add nil key to a Dictionary"];
  7483. }
  7484. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7485. }
  7486. }
  7487. }
  7488. return self;
  7489. }
  7490. - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
  7491. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  7492. if (self) {
  7493. if (dictionary) {
  7494. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7495. }
  7496. }
  7497. return self;
  7498. }
  7499. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7500. #pragma unused(numItems)
  7501. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  7502. }
  7503. - (void)dealloc {
  7504. NSAssert(!_autocreator,
  7505. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7506. [self class], _autocreator);
  7507. [_dictionary release];
  7508. [super dealloc];
  7509. }
  7510. - (instancetype)copyWithZone:(NSZone *)zone {
  7511. return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  7512. }
  7513. - (BOOL)isEqual:(id)other {
  7514. if (self == other) {
  7515. return YES;
  7516. }
  7517. if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
  7518. return NO;
  7519. }
  7520. GPBStringUInt32Dictionary *otherDictionary = other;
  7521. return [_dictionary isEqual:otherDictionary->_dictionary];
  7522. }
  7523. - (NSUInteger)hash {
  7524. return _dictionary.count;
  7525. }
  7526. - (NSString *)description {
  7527. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7528. }
  7529. - (NSUInteger)count {
  7530. return _dictionary.count;
  7531. }
  7532. - (void)enumerateKeysAndUInt32sUsingBlock:
  7533. (void (^)(NSString *key, uint32_t value, BOOL *stop))block {
  7534. BOOL stop = NO;
  7535. NSDictionary *internal = _dictionary;
  7536. NSEnumerator *keys = [internal keyEnumerator];
  7537. NSString *aKey;
  7538. while ((aKey = [keys nextObject])) {
  7539. NSNumber *aValue = internal[aKey];
  7540. block(aKey, [aValue unsignedIntValue], &stop);
  7541. if (stop) {
  7542. break;
  7543. }
  7544. }
  7545. }
  7546. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7547. NSDictionary *internal = _dictionary;
  7548. NSUInteger count = internal.count;
  7549. if (count == 0) {
  7550. return 0;
  7551. }
  7552. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7553. GPBDataType keyDataType = field.mapKeyDataType;
  7554. size_t result = 0;
  7555. NSEnumerator *keys = [internal keyEnumerator];
  7556. NSString *aKey;
  7557. while ((aKey = [keys nextObject])) {
  7558. NSNumber *aValue = internal[aKey];
  7559. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7560. msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
  7561. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7562. }
  7563. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7564. result += tagSize * count;
  7565. return result;
  7566. }
  7567. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7568. asField:(GPBFieldDescriptor *)field {
  7569. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7570. GPBDataType keyDataType = field.mapKeyDataType;
  7571. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7572. NSDictionary *internal = _dictionary;
  7573. NSEnumerator *keys = [internal keyEnumerator];
  7574. NSString *aKey;
  7575. while ((aKey = [keys nextObject])) {
  7576. NSNumber *aValue = internal[aKey];
  7577. [outputStream writeInt32NoTag:tag];
  7578. // Write the size of the message.
  7579. NSString *unwrappedKey = aKey;
  7580. uint32_t unwrappedValue = [aValue unsignedIntValue];
  7581. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7582. msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7583. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7584. // Write the fields.
  7585. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7586. WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7587. }
  7588. }
  7589. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7590. forGPBGenericValueKey:(GPBGenericValue *)key {
  7591. [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
  7592. }
  7593. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7594. [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
  7595. #pragma unused(stop)
  7596. block(key, [NSString stringWithFormat:@"%u", value]);
  7597. }];
  7598. }
  7599. - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
  7600. NSNumber *wrapped = [_dictionary objectForKey:key];
  7601. if (wrapped && value) {
  7602. *value = [wrapped unsignedIntValue];
  7603. }
  7604. return (wrapped != NULL);
  7605. }
  7606. - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
  7607. if (otherDictionary) {
  7608. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7609. if (_autocreator) {
  7610. GPBAutocreatedDictionaryModified(_autocreator, self);
  7611. }
  7612. }
  7613. }
  7614. - (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
  7615. if (!key) {
  7616. [NSException raise:NSInvalidArgumentException
  7617. format:@"Attempting to add nil key to a Dictionary"];
  7618. }
  7619. [_dictionary setObject:@(value) forKey:key];
  7620. if (_autocreator) {
  7621. GPBAutocreatedDictionaryModified(_autocreator, self);
  7622. }
  7623. }
  7624. - (void)removeUInt32ForKey:(NSString *)aKey {
  7625. [_dictionary removeObjectForKey:aKey];
  7626. }
  7627. - (void)removeAll {
  7628. [_dictionary removeAllObjects];
  7629. }
  7630. @end
  7631. #pragma mark - String -> Int32
  7632. @implementation GPBStringInt32Dictionary {
  7633. @package
  7634. NSMutableDictionary *_dictionary;
  7635. }
  7636. - (instancetype)init {
  7637. return [self initWithInt32s:NULL forKeys:NULL count:0];
  7638. }
  7639. - (instancetype)initWithInt32s:(const int32_t [])values
  7640. forKeys:(const NSString * [])keys
  7641. count:(NSUInteger)count {
  7642. self = [super init];
  7643. if (self) {
  7644. _dictionary = [[NSMutableDictionary alloc] init];
  7645. if (count && values && keys) {
  7646. for (NSUInteger i = 0; i < count; ++i) {
  7647. if (!keys[i]) {
  7648. [NSException raise:NSInvalidArgumentException
  7649. format:@"Attempting to add nil key to a Dictionary"];
  7650. }
  7651. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7652. }
  7653. }
  7654. }
  7655. return self;
  7656. }
  7657. - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
  7658. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  7659. if (self) {
  7660. if (dictionary) {
  7661. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7662. }
  7663. }
  7664. return self;
  7665. }
  7666. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7667. #pragma unused(numItems)
  7668. return [self initWithInt32s:NULL forKeys:NULL count:0];
  7669. }
  7670. - (void)dealloc {
  7671. NSAssert(!_autocreator,
  7672. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7673. [self class], _autocreator);
  7674. [_dictionary release];
  7675. [super dealloc];
  7676. }
  7677. - (instancetype)copyWithZone:(NSZone *)zone {
  7678. return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  7679. }
  7680. - (BOOL)isEqual:(id)other {
  7681. if (self == other) {
  7682. return YES;
  7683. }
  7684. if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
  7685. return NO;
  7686. }
  7687. GPBStringInt32Dictionary *otherDictionary = other;
  7688. return [_dictionary isEqual:otherDictionary->_dictionary];
  7689. }
  7690. - (NSUInteger)hash {
  7691. return _dictionary.count;
  7692. }
  7693. - (NSString *)description {
  7694. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7695. }
  7696. - (NSUInteger)count {
  7697. return _dictionary.count;
  7698. }
  7699. - (void)enumerateKeysAndInt32sUsingBlock:
  7700. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  7701. BOOL stop = NO;
  7702. NSDictionary *internal = _dictionary;
  7703. NSEnumerator *keys = [internal keyEnumerator];
  7704. NSString *aKey;
  7705. while ((aKey = [keys nextObject])) {
  7706. NSNumber *aValue = internal[aKey];
  7707. block(aKey, [aValue intValue], &stop);
  7708. if (stop) {
  7709. break;
  7710. }
  7711. }
  7712. }
  7713. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7714. NSDictionary *internal = _dictionary;
  7715. NSUInteger count = internal.count;
  7716. if (count == 0) {
  7717. return 0;
  7718. }
  7719. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7720. GPBDataType keyDataType = field.mapKeyDataType;
  7721. size_t result = 0;
  7722. NSEnumerator *keys = [internal keyEnumerator];
  7723. NSString *aKey;
  7724. while ((aKey = [keys nextObject])) {
  7725. NSNumber *aValue = internal[aKey];
  7726. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7727. msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  7728. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7729. }
  7730. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7731. result += tagSize * count;
  7732. return result;
  7733. }
  7734. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7735. asField:(GPBFieldDescriptor *)field {
  7736. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7737. GPBDataType keyDataType = field.mapKeyDataType;
  7738. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7739. NSDictionary *internal = _dictionary;
  7740. NSEnumerator *keys = [internal keyEnumerator];
  7741. NSString *aKey;
  7742. while ((aKey = [keys nextObject])) {
  7743. NSNumber *aValue = internal[aKey];
  7744. [outputStream writeInt32NoTag:tag];
  7745. // Write the size of the message.
  7746. NSString *unwrappedKey = aKey;
  7747. int32_t unwrappedValue = [aValue intValue];
  7748. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7749. msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7750. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7751. // Write the fields.
  7752. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7753. WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7754. }
  7755. }
  7756. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7757. forGPBGenericValueKey:(GPBGenericValue *)key {
  7758. [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
  7759. }
  7760. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7761. [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
  7762. #pragma unused(stop)
  7763. block(key, [NSString stringWithFormat:@"%d", value]);
  7764. }];
  7765. }
  7766. - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
  7767. NSNumber *wrapped = [_dictionary objectForKey:key];
  7768. if (wrapped && value) {
  7769. *value = [wrapped intValue];
  7770. }
  7771. return (wrapped != NULL);
  7772. }
  7773. - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
  7774. if (otherDictionary) {
  7775. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7776. if (_autocreator) {
  7777. GPBAutocreatedDictionaryModified(_autocreator, self);
  7778. }
  7779. }
  7780. }
  7781. - (void)setInt32:(int32_t)value forKey:(NSString *)key {
  7782. if (!key) {
  7783. [NSException raise:NSInvalidArgumentException
  7784. format:@"Attempting to add nil key to a Dictionary"];
  7785. }
  7786. [_dictionary setObject:@(value) forKey:key];
  7787. if (_autocreator) {
  7788. GPBAutocreatedDictionaryModified(_autocreator, self);
  7789. }
  7790. }
  7791. - (void)removeInt32ForKey:(NSString *)aKey {
  7792. [_dictionary removeObjectForKey:aKey];
  7793. }
  7794. - (void)removeAll {
  7795. [_dictionary removeAllObjects];
  7796. }
  7797. @end
  7798. #pragma mark - String -> UInt64
  7799. @implementation GPBStringUInt64Dictionary {
  7800. @package
  7801. NSMutableDictionary *_dictionary;
  7802. }
  7803. - (instancetype)init {
  7804. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  7805. }
  7806. - (instancetype)initWithUInt64s:(const uint64_t [])values
  7807. forKeys:(const NSString * [])keys
  7808. count:(NSUInteger)count {
  7809. self = [super init];
  7810. if (self) {
  7811. _dictionary = [[NSMutableDictionary alloc] init];
  7812. if (count && values && keys) {
  7813. for (NSUInteger i = 0; i < count; ++i) {
  7814. if (!keys[i]) {
  7815. [NSException raise:NSInvalidArgumentException
  7816. format:@"Attempting to add nil key to a Dictionary"];
  7817. }
  7818. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7819. }
  7820. }
  7821. }
  7822. return self;
  7823. }
  7824. - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
  7825. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  7826. if (self) {
  7827. if (dictionary) {
  7828. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7829. }
  7830. }
  7831. return self;
  7832. }
  7833. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  7834. #pragma unused(numItems)
  7835. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  7836. }
  7837. - (void)dealloc {
  7838. NSAssert(!_autocreator,
  7839. @"%@: Autocreator must be cleared before release, autocreator: %@",
  7840. [self class], _autocreator);
  7841. [_dictionary release];
  7842. [super dealloc];
  7843. }
  7844. - (instancetype)copyWithZone:(NSZone *)zone {
  7845. return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  7846. }
  7847. - (BOOL)isEqual:(id)other {
  7848. if (self == other) {
  7849. return YES;
  7850. }
  7851. if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
  7852. return NO;
  7853. }
  7854. GPBStringUInt64Dictionary *otherDictionary = other;
  7855. return [_dictionary isEqual:otherDictionary->_dictionary];
  7856. }
  7857. - (NSUInteger)hash {
  7858. return _dictionary.count;
  7859. }
  7860. - (NSString *)description {
  7861. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  7862. }
  7863. - (NSUInteger)count {
  7864. return _dictionary.count;
  7865. }
  7866. - (void)enumerateKeysAndUInt64sUsingBlock:
  7867. (void (^)(NSString *key, uint64_t value, BOOL *stop))block {
  7868. BOOL stop = NO;
  7869. NSDictionary *internal = _dictionary;
  7870. NSEnumerator *keys = [internal keyEnumerator];
  7871. NSString *aKey;
  7872. while ((aKey = [keys nextObject])) {
  7873. NSNumber *aValue = internal[aKey];
  7874. block(aKey, [aValue unsignedLongLongValue], &stop);
  7875. if (stop) {
  7876. break;
  7877. }
  7878. }
  7879. }
  7880. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  7881. NSDictionary *internal = _dictionary;
  7882. NSUInteger count = internal.count;
  7883. if (count == 0) {
  7884. return 0;
  7885. }
  7886. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7887. GPBDataType keyDataType = field.mapKeyDataType;
  7888. size_t result = 0;
  7889. NSEnumerator *keys = [internal keyEnumerator];
  7890. NSString *aKey;
  7891. while ((aKey = [keys nextObject])) {
  7892. NSNumber *aValue = internal[aKey];
  7893. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  7894. msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
  7895. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  7896. }
  7897. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  7898. result += tagSize * count;
  7899. return result;
  7900. }
  7901. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  7902. asField:(GPBFieldDescriptor *)field {
  7903. GPBDataType valueDataType = GPBGetFieldDataType(field);
  7904. GPBDataType keyDataType = field.mapKeyDataType;
  7905. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  7906. NSDictionary *internal = _dictionary;
  7907. NSEnumerator *keys = [internal keyEnumerator];
  7908. NSString *aKey;
  7909. while ((aKey = [keys nextObject])) {
  7910. NSNumber *aValue = internal[aKey];
  7911. [outputStream writeInt32NoTag:tag];
  7912. // Write the size of the message.
  7913. NSString *unwrappedKey = aKey;
  7914. uint64_t unwrappedValue = [aValue unsignedLongLongValue];
  7915. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7916. msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  7917. [outputStream writeInt32NoTag:(int32_t)msgSize];
  7918. // Write the fields.
  7919. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  7920. WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  7921. }
  7922. }
  7923. - (void)setGPBGenericValue:(GPBGenericValue *)value
  7924. forGPBGenericValueKey:(GPBGenericValue *)key {
  7925. [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
  7926. }
  7927. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  7928. [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
  7929. #pragma unused(stop)
  7930. block(key, [NSString stringWithFormat:@"%llu", value]);
  7931. }];
  7932. }
  7933. - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
  7934. NSNumber *wrapped = [_dictionary objectForKey:key];
  7935. if (wrapped && value) {
  7936. *value = [wrapped unsignedLongLongValue];
  7937. }
  7938. return (wrapped != NULL);
  7939. }
  7940. - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
  7941. if (otherDictionary) {
  7942. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  7943. if (_autocreator) {
  7944. GPBAutocreatedDictionaryModified(_autocreator, self);
  7945. }
  7946. }
  7947. }
  7948. - (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
  7949. if (!key) {
  7950. [NSException raise:NSInvalidArgumentException
  7951. format:@"Attempting to add nil key to a Dictionary"];
  7952. }
  7953. [_dictionary setObject:@(value) forKey:key];
  7954. if (_autocreator) {
  7955. GPBAutocreatedDictionaryModified(_autocreator, self);
  7956. }
  7957. }
  7958. - (void)removeUInt64ForKey:(NSString *)aKey {
  7959. [_dictionary removeObjectForKey:aKey];
  7960. }
  7961. - (void)removeAll {
  7962. [_dictionary removeAllObjects];
  7963. }
  7964. @end
  7965. #pragma mark - String -> Int64
  7966. @implementation GPBStringInt64Dictionary {
  7967. @package
  7968. NSMutableDictionary *_dictionary;
  7969. }
  7970. - (instancetype)init {
  7971. return [self initWithInt64s:NULL forKeys:NULL count:0];
  7972. }
  7973. - (instancetype)initWithInt64s:(const int64_t [])values
  7974. forKeys:(const NSString * [])keys
  7975. count:(NSUInteger)count {
  7976. self = [super init];
  7977. if (self) {
  7978. _dictionary = [[NSMutableDictionary alloc] init];
  7979. if (count && values && keys) {
  7980. for (NSUInteger i = 0; i < count; ++i) {
  7981. if (!keys[i]) {
  7982. [NSException raise:NSInvalidArgumentException
  7983. format:@"Attempting to add nil key to a Dictionary"];
  7984. }
  7985. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  7986. }
  7987. }
  7988. }
  7989. return self;
  7990. }
  7991. - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
  7992. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  7993. if (self) {
  7994. if (dictionary) {
  7995. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  7996. }
  7997. }
  7998. return self;
  7999. }
  8000. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8001. #pragma unused(numItems)
  8002. return [self initWithInt64s:NULL forKeys:NULL count:0];
  8003. }
  8004. - (void)dealloc {
  8005. NSAssert(!_autocreator,
  8006. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8007. [self class], _autocreator);
  8008. [_dictionary release];
  8009. [super dealloc];
  8010. }
  8011. - (instancetype)copyWithZone:(NSZone *)zone {
  8012. return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  8013. }
  8014. - (BOOL)isEqual:(id)other {
  8015. if (self == other) {
  8016. return YES;
  8017. }
  8018. if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
  8019. return NO;
  8020. }
  8021. GPBStringInt64Dictionary *otherDictionary = other;
  8022. return [_dictionary isEqual:otherDictionary->_dictionary];
  8023. }
  8024. - (NSUInteger)hash {
  8025. return _dictionary.count;
  8026. }
  8027. - (NSString *)description {
  8028. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8029. }
  8030. - (NSUInteger)count {
  8031. return _dictionary.count;
  8032. }
  8033. - (void)enumerateKeysAndInt64sUsingBlock:
  8034. (void (^)(NSString *key, int64_t value, BOOL *stop))block {
  8035. BOOL stop = NO;
  8036. NSDictionary *internal = _dictionary;
  8037. NSEnumerator *keys = [internal keyEnumerator];
  8038. NSString *aKey;
  8039. while ((aKey = [keys nextObject])) {
  8040. NSNumber *aValue = internal[aKey];
  8041. block(aKey, [aValue longLongValue], &stop);
  8042. if (stop) {
  8043. break;
  8044. }
  8045. }
  8046. }
  8047. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8048. NSDictionary *internal = _dictionary;
  8049. NSUInteger count = internal.count;
  8050. if (count == 0) {
  8051. return 0;
  8052. }
  8053. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8054. GPBDataType keyDataType = field.mapKeyDataType;
  8055. size_t result = 0;
  8056. NSEnumerator *keys = [internal keyEnumerator];
  8057. NSString *aKey;
  8058. while ((aKey = [keys nextObject])) {
  8059. NSNumber *aValue = internal[aKey];
  8060. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8061. msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
  8062. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8063. }
  8064. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8065. result += tagSize * count;
  8066. return result;
  8067. }
  8068. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8069. asField:(GPBFieldDescriptor *)field {
  8070. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8071. GPBDataType keyDataType = field.mapKeyDataType;
  8072. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8073. NSDictionary *internal = _dictionary;
  8074. NSEnumerator *keys = [internal keyEnumerator];
  8075. NSString *aKey;
  8076. while ((aKey = [keys nextObject])) {
  8077. NSNumber *aValue = internal[aKey];
  8078. [outputStream writeInt32NoTag:tag];
  8079. // Write the size of the message.
  8080. NSString *unwrappedKey = aKey;
  8081. int64_t unwrappedValue = [aValue longLongValue];
  8082. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8083. msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8084. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8085. // Write the fields.
  8086. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8087. WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8088. }
  8089. }
  8090. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8091. forGPBGenericValueKey:(GPBGenericValue *)key {
  8092. [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
  8093. }
  8094. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8095. [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
  8096. #pragma unused(stop)
  8097. block(key, [NSString stringWithFormat:@"%lld", value]);
  8098. }];
  8099. }
  8100. - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
  8101. NSNumber *wrapped = [_dictionary objectForKey:key];
  8102. if (wrapped && value) {
  8103. *value = [wrapped longLongValue];
  8104. }
  8105. return (wrapped != NULL);
  8106. }
  8107. - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
  8108. if (otherDictionary) {
  8109. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8110. if (_autocreator) {
  8111. GPBAutocreatedDictionaryModified(_autocreator, self);
  8112. }
  8113. }
  8114. }
  8115. - (void)setInt64:(int64_t)value forKey:(NSString *)key {
  8116. if (!key) {
  8117. [NSException raise:NSInvalidArgumentException
  8118. format:@"Attempting to add nil key to a Dictionary"];
  8119. }
  8120. [_dictionary setObject:@(value) forKey:key];
  8121. if (_autocreator) {
  8122. GPBAutocreatedDictionaryModified(_autocreator, self);
  8123. }
  8124. }
  8125. - (void)removeInt64ForKey:(NSString *)aKey {
  8126. [_dictionary removeObjectForKey:aKey];
  8127. }
  8128. - (void)removeAll {
  8129. [_dictionary removeAllObjects];
  8130. }
  8131. @end
  8132. #pragma mark - String -> Bool
  8133. @implementation GPBStringBoolDictionary {
  8134. @package
  8135. NSMutableDictionary *_dictionary;
  8136. }
  8137. - (instancetype)init {
  8138. return [self initWithBools:NULL forKeys:NULL count:0];
  8139. }
  8140. - (instancetype)initWithBools:(const BOOL [])values
  8141. forKeys:(const NSString * [])keys
  8142. count:(NSUInteger)count {
  8143. self = [super init];
  8144. if (self) {
  8145. _dictionary = [[NSMutableDictionary alloc] init];
  8146. if (count && values && keys) {
  8147. for (NSUInteger i = 0; i < count; ++i) {
  8148. if (!keys[i]) {
  8149. [NSException raise:NSInvalidArgumentException
  8150. format:@"Attempting to add nil key to a Dictionary"];
  8151. }
  8152. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8153. }
  8154. }
  8155. }
  8156. return self;
  8157. }
  8158. - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
  8159. self = [self initWithBools:NULL forKeys:NULL count:0];
  8160. if (self) {
  8161. if (dictionary) {
  8162. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8163. }
  8164. }
  8165. return self;
  8166. }
  8167. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8168. #pragma unused(numItems)
  8169. return [self initWithBools:NULL forKeys:NULL count:0];
  8170. }
  8171. - (void)dealloc {
  8172. NSAssert(!_autocreator,
  8173. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8174. [self class], _autocreator);
  8175. [_dictionary release];
  8176. [super dealloc];
  8177. }
  8178. - (instancetype)copyWithZone:(NSZone *)zone {
  8179. return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
  8180. }
  8181. - (BOOL)isEqual:(id)other {
  8182. if (self == other) {
  8183. return YES;
  8184. }
  8185. if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
  8186. return NO;
  8187. }
  8188. GPBStringBoolDictionary *otherDictionary = other;
  8189. return [_dictionary isEqual:otherDictionary->_dictionary];
  8190. }
  8191. - (NSUInteger)hash {
  8192. return _dictionary.count;
  8193. }
  8194. - (NSString *)description {
  8195. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8196. }
  8197. - (NSUInteger)count {
  8198. return _dictionary.count;
  8199. }
  8200. - (void)enumerateKeysAndBoolsUsingBlock:
  8201. (void (^)(NSString *key, BOOL value, BOOL *stop))block {
  8202. BOOL stop = NO;
  8203. NSDictionary *internal = _dictionary;
  8204. NSEnumerator *keys = [internal keyEnumerator];
  8205. NSString *aKey;
  8206. while ((aKey = [keys nextObject])) {
  8207. NSNumber *aValue = internal[aKey];
  8208. block(aKey, [aValue boolValue], &stop);
  8209. if (stop) {
  8210. break;
  8211. }
  8212. }
  8213. }
  8214. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8215. NSDictionary *internal = _dictionary;
  8216. NSUInteger count = internal.count;
  8217. if (count == 0) {
  8218. return 0;
  8219. }
  8220. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8221. GPBDataType keyDataType = field.mapKeyDataType;
  8222. size_t result = 0;
  8223. NSEnumerator *keys = [internal keyEnumerator];
  8224. NSString *aKey;
  8225. while ((aKey = [keys nextObject])) {
  8226. NSNumber *aValue = internal[aKey];
  8227. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8228. msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
  8229. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8230. }
  8231. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8232. result += tagSize * count;
  8233. return result;
  8234. }
  8235. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8236. asField:(GPBFieldDescriptor *)field {
  8237. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8238. GPBDataType keyDataType = field.mapKeyDataType;
  8239. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8240. NSDictionary *internal = _dictionary;
  8241. NSEnumerator *keys = [internal keyEnumerator];
  8242. NSString *aKey;
  8243. while ((aKey = [keys nextObject])) {
  8244. NSNumber *aValue = internal[aKey];
  8245. [outputStream writeInt32NoTag:tag];
  8246. // Write the size of the message.
  8247. NSString *unwrappedKey = aKey;
  8248. BOOL unwrappedValue = [aValue boolValue];
  8249. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8250. msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8251. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8252. // Write the fields.
  8253. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8254. WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8255. }
  8256. }
  8257. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8258. forGPBGenericValueKey:(GPBGenericValue *)key {
  8259. [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
  8260. }
  8261. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8262. [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
  8263. #pragma unused(stop)
  8264. block(key, (value ? @"true" : @"false"));
  8265. }];
  8266. }
  8267. - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
  8268. NSNumber *wrapped = [_dictionary objectForKey:key];
  8269. if (wrapped && value) {
  8270. *value = [wrapped boolValue];
  8271. }
  8272. return (wrapped != NULL);
  8273. }
  8274. - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
  8275. if (otherDictionary) {
  8276. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8277. if (_autocreator) {
  8278. GPBAutocreatedDictionaryModified(_autocreator, self);
  8279. }
  8280. }
  8281. }
  8282. - (void)setBool:(BOOL)value forKey:(NSString *)key {
  8283. if (!key) {
  8284. [NSException raise:NSInvalidArgumentException
  8285. format:@"Attempting to add nil key to a Dictionary"];
  8286. }
  8287. [_dictionary setObject:@(value) forKey:key];
  8288. if (_autocreator) {
  8289. GPBAutocreatedDictionaryModified(_autocreator, self);
  8290. }
  8291. }
  8292. - (void)removeBoolForKey:(NSString *)aKey {
  8293. [_dictionary removeObjectForKey:aKey];
  8294. }
  8295. - (void)removeAll {
  8296. [_dictionary removeAllObjects];
  8297. }
  8298. @end
  8299. #pragma mark - String -> Float
  8300. @implementation GPBStringFloatDictionary {
  8301. @package
  8302. NSMutableDictionary *_dictionary;
  8303. }
  8304. - (instancetype)init {
  8305. return [self initWithFloats:NULL forKeys:NULL count:0];
  8306. }
  8307. - (instancetype)initWithFloats:(const float [])values
  8308. forKeys:(const NSString * [])keys
  8309. count:(NSUInteger)count {
  8310. self = [super init];
  8311. if (self) {
  8312. _dictionary = [[NSMutableDictionary alloc] init];
  8313. if (count && values && keys) {
  8314. for (NSUInteger i = 0; i < count; ++i) {
  8315. if (!keys[i]) {
  8316. [NSException raise:NSInvalidArgumentException
  8317. format:@"Attempting to add nil key to a Dictionary"];
  8318. }
  8319. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8320. }
  8321. }
  8322. }
  8323. return self;
  8324. }
  8325. - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
  8326. self = [self initWithFloats:NULL forKeys:NULL count:0];
  8327. if (self) {
  8328. if (dictionary) {
  8329. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8330. }
  8331. }
  8332. return self;
  8333. }
  8334. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8335. #pragma unused(numItems)
  8336. return [self initWithFloats:NULL forKeys:NULL count:0];
  8337. }
  8338. - (void)dealloc {
  8339. NSAssert(!_autocreator,
  8340. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8341. [self class], _autocreator);
  8342. [_dictionary release];
  8343. [super dealloc];
  8344. }
  8345. - (instancetype)copyWithZone:(NSZone *)zone {
  8346. return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
  8347. }
  8348. - (BOOL)isEqual:(id)other {
  8349. if (self == other) {
  8350. return YES;
  8351. }
  8352. if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
  8353. return NO;
  8354. }
  8355. GPBStringFloatDictionary *otherDictionary = other;
  8356. return [_dictionary isEqual:otherDictionary->_dictionary];
  8357. }
  8358. - (NSUInteger)hash {
  8359. return _dictionary.count;
  8360. }
  8361. - (NSString *)description {
  8362. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8363. }
  8364. - (NSUInteger)count {
  8365. return _dictionary.count;
  8366. }
  8367. - (void)enumerateKeysAndFloatsUsingBlock:
  8368. (void (^)(NSString *key, float value, BOOL *stop))block {
  8369. BOOL stop = NO;
  8370. NSDictionary *internal = _dictionary;
  8371. NSEnumerator *keys = [internal keyEnumerator];
  8372. NSString *aKey;
  8373. while ((aKey = [keys nextObject])) {
  8374. NSNumber *aValue = internal[aKey];
  8375. block(aKey, [aValue floatValue], &stop);
  8376. if (stop) {
  8377. break;
  8378. }
  8379. }
  8380. }
  8381. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8382. NSDictionary *internal = _dictionary;
  8383. NSUInteger count = internal.count;
  8384. if (count == 0) {
  8385. return 0;
  8386. }
  8387. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8388. GPBDataType keyDataType = field.mapKeyDataType;
  8389. size_t result = 0;
  8390. NSEnumerator *keys = [internal keyEnumerator];
  8391. NSString *aKey;
  8392. while ((aKey = [keys nextObject])) {
  8393. NSNumber *aValue = internal[aKey];
  8394. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8395. msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
  8396. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8397. }
  8398. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8399. result += tagSize * count;
  8400. return result;
  8401. }
  8402. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8403. asField:(GPBFieldDescriptor *)field {
  8404. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8405. GPBDataType keyDataType = field.mapKeyDataType;
  8406. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8407. NSDictionary *internal = _dictionary;
  8408. NSEnumerator *keys = [internal keyEnumerator];
  8409. NSString *aKey;
  8410. while ((aKey = [keys nextObject])) {
  8411. NSNumber *aValue = internal[aKey];
  8412. [outputStream writeInt32NoTag:tag];
  8413. // Write the size of the message.
  8414. NSString *unwrappedKey = aKey;
  8415. float unwrappedValue = [aValue floatValue];
  8416. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8417. msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8418. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8419. // Write the fields.
  8420. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8421. WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8422. }
  8423. }
  8424. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8425. forGPBGenericValueKey:(GPBGenericValue *)key {
  8426. [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
  8427. }
  8428. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8429. [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
  8430. #pragma unused(stop)
  8431. block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
  8432. }];
  8433. }
  8434. - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
  8435. NSNumber *wrapped = [_dictionary objectForKey:key];
  8436. if (wrapped && value) {
  8437. *value = [wrapped floatValue];
  8438. }
  8439. return (wrapped != NULL);
  8440. }
  8441. - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
  8442. if (otherDictionary) {
  8443. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8444. if (_autocreator) {
  8445. GPBAutocreatedDictionaryModified(_autocreator, self);
  8446. }
  8447. }
  8448. }
  8449. - (void)setFloat:(float)value forKey:(NSString *)key {
  8450. if (!key) {
  8451. [NSException raise:NSInvalidArgumentException
  8452. format:@"Attempting to add nil key to a Dictionary"];
  8453. }
  8454. [_dictionary setObject:@(value) forKey:key];
  8455. if (_autocreator) {
  8456. GPBAutocreatedDictionaryModified(_autocreator, self);
  8457. }
  8458. }
  8459. - (void)removeFloatForKey:(NSString *)aKey {
  8460. [_dictionary removeObjectForKey:aKey];
  8461. }
  8462. - (void)removeAll {
  8463. [_dictionary removeAllObjects];
  8464. }
  8465. @end
  8466. #pragma mark - String -> Double
  8467. @implementation GPBStringDoubleDictionary {
  8468. @package
  8469. NSMutableDictionary *_dictionary;
  8470. }
  8471. - (instancetype)init {
  8472. return [self initWithDoubles:NULL forKeys:NULL count:0];
  8473. }
  8474. - (instancetype)initWithDoubles:(const double [])values
  8475. forKeys:(const NSString * [])keys
  8476. count:(NSUInteger)count {
  8477. self = [super init];
  8478. if (self) {
  8479. _dictionary = [[NSMutableDictionary alloc] init];
  8480. if (count && values && keys) {
  8481. for (NSUInteger i = 0; i < count; ++i) {
  8482. if (!keys[i]) {
  8483. [NSException raise:NSInvalidArgumentException
  8484. format:@"Attempting to add nil key to a Dictionary"];
  8485. }
  8486. [_dictionary setObject:@(values[i]) forKey:keys[i]];
  8487. }
  8488. }
  8489. }
  8490. return self;
  8491. }
  8492. - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
  8493. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  8494. if (self) {
  8495. if (dictionary) {
  8496. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8497. }
  8498. }
  8499. return self;
  8500. }
  8501. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8502. #pragma unused(numItems)
  8503. return [self initWithDoubles:NULL forKeys:NULL count:0];
  8504. }
  8505. - (void)dealloc {
  8506. NSAssert(!_autocreator,
  8507. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8508. [self class], _autocreator);
  8509. [_dictionary release];
  8510. [super dealloc];
  8511. }
  8512. - (instancetype)copyWithZone:(NSZone *)zone {
  8513. return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
  8514. }
  8515. - (BOOL)isEqual:(id)other {
  8516. if (self == other) {
  8517. return YES;
  8518. }
  8519. if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
  8520. return NO;
  8521. }
  8522. GPBStringDoubleDictionary *otherDictionary = other;
  8523. return [_dictionary isEqual:otherDictionary->_dictionary];
  8524. }
  8525. - (NSUInteger)hash {
  8526. return _dictionary.count;
  8527. }
  8528. - (NSString *)description {
  8529. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8530. }
  8531. - (NSUInteger)count {
  8532. return _dictionary.count;
  8533. }
  8534. - (void)enumerateKeysAndDoublesUsingBlock:
  8535. (void (^)(NSString *key, double value, BOOL *stop))block {
  8536. BOOL stop = NO;
  8537. NSDictionary *internal = _dictionary;
  8538. NSEnumerator *keys = [internal keyEnumerator];
  8539. NSString *aKey;
  8540. while ((aKey = [keys nextObject])) {
  8541. NSNumber *aValue = internal[aKey];
  8542. block(aKey, [aValue doubleValue], &stop);
  8543. if (stop) {
  8544. break;
  8545. }
  8546. }
  8547. }
  8548. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8549. NSDictionary *internal = _dictionary;
  8550. NSUInteger count = internal.count;
  8551. if (count == 0) {
  8552. return 0;
  8553. }
  8554. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8555. GPBDataType keyDataType = field.mapKeyDataType;
  8556. size_t result = 0;
  8557. NSEnumerator *keys = [internal keyEnumerator];
  8558. NSString *aKey;
  8559. while ((aKey = [keys nextObject])) {
  8560. NSNumber *aValue = internal[aKey];
  8561. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8562. msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
  8563. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8564. }
  8565. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8566. result += tagSize * count;
  8567. return result;
  8568. }
  8569. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8570. asField:(GPBFieldDescriptor *)field {
  8571. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8572. GPBDataType keyDataType = field.mapKeyDataType;
  8573. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8574. NSDictionary *internal = _dictionary;
  8575. NSEnumerator *keys = [internal keyEnumerator];
  8576. NSString *aKey;
  8577. while ((aKey = [keys nextObject])) {
  8578. NSNumber *aValue = internal[aKey];
  8579. [outputStream writeInt32NoTag:tag];
  8580. // Write the size of the message.
  8581. NSString *unwrappedKey = aKey;
  8582. double unwrappedValue = [aValue doubleValue];
  8583. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8584. msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8585. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8586. // Write the fields.
  8587. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8588. WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8589. }
  8590. }
  8591. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8592. forGPBGenericValueKey:(GPBGenericValue *)key {
  8593. [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
  8594. }
  8595. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8596. [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
  8597. #pragma unused(stop)
  8598. block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
  8599. }];
  8600. }
  8601. - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
  8602. NSNumber *wrapped = [_dictionary objectForKey:key];
  8603. if (wrapped && value) {
  8604. *value = [wrapped doubleValue];
  8605. }
  8606. return (wrapped != NULL);
  8607. }
  8608. - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
  8609. if (otherDictionary) {
  8610. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8611. if (_autocreator) {
  8612. GPBAutocreatedDictionaryModified(_autocreator, self);
  8613. }
  8614. }
  8615. }
  8616. - (void)setDouble:(double)value forKey:(NSString *)key {
  8617. if (!key) {
  8618. [NSException raise:NSInvalidArgumentException
  8619. format:@"Attempting to add nil key to a Dictionary"];
  8620. }
  8621. [_dictionary setObject:@(value) forKey:key];
  8622. if (_autocreator) {
  8623. GPBAutocreatedDictionaryModified(_autocreator, self);
  8624. }
  8625. }
  8626. - (void)removeDoubleForKey:(NSString *)aKey {
  8627. [_dictionary removeObjectForKey:aKey];
  8628. }
  8629. - (void)removeAll {
  8630. [_dictionary removeAllObjects];
  8631. }
  8632. @end
  8633. #pragma mark - String -> Enum
  8634. @implementation GPBStringEnumDictionary {
  8635. @package
  8636. NSMutableDictionary *_dictionary;
  8637. GPBEnumValidationFunc _validationFunc;
  8638. }
  8639. @synthesize validationFunc = _validationFunc;
  8640. - (instancetype)init {
  8641. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  8642. }
  8643. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  8644. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  8645. }
  8646. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  8647. rawValues:(const int32_t [])rawValues
  8648. forKeys:(const NSString * [])keys
  8649. count:(NSUInteger)count {
  8650. self = [super init];
  8651. if (self) {
  8652. _dictionary = [[NSMutableDictionary alloc] init];
  8653. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  8654. if (count && rawValues && keys) {
  8655. for (NSUInteger i = 0; i < count; ++i) {
  8656. if (!keys[i]) {
  8657. [NSException raise:NSInvalidArgumentException
  8658. format:@"Attempting to add nil key to a Dictionary"];
  8659. }
  8660. [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
  8661. }
  8662. }
  8663. }
  8664. return self;
  8665. }
  8666. - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
  8667. self = [self initWithValidationFunction:dictionary.validationFunc
  8668. rawValues:NULL
  8669. forKeys:NULL
  8670. count:0];
  8671. if (self) {
  8672. if (dictionary) {
  8673. [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
  8674. }
  8675. }
  8676. return self;
  8677. }
  8678. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  8679. capacity:(NSUInteger)numItems {
  8680. #pragma unused(numItems)
  8681. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  8682. }
  8683. - (void)dealloc {
  8684. NSAssert(!_autocreator,
  8685. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8686. [self class], _autocreator);
  8687. [_dictionary release];
  8688. [super dealloc];
  8689. }
  8690. - (instancetype)copyWithZone:(NSZone *)zone {
  8691. return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
  8692. }
  8693. - (BOOL)isEqual:(id)other {
  8694. if (self == other) {
  8695. return YES;
  8696. }
  8697. if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
  8698. return NO;
  8699. }
  8700. GPBStringEnumDictionary *otherDictionary = other;
  8701. return [_dictionary isEqual:otherDictionary->_dictionary];
  8702. }
  8703. - (NSUInteger)hash {
  8704. return _dictionary.count;
  8705. }
  8706. - (NSString *)description {
  8707. return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
  8708. }
  8709. - (NSUInteger)count {
  8710. return _dictionary.count;
  8711. }
  8712. - (void)enumerateKeysAndRawValuesUsingBlock:
  8713. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  8714. BOOL stop = NO;
  8715. NSDictionary *internal = _dictionary;
  8716. NSEnumerator *keys = [internal keyEnumerator];
  8717. NSString *aKey;
  8718. while ((aKey = [keys nextObject])) {
  8719. NSNumber *aValue = internal[aKey];
  8720. block(aKey, [aValue intValue], &stop);
  8721. if (stop) {
  8722. break;
  8723. }
  8724. }
  8725. }
  8726. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8727. NSDictionary *internal = _dictionary;
  8728. NSUInteger count = internal.count;
  8729. if (count == 0) {
  8730. return 0;
  8731. }
  8732. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8733. GPBDataType keyDataType = field.mapKeyDataType;
  8734. size_t result = 0;
  8735. NSEnumerator *keys = [internal keyEnumerator];
  8736. NSString *aKey;
  8737. while ((aKey = [keys nextObject])) {
  8738. NSNumber *aValue = internal[aKey];
  8739. size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
  8740. msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
  8741. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  8742. }
  8743. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  8744. result += tagSize * count;
  8745. return result;
  8746. }
  8747. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  8748. asField:(GPBFieldDescriptor *)field {
  8749. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8750. GPBDataType keyDataType = field.mapKeyDataType;
  8751. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  8752. NSDictionary *internal = _dictionary;
  8753. NSEnumerator *keys = [internal keyEnumerator];
  8754. NSString *aKey;
  8755. while ((aKey = [keys nextObject])) {
  8756. NSNumber *aValue = internal[aKey];
  8757. [outputStream writeInt32NoTag:tag];
  8758. // Write the size of the message.
  8759. NSString *unwrappedKey = aKey;
  8760. int32_t unwrappedValue = [aValue intValue];
  8761. size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8762. msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
  8763. [outputStream writeInt32NoTag:(int32_t)msgSize];
  8764. // Write the fields.
  8765. WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
  8766. WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
  8767. }
  8768. }
  8769. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  8770. forKey:(GPBGenericValue *)key
  8771. keyDataType:(GPBDataType)keyDataType {
  8772. size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
  8773. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  8774. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  8775. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  8776. WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
  8777. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  8778. [outputStream release];
  8779. return data;
  8780. }
  8781. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8782. forGPBGenericValueKey:(GPBGenericValue *)key {
  8783. [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
  8784. }
  8785. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8786. [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
  8787. #pragma unused(stop)
  8788. block(key, @(value));
  8789. }];
  8790. }
  8791. - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
  8792. NSNumber *wrapped = [_dictionary objectForKey:key];
  8793. if (wrapped && value) {
  8794. int32_t result = [wrapped intValue];
  8795. if (!_validationFunc(result)) {
  8796. result = kGPBUnrecognizedEnumeratorValue;
  8797. }
  8798. *value = result;
  8799. }
  8800. return (wrapped != NULL);
  8801. }
  8802. - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
  8803. NSNumber *wrapped = [_dictionary objectForKey:key];
  8804. if (wrapped && rawValue) {
  8805. *rawValue = [wrapped intValue];
  8806. }
  8807. return (wrapped != NULL);
  8808. }
  8809. - (void)enumerateKeysAndEnumsUsingBlock:
  8810. (void (^)(NSString *key, int32_t value, BOOL *stop))block {
  8811. GPBEnumValidationFunc func = _validationFunc;
  8812. BOOL stop = NO;
  8813. NSEnumerator *keys = [_dictionary keyEnumerator];
  8814. NSString *aKey;
  8815. while ((aKey = [keys nextObject])) {
  8816. NSNumber *aValue = _dictionary[aKey];
  8817. int32_t unwrapped = [aValue intValue];
  8818. if (!func(unwrapped)) {
  8819. unwrapped = kGPBUnrecognizedEnumeratorValue;
  8820. }
  8821. block(aKey, unwrapped, &stop);
  8822. if (stop) {
  8823. break;
  8824. }
  8825. }
  8826. }
  8827. - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
  8828. if (otherDictionary) {
  8829. [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
  8830. if (_autocreator) {
  8831. GPBAutocreatedDictionaryModified(_autocreator, self);
  8832. }
  8833. }
  8834. }
  8835. - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
  8836. if (!key) {
  8837. [NSException raise:NSInvalidArgumentException
  8838. format:@"Attempting to add nil key to a Dictionary"];
  8839. }
  8840. [_dictionary setObject:@(value) forKey:key];
  8841. if (_autocreator) {
  8842. GPBAutocreatedDictionaryModified(_autocreator, self);
  8843. }
  8844. }
  8845. - (void)removeEnumForKey:(NSString *)aKey {
  8846. [_dictionary removeObjectForKey:aKey];
  8847. }
  8848. - (void)removeAll {
  8849. [_dictionary removeAllObjects];
  8850. }
  8851. - (void)setEnum:(int32_t)value forKey:(NSString *)key {
  8852. if (!key) {
  8853. [NSException raise:NSInvalidArgumentException
  8854. format:@"Attempting to add nil key to a Dictionary"];
  8855. }
  8856. if (!_validationFunc(value)) {
  8857. [NSException raise:NSInvalidArgumentException
  8858. format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
  8859. value];
  8860. }
  8861. [_dictionary setObject:@(value) forKey:key];
  8862. if (_autocreator) {
  8863. GPBAutocreatedDictionaryModified(_autocreator, self);
  8864. }
  8865. }
  8866. @end
  8867. //%PDDM-EXPAND-END (5 expansions)
  8868. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
  8869. // This block of code is generated, do not edit it directly.
  8870. #pragma mark - Bool -> UInt32
  8871. @implementation GPBBoolUInt32Dictionary {
  8872. @package
  8873. uint32_t _values[2];
  8874. BOOL _valueSet[2];
  8875. }
  8876. - (instancetype)init {
  8877. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  8878. }
  8879. - (instancetype)initWithUInt32s:(const uint32_t [])values
  8880. forKeys:(const BOOL [])keys
  8881. count:(NSUInteger)count {
  8882. self = [super init];
  8883. if (self) {
  8884. for (NSUInteger i = 0; i < count; ++i) {
  8885. int idx = keys[i] ? 1 : 0;
  8886. _values[idx] = values[i];
  8887. _valueSet[idx] = YES;
  8888. }
  8889. }
  8890. return self;
  8891. }
  8892. - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
  8893. self = [self initWithUInt32s:NULL forKeys:NULL count:0];
  8894. if (self) {
  8895. if (dictionary) {
  8896. for (int i = 0; i < 2; ++i) {
  8897. if (dictionary->_valueSet[i]) {
  8898. _values[i] = dictionary->_values[i];
  8899. _valueSet[i] = YES;
  8900. }
  8901. }
  8902. }
  8903. }
  8904. return self;
  8905. }
  8906. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  8907. #pragma unused(numItems)
  8908. return [self initWithUInt32s:NULL forKeys:NULL count:0];
  8909. }
  8910. #if !defined(NS_BLOCK_ASSERTIONS)
  8911. - (void)dealloc {
  8912. NSAssert(!_autocreator,
  8913. @"%@: Autocreator must be cleared before release, autocreator: %@",
  8914. [self class], _autocreator);
  8915. [super dealloc];
  8916. }
  8917. #endif // !defined(NS_BLOCK_ASSERTIONS)
  8918. - (instancetype)copyWithZone:(NSZone *)zone {
  8919. return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  8920. }
  8921. - (BOOL)isEqual:(id)other {
  8922. if (self == other) {
  8923. return YES;
  8924. }
  8925. if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
  8926. return NO;
  8927. }
  8928. GPBBoolUInt32Dictionary *otherDictionary = other;
  8929. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  8930. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  8931. return NO;
  8932. }
  8933. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  8934. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  8935. return NO;
  8936. }
  8937. return YES;
  8938. }
  8939. - (NSUInteger)hash {
  8940. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  8941. }
  8942. - (NSString *)description {
  8943. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  8944. if (_valueSet[0]) {
  8945. [result appendFormat:@"NO: %u", _values[0]];
  8946. }
  8947. if (_valueSet[1]) {
  8948. [result appendFormat:@"YES: %u", _values[1]];
  8949. }
  8950. [result appendString:@" }"];
  8951. return result;
  8952. }
  8953. - (NSUInteger)count {
  8954. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  8955. }
  8956. - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
  8957. int idx = (key ? 1 : 0);
  8958. if (_valueSet[idx]) {
  8959. if (value) {
  8960. *value = _values[idx];
  8961. }
  8962. return YES;
  8963. }
  8964. return NO;
  8965. }
  8966. - (void)setGPBGenericValue:(GPBGenericValue *)value
  8967. forGPBGenericValueKey:(GPBGenericValue *)key {
  8968. int idx = (key->valueBool ? 1 : 0);
  8969. _values[idx] = value->valueUInt32;
  8970. _valueSet[idx] = YES;
  8971. }
  8972. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  8973. if (_valueSet[0]) {
  8974. block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
  8975. }
  8976. if (_valueSet[1]) {
  8977. block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
  8978. }
  8979. }
  8980. - (void)enumerateKeysAndUInt32sUsingBlock:
  8981. (void (^)(BOOL key, uint32_t value, BOOL *stop))block {
  8982. BOOL stop = NO;
  8983. if (_valueSet[0]) {
  8984. block(NO, _values[0], &stop);
  8985. }
  8986. if (!stop && _valueSet[1]) {
  8987. block(YES, _values[1], &stop);
  8988. }
  8989. }
  8990. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  8991. GPBDataType valueDataType = GPBGetFieldDataType(field);
  8992. NSUInteger count = 0;
  8993. size_t result = 0;
  8994. for (int i = 0; i < 2; ++i) {
  8995. if (_valueSet[i]) {
  8996. ++count;
  8997. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  8998. msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  8999. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9000. }
  9001. }
  9002. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9003. result += tagSize * count;
  9004. return result;
  9005. }
  9006. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9007. asField:(GPBFieldDescriptor *)field {
  9008. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9009. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9010. for (int i = 0; i < 2; ++i) {
  9011. if (_valueSet[i]) {
  9012. // Write the tag.
  9013. [outputStream writeInt32NoTag:tag];
  9014. // Write the size of the message.
  9015. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9016. msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9017. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9018. // Write the fields.
  9019. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9020. WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9021. }
  9022. }
  9023. }
  9024. - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
  9025. if (otherDictionary) {
  9026. for (int i = 0; i < 2; ++i) {
  9027. if (otherDictionary->_valueSet[i]) {
  9028. _valueSet[i] = YES;
  9029. _values[i] = otherDictionary->_values[i];
  9030. }
  9031. }
  9032. if (_autocreator) {
  9033. GPBAutocreatedDictionaryModified(_autocreator, self);
  9034. }
  9035. }
  9036. }
  9037. - (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
  9038. int idx = (key ? 1 : 0);
  9039. _values[idx] = value;
  9040. _valueSet[idx] = YES;
  9041. if (_autocreator) {
  9042. GPBAutocreatedDictionaryModified(_autocreator, self);
  9043. }
  9044. }
  9045. - (void)removeUInt32ForKey:(BOOL)aKey {
  9046. _valueSet[aKey ? 1 : 0] = NO;
  9047. }
  9048. - (void)removeAll {
  9049. _valueSet[0] = NO;
  9050. _valueSet[1] = NO;
  9051. }
  9052. @end
  9053. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
  9054. // This block of code is generated, do not edit it directly.
  9055. #pragma mark - Bool -> Int32
  9056. @implementation GPBBoolInt32Dictionary {
  9057. @package
  9058. int32_t _values[2];
  9059. BOOL _valueSet[2];
  9060. }
  9061. - (instancetype)init {
  9062. return [self initWithInt32s:NULL forKeys:NULL count:0];
  9063. }
  9064. - (instancetype)initWithInt32s:(const int32_t [])values
  9065. forKeys:(const BOOL [])keys
  9066. count:(NSUInteger)count {
  9067. self = [super init];
  9068. if (self) {
  9069. for (NSUInteger i = 0; i < count; ++i) {
  9070. int idx = keys[i] ? 1 : 0;
  9071. _values[idx] = values[i];
  9072. _valueSet[idx] = YES;
  9073. }
  9074. }
  9075. return self;
  9076. }
  9077. - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
  9078. self = [self initWithInt32s:NULL forKeys:NULL count:0];
  9079. if (self) {
  9080. if (dictionary) {
  9081. for (int i = 0; i < 2; ++i) {
  9082. if (dictionary->_valueSet[i]) {
  9083. _values[i] = dictionary->_values[i];
  9084. _valueSet[i] = YES;
  9085. }
  9086. }
  9087. }
  9088. }
  9089. return self;
  9090. }
  9091. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9092. #pragma unused(numItems)
  9093. return [self initWithInt32s:NULL forKeys:NULL count:0];
  9094. }
  9095. #if !defined(NS_BLOCK_ASSERTIONS)
  9096. - (void)dealloc {
  9097. NSAssert(!_autocreator,
  9098. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9099. [self class], _autocreator);
  9100. [super dealloc];
  9101. }
  9102. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9103. - (instancetype)copyWithZone:(NSZone *)zone {
  9104. return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
  9105. }
  9106. - (BOOL)isEqual:(id)other {
  9107. if (self == other) {
  9108. return YES;
  9109. }
  9110. if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
  9111. return NO;
  9112. }
  9113. GPBBoolInt32Dictionary *otherDictionary = other;
  9114. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9115. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9116. return NO;
  9117. }
  9118. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9119. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9120. return NO;
  9121. }
  9122. return YES;
  9123. }
  9124. - (NSUInteger)hash {
  9125. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9126. }
  9127. - (NSString *)description {
  9128. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9129. if (_valueSet[0]) {
  9130. [result appendFormat:@"NO: %d", _values[0]];
  9131. }
  9132. if (_valueSet[1]) {
  9133. [result appendFormat:@"YES: %d", _values[1]];
  9134. }
  9135. [result appendString:@" }"];
  9136. return result;
  9137. }
  9138. - (NSUInteger)count {
  9139. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9140. }
  9141. - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
  9142. int idx = (key ? 1 : 0);
  9143. if (_valueSet[idx]) {
  9144. if (value) {
  9145. *value = _values[idx];
  9146. }
  9147. return YES;
  9148. }
  9149. return NO;
  9150. }
  9151. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9152. forGPBGenericValueKey:(GPBGenericValue *)key {
  9153. int idx = (key->valueBool ? 1 : 0);
  9154. _values[idx] = value->valueInt32;
  9155. _valueSet[idx] = YES;
  9156. }
  9157. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9158. if (_valueSet[0]) {
  9159. block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
  9160. }
  9161. if (_valueSet[1]) {
  9162. block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
  9163. }
  9164. }
  9165. - (void)enumerateKeysAndInt32sUsingBlock:
  9166. (void (^)(BOOL key, int32_t value, BOOL *stop))block {
  9167. BOOL stop = NO;
  9168. if (_valueSet[0]) {
  9169. block(NO, _values[0], &stop);
  9170. }
  9171. if (!stop && _valueSet[1]) {
  9172. block(YES, _values[1], &stop);
  9173. }
  9174. }
  9175. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9176. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9177. NSUInteger count = 0;
  9178. size_t result = 0;
  9179. for (int i = 0; i < 2; ++i) {
  9180. if (_valueSet[i]) {
  9181. ++count;
  9182. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9183. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9184. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9185. }
  9186. }
  9187. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9188. result += tagSize * count;
  9189. return result;
  9190. }
  9191. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9192. asField:(GPBFieldDescriptor *)field {
  9193. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9194. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9195. for (int i = 0; i < 2; ++i) {
  9196. if (_valueSet[i]) {
  9197. // Write the tag.
  9198. [outputStream writeInt32NoTag:tag];
  9199. // Write the size of the message.
  9200. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9201. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9202. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9203. // Write the fields.
  9204. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9205. WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9206. }
  9207. }
  9208. }
  9209. - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
  9210. if (otherDictionary) {
  9211. for (int i = 0; i < 2; ++i) {
  9212. if (otherDictionary->_valueSet[i]) {
  9213. _valueSet[i] = YES;
  9214. _values[i] = otherDictionary->_values[i];
  9215. }
  9216. }
  9217. if (_autocreator) {
  9218. GPBAutocreatedDictionaryModified(_autocreator, self);
  9219. }
  9220. }
  9221. }
  9222. - (void)setInt32:(int32_t)value forKey:(BOOL)key {
  9223. int idx = (key ? 1 : 0);
  9224. _values[idx] = value;
  9225. _valueSet[idx] = YES;
  9226. if (_autocreator) {
  9227. GPBAutocreatedDictionaryModified(_autocreator, self);
  9228. }
  9229. }
  9230. - (void)removeInt32ForKey:(BOOL)aKey {
  9231. _valueSet[aKey ? 1 : 0] = NO;
  9232. }
  9233. - (void)removeAll {
  9234. _valueSet[0] = NO;
  9235. _valueSet[1] = NO;
  9236. }
  9237. @end
  9238. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
  9239. // This block of code is generated, do not edit it directly.
  9240. #pragma mark - Bool -> UInt64
  9241. @implementation GPBBoolUInt64Dictionary {
  9242. @package
  9243. uint64_t _values[2];
  9244. BOOL _valueSet[2];
  9245. }
  9246. - (instancetype)init {
  9247. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  9248. }
  9249. - (instancetype)initWithUInt64s:(const uint64_t [])values
  9250. forKeys:(const BOOL [])keys
  9251. count:(NSUInteger)count {
  9252. self = [super init];
  9253. if (self) {
  9254. for (NSUInteger i = 0; i < count; ++i) {
  9255. int idx = keys[i] ? 1 : 0;
  9256. _values[idx] = values[i];
  9257. _valueSet[idx] = YES;
  9258. }
  9259. }
  9260. return self;
  9261. }
  9262. - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
  9263. self = [self initWithUInt64s:NULL forKeys:NULL count:0];
  9264. if (self) {
  9265. if (dictionary) {
  9266. for (int i = 0; i < 2; ++i) {
  9267. if (dictionary->_valueSet[i]) {
  9268. _values[i] = dictionary->_values[i];
  9269. _valueSet[i] = YES;
  9270. }
  9271. }
  9272. }
  9273. }
  9274. return self;
  9275. }
  9276. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9277. #pragma unused(numItems)
  9278. return [self initWithUInt64s:NULL forKeys:NULL count:0];
  9279. }
  9280. #if !defined(NS_BLOCK_ASSERTIONS)
  9281. - (void)dealloc {
  9282. NSAssert(!_autocreator,
  9283. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9284. [self class], _autocreator);
  9285. [super dealloc];
  9286. }
  9287. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9288. - (instancetype)copyWithZone:(NSZone *)zone {
  9289. return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  9290. }
  9291. - (BOOL)isEqual:(id)other {
  9292. if (self == other) {
  9293. return YES;
  9294. }
  9295. if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
  9296. return NO;
  9297. }
  9298. GPBBoolUInt64Dictionary *otherDictionary = other;
  9299. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9300. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9301. return NO;
  9302. }
  9303. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9304. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9305. return NO;
  9306. }
  9307. return YES;
  9308. }
  9309. - (NSUInteger)hash {
  9310. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9311. }
  9312. - (NSString *)description {
  9313. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9314. if (_valueSet[0]) {
  9315. [result appendFormat:@"NO: %llu", _values[0]];
  9316. }
  9317. if (_valueSet[1]) {
  9318. [result appendFormat:@"YES: %llu", _values[1]];
  9319. }
  9320. [result appendString:@" }"];
  9321. return result;
  9322. }
  9323. - (NSUInteger)count {
  9324. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9325. }
  9326. - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
  9327. int idx = (key ? 1 : 0);
  9328. if (_valueSet[idx]) {
  9329. if (value) {
  9330. *value = _values[idx];
  9331. }
  9332. return YES;
  9333. }
  9334. return NO;
  9335. }
  9336. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9337. forGPBGenericValueKey:(GPBGenericValue *)key {
  9338. int idx = (key->valueBool ? 1 : 0);
  9339. _values[idx] = value->valueUInt64;
  9340. _valueSet[idx] = YES;
  9341. }
  9342. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9343. if (_valueSet[0]) {
  9344. block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
  9345. }
  9346. if (_valueSet[1]) {
  9347. block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
  9348. }
  9349. }
  9350. - (void)enumerateKeysAndUInt64sUsingBlock:
  9351. (void (^)(BOOL key, uint64_t value, BOOL *stop))block {
  9352. BOOL stop = NO;
  9353. if (_valueSet[0]) {
  9354. block(NO, _values[0], &stop);
  9355. }
  9356. if (!stop && _valueSet[1]) {
  9357. block(YES, _values[1], &stop);
  9358. }
  9359. }
  9360. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9361. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9362. NSUInteger count = 0;
  9363. size_t result = 0;
  9364. for (int i = 0; i < 2; ++i) {
  9365. if (_valueSet[i]) {
  9366. ++count;
  9367. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9368. msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9369. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9370. }
  9371. }
  9372. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9373. result += tagSize * count;
  9374. return result;
  9375. }
  9376. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9377. asField:(GPBFieldDescriptor *)field {
  9378. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9379. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9380. for (int i = 0; i < 2; ++i) {
  9381. if (_valueSet[i]) {
  9382. // Write the tag.
  9383. [outputStream writeInt32NoTag:tag];
  9384. // Write the size of the message.
  9385. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9386. msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9387. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9388. // Write the fields.
  9389. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9390. WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9391. }
  9392. }
  9393. }
  9394. - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
  9395. if (otherDictionary) {
  9396. for (int i = 0; i < 2; ++i) {
  9397. if (otherDictionary->_valueSet[i]) {
  9398. _valueSet[i] = YES;
  9399. _values[i] = otherDictionary->_values[i];
  9400. }
  9401. }
  9402. if (_autocreator) {
  9403. GPBAutocreatedDictionaryModified(_autocreator, self);
  9404. }
  9405. }
  9406. }
  9407. - (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
  9408. int idx = (key ? 1 : 0);
  9409. _values[idx] = value;
  9410. _valueSet[idx] = YES;
  9411. if (_autocreator) {
  9412. GPBAutocreatedDictionaryModified(_autocreator, self);
  9413. }
  9414. }
  9415. - (void)removeUInt64ForKey:(BOOL)aKey {
  9416. _valueSet[aKey ? 1 : 0] = NO;
  9417. }
  9418. - (void)removeAll {
  9419. _valueSet[0] = NO;
  9420. _valueSet[1] = NO;
  9421. }
  9422. @end
  9423. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
  9424. // This block of code is generated, do not edit it directly.
  9425. #pragma mark - Bool -> Int64
  9426. @implementation GPBBoolInt64Dictionary {
  9427. @package
  9428. int64_t _values[2];
  9429. BOOL _valueSet[2];
  9430. }
  9431. - (instancetype)init {
  9432. return [self initWithInt64s:NULL forKeys:NULL count:0];
  9433. }
  9434. - (instancetype)initWithInt64s:(const int64_t [])values
  9435. forKeys:(const BOOL [])keys
  9436. count:(NSUInteger)count {
  9437. self = [super init];
  9438. if (self) {
  9439. for (NSUInteger i = 0; i < count; ++i) {
  9440. int idx = keys[i] ? 1 : 0;
  9441. _values[idx] = values[i];
  9442. _valueSet[idx] = YES;
  9443. }
  9444. }
  9445. return self;
  9446. }
  9447. - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
  9448. self = [self initWithInt64s:NULL forKeys:NULL count:0];
  9449. if (self) {
  9450. if (dictionary) {
  9451. for (int i = 0; i < 2; ++i) {
  9452. if (dictionary->_valueSet[i]) {
  9453. _values[i] = dictionary->_values[i];
  9454. _valueSet[i] = YES;
  9455. }
  9456. }
  9457. }
  9458. }
  9459. return self;
  9460. }
  9461. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9462. #pragma unused(numItems)
  9463. return [self initWithInt64s:NULL forKeys:NULL count:0];
  9464. }
  9465. #if !defined(NS_BLOCK_ASSERTIONS)
  9466. - (void)dealloc {
  9467. NSAssert(!_autocreator,
  9468. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9469. [self class], _autocreator);
  9470. [super dealloc];
  9471. }
  9472. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9473. - (instancetype)copyWithZone:(NSZone *)zone {
  9474. return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
  9475. }
  9476. - (BOOL)isEqual:(id)other {
  9477. if (self == other) {
  9478. return YES;
  9479. }
  9480. if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
  9481. return NO;
  9482. }
  9483. GPBBoolInt64Dictionary *otherDictionary = other;
  9484. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9485. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9486. return NO;
  9487. }
  9488. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9489. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9490. return NO;
  9491. }
  9492. return YES;
  9493. }
  9494. - (NSUInteger)hash {
  9495. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9496. }
  9497. - (NSString *)description {
  9498. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9499. if (_valueSet[0]) {
  9500. [result appendFormat:@"NO: %lld", _values[0]];
  9501. }
  9502. if (_valueSet[1]) {
  9503. [result appendFormat:@"YES: %lld", _values[1]];
  9504. }
  9505. [result appendString:@" }"];
  9506. return result;
  9507. }
  9508. - (NSUInteger)count {
  9509. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9510. }
  9511. - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
  9512. int idx = (key ? 1 : 0);
  9513. if (_valueSet[idx]) {
  9514. if (value) {
  9515. *value = _values[idx];
  9516. }
  9517. return YES;
  9518. }
  9519. return NO;
  9520. }
  9521. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9522. forGPBGenericValueKey:(GPBGenericValue *)key {
  9523. int idx = (key->valueBool ? 1 : 0);
  9524. _values[idx] = value->valueInt64;
  9525. _valueSet[idx] = YES;
  9526. }
  9527. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9528. if (_valueSet[0]) {
  9529. block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
  9530. }
  9531. if (_valueSet[1]) {
  9532. block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
  9533. }
  9534. }
  9535. - (void)enumerateKeysAndInt64sUsingBlock:
  9536. (void (^)(BOOL key, int64_t value, BOOL *stop))block {
  9537. BOOL stop = NO;
  9538. if (_valueSet[0]) {
  9539. block(NO, _values[0], &stop);
  9540. }
  9541. if (!stop && _valueSet[1]) {
  9542. block(YES, _values[1], &stop);
  9543. }
  9544. }
  9545. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9546. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9547. NSUInteger count = 0;
  9548. size_t result = 0;
  9549. for (int i = 0; i < 2; ++i) {
  9550. if (_valueSet[i]) {
  9551. ++count;
  9552. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9553. msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9554. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9555. }
  9556. }
  9557. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9558. result += tagSize * count;
  9559. return result;
  9560. }
  9561. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9562. asField:(GPBFieldDescriptor *)field {
  9563. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9564. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9565. for (int i = 0; i < 2; ++i) {
  9566. if (_valueSet[i]) {
  9567. // Write the tag.
  9568. [outputStream writeInt32NoTag:tag];
  9569. // Write the size of the message.
  9570. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9571. msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9572. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9573. // Write the fields.
  9574. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9575. WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9576. }
  9577. }
  9578. }
  9579. - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
  9580. if (otherDictionary) {
  9581. for (int i = 0; i < 2; ++i) {
  9582. if (otherDictionary->_valueSet[i]) {
  9583. _valueSet[i] = YES;
  9584. _values[i] = otherDictionary->_values[i];
  9585. }
  9586. }
  9587. if (_autocreator) {
  9588. GPBAutocreatedDictionaryModified(_autocreator, self);
  9589. }
  9590. }
  9591. }
  9592. - (void)setInt64:(int64_t)value forKey:(BOOL)key {
  9593. int idx = (key ? 1 : 0);
  9594. _values[idx] = value;
  9595. _valueSet[idx] = YES;
  9596. if (_autocreator) {
  9597. GPBAutocreatedDictionaryModified(_autocreator, self);
  9598. }
  9599. }
  9600. - (void)removeInt64ForKey:(BOOL)aKey {
  9601. _valueSet[aKey ? 1 : 0] = NO;
  9602. }
  9603. - (void)removeAll {
  9604. _valueSet[0] = NO;
  9605. _valueSet[1] = NO;
  9606. }
  9607. @end
  9608. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
  9609. // This block of code is generated, do not edit it directly.
  9610. #pragma mark - Bool -> Bool
  9611. @implementation GPBBoolBoolDictionary {
  9612. @package
  9613. BOOL _values[2];
  9614. BOOL _valueSet[2];
  9615. }
  9616. - (instancetype)init {
  9617. return [self initWithBools:NULL forKeys:NULL count:0];
  9618. }
  9619. - (instancetype)initWithBools:(const BOOL [])values
  9620. forKeys:(const BOOL [])keys
  9621. count:(NSUInteger)count {
  9622. self = [super init];
  9623. if (self) {
  9624. for (NSUInteger i = 0; i < count; ++i) {
  9625. int idx = keys[i] ? 1 : 0;
  9626. _values[idx] = values[i];
  9627. _valueSet[idx] = YES;
  9628. }
  9629. }
  9630. return self;
  9631. }
  9632. - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
  9633. self = [self initWithBools:NULL forKeys:NULL count:0];
  9634. if (self) {
  9635. if (dictionary) {
  9636. for (int i = 0; i < 2; ++i) {
  9637. if (dictionary->_valueSet[i]) {
  9638. _values[i] = dictionary->_values[i];
  9639. _valueSet[i] = YES;
  9640. }
  9641. }
  9642. }
  9643. }
  9644. return self;
  9645. }
  9646. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9647. #pragma unused(numItems)
  9648. return [self initWithBools:NULL forKeys:NULL count:0];
  9649. }
  9650. #if !defined(NS_BLOCK_ASSERTIONS)
  9651. - (void)dealloc {
  9652. NSAssert(!_autocreator,
  9653. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9654. [self class], _autocreator);
  9655. [super dealloc];
  9656. }
  9657. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9658. - (instancetype)copyWithZone:(NSZone *)zone {
  9659. return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
  9660. }
  9661. - (BOOL)isEqual:(id)other {
  9662. if (self == other) {
  9663. return YES;
  9664. }
  9665. if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
  9666. return NO;
  9667. }
  9668. GPBBoolBoolDictionary *otherDictionary = other;
  9669. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9670. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9671. return NO;
  9672. }
  9673. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9674. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9675. return NO;
  9676. }
  9677. return YES;
  9678. }
  9679. - (NSUInteger)hash {
  9680. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9681. }
  9682. - (NSString *)description {
  9683. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9684. if (_valueSet[0]) {
  9685. [result appendFormat:@"NO: %d", _values[0]];
  9686. }
  9687. if (_valueSet[1]) {
  9688. [result appendFormat:@"YES: %d", _values[1]];
  9689. }
  9690. [result appendString:@" }"];
  9691. return result;
  9692. }
  9693. - (NSUInteger)count {
  9694. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9695. }
  9696. - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
  9697. int idx = (key ? 1 : 0);
  9698. if (_valueSet[idx]) {
  9699. if (value) {
  9700. *value = _values[idx];
  9701. }
  9702. return YES;
  9703. }
  9704. return NO;
  9705. }
  9706. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9707. forGPBGenericValueKey:(GPBGenericValue *)key {
  9708. int idx = (key->valueBool ? 1 : 0);
  9709. _values[idx] = value->valueBool;
  9710. _valueSet[idx] = YES;
  9711. }
  9712. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9713. if (_valueSet[0]) {
  9714. block(@"false", (_values[0] ? @"true" : @"false"));
  9715. }
  9716. if (_valueSet[1]) {
  9717. block(@"true", (_values[1] ? @"true" : @"false"));
  9718. }
  9719. }
  9720. - (void)enumerateKeysAndBoolsUsingBlock:
  9721. (void (^)(BOOL key, BOOL value, BOOL *stop))block {
  9722. BOOL stop = NO;
  9723. if (_valueSet[0]) {
  9724. block(NO, _values[0], &stop);
  9725. }
  9726. if (!stop && _valueSet[1]) {
  9727. block(YES, _values[1], &stop);
  9728. }
  9729. }
  9730. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9731. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9732. NSUInteger count = 0;
  9733. size_t result = 0;
  9734. for (int i = 0; i < 2; ++i) {
  9735. if (_valueSet[i]) {
  9736. ++count;
  9737. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9738. msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9739. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9740. }
  9741. }
  9742. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9743. result += tagSize * count;
  9744. return result;
  9745. }
  9746. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9747. asField:(GPBFieldDescriptor *)field {
  9748. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9749. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9750. for (int i = 0; i < 2; ++i) {
  9751. if (_valueSet[i]) {
  9752. // Write the tag.
  9753. [outputStream writeInt32NoTag:tag];
  9754. // Write the size of the message.
  9755. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9756. msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9757. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9758. // Write the fields.
  9759. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9760. WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9761. }
  9762. }
  9763. }
  9764. - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
  9765. if (otherDictionary) {
  9766. for (int i = 0; i < 2; ++i) {
  9767. if (otherDictionary->_valueSet[i]) {
  9768. _valueSet[i] = YES;
  9769. _values[i] = otherDictionary->_values[i];
  9770. }
  9771. }
  9772. if (_autocreator) {
  9773. GPBAutocreatedDictionaryModified(_autocreator, self);
  9774. }
  9775. }
  9776. }
  9777. - (void)setBool:(BOOL)value forKey:(BOOL)key {
  9778. int idx = (key ? 1 : 0);
  9779. _values[idx] = value;
  9780. _valueSet[idx] = YES;
  9781. if (_autocreator) {
  9782. GPBAutocreatedDictionaryModified(_autocreator, self);
  9783. }
  9784. }
  9785. - (void)removeBoolForKey:(BOOL)aKey {
  9786. _valueSet[aKey ? 1 : 0] = NO;
  9787. }
  9788. - (void)removeAll {
  9789. _valueSet[0] = NO;
  9790. _valueSet[1] = NO;
  9791. }
  9792. @end
  9793. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
  9794. // This block of code is generated, do not edit it directly.
  9795. #pragma mark - Bool -> Float
  9796. @implementation GPBBoolFloatDictionary {
  9797. @package
  9798. float _values[2];
  9799. BOOL _valueSet[2];
  9800. }
  9801. - (instancetype)init {
  9802. return [self initWithFloats:NULL forKeys:NULL count:0];
  9803. }
  9804. - (instancetype)initWithFloats:(const float [])values
  9805. forKeys:(const BOOL [])keys
  9806. count:(NSUInteger)count {
  9807. self = [super init];
  9808. if (self) {
  9809. for (NSUInteger i = 0; i < count; ++i) {
  9810. int idx = keys[i] ? 1 : 0;
  9811. _values[idx] = values[i];
  9812. _valueSet[idx] = YES;
  9813. }
  9814. }
  9815. return self;
  9816. }
  9817. - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
  9818. self = [self initWithFloats:NULL forKeys:NULL count:0];
  9819. if (self) {
  9820. if (dictionary) {
  9821. for (int i = 0; i < 2; ++i) {
  9822. if (dictionary->_valueSet[i]) {
  9823. _values[i] = dictionary->_values[i];
  9824. _valueSet[i] = YES;
  9825. }
  9826. }
  9827. }
  9828. }
  9829. return self;
  9830. }
  9831. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  9832. #pragma unused(numItems)
  9833. return [self initWithFloats:NULL forKeys:NULL count:0];
  9834. }
  9835. #if !defined(NS_BLOCK_ASSERTIONS)
  9836. - (void)dealloc {
  9837. NSAssert(!_autocreator,
  9838. @"%@: Autocreator must be cleared before release, autocreator: %@",
  9839. [self class], _autocreator);
  9840. [super dealloc];
  9841. }
  9842. #endif // !defined(NS_BLOCK_ASSERTIONS)
  9843. - (instancetype)copyWithZone:(NSZone *)zone {
  9844. return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
  9845. }
  9846. - (BOOL)isEqual:(id)other {
  9847. if (self == other) {
  9848. return YES;
  9849. }
  9850. if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
  9851. return NO;
  9852. }
  9853. GPBBoolFloatDictionary *otherDictionary = other;
  9854. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  9855. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  9856. return NO;
  9857. }
  9858. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  9859. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  9860. return NO;
  9861. }
  9862. return YES;
  9863. }
  9864. - (NSUInteger)hash {
  9865. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9866. }
  9867. - (NSString *)description {
  9868. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  9869. if (_valueSet[0]) {
  9870. [result appendFormat:@"NO: %f", _values[0]];
  9871. }
  9872. if (_valueSet[1]) {
  9873. [result appendFormat:@"YES: %f", _values[1]];
  9874. }
  9875. [result appendString:@" }"];
  9876. return result;
  9877. }
  9878. - (NSUInteger)count {
  9879. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  9880. }
  9881. - (BOOL)getFloat:(float *)value forKey:(BOOL)key {
  9882. int idx = (key ? 1 : 0);
  9883. if (_valueSet[idx]) {
  9884. if (value) {
  9885. *value = _values[idx];
  9886. }
  9887. return YES;
  9888. }
  9889. return NO;
  9890. }
  9891. - (void)setGPBGenericValue:(GPBGenericValue *)value
  9892. forGPBGenericValueKey:(GPBGenericValue *)key {
  9893. int idx = (key->valueBool ? 1 : 0);
  9894. _values[idx] = value->valueFloat;
  9895. _valueSet[idx] = YES;
  9896. }
  9897. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  9898. if (_valueSet[0]) {
  9899. block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
  9900. }
  9901. if (_valueSet[1]) {
  9902. block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
  9903. }
  9904. }
  9905. - (void)enumerateKeysAndFloatsUsingBlock:
  9906. (void (^)(BOOL key, float value, BOOL *stop))block {
  9907. BOOL stop = NO;
  9908. if (_valueSet[0]) {
  9909. block(NO, _values[0], &stop);
  9910. }
  9911. if (!stop && _valueSet[1]) {
  9912. block(YES, _values[1], &stop);
  9913. }
  9914. }
  9915. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  9916. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9917. NSUInteger count = 0;
  9918. size_t result = 0;
  9919. for (int i = 0; i < 2; ++i) {
  9920. if (_valueSet[i]) {
  9921. ++count;
  9922. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9923. msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9924. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  9925. }
  9926. }
  9927. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  9928. result += tagSize * count;
  9929. return result;
  9930. }
  9931. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  9932. asField:(GPBFieldDescriptor *)field {
  9933. GPBDataType valueDataType = GPBGetFieldDataType(field);
  9934. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  9935. for (int i = 0; i < 2; ++i) {
  9936. if (_valueSet[i]) {
  9937. // Write the tag.
  9938. [outputStream writeInt32NoTag:tag];
  9939. // Write the size of the message.
  9940. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9941. msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  9942. [outputStream writeInt32NoTag:(int32_t)msgSize];
  9943. // Write the fields.
  9944. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  9945. WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  9946. }
  9947. }
  9948. }
  9949. - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
  9950. if (otherDictionary) {
  9951. for (int i = 0; i < 2; ++i) {
  9952. if (otherDictionary->_valueSet[i]) {
  9953. _valueSet[i] = YES;
  9954. _values[i] = otherDictionary->_values[i];
  9955. }
  9956. }
  9957. if (_autocreator) {
  9958. GPBAutocreatedDictionaryModified(_autocreator, self);
  9959. }
  9960. }
  9961. }
  9962. - (void)setFloat:(float)value forKey:(BOOL)key {
  9963. int idx = (key ? 1 : 0);
  9964. _values[idx] = value;
  9965. _valueSet[idx] = YES;
  9966. if (_autocreator) {
  9967. GPBAutocreatedDictionaryModified(_autocreator, self);
  9968. }
  9969. }
  9970. - (void)removeFloatForKey:(BOOL)aKey {
  9971. _valueSet[aKey ? 1 : 0] = NO;
  9972. }
  9973. - (void)removeAll {
  9974. _valueSet[0] = NO;
  9975. _valueSet[1] = NO;
  9976. }
  9977. @end
  9978. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
  9979. // This block of code is generated, do not edit it directly.
  9980. #pragma mark - Bool -> Double
  9981. @implementation GPBBoolDoubleDictionary {
  9982. @package
  9983. double _values[2];
  9984. BOOL _valueSet[2];
  9985. }
  9986. - (instancetype)init {
  9987. return [self initWithDoubles:NULL forKeys:NULL count:0];
  9988. }
  9989. - (instancetype)initWithDoubles:(const double [])values
  9990. forKeys:(const BOOL [])keys
  9991. count:(NSUInteger)count {
  9992. self = [super init];
  9993. if (self) {
  9994. for (NSUInteger i = 0; i < count; ++i) {
  9995. int idx = keys[i] ? 1 : 0;
  9996. _values[idx] = values[i];
  9997. _valueSet[idx] = YES;
  9998. }
  9999. }
  10000. return self;
  10001. }
  10002. - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
  10003. self = [self initWithDoubles:NULL forKeys:NULL count:0];
  10004. if (self) {
  10005. if (dictionary) {
  10006. for (int i = 0; i < 2; ++i) {
  10007. if (dictionary->_valueSet[i]) {
  10008. _values[i] = dictionary->_values[i];
  10009. _valueSet[i] = YES;
  10010. }
  10011. }
  10012. }
  10013. }
  10014. return self;
  10015. }
  10016. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  10017. #pragma unused(numItems)
  10018. return [self initWithDoubles:NULL forKeys:NULL count:0];
  10019. }
  10020. #if !defined(NS_BLOCK_ASSERTIONS)
  10021. - (void)dealloc {
  10022. NSAssert(!_autocreator,
  10023. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10024. [self class], _autocreator);
  10025. [super dealloc];
  10026. }
  10027. #endif // !defined(NS_BLOCK_ASSERTIONS)
  10028. - (instancetype)copyWithZone:(NSZone *)zone {
  10029. return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
  10030. }
  10031. - (BOOL)isEqual:(id)other {
  10032. if (self == other) {
  10033. return YES;
  10034. }
  10035. if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
  10036. return NO;
  10037. }
  10038. GPBBoolDoubleDictionary *otherDictionary = other;
  10039. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  10040. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  10041. return NO;
  10042. }
  10043. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  10044. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  10045. return NO;
  10046. }
  10047. return YES;
  10048. }
  10049. - (NSUInteger)hash {
  10050. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10051. }
  10052. - (NSString *)description {
  10053. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10054. if (_valueSet[0]) {
  10055. [result appendFormat:@"NO: %lf", _values[0]];
  10056. }
  10057. if (_valueSet[1]) {
  10058. [result appendFormat:@"YES: %lf", _values[1]];
  10059. }
  10060. [result appendString:@" }"];
  10061. return result;
  10062. }
  10063. - (NSUInteger)count {
  10064. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10065. }
  10066. - (BOOL)getDouble:(double *)value forKey:(BOOL)key {
  10067. int idx = (key ? 1 : 0);
  10068. if (_valueSet[idx]) {
  10069. if (value) {
  10070. *value = _values[idx];
  10071. }
  10072. return YES;
  10073. }
  10074. return NO;
  10075. }
  10076. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10077. forGPBGenericValueKey:(GPBGenericValue *)key {
  10078. int idx = (key->valueBool ? 1 : 0);
  10079. _values[idx] = value->valueDouble;
  10080. _valueSet[idx] = YES;
  10081. }
  10082. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10083. if (_valueSet[0]) {
  10084. block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
  10085. }
  10086. if (_valueSet[1]) {
  10087. block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
  10088. }
  10089. }
  10090. - (void)enumerateKeysAndDoublesUsingBlock:
  10091. (void (^)(BOOL key, double value, BOOL *stop))block {
  10092. BOOL stop = NO;
  10093. if (_valueSet[0]) {
  10094. block(NO, _values[0], &stop);
  10095. }
  10096. if (!stop && _valueSet[1]) {
  10097. block(YES, _values[1], &stop);
  10098. }
  10099. }
  10100. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10101. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10102. NSUInteger count = 0;
  10103. size_t result = 0;
  10104. for (int i = 0; i < 2; ++i) {
  10105. if (_valueSet[i]) {
  10106. ++count;
  10107. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10108. msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10109. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10110. }
  10111. }
  10112. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10113. result += tagSize * count;
  10114. return result;
  10115. }
  10116. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10117. asField:(GPBFieldDescriptor *)field {
  10118. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10119. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10120. for (int i = 0; i < 2; ++i) {
  10121. if (_valueSet[i]) {
  10122. // Write the tag.
  10123. [outputStream writeInt32NoTag:tag];
  10124. // Write the size of the message.
  10125. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10126. msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10127. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10128. // Write the fields.
  10129. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10130. WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10131. }
  10132. }
  10133. }
  10134. - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
  10135. if (otherDictionary) {
  10136. for (int i = 0; i < 2; ++i) {
  10137. if (otherDictionary->_valueSet[i]) {
  10138. _valueSet[i] = YES;
  10139. _values[i] = otherDictionary->_values[i];
  10140. }
  10141. }
  10142. if (_autocreator) {
  10143. GPBAutocreatedDictionaryModified(_autocreator, self);
  10144. }
  10145. }
  10146. }
  10147. - (void)setDouble:(double)value forKey:(BOOL)key {
  10148. int idx = (key ? 1 : 0);
  10149. _values[idx] = value;
  10150. _valueSet[idx] = YES;
  10151. if (_autocreator) {
  10152. GPBAutocreatedDictionaryModified(_autocreator, self);
  10153. }
  10154. }
  10155. - (void)removeDoubleForKey:(BOOL)aKey {
  10156. _valueSet[aKey ? 1 : 0] = NO;
  10157. }
  10158. - (void)removeAll {
  10159. _valueSet[0] = NO;
  10160. _valueSet[1] = NO;
  10161. }
  10162. @end
  10163. //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
  10164. // This block of code is generated, do not edit it directly.
  10165. #pragma mark - Bool -> Object
  10166. @implementation GPBBoolObjectDictionary {
  10167. @package
  10168. id _values[2];
  10169. }
  10170. - (instancetype)init {
  10171. return [self initWithObjects:NULL forKeys:NULL count:0];
  10172. }
  10173. - (instancetype)initWithObjects:(const id [])objects
  10174. forKeys:(const BOOL [])keys
  10175. count:(NSUInteger)count {
  10176. self = [super init];
  10177. if (self) {
  10178. for (NSUInteger i = 0; i < count; ++i) {
  10179. if (!objects[i]) {
  10180. [NSException raise:NSInvalidArgumentException
  10181. format:@"Attempting to add nil object to a Dictionary"];
  10182. }else {
  10183. int idx = keys[i] ? 1 : 0;
  10184. [_values[idx] release];
  10185. _values[idx] = (id)[objects[i] retain];
  10186. }
  10187. }
  10188. }
  10189. return self;
  10190. }
  10191. - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
  10192. self = [self initWithObjects:NULL forKeys:NULL count:0];
  10193. if (self) {
  10194. if (dictionary) {
  10195. _values[0] = [dictionary->_values[0] retain];
  10196. _values[1] = [dictionary->_values[1] retain];
  10197. }
  10198. }
  10199. return self;
  10200. }
  10201. - (instancetype)initWithCapacity:(NSUInteger)numItems {
  10202. #pragma unused(numItems)
  10203. return [self initWithObjects:NULL forKeys:NULL count:0];
  10204. }
  10205. - (void)dealloc {
  10206. NSAssert(!_autocreator,
  10207. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10208. [self class], _autocreator);
  10209. [_values[0] release];
  10210. [_values[1] release];
  10211. [super dealloc];
  10212. }
  10213. - (instancetype)copyWithZone:(NSZone *)zone {
  10214. return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
  10215. }
  10216. - (BOOL)isEqual:(id)other {
  10217. if (self == other) {
  10218. return YES;
  10219. }
  10220. if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
  10221. return NO;
  10222. }
  10223. GPBBoolObjectDictionary *otherDictionary = other;
  10224. if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
  10225. ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
  10226. return NO;
  10227. }
  10228. if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
  10229. ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
  10230. return NO;
  10231. }
  10232. return YES;
  10233. }
  10234. - (NSUInteger)hash {
  10235. return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
  10236. }
  10237. - (NSString *)description {
  10238. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10239. if ((_values[0] != nil)) {
  10240. [result appendFormat:@"NO: %@", _values[0]];
  10241. }
  10242. if ((_values[1] != nil)) {
  10243. [result appendFormat:@"YES: %@", _values[1]];
  10244. }
  10245. [result appendString:@" }"];
  10246. return result;
  10247. }
  10248. - (NSUInteger)count {
  10249. return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
  10250. }
  10251. - (id)objectForKey:(BOOL)key {
  10252. return _values[key ? 1 : 0];
  10253. }
  10254. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10255. forGPBGenericValueKey:(GPBGenericValue *)key {
  10256. int idx = (key->valueBool ? 1 : 0);
  10257. [_values[idx] release];
  10258. _values[idx] = [value->valueString retain];
  10259. }
  10260. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10261. if (_values[0] != nil) {
  10262. block(@"false", _values[0]);
  10263. }
  10264. if ((_values[1] != nil)) {
  10265. block(@"true", _values[1]);
  10266. }
  10267. }
  10268. - (void)enumerateKeysAndObjectsUsingBlock:
  10269. (void (^)(BOOL key, id object, BOOL *stop))block {
  10270. BOOL stop = NO;
  10271. if (_values[0] != nil) {
  10272. block(NO, _values[0], &stop);
  10273. }
  10274. if (!stop && (_values[1] != nil)) {
  10275. block(YES, _values[1], &stop);
  10276. }
  10277. }
  10278. - (BOOL)isInitialized {
  10279. if (_values[0] && ![_values[0] isInitialized]) {
  10280. return NO;
  10281. }
  10282. if (_values[1] && ![_values[1] isInitialized]) {
  10283. return NO;
  10284. }
  10285. return YES;
  10286. }
  10287. - (instancetype)deepCopyWithZone:(NSZone *)zone {
  10288. GPBBoolObjectDictionary *newDict =
  10289. [[GPBBoolObjectDictionary alloc] init];
  10290. for (int i = 0; i < 2; ++i) {
  10291. if (_values[i] != nil) {
  10292. newDict->_values[i] = [_values[i] copyWithZone:zone];
  10293. }
  10294. }
  10295. return newDict;
  10296. }
  10297. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10298. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10299. NSUInteger count = 0;
  10300. size_t result = 0;
  10301. for (int i = 0; i < 2; ++i) {
  10302. if (_values[i] != nil) {
  10303. ++count;
  10304. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10305. msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10306. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10307. }
  10308. }
  10309. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10310. result += tagSize * count;
  10311. return result;
  10312. }
  10313. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10314. asField:(GPBFieldDescriptor *)field {
  10315. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10316. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10317. for (int i = 0; i < 2; ++i) {
  10318. if (_values[i] != nil) {
  10319. // Write the tag.
  10320. [outputStream writeInt32NoTag:tag];
  10321. // Write the size of the message.
  10322. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10323. msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10324. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10325. // Write the fields.
  10326. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10327. WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10328. }
  10329. }
  10330. }
  10331. - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
  10332. if (otherDictionary) {
  10333. for (int i = 0; i < 2; ++i) {
  10334. if (otherDictionary->_values[i] != nil) {
  10335. [_values[i] release];
  10336. _values[i] = [otherDictionary->_values[i] retain];
  10337. }
  10338. }
  10339. if (_autocreator) {
  10340. GPBAutocreatedDictionaryModified(_autocreator, self);
  10341. }
  10342. }
  10343. }
  10344. - (void)setObject:(id)object forKey:(BOOL)key {
  10345. if (!object) {
  10346. [NSException raise:NSInvalidArgumentException
  10347. format:@"Attempting to add nil object to a Dictionary"];
  10348. }
  10349. int idx = (key ? 1 : 0);
  10350. [_values[idx] release];
  10351. _values[idx] = [object retain];
  10352. if (_autocreator) {
  10353. GPBAutocreatedDictionaryModified(_autocreator, self);
  10354. }
  10355. }
  10356. - (void)removeObjectForKey:(BOOL)aKey {
  10357. int idx = (aKey ? 1 : 0);
  10358. [_values[idx] release];
  10359. _values[idx] = nil;
  10360. }
  10361. - (void)removeAll {
  10362. for (int i = 0; i < 2; ++i) {
  10363. [_values[i] release];
  10364. _values[i] = nil;
  10365. }
  10366. }
  10367. @end
  10368. //%PDDM-EXPAND-END (8 expansions)
  10369. #pragma mark - Bool -> Enum
  10370. @implementation GPBBoolEnumDictionary {
  10371. @package
  10372. GPBEnumValidationFunc _validationFunc;
  10373. int32_t _values[2];
  10374. BOOL _valueSet[2];
  10375. }
  10376. @synthesize validationFunc = _validationFunc;
  10377. - (instancetype)init {
  10378. return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
  10379. }
  10380. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
  10381. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  10382. }
  10383. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  10384. rawValues:(const int32_t [])rawValues
  10385. forKeys:(const BOOL [])keys
  10386. count:(NSUInteger)count {
  10387. self = [super init];
  10388. if (self) {
  10389. _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
  10390. for (NSUInteger i = 0; i < count; ++i) {
  10391. int idx = keys[i] ? 1 : 0;
  10392. _values[idx] = rawValues[i];
  10393. _valueSet[idx] = YES;
  10394. }
  10395. }
  10396. return self;
  10397. }
  10398. - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
  10399. self = [self initWithValidationFunction:dictionary.validationFunc
  10400. rawValues:NULL
  10401. forKeys:NULL
  10402. count:0];
  10403. if (self) {
  10404. if (dictionary) {
  10405. for (int i = 0; i < 2; ++i) {
  10406. if (dictionary->_valueSet[i]) {
  10407. _values[i] = dictionary->_values[i];
  10408. _valueSet[i] = YES;
  10409. }
  10410. }
  10411. }
  10412. }
  10413. return self;
  10414. }
  10415. - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
  10416. capacity:(NSUInteger)numItems {
  10417. #pragma unused(numItems)
  10418. return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
  10419. }
  10420. #if !defined(NS_BLOCK_ASSERTIONS)
  10421. - (void)dealloc {
  10422. NSAssert(!_autocreator,
  10423. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10424. [self class], _autocreator);
  10425. [super dealloc];
  10426. }
  10427. #endif // !defined(NS_BLOCK_ASSERTIONS)
  10428. - (instancetype)copyWithZone:(NSZone *)zone {
  10429. return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
  10430. }
  10431. - (BOOL)isEqual:(id)other {
  10432. if (self == other) {
  10433. return YES;
  10434. }
  10435. if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
  10436. return NO;
  10437. }
  10438. GPBBoolEnumDictionary *otherDictionary = other;
  10439. if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
  10440. (_valueSet[1] != otherDictionary->_valueSet[1])) {
  10441. return NO;
  10442. }
  10443. if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
  10444. (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
  10445. return NO;
  10446. }
  10447. return YES;
  10448. }
  10449. - (NSUInteger)hash {
  10450. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10451. }
  10452. - (NSString *)description {
  10453. NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
  10454. if (_valueSet[0]) {
  10455. [result appendFormat:@"NO: %d", _values[0]];
  10456. }
  10457. if (_valueSet[1]) {
  10458. [result appendFormat:@"YES: %d", _values[1]];
  10459. }
  10460. [result appendString:@" }"];
  10461. return result;
  10462. }
  10463. - (NSUInteger)count {
  10464. return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
  10465. }
  10466. - (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
  10467. int idx = (key ? 1 : 0);
  10468. if (_valueSet[idx]) {
  10469. if (value) {
  10470. int32_t result = _values[idx];
  10471. if (!_validationFunc(result)) {
  10472. result = kGPBUnrecognizedEnumeratorValue;
  10473. }
  10474. *value = result;
  10475. }
  10476. return YES;
  10477. }
  10478. return NO;
  10479. }
  10480. - (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
  10481. int idx = (key ? 1 : 0);
  10482. if (_valueSet[idx]) {
  10483. if (rawValue) {
  10484. *rawValue = _values[idx];
  10485. }
  10486. return YES;
  10487. }
  10488. return NO;
  10489. }
  10490. - (void)enumerateKeysAndRawValuesUsingBlock:
  10491. (void (^)(BOOL key, int32_t value, BOOL *stop))block {
  10492. BOOL stop = NO;
  10493. if (_valueSet[0]) {
  10494. block(NO, _values[0], &stop);
  10495. }
  10496. if (!stop && _valueSet[1]) {
  10497. block(YES, _values[1], &stop);
  10498. }
  10499. }
  10500. - (void)enumerateKeysAndEnumsUsingBlock:
  10501. (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block {
  10502. BOOL stop = NO;
  10503. GPBEnumValidationFunc func = _validationFunc;
  10504. int32_t validatedValue;
  10505. if (_valueSet[0]) {
  10506. validatedValue = _values[0];
  10507. if (!func(validatedValue)) {
  10508. validatedValue = kGPBUnrecognizedEnumeratorValue;
  10509. }
  10510. block(NO, validatedValue, &stop);
  10511. }
  10512. if (!stop && _valueSet[1]) {
  10513. validatedValue = _values[1];
  10514. if (!func(validatedValue)) {
  10515. validatedValue = kGPBUnrecognizedEnumeratorValue;
  10516. }
  10517. block(YES, validatedValue, &stop);
  10518. }
  10519. }
  10520. //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
  10521. // This block of code is generated, do not edit it directly.
  10522. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  10523. forKey:(GPBGenericValue *)key
  10524. keyDataType:(GPBDataType)keyDataType {
  10525. size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
  10526. msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
  10527. NSMutableData *data = [NSMutableData dataWithLength:msgSize];
  10528. GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
  10529. WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
  10530. WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
  10531. [outputStream release];
  10532. return data;
  10533. }
  10534. //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
  10535. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
  10536. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10537. NSUInteger count = 0;
  10538. size_t result = 0;
  10539. for (int i = 0; i < 2; ++i) {
  10540. if (_valueSet[i]) {
  10541. ++count;
  10542. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10543. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10544. result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
  10545. }
  10546. }
  10547. size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
  10548. result += tagSize * count;
  10549. return result;
  10550. }
  10551. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  10552. asField:(GPBFieldDescriptor *)field {
  10553. GPBDataType valueDataType = GPBGetFieldDataType(field);
  10554. uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
  10555. for (int i = 0; i < 2; ++i) {
  10556. if (_valueSet[i]) {
  10557. // Write the tag.
  10558. [outputStream writeInt32NoTag:tag];
  10559. // Write the size of the message.
  10560. size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10561. msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
  10562. [outputStream writeInt32NoTag:(int32_t)msgSize];
  10563. // Write the fields.
  10564. WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
  10565. WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
  10566. }
  10567. }
  10568. }
  10569. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
  10570. if (_valueSet[0]) {
  10571. block(@"false", @(_values[0]));
  10572. }
  10573. if (_valueSet[1]) {
  10574. block(@"true", @(_values[1]));
  10575. }
  10576. }
  10577. - (void)setGPBGenericValue:(GPBGenericValue *)value
  10578. forGPBGenericValueKey:(GPBGenericValue *)key {
  10579. int idx = (key->valueBool ? 1 : 0);
  10580. _values[idx] = value->valueInt32;
  10581. _valueSet[idx] = YES;
  10582. }
  10583. - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
  10584. if (otherDictionary) {
  10585. for (int i = 0; i < 2; ++i) {
  10586. if (otherDictionary->_valueSet[i]) {
  10587. _valueSet[i] = YES;
  10588. _values[i] = otherDictionary->_values[i];
  10589. }
  10590. }
  10591. if (_autocreator) {
  10592. GPBAutocreatedDictionaryModified(_autocreator, self);
  10593. }
  10594. }
  10595. }
  10596. - (void)setEnum:(int32_t)value forKey:(BOOL)key {
  10597. if (!_validationFunc(value)) {
  10598. [NSException raise:NSInvalidArgumentException
  10599. format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
  10600. value];
  10601. }
  10602. int idx = (key ? 1 : 0);
  10603. _values[idx] = value;
  10604. _valueSet[idx] = YES;
  10605. if (_autocreator) {
  10606. GPBAutocreatedDictionaryModified(_autocreator, self);
  10607. }
  10608. }
  10609. - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
  10610. int idx = (key ? 1 : 0);
  10611. _values[idx] = rawValue;
  10612. _valueSet[idx] = YES;
  10613. if (_autocreator) {
  10614. GPBAutocreatedDictionaryModified(_autocreator, self);
  10615. }
  10616. }
  10617. - (void)removeEnumForKey:(BOOL)aKey {
  10618. _valueSet[aKey ? 1 : 0] = NO;
  10619. }
  10620. - (void)removeAll {
  10621. _valueSet[0] = NO;
  10622. _valueSet[1] = NO;
  10623. }
  10624. @end
  10625. #pragma mark - NSDictionary Subclass
  10626. @implementation GPBAutocreatedDictionary {
  10627. NSMutableDictionary *_dictionary;
  10628. }
  10629. - (void)dealloc {
  10630. NSAssert(!_autocreator,
  10631. @"%@: Autocreator must be cleared before release, autocreator: %@",
  10632. [self class], _autocreator);
  10633. [_dictionary release];
  10634. [super dealloc];
  10635. }
  10636. #pragma mark Required NSDictionary overrides
  10637. - (instancetype)initWithObjects:(const id [])objects
  10638. forKeys:(const id<NSCopying> [])keys
  10639. count:(NSUInteger)count {
  10640. self = [super init];
  10641. if (self) {
  10642. _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
  10643. forKeys:keys
  10644. count:count];
  10645. }
  10646. return self;
  10647. }
  10648. - (NSUInteger)count {
  10649. return [_dictionary count];
  10650. }
  10651. - (id)objectForKey:(id)aKey {
  10652. return [_dictionary objectForKey:aKey];
  10653. }
  10654. - (NSEnumerator *)keyEnumerator {
  10655. if (_dictionary == nil) {
  10656. _dictionary = [[NSMutableDictionary alloc] init];
  10657. }
  10658. return [_dictionary keyEnumerator];
  10659. }
  10660. #pragma mark Required NSMutableDictionary overrides
  10661. // Only need to call GPBAutocreatedDictionaryModified() when adding things
  10662. // since we only autocreate empty dictionaries.
  10663. - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
  10664. if (_dictionary == nil) {
  10665. _dictionary = [[NSMutableDictionary alloc] init];
  10666. }
  10667. [_dictionary setObject:anObject forKey:aKey];
  10668. if (_autocreator) {
  10669. GPBAutocreatedDictionaryModified(_autocreator, self);
  10670. }
  10671. }
  10672. - (void)removeObjectForKey:(id)aKey {
  10673. [_dictionary removeObjectForKey:aKey];
  10674. }
  10675. #pragma mark Extra things hooked
  10676. - (id)copyWithZone:(NSZone *)zone {
  10677. if (_dictionary == nil) {
  10678. return [[NSMutableDictionary allocWithZone:zone] init];
  10679. }
  10680. return [_dictionary copyWithZone:zone];
  10681. }
  10682. - (id)mutableCopyWithZone:(NSZone *)zone {
  10683. if (_dictionary == nil) {
  10684. return [[NSMutableDictionary allocWithZone:zone] init];
  10685. }
  10686. return [_dictionary mutableCopyWithZone:zone];
  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. - (id)objectForKeyedSubscript:(id)key {
  10691. return [_dictionary objectForKeyedSubscript:key];
  10692. }
  10693. // Not really needed, but subscripting is likely common enough it doesn't hurt
  10694. // to ensure it goes directly to the real NSMutableDictionary.
  10695. - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
  10696. if (_dictionary == nil) {
  10697. _dictionary = [[NSMutableDictionary alloc] init];
  10698. }
  10699. [_dictionary setObject:obj forKeyedSubscript:key];
  10700. if (_autocreator) {
  10701. GPBAutocreatedDictionaryModified(_autocreator, self);
  10702. }
  10703. }
  10704. - (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key,
  10705. id obj,
  10706. BOOL *stop))block {
  10707. [_dictionary enumerateKeysAndObjectsUsingBlock:block];
  10708. }
  10709. - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
  10710. usingBlock:(void (NS_NOESCAPE ^)(id key,
  10711. id obj,
  10712. BOOL *stop))block {
  10713. [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
  10714. }
  10715. @end
  10716. #pragma clang diagnostic pop