aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/protobuf/objectivec
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/protobuf/objectivec')
-rw-r--r--third_party/protobuf/objectivec/.gitignore23
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/check_version_stamps.sh55
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/compile_testing_protos.sh149
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/full_mac_build.sh329
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/pddm.py686
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/pddm_tests.py515
-rw-r--r--third_party/protobuf/objectivec/GPBArray.h1967
-rw-r--r--third_party/protobuf/objectivec/GPBArray.m2551
-rw-r--r--third_party/protobuf/objectivec/GPBArray_PackagePrivate.h130
-rw-r--r--third_party/protobuf/objectivec/GPBBootstrap.h123
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream.h253
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream.m538
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h114
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream.h739
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream.m1202
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h126
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor.h288
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor.m1104
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h329
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary.h8570
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary.m13627
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h488
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionInternals.h50
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionInternals.m391
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionRegistry.h87
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionRegistry.m131
-rw-r--r--third_party/protobuf/objectivec/GPBMessage.h461
-rw-r--r--third_party/protobuf/objectivec/GPBMessage.m3243
-rw-r--r--third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h150
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers.h76
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers.m66
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h40
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject.h52
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject.m237
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h46
-rw-r--r--third_party/protobuf/objectivec/GPBRuntimeTypes.h144
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField.h96
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField.m334
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet.h82
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet.m395
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h61
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h49
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities.h539
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities.m1923
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h350
-rw-r--r--third_party/protobuf/objectivec/GPBWellKnownTypes.h245
-rw-r--r--third_party/protobuf/objectivec/GPBWellKnownTypes.m272
-rw-r--r--third_party/protobuf/objectivec/GPBWireFormat.h73
-rw-r--r--third_party/protobuf/objectivec/GPBWireFormat.m85
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj994
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings8
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme335
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme133
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj1167
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings8
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme345
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme134
-rw-r--r--third_party/protobuf/objectivec/README.md188
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj290
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme91
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h37
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m48
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json58
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib680
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist34
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m35
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework10
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static8
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/README.md9
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework10
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static8
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj309
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme91
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h39
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m67
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json68
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard27
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard26
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist47
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h37
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m49
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m39
-rwxr-xr-xthird_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh150
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m63
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBArrayTests.m3611
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m335
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m426
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m206
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m256
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m2418
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m3359
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m3646
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m186
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm1047
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m700
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m2515
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m1210
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests.m2053
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm69
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBPerfTests.m307
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift460
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBTestUtilities.h100
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBTestUtilities.m2546
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m75
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m34
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m255
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m400
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m214
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m258
-rw-r--r--third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h6
-rw-r--r--third_party/protobuf/objectivec/Tests/UnitTests-Info.plist20
-rw-r--r--third_party/protobuf/objectivec/Tests/golden_messagebin0 -> 493 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/golden_packed_fields_messagebin0 -> 493 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m35
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json116
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.pngbin0 -> 8583 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.pngbin0 -> 17744 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.pngbin0 -> 8969 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.pngbin0 -> 18788 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.pngbin0 -> 7021 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.pngbin0 -> 13348 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.pngbin0 -> 11128 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.pngbin0 -> 21792 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json49
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist43
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib33
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings2
-rw-r--r--third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt70
-rw-r--r--third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt116
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_cycle.proto56
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_deprecated.proto95
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto76
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto51
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto47
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto45
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto49
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto40
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto44
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto41
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_objc.proto467
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto49
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto128
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto121
-rwxr-xr-xthird_party/protobuf/objectivec/generate_well_known_types.sh76
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h163
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m112
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h299
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m356
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h128
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m107
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h70
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m83
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h271
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m96
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h73
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m96
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h200
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m293
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h132
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m107
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h440
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m701
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h215
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m439
171 files changed, 93137 insertions, 0 deletions
diff --git a/third_party/protobuf/objectivec/.gitignore b/third_party/protobuf/objectivec/.gitignore
new file mode 100644
index 0000000000..f786ffce82
--- /dev/null
+++ b/third_party/protobuf/objectivec/.gitignore
@@ -0,0 +1,23 @@
+## Build generated
+build/
+DerivedData/
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata/
+
+## Other
+*.moved-aside
+*.xccheckout
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa
diff --git a/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh b/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh
new file mode 100755
index 0000000000..1acbe2a2b7
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh
@@ -0,0 +1,55 @@
+#!/bin/bash -eu
+
+# This script checks that the runtime version number constant in the compiler
+# source and in the runtime source is the same.
+#
+# A distro can be made of the protobuf sources with only a subset of the
+# languages, so if the compiler depended on the Objective C runtime, those
+# builds would break. At the same time, we don't want the runtime source
+# depending on the compiler sources; so two copies of the constant are needed.
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/../.."
+
+die() {
+ echo "Error: $1"
+ exit 1
+}
+
+readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
+readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
+
+check_constant() {
+ local ConstantName="$1"
+
+ # Collect version from generator sources.
+ local GeneratorVersion=$( \
+ cat "${GeneratorSrc}" \
+ | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p"
+ )
+ if [[ -z "${GeneratorVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})."
+ fi
+
+ # Collect version from runtime sources.
+ local RuntimeVersion=$( \
+ cat "${RuntimeSrc}" \
+ | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
+ )
+ if [[ -z "${RuntimeVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
+ fi
+
+ # Compare them.
+ if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then
+ die "${ConstantName} values don't match!
+ Generator: ${GeneratorVersion} from ${GeneratorSrc}
+ Runtime: ${RuntimeVersion} from ${RuntimeSrc}
+"
+ fi
+}
+
+# Do the check.
+check_constant GOOGLE_PROTOBUF_OBJC_VERSION
+
+# Success
diff --git a/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh b/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh
new file mode 100755
index 0000000000..d7f3f60589
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh
@@ -0,0 +1,149 @@
+#!/bin/bash -eu
+# Invoked by the Xcode projects to build the protos needed for the unittests.
+
+readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
+
+# -----------------------------------------------------------------------------
+# Helper for bailing.
+die() {
+ echo "Error: $1"
+ exit 2
+}
+
+# -----------------------------------------------------------------------------
+# What to do.
+case "${ACTION}" in
+ "")
+ # Build, fall thru
+ ;;
+ "clean")
+ rm -rf "${OUTPUT_DIR}"
+ exit 0
+ ;;
+ *)
+ die "Unknown action requested: ${ACTION}"
+ ;;
+esac
+
+# -----------------------------------------------------------------------------
+# Ensure the output dir exists
+mkdir -p "${OUTPUT_DIR}/google/protobuf"
+
+# -----------------------------------------------------------------------------
+# Move to the top of the protobuf directories and ensure there is a protoc
+# binary to use.
+cd "${SRCROOT}/.."
+[[ -x src/protoc ]] || \
+ die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
+
+# -----------------------------------------------------------------------------
+# See the compiler or proto files have changed.
+RUN_PROTOC=no
+if [[ ! -d "${OUTPUT_DIR}" ]] ; then
+ RUN_PROTOC=yes
+else
+ # Find the newest input file (protos, compiler, and this script).
+ # (these patterns catch some extra stuff, but better to over sample than
+ # under)
+ readonly NewestInput=$(find \
+ src/google/protobuf/*.proto \
+ objectivec/Tests/*.proto \
+ src/.libs src/*.la src/protoc \
+ objectivec/DevTools/compile_testing_protos.sh \
+ -type f -print0 \
+ | xargs -0 stat -f "%m %N" \
+ | sort -n | tail -n1 | cut -f2- -d" ")
+ # Find the oldest output file.
+ readonly OldestOutput=$(find \
+ "${OUTPUT_DIR}" \
+ -type f -name "*pbobjc.[hm]" -print0 \
+ | xargs -0 stat -f "%m %N" \
+ | sort -n -r | tail -n1 | cut -f2- -d" ")
+ # If the newest input is newer than the oldest output, regenerate.
+ if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
+ RUN_PROTOC=yes
+ fi
+fi
+
+if [[ "${RUN_PROTOC}" != "yes" ]] ; then
+ # Up to date.
+ exit 0
+fi
+
+# -----------------------------------------------------------------------------
+# Prune out all the files from previous generations to ensure we only have
+# current ones.
+find "${OUTPUT_DIR}" \
+ -type f -name "*pbobjc.[hm]" -print0 \
+ | xargs -0 rm -rf
+
+# -----------------------------------------------------------------------------
+# Helper to invoke protoc
+compile_protos() {
+ src/protoc \
+ --objc_out="${OUTPUT_DIR}/google/protobuf" \
+ --proto_path=src/google/protobuf/ \
+ --proto_path=src \
+ "$@"
+}
+
+# -----------------------------------------------------------------------------
+# Generate most of the proto files that exist in the C++ src tree. Several
+# are used in the tests, but the extra don't hurt in that they ensure ObjC
+# sources can be generated from them.
+
+CORE_PROTO_FILES=(
+ src/google/protobuf/any_test.proto
+ src/google/protobuf/unittest_arena.proto
+ src/google/protobuf/unittest_custom_options.proto
+ src/google/protobuf/unittest_enormous_descriptor.proto
+ src/google/protobuf/unittest_embed_optimize_for.proto
+ src/google/protobuf/unittest_empty.proto
+ src/google/protobuf/unittest_import.proto
+ src/google/protobuf/unittest_import_lite.proto
+ src/google/protobuf/unittest_lite.proto
+ src/google/protobuf/unittest_mset.proto
+ src/google/protobuf/unittest_mset_wire_format.proto
+ src/google/protobuf/unittest_no_arena.proto
+ src/google/protobuf/unittest_no_arena_import.proto
+ src/google/protobuf/unittest_no_generic_services.proto
+ src/google/protobuf/unittest_optimize_for.proto
+ src/google/protobuf/unittest.proto
+ src/google/protobuf/unittest_import_public.proto
+ src/google/protobuf/unittest_import_public_lite.proto
+ src/google/protobuf/unittest_drop_unknown_fields.proto
+ src/google/protobuf/unittest_preserve_unknown_enum.proto
+ src/google/protobuf/map_lite_unittest.proto
+ src/google/protobuf/map_proto2_unittest.proto
+ src/google/protobuf/map_unittest.proto
+ # The unittest_custom_options.proto extends the messages in descriptor.proto
+ # so we build it in to test extending in general. The library doesn't provide
+ # a descriptor as it doesn't use the classes/enums.
+ src/google/protobuf/descriptor.proto
+)
+
+# Note: there is overlap in package.Message names between some of the test
+# files, so they can't be generated all at once. This works because the overlap
+# isn't linked into a single binary.
+for a_proto in "${CORE_PROTO_FILES[@]}" ; do
+ compile_protos "${a_proto}"
+done
+
+# -----------------------------------------------------------------------------
+# Generate the Objective C specific testing protos.
+compile_protos \
+ --proto_path="objectivec/Tests" \
+ objectivec/Tests/unittest_cycle.proto \
+ objectivec/Tests/unittest_deprecated.proto \
+ objectivec/Tests/unittest_deprecated_file.proto \
+ objectivec/Tests/unittest_extension_chain_a.proto \
+ objectivec/Tests/unittest_extension_chain_b.proto \
+ objectivec/Tests/unittest_extension_chain_c.proto \
+ objectivec/Tests/unittest_extension_chain_d.proto \
+ objectivec/Tests/unittest_extension_chain_e.proto \
+ objectivec/Tests/unittest_extension_chain_f.proto \
+ objectivec/Tests/unittest_extension_chain_g.proto \
+ objectivec/Tests/unittest_runtime_proto2.proto \
+ objectivec/Tests/unittest_runtime_proto3.proto \
+ objectivec/Tests/unittest_objc.proto \
+ objectivec/Tests/unittest_objc_startup.proto
diff --git a/third_party/protobuf/objectivec/DevTools/full_mac_build.sh b/third_party/protobuf/objectivec/DevTools/full_mac_build.sh
new file mode 100755
index 0000000000..ea9fd2736b
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/full_mac_build.sh
@@ -0,0 +1,329 @@
+#!/bin/bash
+#
+# Helper to do build so you don't have to remember all the steps/args.
+
+
+set -eu
+
+# Some base locations.
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/../.."
+
+printUsage() {
+ NAME=$(basename "${0}")
+ cat << EOF
+usage: ${NAME} [OPTIONS]
+
+This script does the common build steps needed.
+
+OPTIONS:
+
+ General:
+
+ -h, --help
+ Show this message
+ -c, --clean
+ Issue a clean before the normal build.
+ -a, --autogen
+ Start by rerunning autogen & configure.
+ -r, --regenerate-descriptors
+ Run generate_descriptor_proto.sh to regenerate all the checked in
+ proto sources.
+ -j #, --jobs #
+ Force the number of parallel jobs (useful for debugging build issues).
+ --core-only
+ Skip some of the core protobuf build/checks to shorten the build time.
+ --skip-xcode
+ Skip the invoke of Xcode to test the runtime on both iOS and OS X.
+ --skip-xcode-ios
+ Skip the invoke of Xcode to test the runtime on iOS.
+ --skip-xcode-debug
+ Skip the Xcode Debug configuration.
+ --skip-xcode-release
+ Skip the Xcode Release configuration.
+ --skip-xcode-osx
+ Skip the invoke of Xcode to test the runtime on OS X.
+ --skip-objc-conformance
+ Skip the Objective C conformance tests (run on OS X).
+ --xcode-quiet
+ Pass -quiet to xcodebuild.
+
+EOF
+}
+
+header() {
+ echo ""
+ echo "========================================================================"
+ echo " ${@}"
+ echo "========================================================================"
+}
+
+# Thanks to libtool, builds can fail in odd ways and since it eats some output
+# it can be hard to spot, so force error output if make exits with a non zero.
+wrapped_make() {
+ set +e # Don't stop if the command fails.
+ make $*
+ MAKE_EXIT_STATUS=$?
+ if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
+ echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
+ exit ${MAKE_EXIT_STATUS}
+ fi
+ set -e
+}
+
+NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
+if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then
+ NUM_MAKE_JOBS=2
+fi
+
+DO_AUTOGEN=no
+DO_CLEAN=no
+REGEN_DESCRIPTORS=no
+CORE_ONLY=no
+DO_XCODE_IOS_TESTS=yes
+DO_XCODE_OSX_TESTS=yes
+DO_XCODE_DEBUG=yes
+DO_XCODE_RELEASE=yes
+DO_OBJC_CONFORMANCE_TESTS=yes
+XCODE_QUIET=no
+while [[ $# != 0 ]]; do
+ case "${1}" in
+ -h | --help )
+ printUsage
+ exit 0
+ ;;
+ -c | --clean )
+ DO_CLEAN=yes
+ ;;
+ -a | --autogen )
+ DO_AUTOGEN=yes
+ ;;
+ -r | --regenerate-descriptors )
+ REGEN_DESCRIPTORS=yes
+ ;;
+ -j | --jobs )
+ shift
+ NUM_MAKE_JOBS="${1}"
+ ;;
+ --core-only )
+ CORE_ONLY=yes
+ ;;
+ --skip-xcode )
+ DO_XCODE_IOS_TESTS=no
+ DO_XCODE_OSX_TESTS=no
+ ;;
+ --skip-xcode-ios )
+ DO_XCODE_IOS_TESTS=no
+ ;;
+ --skip-xcode-osx )
+ DO_XCODE_OSX_TESTS=no
+ ;;
+ --skip-xcode-debug )
+ DO_XCODE_DEBUG=no
+ ;;
+ --skip-xcode-release )
+ DO_XCODE_RELEASE=no
+ ;;
+ --skip-objc-conformance )
+ DO_OBJC_CONFORMANCE_TESTS=no
+ ;;
+ --xcode-quiet )
+ XCODE_QUIET=yes
+ ;;
+ -*)
+ echo "ERROR: Unknown option: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ *)
+ echo "ERROR: Unknown argument: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Into the proto dir.
+cd "${ProtoRootDir}"
+
+# if no Makefile, force the autogen.
+if [[ ! -f Makefile ]] ; then
+ DO_AUTOGEN=yes
+fi
+
+if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
+ header "Running autogen & configure"
+ ./autogen.sh
+ ./configure \
+ CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" \
+ CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
+fi
+
+if [[ "${DO_CLEAN}" == "yes" ]] ; then
+ header "Cleaning"
+ wrapped_make clean
+ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_CLEAN_BASE_IOS=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_iOS.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
+ fi
+ fi
+ if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_CLEAN_BASE_OSX=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_OSX.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
+ fi
+ fi
+fi
+
+if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
+ header "Regenerating the descriptor sources."
+ ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
+fi
+
+if [[ "${CORE_ONLY}" == "yes" ]] ; then
+ header "Building core Only"
+ wrapped_make -j "${NUM_MAKE_JOBS}"
+else
+ header "Building"
+ # Can't issue these together, when fully parallel, something sometimes chokes
+ # at random.
+ wrapped_make -j "${NUM_MAKE_JOBS}" all
+ wrapped_make -j "${NUM_MAKE_JOBS}" check
+ # Fire off the conformance tests also.
+ cd conformance
+ wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
+ cd ..
+fi
+
+# Ensure the WKT sources checked in are current.
+objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
+
+header "Checking on the ObjC Runtime Code"
+objectivec/DevTools/pddm_tests.py
+if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
+ echo ""
+ echo "Update by running:"
+ echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
+ exit 1
+fi
+
+readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
+readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
+
+if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_IOS=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_iOS.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${XCODE_QUIET}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_IOS+=( -quiet )
+ fi
+ # Don't need to worry about form factors or retina/non retina;
+ # just pick a mix of OS Versions and 32/64 bit.
+ # NOTE: Different Xcode have different simulated hardware/os support.
+ case "${XCODE_VERSION}" in
+ 6.* )
+ echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
+ exit 10
+ ;;
+ 7.* )
+ echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
+ echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
+ exit 11
+ ;;
+ 8.0* )
+ # The 8.* device seem to hang and never start under Xcode 8.
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.0" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=9.0" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.0" # 64bit
+ )
+ ;;
+ 8.1* )
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.1" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.1" # 64bit
+ )
+ ;;
+ 8.2* )
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.2" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.2" # 64bit
+ )
+ ;;
+ * )
+ echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}"
+ exit 2
+ ;;
+ esac
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ header "Doing Xcode iOS build/tests - Debug"
+ "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ header "Doing Xcode iOS build/tests - Release"
+ "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
+ fi
+ # Don't leave the simulator in the developer's face.
+ killall Simulator
+fi
+if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_OSX=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_OSX.xcodeproj
+ -scheme ProtocolBuffers
+ # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
+ -destination "platform=OS X,arch=x86_64" # 64bit
+ )
+ if [[ "${XCODE_QUIET}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_OSX+=( -quiet )
+ fi
+ case "${XCODE_VERSION}" in
+ 6.* )
+ echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
+ exit 10
+ ;;
+ 7.* )
+ echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
+ echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
+ exit 11
+ ;;
+ esac
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ header "Doing Xcode OS X build/tests - Debug"
+ "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ header "Doing Xcode OS X build/tests - Release"
+ "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
+ fi
+fi
+
+if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
+ header "Running ObjC Conformance Tests"
+ cd conformance
+ wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
+ cd ..
+fi
diff --git a/third_party/protobuf/objectivec/DevTools/pddm.py b/third_party/protobuf/objectivec/DevTools/pddm.py
new file mode 100755
index 0000000000..9a11fec449
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/pddm.py
@@ -0,0 +1,686 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2015 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""PDDM - Poor Developers' Debug-able Macros
+
+A simple markup that can be added in comments of source so they can then be
+expanded out into code. Most of this could be done with CPP macros, but then
+developers can't really step through them in the debugger, this way they are
+expanded to the same code, but you can debug them.
+
+Any file can be processed, but the syntax is designed around a C based compiler.
+Processed lines start with "//%". There are three types of sections you can
+create: Text (left alone), Macro Definitions, and Macro Expansions. There is
+no order required between definitions and expansions, all definitions are read
+before any expansions are processed (thus, if desired, definitions can be put
+at the end of the file to keep them out of the way of the code).
+
+Macro Definitions are started with "//%PDDM-DEFINE Name(args)" and all lines
+afterwards that start with "//%" are included in the definition. Multiple
+macros can be defined in one block by just using a another "//%PDDM-DEFINE"
+line to start the next macro. Optionally, a macro can be ended with
+"//%PDDM-DEFINE-END", this can be useful when you want to make it clear that
+trailing blank lines are included in the macro. You can also end a definition
+with an expansion.
+
+Macro Expansions are started by single lines containing
+"//%PDDM-EXPAND Name(args)" and then with "//%PDDM-EXPAND-END" or another
+expansions. All lines in-between are replaced by the result of the expansion.
+The first line of the expansion is always a blank like just for readability.
+
+Expansion itself is pretty simple, one macro can invoke another macro, but
+you cannot nest the invoke of a macro in another macro (i.e. - can't do
+"foo(bar(a))", but you can define foo(a) and bar(b) where bar invokes foo()
+within its expansion.
+
+When macros are expanded, the arg references can also add "$O" suffix to the
+name (i.e. - "NAME$O") to specify an option to be applied. The options are:
+
+ $S - Replace each character in the value with a space.
+ $l - Lowercase the first letter of the value.
+ $L - Lowercase the whole value.
+ $u - Uppercase the first letter of the value.
+ $U - Uppercase the whole value.
+
+Within a macro you can use ## to cause things to get joined together after
+expansion (i.e. - "a##b" within a macro will become "ab").
+
+Example:
+
+ int foo(MyEnum x) {
+ switch (x) {
+ //%PDDM-EXPAND case(Enum_Left, 1)
+ //%PDDM-EXPAND case(Enum_Center, 2)
+ //%PDDM-EXPAND case(Enum_Right, 3)
+ //%PDDM-EXPAND-END
+ }
+
+ //%PDDM-DEFINE case(_A, _B)
+ //% case _A:
+ //% return _B;
+
+ A macro ends at the start of the next one, or an optional %PDDM-DEFINE-END
+ can be used to avoid adding extra blank lines/returns (or make it clear when
+ it is desired).
+
+ One macro can invoke another by simply using its name NAME(ARGS). You cannot
+ nest an invoke inside another (i.e. - NAME1(NAME2(ARGS)) isn't supported).
+
+ Within a macro you can use ## to cause things to get joined together after
+ processing (i.e. - "a##b" within a macro will become "ab").
+
+
+"""
+
+import optparse
+import os
+import re
+import sys
+
+
+# Regex for macro definition.
+_MACRO_RE = re.compile(r'(?P<name>\w+)\((?P<args>.*?)\)')
+# Regex for macro's argument definition.
+_MACRO_ARG_NAME_RE = re.compile(r'^\w+$')
+
+# Line inserted after each EXPAND.
+_GENERATED_CODE_LINE = (
+ '// This block of code is generated, do not edit it directly.'
+)
+
+
+def _MacroRefRe(macro_names):
+ # Takes in a list of macro names and makes a regex that will match invokes
+ # of those macros.
+ return re.compile(r'\b(?P<macro_ref>(?P<name>(%s))\((?P<args>.*?)\))' %
+ '|'.join(macro_names))
+
+def _MacroArgRefRe(macro_arg_names):
+ # Takes in a list of macro arg names and makes a regex that will match
+ # uses of those args.
+ return re.compile(r'\b(?P<name>(%s))(\$(?P<option>.))?\b' %
+ '|'.join(macro_arg_names))
+
+
+class PDDMError(Exception):
+ """Error thrown by pddm."""
+ pass
+
+
+class MacroCollection(object):
+ """Hold a set of macros and can resolve/expand them."""
+
+ def __init__(self, a_file=None):
+ """Initializes the collection.
+
+ Args:
+ a_file: The file like stream to parse.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ self._macros = dict()
+ if a_file:
+ self.ParseInput(a_file)
+
+ class MacroDefinition(object):
+ """Holds a macro definition."""
+
+ def __init__(self, name, arg_names):
+ self._name = name
+ self._args = tuple(arg_names)
+ self._body = ''
+ self._needNewLine = False
+
+ def AppendLine(self, line):
+ if self._needNewLine:
+ self._body += '\n'
+ self._body += line
+ self._needNewLine = not line.endswith('\n')
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def args(self):
+ return self._args
+
+ @property
+ def body(self):
+ return self._body
+
+ def ParseInput(self, a_file):
+ """Consumes input extracting definitions.
+
+ Args:
+ a_file: The file like stream to parse.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ input_lines = a_file.read().splitlines()
+ self.ParseLines(input_lines)
+
+ def ParseLines(self, input_lines):
+ """Parses list of lines.
+
+ Args:
+ input_lines: A list of strings of input to parse (no newlines on the
+ strings).
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ current_macro = None
+ for line in input_lines:
+ if line.startswith('PDDM-'):
+ directive = line.split(' ', 1)[0]
+ if directive == 'PDDM-DEFINE':
+ name, args = self._ParseDefineLine(line)
+ if self._macros.get(name):
+ raise PDDMError('Attempt to redefine macro: "%s"' % line)
+ current_macro = self.MacroDefinition(name, args)
+ self._macros[name] = current_macro
+ continue
+ if directive == 'PDDM-DEFINE-END':
+ if not current_macro:
+ raise PDDMError('Got DEFINE-END directive without an active macro:'
+ ' "%s"' % line)
+ current_macro = None
+ continue
+ raise PDDMError('Hit a line with an unknown directive: "%s"' % line)
+
+ if current_macro:
+ current_macro.AppendLine(line)
+ continue
+
+ # Allow blank lines between macro definitions.
+ if line.strip() == '':
+ continue
+
+ raise PDDMError('Hit a line that wasn\'t a directive and no open macro'
+ ' definition: "%s"' % line)
+
+ def _ParseDefineLine(self, input_line):
+ assert input_line.startswith('PDDM-DEFINE')
+ line = input_line[12:].strip()
+ match = _MACRO_RE.match(line)
+ # Must match full line
+ if match is None or match.group(0) != line:
+ raise PDDMError('Failed to parse macro definition: "%s"' % input_line)
+ name = match.group('name')
+ args_str = match.group('args').strip()
+ args = []
+ if args_str:
+ for part in args_str.split(','):
+ arg = part.strip()
+ if arg == '':
+ raise PDDMError('Empty arg name in macro definition: "%s"'
+ % input_line)
+ if not _MACRO_ARG_NAME_RE.match(arg):
+ raise PDDMError('Invalid arg name "%s" in macro definition: "%s"'
+ % (arg, input_line))
+ if arg in args:
+ raise PDDMError('Arg name "%s" used more than once in macro'
+ ' definition: "%s"' % (arg, input_line))
+ args.append(arg)
+ return (name, tuple(args))
+
+ def Expand(self, macro_ref_str):
+ """Expands the macro reference.
+
+ Args:
+ macro_ref_str: String of a macro reference (i.e. foo(a, b)).
+
+ Returns:
+ The text from the expansion.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ match = _MACRO_RE.match(macro_ref_str)
+ if match is None or match.group(0) != macro_ref_str:
+ raise PDDMError('Failed to parse macro reference: "%s"' % macro_ref_str)
+ if match.group('name') not in self._macros:
+ raise PDDMError('No macro named "%s".' % match.group('name'))
+ return self._Expand(match, [], macro_ref_str)
+
+ def _FormatStack(self, macro_ref_stack):
+ result = ''
+ for _, macro_ref in reversed(macro_ref_stack):
+ result += '\n...while expanding "%s".' % macro_ref
+ return result
+
+ def _Expand(self, macro_ref_match, macro_stack, macro_ref_str=None):
+ if macro_ref_str is None:
+ macro_ref_str = macro_ref_match.group('macro_ref')
+ name = macro_ref_match.group('name')
+ for prev_name, prev_macro_ref in macro_stack:
+ if name == prev_name:
+ raise PDDMError('Found macro recusion, invoking "%s":%s' %
+ (macro_ref_str, self._FormatStack(macro_stack)))
+ macro = self._macros[name]
+ args_str = macro_ref_match.group('args').strip()
+ args = []
+ if args_str or len(macro.args):
+ args = [x.strip() for x in args_str.split(',')]
+ if len(args) != len(macro.args):
+ raise PDDMError('Expected %d args, got: "%s".%s' %
+ (len(macro.args), macro_ref_str,
+ self._FormatStack(macro_stack)))
+ # Replace args usages.
+ result = self._ReplaceArgValues(macro, args, macro_ref_str, macro_stack)
+ # Expand any macro invokes.
+ new_macro_stack = macro_stack + [(name, macro_ref_str)]
+ while True:
+ eval_result = self._EvalMacrosRefs(result, new_macro_stack)
+ # Consume all ## directives to glue things together.
+ eval_result = eval_result.replace('##', '')
+ if eval_result == result:
+ break
+ result = eval_result
+ return result
+
+ def _ReplaceArgValues(self,
+ macro, arg_values, macro_ref_to_report, macro_stack):
+ if len(arg_values) == 0:
+ # Nothing to do
+ return macro.body
+ assert len(arg_values) == len(macro.args)
+ args = dict(zip(macro.args, arg_values))
+ def _lookupArg(match):
+ val = args[match.group('name')]
+ opt = match.group('option')
+ if opt:
+ if opt == 'S': # Spaces for the length
+ return ' ' * len(val)
+ elif opt == 'l': # Lowercase first character
+ if val:
+ return val[0].lower() + val[1:]
+ else:
+ return val
+ elif opt == 'L': # All Lowercase
+ return val.lower()
+ elif opt == 'u': # Uppercase first character
+ if val:
+ return val[0].upper() + val[1:]
+ else:
+ return val
+ elif opt == 'U': # All Uppercase
+ return val.upper()
+ else:
+ raise PDDMError('Unknown arg option "%s$%s" while expanding "%s".%s'
+ % (match.group('name'), match.group('option'),
+ macro_ref_to_report,
+ self._FormatStack(macro_stack)))
+ return val
+ # Let the regex do the work!
+ macro_arg_ref_re = _MacroArgRefRe(macro.args)
+ return macro_arg_ref_re.sub(_lookupArg, macro.body)
+
+ def _EvalMacrosRefs(self, text, macro_stack):
+ macro_ref_re = _MacroRefRe(self._macros.keys())
+ def _resolveMacro(match):
+ return self._Expand(match, macro_stack)
+ return macro_ref_re.sub(_resolveMacro, text)
+
+
+class SourceFile(object):
+ """Represents a source file with PDDM directives in it."""
+
+ def __init__(self, a_file, import_resolver=None):
+ """Initializes the file reading in the file.
+
+ Args:
+ a_file: The file to read in.
+ import_resolver: a function that given a path will return a stream for
+ the contents.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ self._sections = []
+ self._original_content = a_file.read()
+ self._import_resolver = import_resolver
+ self._processed_content = None
+
+ class SectionBase(object):
+
+ def __init__(self, first_line_num):
+ self._lines = []
+ self._first_line_num = first_line_num
+
+ def TryAppend(self, line, line_num):
+ """Try appending a line.
+
+ Args:
+ line: The line to append.
+ line_num: The number of the line.
+
+ Returns:
+ A tuple of (SUCCESS, CAN_ADD_MORE). If SUCCESS if False, the line
+ wasn't append. If SUCCESS is True, then CAN_ADD_MORE is True/False to
+ indicate if more lines can be added after this one.
+ """
+ assert False, "sublcass should have overridden"
+ return (False, False)
+
+ def HitEOF(self):
+ """Called when the EOF was reached for for a given section."""
+ pass
+
+ def BindMacroCollection(self, macro_collection):
+ """Binds the chunk to a macro collection.
+
+ Args:
+ macro_collection: The collection to bind too.
+ """
+ pass
+
+ def Append(self, line):
+ self._lines.append(line)
+
+ @property
+ def lines(self):
+ return self._lines
+
+ @property
+ def num_lines_captured(self):
+ return len(self._lines)
+
+ @property
+ def first_line_num(self):
+ return self._first_line_num
+
+ @property
+ def first_line(self):
+ if not self._lines:
+ return ''
+ return self._lines[0]
+
+ @property
+ def text(self):
+ return '\n'.join(self.lines) + '\n'
+
+ class TextSection(SectionBase):
+ """Text section that is echoed out as is."""
+
+ def TryAppend(self, line, line_num):
+ if line.startswith('//%PDDM'):
+ return (False, False)
+ self.Append(line)
+ return (True, True)
+
+ class ExpansionSection(SectionBase):
+ """Section that is the result of an macro expansion."""
+
+ def __init__(self, first_line_num):
+ SourceFile.SectionBase.__init__(self, first_line_num)
+ self._macro_collection = None
+
+ def TryAppend(self, line, line_num):
+ if line.startswith('//%PDDM'):
+ directive = line.split(' ', 1)[0]
+ if directive == '//%PDDM-EXPAND':
+ self.Append(line)
+ return (True, True)
+ if directive == '//%PDDM-EXPAND-END':
+ assert self.num_lines_captured > 0
+ return (True, False)
+ raise PDDMError('Ran into directive ("%s", line %d) while in "%s".' %
+ (directive, line_num, self.first_line))
+ # Eat other lines.
+ return (True, True)
+
+ def HitEOF(self):
+ raise PDDMError('Hit the end of the file while in "%s".' %
+ self.first_line)
+
+ def BindMacroCollection(self, macro_collection):
+ self._macro_collection = macro_collection
+
+ @property
+ def lines(self):
+ captured_lines = SourceFile.SectionBase.lines.fget(self)
+ directive_len = len('//%PDDM-EXPAND')
+ result = []
+ for line in captured_lines:
+ result.append(line)
+ if self._macro_collection:
+ # Always add a blank line, seems to read better. (If need be, add an
+ # option to the EXPAND to indicate if this should be done.)
+ result.extend([_GENERATED_CODE_LINE, ''])
+ macro = line[directive_len:].strip()
+ try:
+ expand_result = self._macro_collection.Expand(macro)
+ # Since expansions are line oriented, strip trailing whitespace
+ # from the lines.
+ lines = [x.rstrip() for x in expand_result.split('\n')]
+ result.append('\n'.join(lines))
+ except PDDMError as e:
+ raise PDDMError('%s\n...while expanding "%s" from the section'
+ ' that started:\n Line %d: %s' %
+ (e.message, macro,
+ self.first_line_num, self.first_line))
+
+ # Add the ending marker.
+ if len(captured_lines) == 1:
+ result.append('//%%PDDM-EXPAND-END %s' %
+ captured_lines[0][directive_len:].strip())
+ else:
+ result.append('//%%PDDM-EXPAND-END (%s expansions)' % len(captured_lines))
+
+ return result
+
+ class DefinitionSection(SectionBase):
+ """Section containing macro definitions"""
+
+ def TryAppend(self, line, line_num):
+ if not line.startswith('//%'):
+ return (False, False)
+ if line.startswith('//%PDDM'):
+ directive = line.split(' ', 1)[0]
+ if directive == "//%PDDM-EXPAND":
+ return False, False
+ if directive not in ('//%PDDM-DEFINE', '//%PDDM-DEFINE-END'):
+ raise PDDMError('Ran into directive ("%s", line %d) while in "%s".' %
+ (directive, line_num, self.first_line))
+ self.Append(line)
+ return (True, True)
+
+ def BindMacroCollection(self, macro_collection):
+ if macro_collection:
+ try:
+ # Parse the lines after stripping the prefix.
+ macro_collection.ParseLines([x[3:] for x in self.lines])
+ except PDDMError as e:
+ raise PDDMError('%s\n...while parsing section that started:\n'
+ ' Line %d: %s' %
+ (e.message, self.first_line_num, self.first_line))
+
+ class ImportDefinesSection(SectionBase):
+ """Section containing an import of PDDM-DEFINES from an external file."""
+
+ def __init__(self, first_line_num, import_resolver):
+ SourceFile.SectionBase.__init__(self, first_line_num)
+ self._import_resolver = import_resolver
+
+ def TryAppend(self, line, line_num):
+ if not line.startswith('//%PDDM-IMPORT-DEFINES '):
+ return (False, False)
+ assert self.num_lines_captured == 0
+ self.Append(line)
+ return (True, False)
+
+ def BindMacroCollection(self, macro_colletion):
+ if not macro_colletion:
+ return
+ if self._import_resolver is None:
+ raise PDDMError('Got an IMPORT-DEFINES without a resolver (line %d):'
+ ' "%s".' % (self.first_line_num, self.first_line))
+ import_name = self.first_line.split(' ', 1)[1].strip()
+ imported_file = self._import_resolver(import_name)
+ if imported_file is None:
+ raise PDDMError('Resolver failed to find "%s" (line %d):'
+ ' "%s".' %
+ (import_name, self.first_line_num, self.first_line))
+ try:
+ imported_src_file = SourceFile(imported_file, self._import_resolver)
+ imported_src_file._ParseFile()
+ for section in imported_src_file._sections:
+ section.BindMacroCollection(macro_colletion)
+ except PDDMError as e:
+ raise PDDMError('%s\n...while importing defines:\n'
+ ' Line %d: %s' %
+ (e.message, self.first_line_num, self.first_line))
+
+ def _ParseFile(self):
+ self._sections = []
+ lines = self._original_content.splitlines()
+ cur_section = None
+ for line_num, line in enumerate(lines, 1):
+ if not cur_section:
+ cur_section = self._MakeSection(line, line_num)
+ was_added, accept_more = cur_section.TryAppend(line, line_num)
+ if not was_added:
+ cur_section = self._MakeSection(line, line_num)
+ was_added, accept_more = cur_section.TryAppend(line, line_num)
+ assert was_added
+ if not accept_more:
+ cur_section = None
+
+ if cur_section:
+ cur_section.HitEOF()
+
+ def _MakeSection(self, line, line_num):
+ if not line.startswith('//%PDDM'):
+ section = self.TextSection(line_num)
+ else:
+ directive = line.split(' ', 1)[0]
+ if directive == '//%PDDM-EXPAND':
+ section = self.ExpansionSection(line_num)
+ elif directive == '//%PDDM-DEFINE':
+ section = self.DefinitionSection(line_num)
+ elif directive == '//%PDDM-IMPORT-DEFINES':
+ section = self.ImportDefinesSection(line_num, self._import_resolver)
+ else:
+ raise PDDMError('Unexpected line %d: "%s".' % (line_num, line))
+ self._sections.append(section)
+ return section
+
+ def ProcessContent(self, strip_expansion=False):
+ """Processes the file contents."""
+ self._ParseFile()
+ if strip_expansion:
+ # Without a collection the expansions become blank, removing them.
+ collection = None
+ else:
+ collection = MacroCollection()
+ for section in self._sections:
+ section.BindMacroCollection(collection)
+ result = ''
+ for section in self._sections:
+ result += section.text
+ self._processed_content = result
+
+ @property
+ def original_content(self):
+ return self._original_content
+
+ @property
+ def processed_content(self):
+ return self._processed_content
+
+
+def main(args):
+ usage = '%prog [OPTIONS] PATH ...'
+ description = (
+ 'Processes PDDM directives in the given paths and write them back out.'
+ )
+ parser = optparse.OptionParser(usage=usage, description=description)
+ parser.add_option('--dry-run',
+ default=False, action='store_true',
+ help='Don\'t write back to the file(s), just report if the'
+ ' contents needs an update and exit with a value of 1.')
+ parser.add_option('--verbose',
+ default=False, action='store_true',
+ help='Reports is a file is already current.')
+ parser.add_option('--collapse',
+ default=False, action='store_true',
+ help='Removes all the generated code.')
+ opts, extra_args = parser.parse_args(args)
+
+ if not extra_args:
+ parser.error('Need atleast one file to process')
+
+ result = 0
+ for a_path in extra_args:
+ if not os.path.exists(a_path):
+ sys.stderr.write('ERROR: File not found: %s\n' % a_path)
+ return 100
+
+ def _ImportResolver(name):
+ # resolve based on the file being read.
+ a_dir = os.path.dirname(a_path)
+ import_path = os.path.join(a_dir, name)
+ if not os.path.exists(import_path):
+ return None
+ return open(import_path, 'r')
+
+ with open(a_path, 'r') as f:
+ src_file = SourceFile(f, _ImportResolver)
+
+ try:
+ src_file.ProcessContent(strip_expansion=opts.collapse)
+ except PDDMError as e:
+ sys.stderr.write('ERROR: %s\n...While processing "%s"\n' %
+ (e.message, a_path))
+ return 101
+
+ if src_file.processed_content != src_file.original_content:
+ if not opts.dry_run:
+ print 'Updating for "%s".' % a_path
+ with open(a_path, 'w') as f:
+ f.write(src_file.processed_content)
+ else:
+ # Special result to indicate things need updating.
+ print 'Update needed for "%s".' % a_path
+ result = 1
+ elif opts.verbose:
+ print 'No update for "%s".' % a_path
+
+ return result
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
diff --git a/third_party/protobuf/objectivec/DevTools/pddm_tests.py b/third_party/protobuf/objectivec/DevTools/pddm_tests.py
new file mode 100755
index 0000000000..8a73b8427b
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/pddm_tests.py
@@ -0,0 +1,515 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2015 Google Inc. All rights reserved.
+# https://developers.google.com/protocol-buffers/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Tests for pddm.py."""
+
+import io
+import unittest
+
+import pddm
+
+
+class TestParsingMacros(unittest.TestCase):
+
+ def testParseEmpty(self):
+ f = io.StringIO(u'')
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 0)
+
+ def testParseOne(self):
+ f = io.StringIO(u"""PDDM-DEFINE foo( )
+body""")
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 1)
+ macro = result._macros.get('foo')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'foo')
+ self.assertEquals(macro.args, tuple())
+ self.assertEquals(macro.body, 'body')
+
+ def testParseGeneral(self):
+ # Tests multiple defines, spaces in all places, etc.
+ f = io.StringIO(u"""
+PDDM-DEFINE noArgs( )
+body1
+body2
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE oneArg(foo)
+body3
+PDDM-DEFINE twoArgs( bar_ , baz )
+body4
+body5""")
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 3)
+ macro = result._macros.get('noArgs')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'noArgs')
+ self.assertEquals(macro.args, tuple())
+ self.assertEquals(macro.body, 'body1\nbody2\n')
+ macro = result._macros.get('oneArg')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'oneArg')
+ self.assertEquals(macro.args, ('foo',))
+ self.assertEquals(macro.body, 'body3')
+ macro = result._macros.get('twoArgs')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'twoArgs')
+ self.assertEquals(macro.args, ('bar_', 'baz'))
+ self.assertEquals(macro.body, 'body4\nbody5')
+ # Add into existing collection
+ f = io.StringIO(u"""
+PDDM-DEFINE another(a,b,c)
+body1
+body2""")
+ result.ParseInput(f)
+ self.assertEqual(len(result._macros), 4)
+ macro = result._macros.get('another')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'another')
+ self.assertEquals(macro.args, ('a', 'b', 'c'))
+ self.assertEquals(macro.body, 'body1\nbody2')
+
+ def testParseDirectiveIssues(self):
+ test_list = [
+ # Unknown directive
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINED foo\nbaz',
+ 'Hit a line with an unknown directive: '),
+ # End without begin
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE-END\nPDDM-DEFINE-END\n',
+ 'Got DEFINE-END directive without an active macro: '),
+ # Line not in macro block
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE-END\nmumble\n',
+ 'Hit a line that wasn\'t a directive and no open macro definition: '),
+ # Redefine macro
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE foo(a)\nmumble\n',
+ 'Attempt to redefine macro: '),
+ ]
+ for idx, (input_str, expected_prefix) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ result = pddm.MacroCollection(f)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertTrue(e.message.startswith(expected_prefix),
+ 'Entry %d failed: %r' % (idx, e))
+
+ def testParseBeginIssues(self):
+ test_list = [
+ # 1. No name
+ (u'PDDM-DEFINE\nmumble',
+ 'Failed to parse macro definition: '),
+ # 2. No name (with spaces)
+ (u'PDDM-DEFINE \nmumble',
+ 'Failed to parse macro definition: '),
+ # 3. No open paren
+ (u'PDDM-DEFINE foo\nmumble',
+ 'Failed to parse macro definition: '),
+ # 4. No close paren
+ (u'PDDM-DEFINE foo(\nmumble',
+ 'Failed to parse macro definition: '),
+ # 5. No close paren (with args)
+ (u'PDDM-DEFINE foo(a, b\nmumble',
+ 'Failed to parse macro definition: '),
+ # 6. No name before args
+ (u'PDDM-DEFINE (a, b)\nmumble',
+ 'Failed to parse macro definition: '),
+ # 7. No name before args
+ (u'PDDM-DEFINE foo bar(a, b)\nmumble',
+ 'Failed to parse macro definition: '),
+ # 8. Empty arg name
+ (u'PDDM-DEFINE foo(a, ,b)\nmumble',
+ 'Empty arg name in macro definition: '),
+ (u'PDDM-DEFINE foo(a,,b)\nmumble',
+ 'Empty arg name in macro definition: '),
+ # 10. Duplicate name
+ (u'PDDM-DEFINE foo(a,b,a,c)\nmumble',
+ 'Arg name "a" used more than once in macro definition: '),
+ # 11. Invalid arg name
+ (u'PDDM-DEFINE foo(a b,c)\nmumble',
+ 'Invalid arg name "a b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a.b,c)\nmumble',
+ 'Invalid arg name "a.b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a-b,c)\nmumble',
+ 'Invalid arg name "a-b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a,b,c.)\nmumble',
+ 'Invalid arg name "c." in macro definition: '),
+ # 15. Extra stuff after the name
+ (u'PDDM-DEFINE foo(a,c) foo\nmumble',
+ 'Failed to parse macro definition: '),
+ (u'PDDM-DEFINE foo(a,c) foo)\nmumble',
+ 'Failed to parse macro definition: '),
+ ]
+ for idx, (input_str, expected_prefix) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ result = pddm.MacroCollection(f)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertTrue(e.message.startswith(expected_prefix),
+ 'Entry %d failed: %r' % (idx, e))
+
+
+class TestExpandingMacros(unittest.TestCase):
+
+ def testExpandBasics(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE noArgs( )
+body1
+body2
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE oneArg(a)
+body3 a
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE twoArgs(b,c)
+body4 b c
+body5
+PDDM-DEFINE-END
+
+""")
+ mc = pddm.MacroCollection(f)
+ test_list = [
+ (u'noArgs()',
+ 'body1\nbody2\n'),
+ (u'oneArg(wee)',
+ 'body3 wee\n'),
+ (u'twoArgs(having some, fun)',
+ 'body4 having some fun\nbody5'),
+ # One arg, pass empty.
+ (u'oneArg()',
+ 'body3 \n'),
+ # Two args, gets empty in each slot.
+ (u'twoArgs(, empty)',
+ 'body4 empty\nbody5'),
+ (u'twoArgs(empty, )',
+ 'body4 empty \nbody5'),
+ (u'twoArgs(, )',
+ 'body4 \nbody5'),
+ ]
+ for idx, (input_str, expected) in enumerate(test_list, 1):
+ result = mc.Expand(input_str)
+ self.assertEqual(result, expected,
+ 'Entry %d --\n Result: %r\n Expected: %r' %
+ (idx, result, expected))
+
+ def testExpandArgOptions(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE bar(a)
+a-a$S-a$l-a$L-a$u-a$U
+PDDM-DEFINE-END
+""")
+ mc = pddm.MacroCollection(f)
+
+ self.assertEqual(mc.Expand('bar(xYz)'), 'xYz- -xYz-xyz-XYz-XYZ')
+ self.assertEqual(mc.Expand('bar(MnoP)'), 'MnoP- -mnoP-mnop-MnoP-MNOP')
+ # Test empty
+ self.assertEqual(mc.Expand('bar()'), '-----')
+
+ def testExpandSimpleMacroErrors(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE foo(a, b)
+<a-z>
+PDDM-DEFINE baz(a)
+a - a$z
+""")
+ mc = pddm.MacroCollection(f)
+ test_list = [
+ # 1. Unknown macro
+ (u'bar()',
+ 'No macro named "bar".'),
+ (u'bar(a)',
+ 'No macro named "bar".'),
+ # 3. Arg mismatch
+ (u'foo()',
+ 'Expected 2 args, got: "foo()".'),
+ (u'foo(a b)',
+ 'Expected 2 args, got: "foo(a b)".'),
+ (u'foo(a,b,c)',
+ 'Expected 2 args, got: "foo(a,b,c)".'),
+ # 6. Unknown option in expansion
+ (u'baz(mumble)',
+ 'Unknown arg option "a$z" while expanding "baz(mumble)".'),
+ ]
+ for idx, (input_str, expected_err) in enumerate(test_list, 1):
+ try:
+ result = mc.Expand(input_str)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message, expected_err,
+ 'Entry %d failed: %r' % (idx, e))
+
+ def testExpandReferences(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE StartIt()
+foo(abc, def)
+foo(ghi, jkl)
+PDDM-DEFINE foo(a, b)
+bar(a, int)
+bar(b, NSString *)
+PDDM-DEFINE bar(n, t)
+- (t)n;
+- (void)set##n$u##:(t)value;
+
+""")
+ mc = pddm.MacroCollection(f)
+ expected = """- (int)abc;
+- (void)setAbc:(int)value;
+
+- (NSString *)def;
+- (void)setDef:(NSString *)value;
+
+- (int)ghi;
+- (void)setGhi:(int)value;
+
+- (NSString *)jkl;
+- (void)setJkl:(NSString *)value;
+"""
+ self.assertEqual(mc.Expand('StartIt()'), expected)
+
+ def testCatchRecursion(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE foo(a, b)
+bar(1, a)
+bar(2, b)
+PDDM-DEFINE bar(x, y)
+foo(x, y)
+""")
+ mc = pddm.MacroCollection(f)
+ try:
+ result = mc.Expand('foo(A,B)')
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'Found macro recusion, invoking "foo(1, A)":\n...while expanding "bar(1, A)".\n...while expanding "foo(A,B)".')
+
+
+class TestParsingSource(unittest.TestCase):
+
+ def testBasicParse(self):
+ test_list = [
+ # 1. no directives
+ (u'a\nb\nc',
+ (3,) ),
+ # 2. One define
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\nc',
+ (1, 2, 1) ),
+ # 3. Two defines
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\n//%PDDM-DEFINE bar()\n//%body2\nc',
+ (1, 4, 1) ),
+ # 4. Two defines with ends
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\n//%PDDM-DEFINE-END\n'
+ u'//%PDDM-DEFINE bar()\n//%body2\n//%PDDM-DEFINE-END\nc',
+ (1, 6, 1) ),
+ # 5. One expand, one define (that runs to end of file)
+ (u'a\n//%PDDM-EXPAND foo()\nbody\n//%PDDM-EXPAND-END\n'
+ u'//%PDDM-DEFINE bar()\n//%body2\n',
+ (1, 1, 2) ),
+ # 6. One define ended with an expand.
+ (u'a\nb\n//%PDDM-DEFINE bar()\n//%body2\n'
+ u'//%PDDM-EXPAND bar()\nbody2\n//%PDDM-EXPAND-END\n',
+ (2, 2, 1) ),
+ # 7. Two expands (one end), one define.
+ (u'a\n//%PDDM-EXPAND foo(1)\nbody\n//%PDDM-EXPAND foo(2)\nbody2\n//%PDDM-EXPAND-END\n'
+ u'//%PDDM-DEFINE foo()\n//%body2\n',
+ (1, 2, 2) ),
+ ]
+ for idx, (input_str, line_counts) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ sf._ParseFile()
+ self.assertEqual(len(sf._sections), len(line_counts),
+ 'Entry %d -- %d != %d' %
+ (idx, len(sf._sections), len(line_counts)))
+ for idx2, (sec, expected) in enumerate(zip(sf._sections, line_counts), 1):
+ self.assertEqual(sec.num_lines_captured, expected,
+ 'Entry %d, section %d -- %d != %d' %
+ (idx, idx2, sec.num_lines_captured, expected))
+
+ def testErrors(self):
+ test_list = [
+ # 1. Directive within expansion
+ (u'//%PDDM-EXPAND a()\n//%PDDM-BOGUS',
+ 'Ran into directive ("//%PDDM-BOGUS", line 2) while in "//%PDDM-EXPAND a()".'),
+ (u'//%PDDM-EXPAND a()\n//%PDDM-DEFINE a()\n//%body\n',
+ 'Ran into directive ("//%PDDM-DEFINE", line 2) while in "//%PDDM-EXPAND a()".'),
+ # 3. Expansion ran off end of file
+ (u'//%PDDM-EXPAND a()\na\nb\n',
+ 'Hit the end of the file while in "//%PDDM-EXPAND a()".'),
+ # 4. Directive within define
+ (u'//%PDDM-DEFINE a()\n//%body\n//%PDDM-BOGUS',
+ 'Ran into directive ("//%PDDM-BOGUS", line 3) while in "//%PDDM-DEFINE a()".'),
+ (u'//%PDDM-DEFINE a()\n//%body\n//%PDDM-EXPAND-END a()',
+ 'Ran into directive ("//%PDDM-EXPAND-END", line 3) while in "//%PDDM-DEFINE a()".'),
+ # 6. Directives that shouldn't start sections
+ (u'a\n//%PDDM-DEFINE-END a()\n//a\n',
+ 'Unexpected line 2: "//%PDDM-DEFINE-END a()".'),
+ (u'a\n//%PDDM-EXPAND-END a()\n//a\n',
+ 'Unexpected line 2: "//%PDDM-EXPAND-END a()".'),
+ (u'//%PDDM-BOGUS\n//a\n',
+ 'Unexpected line 1: "//%PDDM-BOGUS".'),
+ ]
+ for idx, (input_str, expected_err) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ pddm.SourceFile(f)._ParseFile()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message, expected_err,
+ 'Entry %d failed: %r' % (idx, e))
+
+class TestProcessingSource(unittest.TestCase):
+
+ def testBasics(self):
+ input_str = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+//%PDDM-EXPAND-END
+bar
+//%PDDM-EXPAND mumble(def)
+//%PDDM-EXPAND mumble(ghi)
+//%PDDM-EXPAND-END
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ input_str2 = u"""
+//%PDDM-DEFINE getName(x_)
+//%do##x_$u##(int x_);
+
+"""
+ expected = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+// This block of code is generated, do not edit it directly.
+
+abc: doAbc(int abc);
+//%PDDM-EXPAND-END mumble(abc)
+bar
+//%PDDM-EXPAND mumble(def)
+// This block of code is generated, do not edit it directly.
+
+def: doDef(int def);
+//%PDDM-EXPAND mumble(ghi)
+// This block of code is generated, do not edit it directly.
+
+ghi: doGhi(int ghi);
+//%PDDM-EXPAND-END (2 expansions)
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ expected_stripped = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+//%PDDM-EXPAND-END mumble(abc)
+bar
+//%PDDM-EXPAND mumble(def)
+//%PDDM-EXPAND mumble(ghi)
+//%PDDM-EXPAND-END (2 expansions)
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ def _Resolver(name):
+ self.assertEqual(name, 'ImportFile')
+ return io.StringIO(input_str2)
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f, _Resolver)
+ sf.ProcessContent()
+ self.assertEqual(sf.processed_content, expected)
+ # Feed it through and nothing should change.
+ f2 = io.StringIO(sf.processed_content)
+ sf2 = pddm.SourceFile(f2, _Resolver)
+ sf2.ProcessContent()
+ self.assertEqual(sf2.processed_content, expected)
+ self.assertEqual(sf2.processed_content, sf.processed_content)
+ # Test stripping (with the original input and expanded version).
+ f2 = io.StringIO(input_str)
+ sf2 = pddm.SourceFile(f2)
+ sf2.ProcessContent(strip_expansion=True)
+ self.assertEqual(sf2.processed_content, expected_stripped)
+ f2 = io.StringIO(sf.processed_content)
+ sf2 = pddm.SourceFile(f2, _Resolver)
+ sf2.ProcessContent(strip_expansion=True)
+ self.assertEqual(sf2.processed_content, expected_stripped)
+
+ def testProcessFileWithMacroParseError(self):
+ input_str = u"""
+foo
+//%PDDM-DEFINE mumble(a_)
+//%body
+//%PDDM-DEFINE mumble(x_)
+//%body2
+
+"""
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ try:
+ sf.ProcessContent()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'Attempt to redefine macro: "PDDM-DEFINE mumble(x_)"\n'
+ '...while parsing section that started:\n'
+ ' Line 3: //%PDDM-DEFINE mumble(a_)')
+
+ def testProcessFileWithExpandError(self):
+ input_str = u"""
+foo
+//%PDDM-DEFINE mumble(a_)
+//%body
+//%PDDM-EXPAND foobar(x_)
+//%PDDM-EXPAND-END
+
+"""
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ try:
+ sf.ProcessContent()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'No macro named "foobar".\n'
+ '...while expanding "foobar(x_)" from the section that'
+ ' started:\n Line 5: //%PDDM-EXPAND foobar(x_)')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/objectivec/GPBArray.h b/third_party/protobuf/objectivec/GPBArray.h
new file mode 100644
index 0000000000..638b2882d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray.h
@@ -0,0 +1,1967 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+//%PDDM-EXPAND DECLARE_ARRAYS()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+/**
+ * Class used for repeated fields of int32_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBInt32Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBInt32Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBInt32Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(int32_t)value;
+
+/**
+ * Creates and initializes a GPBInt32Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBInt32Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBInt32Array *)array;
+
+/**
+ * Creates and initializes a GPBInt32Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBInt32Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBInt32Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const int32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBInt32Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBInt32Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBInt32Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - UInt32
+
+/**
+ * Class used for repeated fields of uint32_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBUInt32Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBUInt32Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(uint32_t)value;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBUInt32Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBUInt32Array *)array;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBUInt32Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBUInt32Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBUInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const uint32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBUInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBUInt32Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBUInt32Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (uint32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(uint32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const uint32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBUInt32Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(uint32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint32_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Int64
+
+/**
+ * Class used for repeated fields of int64_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBInt64Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBInt64Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBInt64Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(int64_t)value;
+
+/**
+ * Creates and initializes a GPBInt64Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBInt64Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBInt64Array *)array;
+
+/**
+ * Creates and initializes a GPBInt64Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBInt64Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBInt64Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const int64_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBInt64Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBInt64Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int64_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int64_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int64_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBInt64Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int64_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int64_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - UInt64
+
+/**
+ * Class used for repeated fields of uint64_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBUInt64Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBUInt64Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(uint64_t)value;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBUInt64Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBUInt64Array *)array;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBUInt64Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBUInt64Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBUInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const uint64_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBUInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBUInt64Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBUInt64Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (uint64_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(uint64_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const uint64_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBUInt64Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(uint64_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint64_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Float
+
+/**
+ * Class used for repeated fields of float values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBFloatArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBFloatArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBFloatArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBFloatArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(float)value;
+
+/**
+ * Creates and initializes a GPBFloatArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBFloatArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBFloatArray *)array;
+
+/**
+ * Creates and initializes a GPBFloatArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBFloatArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBFloatArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBFloatArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const float [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBFloatArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBFloatArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBFloatArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (float)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(float)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const float [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBFloatArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(float)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(float)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Double
+
+/**
+ * Class used for repeated fields of double values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBDoubleArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBDoubleArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBDoubleArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(double)value;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBDoubleArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBDoubleArray *)array;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBDoubleArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBDoubleArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBDoubleArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const double [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBDoubleArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBDoubleArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBDoubleArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (double)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(double)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const double [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBDoubleArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(double)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(double)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Bool
+
+/**
+ * Class used for repeated fields of BOOL values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBBoolArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBBoolArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBBoolArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(BOOL)value;
+
+/**
+ * Creates and initializes a GPBBoolArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBBoolArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBBoolArray *)array;
+
+/**
+ * Creates and initializes a GPBBoolArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBBoolArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBBoolArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBBoolArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const BOOL [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBBoolArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBBoolArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBBoolArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (BOOL)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(BOOL)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const BOOL [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBBoolArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(BOOL)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(BOOL)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Enum
+
+/**
+ * This class is used for repeated fields of int32_t values. This performs
+ * better than boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBEnumArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty GPBEnumArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBEnumArray with the enum validation function
+ * given.
+ *
+ * @param func The enum validation function for the array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a GPBEnumArray with the enum validation function
+ * given and the single raw value given.
+ *
+ * @param func The enum validation function for the array.
+ * @param value The raw value to add to this array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)value;
+
+/**
+ * Creates and initializes a GPBEnumArray that adds the elements from the
+ * given array.
+ *
+ * @param array Array containing the values to add to the new array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValueArray:(GPBEnumArray *)array;
+
+/**
+ * Creates and initializes a GPBEnumArray with the given enum validation
+ * function and with the givencapacity.
+ *
+ * @param func The enum validation function for the array.
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBEnumArray with a capacity of count.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count;
+
+/**
+ * Initializes the array with the given enum validation function.
+ *
+ * @param func The enum validation function for the array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param func The enum validation function for the array.
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBEnumArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param func The enum validation function for the array.
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBEnumArray with a capacity of count.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
+// valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+// These methods bypass the validationFunc to provide access to values that were not
+// known at the time the binary was compiled.
+
+/**
+ * Gets the raw enum value at the given index.
+ *
+ * @param index The index of the raw enum value to get.
+ *
+ * @return The raw enum value at the given index.
+ **/
+- (int32_t)rawValueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value;
+
+// These methods bypass the validationFunc to provide setting of values that were not
+// known at the time the binary was compiled.
+
+/**
+ * Adds a raw enum value to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param value The raw enum value to add to the array.
+ **/
+- (void)addRawValue:(int32_t)value;
+
+/**
+ * Adds raw enum values to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param array Array containing the raw enum values to add to this array.
+ **/
+- (void)addRawValuesFromArray:(GPBEnumArray *)array;
+
+/**
+ * Adds raw enum values to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param values Array containing the raw enum values to add to this array.
+ * @param count The number of raw values to add.
+ **/
+- (void)addRawValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Inserts a raw enum value at the given index.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param value Raw enum value to add.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertRawValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the raw enum value at the given index with the given value.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The raw enum value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(int32_t)value;
+
+// No validation applies to these methods.
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+//%PDDM-EXPAND-END DECLARE_ARRAYS()
+
+NS_ASSUME_NONNULL_END
+
+//%PDDM-DEFINE DECLARE_ARRAYS()
+//%ARRAY_INTERFACE_SIMPLE(Int32, int32_t)
+//%ARRAY_INTERFACE_SIMPLE(UInt32, uint32_t)
+//%ARRAY_INTERFACE_SIMPLE(Int64, int64_t)
+//%ARRAY_INTERFACE_SIMPLE(UInt64, uint64_t)
+//%ARRAY_INTERFACE_SIMPLE(Float, float)
+//%ARRAY_INTERFACE_SIMPLE(Double, double)
+//%ARRAY_INTERFACE_SIMPLE(Bool, BOOL)
+//%ARRAY_INTERFACE_ENUM(Enum, int32_t)
+
+//
+// The common case (everything but Enum)
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_SIMPLE(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%/**
+//% * Class used for repeated fields of ##TYPE## values. This performs better than
+//% * boxing into NSNumbers in NSArrays.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##NAME##Array : NSObject <NSCopying>
+//%
+//%/** The number of elements contained in the array. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%
+//%/**
+//% * @return A newly instanced and empty GPB##NAME##Array.
+//% **/
+//%+ (instancetype)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the single element given.
+//% *
+//% * @param value The value to be placed in the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with value in it.
+//% **/
+//%+ (instancetype)arrayWithValue:(TYPE)value;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the contents of the given
+//% * array.
+//% *
+//% * @param array Array with the contents to be put into the new array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with the contents of array.
+//% **/
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the given capacity.
+//% *
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with a capacity of count.
+//% **/
+//%+ (instancetype)arrayWithCapacity:(NSUInteger)count;
+//%
+//%/**
+//% * @return A newly initialized and empty GPB##NAME##Array.
+//% **/
+//%- (instancetype)init NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param values An array with the values to put inside this array.
+//% * @param count The number of elements to copy into the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValues:(const TYPE [__nullable])values
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param array An array with the values to put inside this array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Initializes the array with the given capacity.
+//% *
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a capacity of count.
+//% **/
+//%- (instancetype)initWithCapacity:(NSUInteger)count;
+//%
+//%ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, Basic)
+//%
+//%ARRAY_MUTABLE_INTERFACE(NAME, TYPE, Basic)
+//%
+//%@end
+//%
+
+//
+// Macros specific to Enums (to tweak their interface).
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_ENUM(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%/**
+//% * This class is used for repeated fields of ##TYPE## values. This performs
+//% * better than boxing into NSNumbers in NSArrays.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##NAME##Array : NSObject <NSCopying>
+//%
+//%/** The number of elements contained in the array. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%/** The validation function to check if the enums are valid. */
+//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+//%
+//%/**
+//% * @return A newly instanced and empty GPB##NAME##Array.
+//% **/
+//%+ (instancetype)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the enum validation function
+//% * given.
+//% *
+//% * @param func The enum validation function for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the enum validation function
+//% * given and the single raw value given.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param value The raw value to add to this array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValue:(TYPE)value;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array that adds the elements from the
+//% * given array.
+//% *
+//% * @param array Array containing the values to add to the new array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the given enum validation
+//% * function and with the givencapacity.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with a capacity of count.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array with the given enum validation function.
+//% *
+//% * @param func The enum validation function for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param values An array with the values to put inside this array.
+//% * @param count The number of elements to copy into the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const TYPE [__nullable])values
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param array An array with the values to put inside this array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Initializes the array with the given capacity.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a capacity of count.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)count;
+//%
+//%// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
+//%// valid enumerator as defined by validationFunc. If the actual value is
+//%// desired, use "raw" version of the method.
+//%
+//%ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, NAME)
+//%
+//%// These methods bypass the validationFunc to provide access to values that were not
+//%// known at the time the binary was compiled.
+//%
+//%/**
+//% * Gets the raw enum value at the given index.
+//% *
+//% * @param index The index of the raw enum value to get.
+//% *
+//% * @return The raw enum value at the given index.
+//% **/
+//%- (TYPE)rawValueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateRawValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param opts Options to control the enumeration.
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%// If value is not a valid enumerator as defined by validationFunc, these
+//%// methods will assert in debug, and will log in release and assign the value
+//%// to the default value. Use the rawValue methods below to assign non enumerator
+//%// values.
+//%
+//%ARRAY_MUTABLE_INTERFACE(NAME, TYPE, NAME)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME)
+//%/**
+//% * Gets the value at the given index.
+//% *
+//% * @param index The index of the value to get.
+//% *
+//% * @return The value at the given index.
+//% **/
+//%- (TYPE)valueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param opts Options to control the enumeration.
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+
+//%PDDM-DEFINE ARRAY_MUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME)
+//%/**
+//% * Adds a value to this array.
+//% *
+//% * @param value The value to add to this array.
+//% **/
+//%- (void)addValue:(TYPE)value;
+//%
+//%/**
+//% * Adds values to this array.
+//% *
+//% * @param values The values to add to this array.
+//% * @param count The number of elements to add.
+//% **/
+//%- (void)addValues:(const TYPE [__nullable])values count:(NSUInteger)count;
+//%
+//%ARRAY_EXTRA_MUTABLE_METHODS1_##HELPER_NAME(NAME, TYPE)
+//%/**
+//% * Inserts a value into the given position.
+//% *
+//% * @param value The value to add to this array.
+//% * @param index The index into which to insert the value.
+//% **/
+//%- (void)insertValue:(TYPE)value atIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Replaces the value at the given index with the given value.
+//% *
+//% * @param index The index for which to replace the value.
+//% * @param value The value to replace with.
+//% **/
+//%- (void)replaceValueAtIndex:(NSUInteger)index withValue:(TYPE)value;
+//%ARRAY_EXTRA_MUTABLE_METHODS2_##HELPER_NAME(NAME, TYPE)
+//%/**
+//% * Removes the value at the given index.
+//% *
+//% * @param index The index of the value to remove.
+//% **/
+//%- (void)removeValueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Removes all the values from this array.
+//% **/
+//%- (void)removeAll;
+//%
+//%/**
+//% * Exchanges the values between the given indexes.
+//% *
+//% * @param idx1 The index of the first element to exchange.
+//% * @param idx2 The index of the second element to exchange.
+//% **/
+//%- (void)exchangeValueAtIndex:(NSUInteger)idx1
+//% withValueAtIndex:(NSUInteger)idx2;
+
+//
+// These are hooks invoked by the above to do insert as needed.
+//
+
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS1_Basic(NAME, TYPE)
+//%/**
+//% * Adds the values from the given array to this array.
+//% *
+//% * @param array The array containing the elements to add to this array.
+//% **/
+//%- (void)addValuesFromArray:(GPB##NAME##Array *)array;
+//%
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS2_Basic(NAME, TYPE)
+// Empty
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS1_Enum(NAME, TYPE)
+// Empty
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS2_Enum(NAME, TYPE)
+//%
+//%// These methods bypass the validationFunc to provide setting of values that were not
+//%// known at the time the binary was compiled.
+//%
+//%/**
+//% * Adds a raw enum value to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param value The raw enum value to add to the array.
+//% **/
+//%- (void)addRawValue:(TYPE)value;
+//%
+//%/**
+//% * Adds raw enum values to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param array Array containing the raw enum values to add to this array.
+//% **/
+//%- (void)addRawValuesFromArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Adds raw enum values to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param values Array containing the raw enum values to add to this array.
+//% * @param count The number of raw values to add.
+//% **/
+//%- (void)addRawValues:(const TYPE [__nullable])values count:(NSUInteger)count;
+//%
+//%/**
+//% * Inserts a raw enum value at the given index.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param value Raw enum value to add.
+//% * @param index The index into which to insert the value.
+//% **/
+//%- (void)insertRawValue:(TYPE)value atIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Replaces the raw enum value at the given index with the given value.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param index The index for which to replace the value.
+//% * @param value The raw enum value to replace with.
+//% **/
+//%- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(TYPE)value;
+//%
+//%// No validation applies to these methods.
+//%
diff --git a/third_party/protobuf/objectivec/GPBArray.m b/third_party/protobuf/objectivec/GPBArray.m
new file mode 100644
index 0000000000..f401631d12
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray.m
@@ -0,0 +1,2551 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBArray_PackagePrivate.h"
+
+#import "GPBMessage_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Mutable arrays use an internal buffer that can always hold a multiple of this elements.
+#define kChunkSize 16
+#define CapacityFromCount(x) (((x / kChunkSize) + 1) * kChunkSize)
+
+static BOOL ArrayDefault_IsValidValue(int32_t value) {
+ // Anything but the bad value marker is allowed.
+ return (value != kGPBUnrecognizedEnumeratorValue);
+}
+
+//%PDDM-DEFINE VALIDATE_RANGE(INDEX, COUNT)
+//% if (INDEX >= COUNT) {
+//% [NSException raise:NSRangeException
+//% format:@"Index (%lu) beyond bounds (%lu)",
+//% (unsigned long)INDEX, (unsigned long)COUNT];
+//% }
+//%PDDM-DEFINE MAYBE_GROW_TO_SET_COUNT(NEW_COUNT)
+//% if (NEW_COUNT > _capacity) {
+//% [self internalResizeToCapacity:CapacityFromCount(NEW_COUNT)];
+//% }
+//% _count = NEW_COUNT;
+//%PDDM-DEFINE SET_COUNT_AND_MAYBE_SHRINK(NEW_COUNT)
+//% _count = NEW_COUNT;
+//% if ((NEW_COUNT + (2 * kChunkSize)) < _capacity) {
+//% [self internalResizeToCapacity:CapacityFromCount(NEW_COUNT)];
+//% }
+
+//
+// Macros for the common basic cases.
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_SIMPLE(NAME, TYPE, FORMAT)
+//%#pragma mark - NAME
+//%
+//%@implementation GPB##NAME##Array {
+//% @package
+//% TYPE *_values;
+//% NSUInteger _count;
+//% NSUInteger _capacity;
+//%}
+//%
+//%@synthesize count = _count;
+//%
+//%+ (instancetype)array {
+//% return [[[self alloc] init] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithValue:(TYPE)value {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+//% // the type correct.
+//% return [[(GPB##NAME##Array*)[self alloc] initWithValues:&value count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array {
+//% return [[(GPB##NAME##Array*)[self alloc] initWithValueArray:array] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithCapacity:(NSUInteger)count {
+//% return [[[self alloc] initWithCapacity:count] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% self = [super init];
+//% // No work needed;
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array {
+//% return [self initWithValues:array->_values count:array->_count];
+//%}
+//%
+//%- (instancetype)initWithValues:(const TYPE [])values count:(NSUInteger)count {
+//% self = [self init];
+//% if (self) {
+//% if (count && values) {
+//% _values = reallocf(_values, count * sizeof(TYPE));
+//% if (_values != NULL) {
+//% _capacity = count;
+//% memcpy(_values, values, count * sizeof(TYPE));
+//% _count = count;
+//% } else {
+//% [self release];
+//% [NSException raise:NSMallocException
+//% format:@"Failed to allocate %lu bytes",
+//% (unsigned long)(count * sizeof(TYPE))];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)count {
+//% self = [self initWithValues:NULL count:0];
+//% if (self && count) {
+//% [self internalResizeToCapacity:count];
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPB##NAME##Array allocWithZone:zone] initWithValues:_values count:_count];
+//%}
+//%
+//%ARRAY_IMMUTABLE_CORE(NAME, TYPE, , FORMAT)
+//%
+//%- (TYPE)valueAtIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count)
+//% return _values[index];
+//%}
+//%
+//%ARRAY_MUTABLE_CORE(NAME, TYPE, , FORMAT)
+//%@end
+//%
+
+//
+// Some core macros used for both the simple types and Enums.
+//
+
+//%PDDM-DEFINE ARRAY_IMMUTABLE_CORE(NAME, TYPE, ACCESSOR_NAME, FORMAT)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% free(_values);
+//% [super dealloc];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPB##NAME##Array class]]) {
+//% return NO;
+//% }
+//% GPB##NAME##Array *otherArray = other;
+//% return (_count == otherArray->_count
+//% && memcmp(_values, otherArray->_values, (_count * sizeof(TYPE))) == 0);
+//%}
+//%
+//%- (NSUInteger)hash {
+//% // Follow NSArray's lead, and use the count as the hash.
+//% return _count;
+//%}
+//%
+//%- (NSString *)description {
+//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+//% for (NSUInteger i = 0, count = _count; i < count; ++i) {
+//% if (i == 0) {
+//% [result appendFormat:@"##FORMAT##", _values[i]];
+//% } else {
+//% [result appendFormat:@", ##FORMAT##", _values[i]];
+//% }
+//% }
+//% [result appendFormat:@" }"];
+//% return result;
+//%}
+//%
+//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block {
+//% [self enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+//%}
+//%
+//%- (void)enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)opts
+//% ACCESSOR_NAME$S usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block {
+//% // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+//% BOOL stop = NO;
+//% if ((opts & NSEnumerationReverse) == 0) {
+//% for (NSUInteger i = 0, count = _count; i < count; ++i) {
+//% block(_values[i], i, &stop);
+//% if (stop) break;
+//% }
+//% } else if (_count > 0) {
+//% for (NSUInteger i = _count; i > 0; --i) {
+//% block(_values[i - 1], (i - 1), &stop);
+//% if (stop) break;
+//% }
+//% }
+//%}
+
+//%PDDM-DEFINE MUTATION_HOOK_None()
+//%PDDM-DEFINE MUTATION_METHODS(NAME, TYPE, ACCESSOR_NAME, HOOK_1, HOOK_2)
+//%- (void)add##ACCESSOR_NAME##Value:(TYPE)value {
+//% [self add##ACCESSOR_NAME##Values:&value count:1];
+//%}
+//%
+//%- (void)add##ACCESSOR_NAME##Values:(const TYPE [])values count:(NSUInteger)count {
+//% if (values == NULL || count == 0) return;
+//%MUTATION_HOOK_##HOOK_1() NSUInteger initialCount = _count;
+//% NSUInteger newCount = initialCount + count;
+//%MAYBE_GROW_TO_SET_COUNT(newCount)
+//% memcpy(&_values[initialCount], values, count * sizeof(TYPE));
+//% if (_autocreator) {
+//% GPBAutocreatedArrayModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)insert##ACCESSOR_NAME##Value:(TYPE)value atIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count + 1)
+//%MUTATION_HOOK_##HOOK_2() NSUInteger initialCount = _count;
+//% NSUInteger newCount = initialCount + 1;
+//%MAYBE_GROW_TO_SET_COUNT(newCount)
+//% if (index != initialCount) {
+//% memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(TYPE));
+//% }
+//% _values[index] = value;
+//% if (_autocreator) {
+//% GPBAutocreatedArrayModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)replaceValueAtIndex:(NSUInteger)index with##ACCESSOR_NAME##Value:(TYPE)value {
+//%VALIDATE_RANGE(index, _count)
+//%MUTATION_HOOK_##HOOK_2() _values[index] = value;
+//%}
+
+//%PDDM-DEFINE ARRAY_MUTABLE_CORE(NAME, TYPE, ACCESSOR_NAME, FORMAT)
+//%- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+//% _values = reallocf(_values, newCapacity * sizeof(TYPE));
+//% if (_values == NULL) {
+//% _capacity = 0;
+//% _count = 0;
+//% [NSException raise:NSMallocException
+//% format:@"Failed to allocate %lu bytes",
+//% (unsigned long)(newCapacity * sizeof(TYPE))];
+//% }
+//% _capacity = newCapacity;
+//%}
+//%
+//%MUTATION_METHODS(NAME, TYPE, ACCESSOR_NAME, None, None)
+//%
+//%- (void)add##ACCESSOR_NAME##ValuesFromArray:(GPB##NAME##Array *)array {
+//% [self add##ACCESSOR_NAME##Values:array->_values count:array->_count];
+//%}
+//%
+//%- (void)removeValueAtIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count)
+//% NSUInteger newCount = _count - 1;
+//% if (index != newCount) {
+//% memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(TYPE));
+//% }
+//%SET_COUNT_AND_MAYBE_SHRINK(newCount)
+//%}
+//%
+//%- (void)removeAll {
+//%SET_COUNT_AND_MAYBE_SHRINK(0)
+//%}
+//%
+//%- (void)exchangeValueAtIndex:(NSUInteger)idx1
+//% withValueAtIndex:(NSUInteger)idx2 {
+//%VALIDATE_RANGE(idx1, _count)
+//%VALIDATE_RANGE(idx2, _count)
+//% TYPE temp = _values[idx1];
+//% _values[idx1] = _values[idx2];
+//% _values[idx2] = temp;
+//%}
+//%
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int32, int32_t, %d)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@implementation GPBInt32Array {
+ @package
+ int32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(int32_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBInt32Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBInt32Array *)array {
+ return [[(GPBInt32Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBInt32Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const int32_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Array class]]) {
+ return NO;
+ }
+ GPBInt32Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (int32_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(int32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBInt32Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt32, uint32_t, %u)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32
+
+@implementation GPBUInt32Array {
+ @package
+ uint32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(uint32_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBUInt32Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBUInt32Array *)array {
+ return [[(GPBUInt32Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBUInt32Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const uint32_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(uint32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(uint32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(uint32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Array class]]) {
+ return NO;
+ }
+ GPBUInt32Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(uint32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%u", _values[i]];
+ } else {
+ [result appendFormat:@", %u", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (uint32_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(uint32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(uint32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(uint32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const uint32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(uint32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(uint32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(uint32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBUInt32Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(uint32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ uint32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int64, int64_t, %lld)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64
+
+@implementation GPBInt64Array {
+ @package
+ int64_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(int64_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBInt64Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBInt64Array *)array {
+ return [[(GPBInt64Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBInt64Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const int64_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int64_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int64_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int64_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Array class]]) {
+ return NO;
+ }
+ GPBInt64Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int64_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%lld", _values[i]];
+ } else {
+ [result appendFormat:@", %lld", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (int64_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int64_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int64_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(int64_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int64_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int64_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int64_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int64_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int64_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBInt64Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int64_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int64_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt64, uint64_t, %llu)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64
+
+@implementation GPBUInt64Array {
+ @package
+ uint64_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(uint64_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBUInt64Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBUInt64Array *)array {
+ return [[(GPBUInt64Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBUInt64Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const uint64_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(uint64_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(uint64_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(uint64_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Array class]]) {
+ return NO;
+ }
+ GPBUInt64Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(uint64_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%llu", _values[i]];
+ } else {
+ [result appendFormat:@", %llu", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (uint64_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(uint64_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(uint64_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(uint64_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const uint64_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(uint64_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(uint64_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(uint64_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint64_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBUInt64Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(uint64_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ uint64_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Float, float, %f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Float
+
+@implementation GPBFloatArray {
+ @package
+ float *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(float)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBFloatArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBFloatArray *)array {
+ return [[(GPBFloatArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBFloatArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const float [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(float));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(float));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(float))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBFloatArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBFloatArray class]]) {
+ return NO;
+ }
+ GPBFloatArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(float))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%f", _values[i]];
+ } else {
+ [result appendFormat:@", %f", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (float)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(float));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(float))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(float)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const float [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(float));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(float)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(float));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(float)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBFloatArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(float));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ float temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Double, double, %lf)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Double
+
+@implementation GPBDoubleArray {
+ @package
+ double *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(double)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBDoubleArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBDoubleArray *)array {
+ return [[(GPBDoubleArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBDoubleArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const double [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(double));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(double));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(double))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBDoubleArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBDoubleArray class]]) {
+ return NO;
+ }
+ GPBDoubleArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(double))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%lf", _values[i]];
+ } else {
+ [result appendFormat:@", %lf", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (double)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(double));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(double))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(double)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const double [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(double));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(double)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(double));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(double)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBDoubleArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(double));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ double temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Bool, BOOL, %d)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool
+
+@implementation GPBBoolArray {
+ @package
+ BOOL *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(BOOL)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBBoolArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBBoolArray *)array {
+ return [[(GPBBoolArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBBoolArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const BOOL [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(BOOL));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(BOOL));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(BOOL))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolArray class]]) {
+ return NO;
+ }
+ GPBBoolArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(BOOL))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (BOOL)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(BOOL));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(BOOL))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(BOOL)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const BOOL [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(BOOL));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(BOOL)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(BOOL));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(BOOL)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBBoolArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(BOOL));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ BOOL temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND-END (7 expansions)
+
+#pragma mark - Enum
+
+@implementation GPBEnumArray {
+ @package
+ GPBEnumValidationFunc _validationFunc;
+ int32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)array {
+ return [[[self alloc] initWithValidationFunction:NULL] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)value {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:&value
+ count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBEnumArray *)array {
+ return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count {
+ return [[[self alloc] initWithValidationFunction:func capacity:count] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL];
+}
+
+- (instancetype)initWithValueArray:(GPBEnumArray *)array {
+ return [self initWithValidationFunction:array->_validationFunc
+ rawValues:array->_values
+ count:array->_count];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ self = [super init];
+ if (self) {
+ _validationFunc = (func != NULL ? func : ArrayDefault_IsValidValue);
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])values
+ count:(NSUInteger)count {
+ self = [self initWithValidationFunction:func];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count {
+ self = [self initWithValidationFunction:func];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBEnumArray allocWithZone:zone]
+ initWithValidationFunction:_validationFunc
+ rawValues:_values
+ count:_count];
+}
+
+//%PDDM-EXPAND ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d)
+// This block of code is generated, do not edit it directly.
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBEnumArray class]]) {
+ return NO;
+ }
+ GPBEnumArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateRawValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+//%PDDM-EXPAND-END ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d)
+
+- (int32_t)valueAtIndex:(NSUInteger)index {
+//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
+// This block of code is generated, do not edit it directly.
+
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
+ int32_t result = _values[index];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ return result;
+}
+
+- (int32_t)rawValueAtIndex:(NSUInteger)index {
+//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
+// This block of code is generated, do not edit it directly.
+
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
+ return _values[index];
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ GPBEnumValidationFunc func = _validationFunc;
+ if ((opts & NSEnumerationReverse) == 0) {
+ int32_t *scan = _values;
+ int32_t *end = scan + _count;
+ for (NSUInteger i = 0; scan < end; ++i, ++scan) {
+ int32_t value = *scan;
+ if (!func(value)) {
+ value = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(value, i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ int32_t *end = _values;
+ int32_t *scan = end + (_count - 1);
+ for (NSUInteger i = (_count - 1); scan >= end; --i, --scan) {
+ int32_t value = *scan;
+ if (!func(value)) {
+ value = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(value, i, &stop);
+ if (stop) break;
+ }
+ }
+}
+
+//%PDDM-EXPAND ARRAY_MUTABLE_CORE(Enum, int32_t, Raw, %d)
+// This block of code is generated, do not edit it directly.
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addRawValue:(int32_t)value {
+ [self addRawValues:&value count:1];
+}
+
+- (void)addRawValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertRawValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addRawValuesFromArray:(GPBEnumArray *)array {
+ [self addRawValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+//%PDDM-EXPAND MUTATION_METHODS(Enum, int32_t, , EnumValidationList, EnumValidationOne)
+// This block of code is generated, do not edit it directly.
+
+- (void)addValue:(int32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ GPBEnumValidationFunc func = _validationFunc;
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!func(values[i])) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], values[i]];
+ }
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], value];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], value];
+ }
+ _values[index] = value;
+}
+//%PDDM-EXPAND-END (2 expansions)
+
+//%PDDM-DEFINE MUTATION_HOOK_EnumValidationList()
+//% GPBEnumValidationFunc func = _validationFunc;
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% if (!func(values[i])) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"%@: Attempt to set an unknown enum value (%d)",
+//% [self class], values[i]];
+//% }
+//% }
+//%
+//%PDDM-DEFINE MUTATION_HOOK_EnumValidationOne()
+//% if (!_validationFunc(value)) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"%@: Attempt to set an unknown enum value (%d)",
+//% [self class], value];
+//% }
+//%
+
+@end
+
+#pragma mark - NSArray Subclass
+
+@implementation GPBAutocreatedArray {
+ NSMutableArray *_array;
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_array release];
+ [super dealloc];
+}
+
+#pragma mark Required NSArray overrides
+
+- (NSUInteger)count {
+ return [_array count];
+}
+
+- (id)objectAtIndex:(NSUInteger)idx {
+ return [_array objectAtIndex:idx];
+}
+
+#pragma mark Required NSMutableArray overrides
+
+// Only need to call GPBAutocreatedArrayModified() when adding things since
+// we only autocreate empty arrays.
+
+- (void)insertObject:(id)anObject atIndex:(NSUInteger)idx {
+ if (_array == nil) {
+ _array = [[NSMutableArray alloc] init];
+ }
+ [_array insertObject:anObject atIndex:idx];
+
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)removeObject:(id)anObject {
+ [_array removeObject:anObject];
+}
+
+- (void)removeObjectAtIndex:(NSUInteger)idx {
+ [_array removeObjectAtIndex:idx];
+}
+
+- (void)addObject:(id)anObject {
+ if (_array == nil) {
+ _array = [[NSMutableArray alloc] init];
+ }
+ [_array addObject:anObject];
+
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)removeLastObject {
+ [_array removeLastObject];
+}
+
+- (void)replaceObjectAtIndex:(NSUInteger)idx withObject:(id)anObject {
+ [_array replaceObjectAtIndex:idx withObject:anObject];
+}
+
+#pragma mark Extra things hooked
+
+- (id)copyWithZone:(NSZone *)zone {
+ if (_array == nil) {
+ return [[NSMutableArray allocWithZone:zone] init];
+ }
+ return [_array copyWithZone:zone];
+}
+
+- (id)mutableCopyWithZone:(NSZone *)zone {
+ if (_array == nil) {
+ return [[NSMutableArray allocWithZone:zone] init];
+ }
+ return [_array mutableCopyWithZone:zone];
+}
+
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
+ objects:(id __unsafe_unretained [])buffer
+ count:(NSUInteger)len {
+ return [_array countByEnumeratingWithState:state objects:buffer count:len];
+}
+
+- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
+ [_array enumerateObjectsUsingBlock:block];
+}
+
+- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
+ [_array enumerateObjectsWithOptions:opts usingBlock:block];
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h b/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h
new file mode 100644
index 0000000000..35a4538131
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h
@@ -0,0 +1,130 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBArray.h"
+
+@class GPBMessage;
+
+//%PDDM-DEFINE DECLARE_ARRAY_EXTRAS()
+//%ARRAY_INTERFACE_EXTRAS(Int32, int32_t)
+//%ARRAY_INTERFACE_EXTRAS(UInt32, uint32_t)
+//%ARRAY_INTERFACE_EXTRAS(Int64, int64_t)
+//%ARRAY_INTERFACE_EXTRAS(UInt64, uint64_t)
+//%ARRAY_INTERFACE_EXTRAS(Float, float)
+//%ARRAY_INTERFACE_EXTRAS(Double, double)
+//%ARRAY_INTERFACE_EXTRAS(Bool, BOOL)
+//%ARRAY_INTERFACE_EXTRAS(Enum, int32_t)
+
+//%PDDM-DEFINE ARRAY_INTERFACE_EXTRAS(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%@interface GPB##NAME##Array () {
+//% @package
+//% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+//%}
+//%@end
+//%
+
+//%PDDM-EXPAND DECLARE_ARRAY_EXTRAS()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@interface GPBInt32Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - UInt32
+
+@interface GPBUInt32Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Int64
+
+@interface GPBInt64Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - UInt64
+
+@interface GPBUInt64Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Float
+
+@interface GPBFloatArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Double
+
+@interface GPBDoubleArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Bool
+
+@interface GPBBoolArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Enum
+
+@interface GPBEnumArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+//%PDDM-EXPAND-END DECLARE_ARRAY_EXTRAS()
+
+#pragma mark - NSArray Subclass
+
+@interface GPBAutocreatedArray : NSMutableArray {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
diff --git a/third_party/protobuf/objectivec/GPBBootstrap.h b/third_party/protobuf/objectivec/GPBBootstrap.h
new file mode 100644
index 0000000000..ed53ae7cbc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBBootstrap.h
@@ -0,0 +1,123 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+/**
+ * The Objective C runtime has complete enough info that most protos don’t end
+ * up using this, so leaving it on is no cost or very little cost. If you
+ * happen to see it causing bloat, this is the way to disable it. If you do
+ * need to disable it, try only disabling it for Release builds as having
+ * full TextFormat can be useful for debugging.
+ **/
+#ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+#define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
+#endif
+
+// Used in the generated code to give sizes to enums. int32_t was chosen based
+// on the fact that Protocol Buffers enums are limited to this range.
+#if !__has_feature(objc_fixed_enum)
+ #error All supported Xcode versions should support objc_fixed_enum.
+#endif
+
+// If the headers are imported into Objective-C++, we can run into an issue
+// where the defintion of NS_ENUM (really CF_ENUM) changes based on the C++
+// standard that is in effect. If it isn't C++11 or higher, the definition
+// doesn't allow us to forward declare. We work around this one case by
+// providing a local definition. The default case has to use NS_ENUM for the
+// magic that is Swift bridging of enums.
+#if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
+ #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t
+#else
+ #define GPB_ENUM(X) NS_ENUM(int32_t, X)
+#endif
+
+/**
+ * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
+ *
+ * ```
+ * GPB_ENUM_FWD_DECLARE(Foo_Enum)
+ *
+ * @interface BarClass : NSObject
+ * @property (nonatomic) enum Foo_Enum value;
+ * - (void)bazMethod:(enum Foo_Enum):value;
+ * @end
+ * ```
+ **/
+#define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
+
+/**
+ * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
+ **/
+#if !defined(DEBUG)
+#define GPB_INLINE static __inline__ __attribute__((always_inline))
+#else
+#define GPB_INLINE static __inline__
+#endif
+
+/**
+ * For use in public headers that might need to deal with ARC.
+ **/
+#ifndef GPB_UNSAFE_UNRETAINED
+#if __has_feature(objc_arc)
+#define GPB_UNSAFE_UNRETAINED __unsafe_unretained
+#else
+#define GPB_UNSAFE_UNRETAINED
+#endif
+#endif
+
+// If property name starts with init we need to annotate it to get past ARC.
+// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
+//
+// Meant to be used internally by generated code.
+#define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
+
+// ----------------------------------------------------------------------------
+// These version numbers are all internal to the ObjC Protobuf runtime; they
+// are used to ensure compatibility between the generated sources and the
+// headers being compiled against and/or the version of sources being run
+// against.
+//
+// They are all #defines so the values are captured into every .o file they
+// are used in and to allow comparisons in the preprocessor.
+
+// Current library runtime version.
+// - Gets bumped when the runtime makes changes to the interfaces between the
+// generated code and runtime (things added/removed, etc).
+#define GOOGLE_PROTOBUF_OBJC_VERSION 30002
+
+// Minimum runtime version supported for compiling/running against.
+// - Gets changed when support for the older generated code is dropped.
+#define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
+
+
+// This is a legacy constant now frozen in time for old generated code. If
+// GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
+// this should also change to break code compiled with an old runtime that
+// can't be supported any more.
+#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream.h b/third_party/protobuf/objectivec/GPBCodedInputStream.h
new file mode 100644
index 0000000000..fbe5009c92
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream.h
@@ -0,0 +1,253 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBMessage;
+@class GPBExtensionRegistry;
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+/**
+ * @c GPBCodedInputStream exception name. Exceptions raised from
+ * @c GPBCodedInputStream contain an underlying error in the userInfo dictionary
+ * under the GPBCodedInputStreamUnderlyingErrorKey key.
+ **/
+extern NSString *const GPBCodedInputStreamException;
+
+/** The key under which the underlying NSError from the exception is stored. */
+extern NSString *const GPBCodedInputStreamUnderlyingErrorKey;
+
+/** NSError domain used for @c GPBCodedInputStream errors. */
+extern NSString *const GPBCodedInputStreamErrorDomain;
+
+/**
+ * Error code for NSError with @c GPBCodedInputStreamErrorDomain.
+ **/
+typedef NS_ENUM(NSInteger, GPBCodedInputStreamErrorCode) {
+ /** The size does not fit in the remaining bytes to be read. */
+ GPBCodedInputStreamErrorInvalidSize = -100,
+ /** Attempted to read beyond the subsection limit. */
+ GPBCodedInputStreamErrorSubsectionLimitReached = -101,
+ /** The requested subsection limit is invalid. */
+ GPBCodedInputStreamErrorInvalidSubsectionLimit = -102,
+ /** Invalid tag read. */
+ GPBCodedInputStreamErrorInvalidTag = -103,
+ /** Invalid UTF-8 character in a string. */
+ GPBCodedInputStreamErrorInvalidUTF8 = -104,
+ /** Invalid VarInt read. */
+ GPBCodedInputStreamErrorInvalidVarInt = -105,
+ /** The maximum recursion depth of messages was exceeded. */
+ GPBCodedInputStreamErrorRecursionDepthExceeded = -106,
+};
+
+CF_EXTERN_C_END
+
+/**
+ * Reads and decodes protocol message fields.
+ *
+ * The common uses of protocol buffers shouldn't need to use this class.
+ * @c GPBMessage's provide a @c +parseFromData:error: and
+ * @c +parseFromData:extensionRegistry:error: method that will decode a
+ * message for you.
+ *
+ * @note Subclassing of @c GPBCodedInputStream is NOT supported.
+ **/
+@interface GPBCodedInputStream : NSObject
+
+/**
+ * Creates a new stream wrapping some data.
+ *
+ * @param data The data to wrap inside the stream.
+ *
+ * @return A newly instanced GPBCodedInputStream.
+ **/
++ (instancetype)streamWithData:(NSData *)data;
+
+/**
+ * Initializes a stream wrapping some data.
+ *
+ * @param data The data to wrap inside the stream.
+ *
+ * @return A newly initialized GPBCodedInputStream.
+ **/
+- (instancetype)initWithData:(NSData *)data;
+
+/**
+ * Attempts to read a field tag, returning zero if we have reached EOF.
+ * Protocol message parsers use this to read tags, since a protocol message
+ * may legally end wherever a tag occurs, and zero is not a valid tag number.
+ *
+ * @return The field tag, or zero if EOF was reached.
+ **/
+- (int32_t)readTag;
+
+/**
+ * @return A double read from the stream.
+ **/
+- (double)readDouble;
+/**
+ * @return A float read from the stream.
+ **/
+- (float)readFloat;
+/**
+ * @return A uint64 read from the stream.
+ **/
+- (uint64_t)readUInt64;
+/**
+ * @return A uint32 read from the stream.
+ **/
+- (uint32_t)readUInt32;
+/**
+ * @return An int64 read from the stream.
+ **/
+- (int64_t)readInt64;
+/**
+ * @return An int32 read from the stream.
+ **/
+- (int32_t)readInt32;
+/**
+ * @return A fixed64 read from the stream.
+ **/
+- (uint64_t)readFixed64;
+/**
+ * @return A fixed32 read from the stream.
+ **/
+- (uint32_t)readFixed32;
+/**
+ * @return An enum read from the stream.
+ **/
+- (int32_t)readEnum;
+/**
+ * @return A sfixed32 read from the stream.
+ **/
+- (int32_t)readSFixed32;
+/**
+ * @return A fixed64 read from the stream.
+ **/
+- (int64_t)readSFixed64;
+/**
+ * @return A sint32 read from the stream.
+ **/
+- (int32_t)readSInt32;
+/**
+ * @return A sint64 read from the stream.
+ **/
+- (int64_t)readSInt64;
+/**
+ * @return A boolean read from the stream.
+ **/
+- (BOOL)readBool;
+/**
+ * @return A string read from the stream.
+ **/
+- (NSString *)readString;
+/**
+ * @return Data read from the stream.
+ **/
+- (NSData *)readBytes;
+
+/**
+ * Read an embedded message field value from the stream.
+ *
+ * @param message The message to set fields on as they are read.
+ * @param extensionRegistry An optional extension registry to use to lookup
+ * extensions for message.
+ **/
+- (void)readMessage:(GPBMessage *)message
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+
+/**
+ * Reads and discards a single field, given its tag value.
+ *
+ * @param tag The tag number of the field to skip.
+ *
+ * @return NO if the tag is an endgroup tag (in which case nothing is skipped),
+ * YES in all other cases.
+ **/
+- (BOOL)skipField:(int32_t)tag;
+
+/**
+ * Reads and discards an entire message. This will read either until EOF or
+ * until an endgroup tag, whichever comes first.
+ **/
+- (void)skipMessage;
+
+/**
+ * Check to see if the logical end of the stream has been reached.
+ *
+ * @note This can return NO when there is no more data, but the current parsing
+ * expected more data.
+ *
+ * @return YES if the logical end of the stream has been reached, NO otherwise.
+ **/
+- (BOOL)isAtEnd;
+
+/**
+ * @return The offset into the stream.
+ **/
+- (size_t)position;
+
+/**
+ * Moves the limit to the given byte offset starting at the current location.
+ *
+ * @exception GPBCodedInputStreamException If the requested bytes exceeed the
+ * current limit.
+ *
+ * @param byteLimit The number of bytes to move the limit, offset to the current
+ * location.
+ *
+ * @return The limit offset before moving the new limit.
+ */
+- (size_t)pushLimit:(size_t)byteLimit;
+
+/**
+ * Moves the limit back to the offset as it was before calling pushLimit:.
+ *
+ * @param oldLimit The number of bytes to move the current limit. Usually this
+ * is the value returned by the pushLimit: method.
+ */
+- (void)popLimit:(size_t)oldLimit;
+
+/**
+ * Verifies that the last call to -readTag returned the given tag value. This
+ * is used to verify that a nested group ended with the correct end tag.
+ *
+ * @exception NSParseErrorException If the value does not match the last tag.
+ *
+ * @param expected The tag that was expected.
+ **/
+- (void)checkLastTagWas:(int32_t)expected;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream.m b/third_party/protobuf/objectivec/GPBCodedInputStream.m
new file mode 100644
index 0000000000..eef053534b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream.m
@@ -0,0 +1,538 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "GPBWireFormat.h"
+
+NSString *const GPBCodedInputStreamException =
+ GPBNSStringifySymbol(GPBCodedInputStreamException);
+
+NSString *const GPBCodedInputStreamUnderlyingErrorKey =
+ GPBNSStringifySymbol(GPBCodedInputStreamUnderlyingErrorKey);
+
+NSString *const GPBCodedInputStreamErrorDomain =
+ GPBNSStringifySymbol(GPBCodedInputStreamErrorDomain);
+
+// Matching:
+// https://github.com/google/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/CodedInputStream.java#L62
+// private static final int DEFAULT_RECURSION_LIMIT = 100;
+// https://github.com/google/protobuf/blob/master/src/google/protobuf/io/coded_stream.cc#L86
+// int CodedInputStream::default_recursion_limit_ = 100;
+static const NSUInteger kDefaultRecursionLimit = 100;
+
+static void RaiseException(NSInteger code, NSString *reason) {
+ NSDictionary *errorInfo = nil;
+ if ([reason length]) {
+ errorInfo = @{ GPBErrorReasonKey: reason };
+ }
+ NSError *error = [NSError errorWithDomain:GPBCodedInputStreamErrorDomain
+ code:code
+ userInfo:errorInfo];
+
+ NSDictionary *exceptionInfo =
+ @{ GPBCodedInputStreamUnderlyingErrorKey: error };
+ [[[NSException alloc] initWithName:GPBCodedInputStreamException
+ reason:reason
+ userInfo:exceptionInfo] raise];
+}
+
+static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
+ size_t newSize = state->bufferPos + size;
+ if (newSize > state->bufferSize) {
+ RaiseException(GPBCodedInputStreamErrorInvalidSize, nil);
+ }
+ if (newSize > state->currentLimit) {
+ // Fast forward to end of currentLimit;
+ state->bufferPos = state->currentLimit;
+ RaiseException(GPBCodedInputStreamErrorSubsectionLimitReached, nil);
+ }
+}
+
+static int8_t ReadRawByte(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int8_t));
+ return ((int8_t *)state->bytes)[state->bufferPos++];
+}
+
+static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int32_t));
+ int32_t value = OSReadLittleInt32(state->bytes, state->bufferPos);
+ state->bufferPos += sizeof(int32_t);
+ return value;
+}
+
+static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int64_t));
+ int64_t value = OSReadLittleInt64(state->bytes, state->bufferPos);
+ state->bufferPos += sizeof(int64_t);
+ return value;
+}
+
+static int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
+ int8_t tmp = ReadRawByte(state);
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int32_t result = tmp & 0x7f;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = ReadRawByte(state)) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (ReadRawByte(state) >= 0) {
+ return result;
+ }
+ }
+ RaiseException(GPBCodedInputStreamErrorInvalidVarInt,
+ @"Invalid VarInt32");
+ }
+ }
+ }
+ }
+ return result;
+}
+
+static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
+ int32_t shift = 0;
+ int64_t result = 0;
+ while (shift < 64) {
+ int8_t b = ReadRawByte(state);
+ result |= (int64_t)(b & 0x7F) << shift;
+ if ((b & 0x80) == 0) {
+ return result;
+ }
+ shift += 7;
+ }
+ RaiseException(GPBCodedInputStreamErrorInvalidVarInt, @"Invalid VarInt64");
+ return 0;
+}
+
+static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
+ CheckSize(state, size);
+ state->bufferPos += size;
+}
+
+double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawLittleEndian64(state);
+ return GPBConvertInt64ToDouble(value);
+}
+
+float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawLittleEndian32(state);
+ return GPBConvertInt32ToFloat(value);
+}
+
+uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state) {
+ uint64_t value = ReadRawVarint64(state);
+ return value;
+}
+
+uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state) {
+ uint32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawVarint64(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state) {
+ uint64_t value = ReadRawLittleEndian64(state);
+ return value;
+}
+
+uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state) {
+ uint32_t value = ReadRawLittleEndian32(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawLittleEndian32(state);
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawLittleEndian64(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state) {
+ int32_t value = GPBDecodeZigZag32(ReadRawVarint32(state));
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state) {
+ int64_t value = GPBDecodeZigZag64(ReadRawVarint64(state));
+ return value;
+}
+
+BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state) {
+ return ReadRawVarint32(state) != 0;
+}
+
+int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
+ if (GPBCodedInputStreamIsAtEnd(state)) {
+ state->lastTag = 0;
+ return 0;
+ }
+
+ state->lastTag = ReadRawVarint32(state);
+ if (state->lastTag == 0) {
+ // If we actually read zero, that's not a valid tag.
+ RaiseException(GPBCodedInputStreamErrorInvalidTag,
+ @"A zero tag on the wire is invalid.");
+ }
+ // Tags have to include a valid wireformat, check that also.
+ if (!GPBWireFormatIsValidTag(state->lastTag)) {
+ RaiseException(GPBCodedInputStreamErrorInvalidTag,
+ @"Invalid wireformat in tag.");
+ }
+ return state->lastTag;
+}
+
+NSString *GPBCodedInputStreamReadRetainedString(
+ GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ NSString *result;
+ if (size == 0) {
+ result = @"";
+ } else {
+ CheckSize(state, size);
+ result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
+ length:size
+ encoding:NSUTF8StringEncoding];
+ state->bufferPos += size;
+ if (!result) {
+#ifdef DEBUG
+ // https://developers.google.com/protocol-buffers/docs/proto#scalar
+ NSLog(@"UTF-8 failure, is some field type 'string' when it should be "
+ @"'bytes'?");
+#endif
+ RaiseException(GPBCodedInputStreamErrorInvalidUTF8, nil);
+ }
+ }
+ return result;
+}
+
+NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ if (size < 0) return nil;
+ CheckSize(state, size);
+ NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos
+ length:size];
+ state->bufferPos += size;
+ return result;
+}
+
+NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
+ GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ if (size < 0) return nil;
+ CheckSize(state, size);
+ // Cast is safe because freeWhenDone is NO.
+ NSData *result = [[NSData alloc]
+ initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
+ length:size
+ freeWhenDone:NO];
+ state->bufferPos += size;
+ return result;
+}
+
+size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
+ size_t byteLimit) {
+ byteLimit += state->bufferPos;
+ size_t oldLimit = state->currentLimit;
+ if (byteLimit > oldLimit) {
+ RaiseException(GPBCodedInputStreamErrorInvalidSubsectionLimit, nil);
+ }
+ state->currentLimit = byteLimit;
+ return oldLimit;
+}
+
+void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
+ size_t oldLimit) {
+ state->currentLimit = oldLimit;
+}
+
+size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) {
+ return state->currentLimit - state->bufferPos;
+}
+
+BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) {
+ return (state->bufferPos == state->bufferSize) ||
+ (state->bufferPos == state->currentLimit);
+}
+
+void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
+ int32_t value) {
+ if (state->lastTag != value) {
+ RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read");
+ }
+}
+
+@implementation GPBCodedInputStream
+
++ (instancetype)streamWithData:(NSData *)data {
+ return [[[self alloc] initWithData:data] autorelease];
+}
+
+- (instancetype)initWithData:(NSData *)data {
+ if ((self = [super init])) {
+#ifdef DEBUG
+ NSCAssert([self class] == [GPBCodedInputStream class],
+ @"Subclassing of GPBCodedInputStream is not allowed.");
+#endif
+ buffer_ = [data retain];
+ state_.bytes = (const uint8_t *)[data bytes];
+ state_.bufferSize = [data length];
+ state_.currentLimit = state_.bufferSize;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [buffer_ release];
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (int32_t)readTag {
+ return GPBCodedInputStreamReadTag(&state_);
+}
+
+- (void)checkLastTagWas:(int32_t)value {
+ GPBCodedInputStreamCheckLastTagWas(&state_, value);
+}
+
+- (BOOL)skipField:(int32_t)tag {
+ NSAssert(GPBWireFormatIsValidTag(tag), @"Invalid tag");
+ switch (GPBWireFormatGetTagWireType(tag)) {
+ case GPBWireFormatVarint:
+ GPBCodedInputStreamReadInt32(&state_);
+ return YES;
+ case GPBWireFormatFixed64:
+ SkipRawData(&state_, sizeof(int64_t));
+ return YES;
+ case GPBWireFormatLengthDelimited:
+ SkipRawData(&state_, ReadRawVarint32(&state_));
+ return YES;
+ case GPBWireFormatStartGroup:
+ [self skipMessage];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag),
+ GPBWireFormatEndGroup));
+ return YES;
+ case GPBWireFormatEndGroup:
+ return NO;
+ case GPBWireFormatFixed32:
+ SkipRawData(&state_, sizeof(int32_t));
+ return YES;
+ }
+}
+
+- (void)skipMessage {
+ while (YES) {
+ int32_t tag = GPBCodedInputStreamReadTag(&state_);
+ if (tag == 0 || ![self skipField:tag]) {
+ return;
+ }
+ }
+}
+
+- (BOOL)isAtEnd {
+ return GPBCodedInputStreamIsAtEnd(&state_);
+}
+
+- (size_t)position {
+ return state_.bufferPos;
+}
+
+- (size_t)pushLimit:(size_t)byteLimit {
+ return GPBCodedInputStreamPushLimit(&state_, byteLimit);
+}
+
+- (void)popLimit:(size_t)oldLimit {
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (double)readDouble {
+ return GPBCodedInputStreamReadDouble(&state_);
+}
+
+- (float)readFloat {
+ return GPBCodedInputStreamReadFloat(&state_);
+}
+
+- (uint64_t)readUInt64 {
+ return GPBCodedInputStreamReadUInt64(&state_);
+}
+
+- (int64_t)readInt64 {
+ return GPBCodedInputStreamReadInt64(&state_);
+}
+
+- (int32_t)readInt32 {
+ return GPBCodedInputStreamReadInt32(&state_);
+}
+
+- (uint64_t)readFixed64 {
+ return GPBCodedInputStreamReadFixed64(&state_);
+}
+
+- (uint32_t)readFixed32 {
+ return GPBCodedInputStreamReadFixed32(&state_);
+}
+
+- (BOOL)readBool {
+ return GPBCodedInputStreamReadBool(&state_);
+}
+
+- (NSString *)readString {
+ return [GPBCodedInputStreamReadRetainedString(&state_) autorelease];
+}
+
+- (void)readGroup:(int32_t)fieldNumber
+ message:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
+ --state_.recursionDepth;
+}
+
+- (void)readUnknownGroup:(int32_t)fieldNumber
+ message:(GPBUnknownFieldSet *)message {
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
+ --state_.recursionDepth;
+}
+
+- (void)readMessage:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ int32_t length = ReadRawVarint32(&state_);
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
+ GPBCodedInputStreamCheckLastTagWas(&state_, 0);
+ --state_.recursionDepth;
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (void)readMapEntry:(id)mapDictionary
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ field:(GPBFieldDescriptor *)field
+ parentMessage:(GPBMessage *)parentMessage {
+ int32_t length = ReadRawVarint32(&state_);
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
+ ++state_.recursionDepth;
+ GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field,
+ parentMessage);
+ GPBCodedInputStreamCheckLastTagWas(&state_, 0);
+ --state_.recursionDepth;
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (NSData *)readBytes {
+ return [GPBCodedInputStreamReadRetainedBytes(&state_) autorelease];
+}
+
+- (uint32_t)readUInt32 {
+ return GPBCodedInputStreamReadUInt32(&state_);
+}
+
+- (int32_t)readEnum {
+ return GPBCodedInputStreamReadEnum(&state_);
+}
+
+- (int32_t)readSFixed32 {
+ return GPBCodedInputStreamReadSFixed32(&state_);
+}
+
+- (int64_t)readSFixed64 {
+ return GPBCodedInputStreamReadSFixed64(&state_);
+}
+
+- (int32_t)readSInt32 {
+ return GPBCodedInputStreamReadSInt32(&state_);
+}
+
+- (int64_t)readSInt64 {
+ return GPBCodedInputStreamReadSInt64(&state_);
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h b/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h
new file mode 100644
index 0000000000..90bd0c92ce
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h
@@ -0,0 +1,114 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBCodedInputStream.h"
+
+#import <libkern/OSAtomic.h>
+
+@class GPBUnknownFieldSet;
+@class GPBFieldDescriptor;
+
+typedef struct GPBCodedInputStreamState {
+ const uint8_t *bytes;
+ size_t bufferSize;
+ size_t bufferPos;
+
+ // For parsing subsections of an input stream you can put a hard limit on
+ // how much should be read. Normally the limit is the end of the stream,
+ // but you can adjust it to anywhere, and if you hit it you will be at the
+ // end of the stream, until you adjust the limit.
+ size_t currentLimit;
+ int32_t lastTag;
+ NSUInteger recursionDepth;
+} GPBCodedInputStreamState;
+
+@interface GPBCodedInputStream () {
+ @package
+ struct GPBCodedInputStreamState state_;
+ NSData *buffer_;
+}
+
+// Group support is deprecated, so we hide this interface from users, but
+// support for older data.
+- (void)readGroup:(int32_t)fieldNumber
+ message:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+
+// Reads a group field value from the stream and merges it into the given
+// UnknownFieldSet.
+- (void)readUnknownGroup:(int32_t)fieldNumber
+ message:(GPBUnknownFieldSet *)message;
+
+// Reads a map entry.
+- (void)readMapEntry:(id)mapDictionary
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ field:(GPBFieldDescriptor *)field
+ parentMessage:(GPBMessage *)parentMessage;
+@end
+
+CF_EXTERN_C_BEGIN
+
+int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state);
+
+double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state);
+float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state);
+uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state);
+uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state);
+uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state);
+uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
+BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
+NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
+ __attribute((ns_returns_retained));
+NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
+ __attribute((ns_returns_retained));
+NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
+ GPBCodedInputStreamState *state) __attribute((ns_returns_retained));
+
+size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
+ size_t byteLimit);
+void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
+ size_t oldLimit);
+size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state);
+BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state);
+void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
+ int32_t value);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream.h b/third_party/protobuf/objectivec/GPBCodedOutputStream.h
new file mode 100644
index 0000000000..d6fff3dbb6
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream.h
@@ -0,0 +1,739 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+#import "GPBWireFormat.h"
+
+@class GPBBoolArray;
+@class GPBDoubleArray;
+@class GPBEnumArray;
+@class GPBFloatArray;
+@class GPBMessage;
+@class GPBInt32Array;
+@class GPBInt64Array;
+@class GPBUInt32Array;
+@class GPBUInt64Array;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Writes out protocol message fields.
+ *
+ * The common uses of protocol buffers shouldn't need to use this class.
+ * GPBMessage's provide a -data method that will serialize the message for you.
+ *
+ * @note Subclassing of GPBCodedOutputStream is NOT supported.
+ **/
+@interface GPBCodedOutputStream : NSObject
+
+/**
+ * Creates a stream to fill in the given data. Data must be sized to fit or
+ * an error will be raised when out of space.
+ *
+ * @param data The data where the stream will be written to.
+ *
+ * @return A newly instanced GPBCodedOutputStream.
+ **/
++ (instancetype)streamWithData:(NSMutableData *)data;
+
+/**
+ * Creates a stream to write into the given NSOutputStream.
+ *
+ * @param output The output stream where the stream will be written to.
+ *
+ * @return A newly instanced GPBCodedOutputStream.
+ **/
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output;
+
+/**
+ * Initializes a stream to fill in the given data. Data must be sized to fit
+ * or an error will be raised when out of space.
+ *
+ * @param data The data where the stream will be written to.
+ *
+ * @return A newly initialized GPBCodedOutputStream.
+ **/
+- (instancetype)initWithData:(NSMutableData *)data;
+
+/**
+ * Initializes a stream to write into the given @c NSOutputStream.
+ *
+ * @param output The output stream where the stream will be written to.
+ *
+ * @return A newly initialized GPBCodedOutputStream.
+ **/
+- (instancetype)initWithOutputStream:(NSOutputStream *)output;
+
+/**
+ * Flush any buffered data out.
+ **/
+- (void)flush;
+
+/**
+ * Write the raw byte out.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawByte:(uint8_t)value;
+
+/**
+ * Write the tag for the given field number and wire format.
+ *
+ * @param fieldNumber The field number.
+ * @param format The wire format the data for the field will be in.
+ **/
+- (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format;
+
+/**
+ * Write a 32bit value out in little endian format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawLittleEndian32:(int32_t)value;
+/**
+ * Write a 64bit value out in little endian format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawLittleEndian64:(int64_t)value;
+
+/**
+ * Write a 32bit value out in varint format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarint32:(int32_t)value;
+/**
+ * Write a 64bit value out in varint format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarint64:(int64_t)value;
+
+/**
+ * Write a size_t out as a 32bit varint value.
+ *
+ * @note This will truncate 64 bit values to 32.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarintSizeTAs32:(size_t)value;
+
+/**
+ * Writes the contents of an NSData out.
+ *
+ * @param data The data to write out.
+ **/
+- (void)writeRawData:(NSData *)data;
+/**
+ * Writes out the given data.
+ *
+ * @param data The data blob to write out.
+ * @param offset The offset into the blob to start writing out.
+ * @param length The number of bytes from the blob to write out.
+ **/
+- (void)writeRawPtr:(const void *)data
+ offset:(size_t)offset
+ length:(size_t)length;
+
+//%PDDM-EXPAND _WRITE_DECLS()
+// This block of code is generated, do not edit it directly.
+
+/**
+ * Write a double for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeDouble:(int32_t)fieldNumber value:(double)value;
+/**
+ * Write a packed array of double for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeDoubleArray:(int32_t)fieldNumber
+ values:(GPBDoubleArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a double without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeDoubleNoTag:(double)value;
+
+/**
+ * Write a float for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFloat:(int32_t)fieldNumber value:(float)value;
+/**
+ * Write a packed array of float for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFloatArray:(int32_t)fieldNumber
+ values:(GPBFloatArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a float without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFloatNoTag:(float)value;
+
+/**
+ * Write a uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value;
+/**
+ * Write a packed array of uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeUInt64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeUInt64NoTag:(uint64_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeInt64NoTag:(int64_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeInt32NoTag:(int32_t)value;
+
+/**
+ * Write a uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value;
+/**
+ * Write a packed array of uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeUInt32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeUInt32NoTag:(uint32_t)value;
+
+/**
+ * Write a uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value;
+/**
+ * Write a packed array of uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFixed64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFixed64NoTag:(uint64_t)value;
+
+/**
+ * Write a uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value;
+/**
+ * Write a packed array of uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFixed32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFixed32NoTag:(uint32_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSInt32NoTag:(int32_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSInt64NoTag:(int64_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSFixed64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed64NoTag:(int64_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSFixed32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed32NoTag:(int32_t)value;
+
+/**
+ * Write a BOOL for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeBool:(int32_t)fieldNumber value:(BOOL)value;
+/**
+ * Write a packed array of BOOL for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeBoolArray:(int32_t)fieldNumber
+ values:(GPBBoolArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a BOOL without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeBoolNoTag:(BOOL)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeEnumArray:(int32_t)fieldNumber
+ values:(GPBEnumArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeEnumNoTag:(int32_t)value;
+
+/**
+ * Write a NSString for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeString:(int32_t)fieldNumber value:(NSString *)value;
+/**
+ * Write an array of NSString for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray<NSString*> *)values;
+/**
+ * Write a NSString without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeStringNoTag:(NSString *)value;
+
+/**
+ * Write a GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value;
+/**
+ * Write an array of GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values;
+/**
+ * Write a GPBMessage without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeMessageNoTag:(GPBMessage *)value;
+
+/**
+ * Write a NSData for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value;
+/**
+ * Write an array of NSData for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray<NSData*> *)values;
+/**
+ * Write a NSData without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeBytesNoTag:(NSData *)value;
+
+/**
+ * Write a GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeGroup:(int32_t)fieldNumber
+ value:(GPBMessage *)value;
+/**
+ * Write an array of GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values;
+/**
+ * Write a GPBMessage without any tag (but does write the endGroup tag).
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeGroupNoTag:(int32_t)fieldNumber
+ value:(GPBMessage *)value;
+
+/**
+ * Write a GPBUnknownFieldSet for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUnknownGroup:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value;
+/**
+ * Write an array of GPBUnknownFieldSet for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray<GPBUnknownFieldSet*> *)values;
+/**
+ * Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag).
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value;
+
+//%PDDM-EXPAND-END _WRITE_DECLS()
+
+/**
+Write a MessageSet extension field to the stream. For historical reasons,
+the wire format differs from normal fields.
+
+@param fieldNumber The extension field number to write out.
+@param value The message from where to get the extension.
+*/
+- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value;
+
+/**
+Write an unparsed MessageSet extension field to the stream. For historical
+reasons, the wire format differs from normal fields.
+
+@param fieldNumber The extension field number to write out.
+@param value The raw message from where to get the extension.
+*/
+- (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+// Write methods for types that can be in packed arrays.
+//%PDDM-DEFINE _WRITE_PACKABLE_DECLS(NAME, ARRAY_TYPE, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE)value;
+//%/**
+//% * Write a packed array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% * @param tag The tag assigned to the values.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber
+//% NAME$S values:(GPB##ARRAY_TYPE##Array *)values
+//% NAME$S tag:(uint32_t)tag;
+//%/**
+//% * Write a TYPE without any tag.
+//% *
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(TYPE)value;
+//%
+// Write methods for types that aren't in packed arrays.
+//%PDDM-DEFINE _WRITE_UNPACKABLE_DECLS(NAME, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE *)value;
+//%/**
+//% * Write an array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values;
+//%/**
+//% * Write a TYPE without any tag.
+//% *
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(TYPE *)value;
+//%
+// Special write methods for Groups.
+//%PDDM-DEFINE _WRITE_GROUP_DECLS(NAME, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber
+//% NAME$S value:(TYPE *)value;
+//%/**
+//% * Write an array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values;
+//%/**
+//% * Write a TYPE without any tag (but does write the endGroup tag).
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(int32_t)fieldNumber
+//% NAME$S value:(TYPE *)value;
+//%
+
+// One macro to hide it all up above.
+//%PDDM-DEFINE _WRITE_DECLS()
+//%_WRITE_PACKABLE_DECLS(Double, Double, double)
+//%_WRITE_PACKABLE_DECLS(Float, Float, float)
+//%_WRITE_PACKABLE_DECLS(UInt64, UInt64, uint64_t)
+//%_WRITE_PACKABLE_DECLS(Int64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(Int32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(UInt32, UInt32, uint32_t)
+//%_WRITE_PACKABLE_DECLS(Fixed64, UInt64, uint64_t)
+//%_WRITE_PACKABLE_DECLS(Fixed32, UInt32, uint32_t)
+//%_WRITE_PACKABLE_DECLS(SInt32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(SInt64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(SFixed64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(SFixed32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(Bool, Bool, BOOL)
+//%_WRITE_PACKABLE_DECLS(Enum, Enum, int32_t)
+//%_WRITE_UNPACKABLE_DECLS(String, NSString)
+//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage)
+//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData)
+//%_WRITE_GROUP_DECLS(Group, GPBMessage)
+//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet)
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream.m b/third_party/protobuf/objectivec/GPBCodedOutputStream.m
new file mode 100644
index 0000000000..7c3ab44715
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream.m
@@ -0,0 +1,1202 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedOutputStream_PackagePrivate.h"
+
+#import <mach/vm_param.h>
+
+#import "GPBArray.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// Structure for containing state of a GPBCodedInputStream. Brought out into
+// a struct so that we can inline several common functions instead of dealing
+// with overhead of ObjC dispatch.
+typedef struct GPBOutputBufferState {
+ uint8_t *bytes;
+ size_t size;
+ size_t position;
+ NSOutputStream *output;
+} GPBOutputBufferState;
+
+@implementation GPBCodedOutputStream {
+ GPBOutputBufferState state_;
+ NSMutableData *buffer_;
+}
+
+static const int32_t LITTLE_ENDIAN_32_SIZE = sizeof(uint32_t);
+static const int32_t LITTLE_ENDIAN_64_SIZE = sizeof(uint64_t);
+
+// Internal helper that writes the current buffer to the output. The
+// buffer position is reset to its initial value when this returns.
+static void GPBRefreshBuffer(GPBOutputBufferState *state) {
+ if (state->output == nil) {
+ // We're writing to a single buffer.
+ [NSException raise:@"OutOfSpace" format:@""];
+ }
+ if (state->position != 0) {
+ NSInteger written =
+ [state->output write:state->bytes maxLength:state->position];
+ if (written != (NSInteger)state->position) {
+ [NSException raise:@"WriteFailed" format:@""];
+ }
+ state->position = 0;
+ }
+}
+
+static void GPBWriteRawByte(GPBOutputBufferState *state, uint8_t value) {
+ if (state->position == state->size) {
+ GPBRefreshBuffer(state);
+ }
+ state->bytes[state->position++] = value;
+}
+
+static void GPBWriteRawVarint32(GPBOutputBufferState *state, int32_t value) {
+ while (YES) {
+ if ((value & ~0x7F) == 0) {
+ uint8_t val = (uint8_t)value;
+ GPBWriteRawByte(state, val);
+ return;
+ } else {
+ GPBWriteRawByte(state, (value & 0x7F) | 0x80);
+ value = GPBLogicalRightShift32(value, 7);
+ }
+ }
+}
+
+static void GPBWriteRawVarint64(GPBOutputBufferState *state, int64_t value) {
+ while (YES) {
+ if ((value & ~0x7FL) == 0) {
+ uint8_t val = (uint8_t)value;
+ GPBWriteRawByte(state, val);
+ return;
+ } else {
+ GPBWriteRawByte(state, ((int32_t)value & 0x7F) | 0x80);
+ value = GPBLogicalRightShift64(value, 7);
+ }
+ }
+}
+
+static void GPBWriteInt32NoTag(GPBOutputBufferState *state, int32_t value) {
+ if (value >= 0) {
+ GPBWriteRawVarint32(state, value);
+ } else {
+ // Must sign-extend
+ GPBWriteRawVarint64(state, value);
+ }
+}
+
+static void GPBWriteUInt32(GPBOutputBufferState *state, int32_t fieldNumber,
+ uint32_t value) {
+ GPBWriteTagWithFormat(state, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(state, value);
+}
+
+static void GPBWriteTagWithFormat(GPBOutputBufferState *state,
+ uint32_t fieldNumber, GPBWireFormat format) {
+ GPBWriteRawVarint32(state, GPBWireFormatMakeTag(fieldNumber, format));
+}
+
+static void GPBWriteRawLittleEndian32(GPBOutputBufferState *state,
+ int32_t value) {
+ GPBWriteRawByte(state, (value)&0xFF);
+ GPBWriteRawByte(state, (value >> 8) & 0xFF);
+ GPBWriteRawByte(state, (value >> 16) & 0xFF);
+ GPBWriteRawByte(state, (value >> 24) & 0xFF);
+}
+
+static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state,
+ int64_t value) {
+ GPBWriteRawByte(state, (int32_t)(value)&0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 8) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 16) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 24) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 32) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 40) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 48) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 56) & 0xFF);
+}
+
+- (void)dealloc {
+ [self flush];
+ [state_.output close];
+ [state_.output release];
+ [buffer_ release];
+
+ [super dealloc];
+}
+
+- (instancetype)initWithOutputStream:(NSOutputStream *)output {
+ NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE];
+ return [self initWithOutputStream:output data:data];
+}
+
+- (instancetype)initWithData:(NSMutableData *)data {
+ return [self initWithOutputStream:nil data:data];
+}
+
+// This initializer isn't exposed, but it is the designated initializer.
+// Setting OutputStream and NSData is to control the buffering behavior/size
+// of the work, but that is more obvious via the bufferSize: version.
+- (instancetype)initWithOutputStream:(NSOutputStream *)output
+ data:(NSMutableData *)data {
+ if ((self = [super init])) {
+ buffer_ = [data retain];
+ [output open];
+ state_.bytes = [data mutableBytes];
+ state_.size = [data length];
+ state_.output = [output retain];
+ }
+ return self;
+}
+
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output {
+ NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE];
+ return [[[self alloc] initWithOutputStream:output
+ data:data] autorelease];
+}
+
++ (instancetype)streamWithData:(NSMutableData *)data {
+ return [[[self alloc] initWithData:data] autorelease];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (void)writeDoubleNoTag:(double)value {
+ GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value));
+}
+
+- (void)writeDouble:(int32_t)fieldNumber value:(double)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value));
+}
+
+- (void)writeFloatNoTag:(float)value {
+ GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value));
+}
+
+- (void)writeFloat:(int32_t)fieldNumber value:(float)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value));
+}
+
+- (void)writeUInt64NoTag:(uint64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt64NoTag:(int64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt32NoTag:(int32_t)value {
+ GPBWriteInt32NoTag(&state_, value);
+}
+
+- (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteInt32NoTag(&state_, value);
+}
+
+- (void)writeFixed64NoTag:(uint64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeFixed32NoTag:(uint32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeBoolNoTag:(BOOL)value {
+ GPBWriteRawByte(&state_, (value ? 1 : 0));
+}
+
+- (void)writeBool:(int32_t)fieldNumber value:(BOOL)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawByte(&state_, (value ? 1 : 0));
+}
+
+- (void)writeStringNoTag:(const NSString *)value {
+ size_t length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ GPBWriteRawVarint32(&state_, (int32_t)length);
+ if (length == 0) {
+ return;
+ }
+
+ const char *quickString =
+ CFStringGetCStringPtr((CFStringRef)value, kCFStringEncodingUTF8);
+
+ // Fast path: Most strings are short, if the buffer already has space,
+ // add to it directly.
+ NSUInteger bufferBytesLeft = state_.size - state_.position;
+ if (bufferBytesLeft >= length) {
+ NSUInteger usedBufferLength = 0;
+ BOOL result;
+ if (quickString != NULL) {
+ memcpy(state_.bytes + state_.position, quickString, length);
+ usedBufferLength = length;
+ result = YES;
+ } else {
+ result = [value getBytes:state_.bytes + state_.position
+ maxLength:bufferBytesLeft
+ usedLength:&usedBufferLength
+ encoding:NSUTF8StringEncoding
+ options:(NSStringEncodingConversionOptions)0
+ range:NSMakeRange(0, [value length])
+ remainingRange:NULL];
+ }
+ if (result) {
+ NSAssert2((usedBufferLength == length),
+ @"Our UTF8 calc was wrong? %tu vs %zd", usedBufferLength,
+ length);
+ state_.position += usedBufferLength;
+ return;
+ }
+ } else if (quickString != NULL) {
+ [self writeRawPtr:quickString offset:0 length:length];
+ } else {
+ // Slow path: just get it as data and write it out.
+ NSData *utf8Data = [value dataUsingEncoding:NSUTF8StringEncoding];
+ NSAssert2(([utf8Data length] == length),
+ @"Strings UTF8 length was wrong? %tu vs %zd", [utf8Data length],
+ length);
+ [self writeRawData:utf8Data];
+ }
+}
+
+- (void)writeString:(int32_t)fieldNumber value:(NSString *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeStringNoTag:value];
+}
+
+- (void)writeGroupNoTag:(int32_t)fieldNumber value:(GPBMessage *)value {
+ [value writeToCodedOutputStream:self];
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
+}
+
+- (void)writeGroup:(int32_t)fieldNumber value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup);
+ [self writeGroupNoTag:fieldNumber value:value];
+}
+
+- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
+ value:(const GPBUnknownFieldSet *)value {
+ [value writeToCodedOutputStream:self];
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
+}
+
+- (void)writeUnknownGroup:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup);
+ [self writeUnknownGroupNoTag:fieldNumber value:value];
+}
+
+- (void)writeMessageNoTag:(GPBMessage *)value {
+ GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]);
+ [value writeToCodedOutputStream:self];
+}
+
+- (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeMessageNoTag:value];
+}
+
+- (void)writeBytesNoTag:(NSData *)value {
+ GPBWriteRawVarint32(&state_, (int32_t)[value length]);
+ [self writeRawData:value];
+}
+
+- (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeBytesNoTag:value];
+}
+
+- (void)writeUInt32NoTag:(uint32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value {
+ GPBWriteUInt32(&state_, fieldNumber, value);
+}
+
+- (void)writeEnumNoTag:(int32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeSFixed32NoTag:(int32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeSFixed64NoTag:(int64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeSInt32NoTag:(int32_t)value {
+ GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value));
+}
+
+- (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value));
+}
+
+- (void)writeSInt64NoTag:(int64_t)value {
+ GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value));
+}
+
+- (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value));
+}
+
+//%PDDM-DEFINE WRITE_PACKABLE_DEFNS(NAME, ARRAY_TYPE, TYPE, ACCESSOR_NAME)
+//%- (void)write##NAME##Array:(int32_t)fieldNumber
+//% NAME$S values:(GPB##ARRAY_TYPE##Array *)values
+//% NAME$S tag:(uint32_t)tag {
+//% if (tag != 0) {
+//% if (values.count == 0) return;
+//% __block size_t dataSize = 0;
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% dataSize += GPBCompute##NAME##SizeNoTag(value);
+//% }];
+//% GPBWriteRawVarint32(&state_, tag);
+//% GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% [self write##NAME##NoTag:value];
+//% }];
+//% } else {
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% [self write##NAME:fieldNumber value:value];
+//% }];
+//% }
+//%}
+//%
+//%PDDM-DEFINE WRITE_UNPACKABLE_DEFNS(NAME, TYPE)
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray *)values {
+//% for (TYPE *value in values) {
+//% [self write##NAME:fieldNumber value:value];
+//% }
+//%}
+//%
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Double, Double, double, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeDoubleArray:(int32_t)fieldNumber
+ values:(GPBDoubleArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeDoubleSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeDoubleNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeDouble:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Float, Float, float, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFloatArray:(int32_t)fieldNumber
+ values:(GPBFloatArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFloatSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFloatNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFloat:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt64, UInt64, uint64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUInt64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeUInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt32, UInt32, uint32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUInt32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeUInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed64, UInt64, uint64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFixed64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFixed64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed32, UInt32, uint32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFixed32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFixed32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSFixed64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSFixed64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSFixed32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSFixed32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Bool, Bool, BOOL, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeBoolArray:(int32_t)fieldNumber
+ values:(GPBBoolArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeBoolSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeBoolNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeBool:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Enum, Enum, int32_t, Raw)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeEnumArray:(int32_t)fieldNumber
+ values:(GPBEnumArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeEnumSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeEnumNoTag:value];
+ }];
+ } else {
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeEnum:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(String, NSString)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (NSString *value in values) {
+ [self writeString:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Message, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBMessage *value in values) {
+ [self writeMessage:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Bytes, NSData)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (NSData *value in values) {
+ [self writeBytes:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Group, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBMessage *value in values) {
+ [self writeGroup:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBUnknownFieldSet *value in values) {
+ [self writeUnknownGroup:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND-END (19 expansions)
+
+- (void)writeMessageSetExtension:(int32_t)fieldNumber
+ value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatStartGroup);
+ GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber);
+ [self writeMessage:GPBWireFormatMessageSetMessage value:value];
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatEndGroup);
+}
+
+- (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value {
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatStartGroup);
+ GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber);
+ [self writeBytes:GPBWireFormatMessageSetMessage value:value];
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatEndGroup);
+}
+
+- (void)flush {
+ if (state_.output != nil) {
+ GPBRefreshBuffer(&state_);
+ }
+}
+
+- (void)writeRawByte:(uint8_t)value {
+ GPBWriteRawByte(&state_, value);
+}
+
+- (void)writeRawData:(const NSData *)data {
+ [self writeRawPtr:[data bytes] offset:0 length:[data length]];
+}
+
+- (void)writeRawPtr:(const void *)value
+ offset:(size_t)offset
+ length:(size_t)length {
+ if (value == nil || length == 0) {
+ return;
+ }
+
+ NSUInteger bufferLength = state_.size;
+ NSUInteger bufferBytesLeft = bufferLength - state_.position;
+ if (bufferBytesLeft >= length) {
+ // We have room in the current buffer.
+ memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, length);
+ state_.position += length;
+ } else {
+ // Write extends past current buffer. Fill the rest of this buffer and
+ // flush.
+ size_t bytesWritten = bufferBytesLeft;
+ memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset,
+ bytesWritten);
+ offset += bytesWritten;
+ length -= bytesWritten;
+ state_.position = bufferLength;
+ GPBRefreshBuffer(&state_);
+ bufferLength = state_.size;
+
+ // Now deal with the rest.
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ if (length <= bufferLength) {
+ // Fits in new buffer.
+ memcpy(state_.bytes, ((uint8_t *)value) + offset, length);
+ state_.position = length;
+ } else {
+ // Write is very big. Let's do it all at once.
+ [state_.output write:((uint8_t *)value) + offset maxLength:length];
+ }
+ }
+}
+
+- (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format {
+ GPBWriteTagWithFormat(&state_, fieldNumber, format);
+}
+
+- (void)writeRawVarint32:(int32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeRawVarintSizeTAs32:(size_t)value {
+ // Note the truncation.
+ GPBWriteRawVarint32(&state_, (int32_t)value);
+}
+
+- (void)writeRawVarint64:(int64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeRawLittleEndian32:(int32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeRawLittleEndian64:(int64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+#pragma clang diagnostic pop
+
+@end
+
+size_t GPBComputeDoubleSizeNoTag(Float64 value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeFloatSizeNoTag(Float32 value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeUInt64SizeNoTag(uint64_t value) {
+ return GPBComputeRawVarint64Size(value);
+}
+
+size_t GPBComputeInt64SizeNoTag(int64_t value) {
+ return GPBComputeRawVarint64Size(value);
+}
+
+size_t GPBComputeInt32SizeNoTag(int32_t value) {
+ if (value >= 0) {
+ return GPBComputeRawVarint32Size(value);
+ } else {
+ // Must sign-extend.
+ return 10;
+ }
+}
+
+size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) {
+ return GPBComputeInt32SizeNoTag((int32_t)value);
+}
+
+size_t GPBComputeFixed64SizeNoTag(uint64_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeFixed32SizeNoTag(uint32_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeBoolSizeNoTag(BOOL value) {
+#pragma unused(value)
+ return 1;
+}
+
+size_t GPBComputeStringSizeNoTag(NSString *value) {
+ NSUInteger length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ return GPBComputeRawVarint32SizeForInteger(length) + length;
+}
+
+size_t GPBComputeGroupSizeNoTag(GPBMessage *value) {
+ return [value serializedSize];
+}
+
+size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) {
+ return value.serializedSize;
+}
+
+size_t GPBComputeMessageSizeNoTag(GPBMessage *value) {
+ size_t size = [value serializedSize];
+ return GPBComputeRawVarint32SizeForInteger(size) + size;
+}
+
+size_t GPBComputeBytesSizeNoTag(NSData *value) {
+ NSUInteger valueLength = [value length];
+ return GPBComputeRawVarint32SizeForInteger(valueLength) + valueLength;
+}
+
+size_t GPBComputeUInt32SizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(value);
+}
+
+size_t GPBComputeEnumSizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(value);
+}
+
+size_t GPBComputeSFixed32SizeNoTag(int32_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeSFixed64SizeNoTag(int64_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeSInt32SizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(GPBEncodeZigZag32(value));
+}
+
+size_t GPBComputeSInt64SizeNoTag(int64_t value) {
+ return GPBComputeRawVarint64Size(GPBEncodeZigZag64(value));
+}
+
+size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeDoubleSizeNoTag(value);
+}
+
+size_t GPBComputeFloatSize(int32_t fieldNumber, float value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFloatSizeNoTag(value);
+}
+
+size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeUInt64SizeNoTag(value);
+}
+
+size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeInt64SizeNoTag(value);
+}
+
+size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeInt32SizeNoTag(value);
+}
+
+size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFixed64SizeNoTag(value);
+}
+
+size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFixed32SizeNoTag(value);
+}
+
+size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeBoolSizeNoTag(value);
+}
+
+size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeStringSizeNoTag(value);
+}
+
+size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) {
+ return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value);
+}
+
+size_t GPBComputeUnknownGroupSize(int32_t fieldNumber,
+ GPBUnknownFieldSet *value) {
+ return GPBComputeTagSize(fieldNumber) * 2 +
+ GPBComputeUnknownGroupSizeNoTag(value);
+}
+
+size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value);
+}
+
+size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeBytesSizeNoTag(value);
+}
+
+size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeUInt32SizeNoTag(value);
+}
+
+size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeEnumSizeNoTag(value);
+}
+
+size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed32SizeNoTag(value);
+}
+
+size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed64SizeNoTag(value);
+}
+
+size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSInt32SizeNoTag(value);
+}
+
+size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) +
+ GPBComputeRawVarint64Size(GPBEncodeZigZag64(value));
+}
+
+size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber,
+ GPBMessage *value) {
+ return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 +
+ GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) +
+ GPBComputeMessageSize(GPBWireFormatMessageSetMessage, value);
+}
+
+size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber,
+ NSData *value) {
+ return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 +
+ GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) +
+ GPBComputeBytesSize(GPBWireFormatMessageSetMessage, value);
+}
+
+size_t GPBComputeTagSize(int32_t fieldNumber) {
+ return GPBComputeRawVarint32Size(
+ GPBWireFormatMakeTag(fieldNumber, GPBWireFormatVarint));
+}
+
+size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) {
+ size_t result = GPBComputeTagSize(field_number);
+ if (dataType == GPBDataTypeGroup) {
+ // Groups have both a start and an end tag.
+ return result * 2;
+ } else {
+ return result;
+ }
+}
+
+size_t GPBComputeRawVarint32Size(int32_t value) {
+ // value is treated as unsigned, so it won't be sign-extended if negative.
+ if ((value & (0xffffffff << 7)) == 0) return 1;
+ if ((value & (0xffffffff << 14)) == 0) return 2;
+ if ((value & (0xffffffff << 21)) == 0) return 3;
+ if ((value & (0xffffffff << 28)) == 0) return 4;
+ return 5;
+}
+
+size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) {
+ // Note the truncation.
+ return GPBComputeRawVarint32Size((int32_t)value);
+}
+
+size_t GPBComputeRawVarint64Size(int64_t value) {
+ if ((value & (0xffffffffffffffffL << 7)) == 0) return 1;
+ if ((value & (0xffffffffffffffffL << 14)) == 0) return 2;
+ if ((value & (0xffffffffffffffffL << 21)) == 0) return 3;
+ if ((value & (0xffffffffffffffffL << 28)) == 0) return 4;
+ if ((value & (0xffffffffffffffffL << 35)) == 0) return 5;
+ if ((value & (0xffffffffffffffffL << 42)) == 0) return 6;
+ if ((value & (0xffffffffffffffffL << 49)) == 0) return 7;
+ if ((value & (0xffffffffffffffffL << 56)) == 0) return 8;
+ if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
+ return 10;
+}
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h b/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h
new file mode 100644
index 0000000000..2e7bb4c4a2
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h
@@ -0,0 +1,126 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedOutputStream.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+size_t GPBComputeDoubleSize(int32_t fieldNumber, double value)
+ __attribute__((const));
+size_t GPBComputeFloatSize(int32_t fieldNumber, float value)
+ __attribute__((const));
+size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value)
+ __attribute__((const));
+size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value)
+ __attribute__((const));
+size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value)
+ __attribute__((const));
+size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value)
+ __attribute__((const));
+size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value)
+ __attribute__((const));
+size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+size_t GPBComputeUnknownGroupSize(int32_t fieldNumber,
+ GPBUnknownFieldSet *value)
+ __attribute__((const));
+size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value)
+ __attribute__((const));
+size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value)
+ __attribute__((const));
+size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeTagSize(int32_t fieldNumber) __attribute__((const));
+size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType)
+ __attribute__((const));
+
+size_t GPBComputeDoubleSizeNoTag(double value) __attribute__((const));
+size_t GPBComputeFloatSizeNoTag(float value) __attribute__((const));
+size_t GPBComputeUInt64SizeNoTag(uint64_t value) __attribute__((const));
+size_t GPBComputeInt64SizeNoTag(int64_t value) __attribute__((const));
+size_t GPBComputeInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeFixed64SizeNoTag(uint64_t value) __attribute__((const));
+size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const));
+size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const));
+size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const));
+size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const));
+size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value)
+ __attribute__((const));
+size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const));
+size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const));
+size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeEnumSizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSFixed32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSFixed64SizeNoTag(int64_t value) __attribute__((const));
+size_t GPBComputeSInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSInt64SizeNoTag(int64_t value) __attribute__((const));
+
+// Note that this will calculate the size of 64 bit values truncated to 32.
+size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) __attribute__((const));
+
+size_t GPBComputeRawVarint32Size(int32_t value) __attribute__((const));
+size_t GPBComputeRawVarint64Size(int64_t value) __attribute__((const));
+
+// Note that this will calculate the size of 64 bit values truncated to 32.
+size_t GPBComputeRawVarint32SizeForInteger(NSInteger value)
+ __attribute__((const));
+
+// Compute the number of bytes that would be needed to encode a
+// MessageSet extension to the stream. For historical reasons,
+// the wire format differs from normal fields.
+size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+
+// Compute the number of bytes that would be needed to encode an
+// unparsed MessageSet extension field to the stream. For
+// historical reasons, the wire format differs from normal fields.
+size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value)
+ __attribute__((const));
+
+size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+
+CF_EXTERN_C_END
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBDescriptor.h b/third_party/protobuf/objectivec/GPBDescriptor.h
new file mode 100644
index 0000000000..651f4de08f
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor.h
@@ -0,0 +1,288 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+@class GPBEnumDescriptor;
+@class GPBFieldDescriptor;
+@class GPBFileDescriptor;
+@class GPBOneofDescriptor;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** Syntax used in the proto file. */
+typedef NS_ENUM(uint8_t, GPBFileSyntax) {
+ /** Unknown syntax. */
+ GPBFileSyntaxUnknown = 0,
+ /** Proto2 syntax. */
+ GPBFileSyntaxProto2 = 2,
+ /** Proto3 syntax. */
+ GPBFileSyntaxProto3 = 3,
+};
+
+/** Type of proto field. */
+typedef NS_ENUM(uint8_t, GPBFieldType) {
+ /** Optional/required field. Only valid for proto2 fields. */
+ GPBFieldTypeSingle,
+ /** Repeated field. */
+ GPBFieldTypeRepeated,
+ /** Map field. */
+ GPBFieldTypeMap,
+};
+
+/**
+ * Describes a proto message.
+ **/
+@interface GPBDescriptor : NSObject<NSCopying>
+
+/** Name of the message. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Fields declared in the message. */
+@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
+/** Oneofs declared in the message. */
+@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
+/** Extension range declared for the message. */
+@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
+/** Number of extension ranges declared for the message. */
+@property(nonatomic, readonly) uint32_t extensionRangesCount;
+/** Descriptor for the file where the message was defined. */
+@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
+
+/** Whether the message is in wire format or not. */
+@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
+/** The class of this message. */
+@property(nonatomic, readonly) Class messageClass;
+/** Containing message descriptor if this message is nested, or nil otherwise. */
+@property(readonly, nullable) GPBDescriptor *containingType;
+/**
+ * Fully qualified name for this message (package.message). Can be nil if the
+ * value is unable to be computed.
+ */
+@property(readonly, nullable) NSString *fullName;
+
+/**
+ * Gets the field for the given number.
+ *
+ * @param fieldNumber The number for the field to get.
+ *
+ * @return The field descriptor for the given number, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
+
+/**
+ * Gets the field for the given name.
+ *
+ * @param name The name for the field to get.
+ *
+ * @return The field descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
+
+/**
+ * Gets the oneof for the given name.
+ *
+ * @param name The name for the oneof to get.
+ *
+ * @return The oneof descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
+
+@end
+
+/**
+ * Describes a proto file.
+ **/
+@interface GPBFileDescriptor : NSObject
+
+/** The package declared in the proto file. */
+@property(nonatomic, readonly, copy) NSString *package;
+/** The objc prefix declared in the proto file. */
+@property(nonatomic, readonly, copy, nullable) NSString *objcPrefix;
+/** The syntax of the proto file. */
+@property(nonatomic, readonly) GPBFileSyntax syntax;
+
+@end
+
+/**
+ * Describes a oneof field.
+ **/
+@interface GPBOneofDescriptor : NSObject
+/** Name of the oneof field. */
+@property(nonatomic, readonly) NSString *name;
+/** Fields declared in the oneof. */
+@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields;
+
+/**
+ * Gets the field for the given number.
+ *
+ * @param fieldNumber The number for the field to get.
+ *
+ * @return The field descriptor for the given number, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
+
+/**
+ * Gets the field for the given name.
+ *
+ * @param name The name for the field to get.
+ *
+ * @return The field descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
+
+@end
+
+/**
+ * Describes a proto field.
+ **/
+@interface GPBFieldDescriptor : NSObject
+
+/** Name of the field. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Number associated with the field. */
+@property(nonatomic, readonly) uint32_t number;
+/** Data type contained in the field. */
+@property(nonatomic, readonly) GPBDataType dataType;
+/** Whether it has a default value or not. */
+@property(nonatomic, readonly) BOOL hasDefaultValue;
+/** Default value for the field. */
+@property(nonatomic, readonly) GPBGenericValue defaultValue;
+/** Whether this field is required. Only valid for proto2 fields. */
+@property(nonatomic, readonly, getter=isRequired) BOOL required;
+/** Whether this field is optional. */
+@property(nonatomic, readonly, getter=isOptional) BOOL optional;
+/** Type of field (single, repeated, map). */
+@property(nonatomic, readonly) GPBFieldType fieldType;
+/** Type of the key if the field is a map. The value's type is -fieldType. */
+@property(nonatomic, readonly) GPBDataType mapKeyDataType;
+/** Whether the field is packable. */
+@property(nonatomic, readonly, getter=isPackable) BOOL packable;
+
+/** The containing oneof if this field is part of one, nil otherwise. */
+@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
+
+/** Class of the message if the field is of message type. */
+@property(nonatomic, readonly, assign, nullable) Class msgClass;
+
+/** Descriptor for the enum if this field is an enum. */
+@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
+
+/**
+ * Checks whether the given enum raw value is a valid enum value.
+ *
+ * @param value The raw enum value to check.
+ *
+ * @return YES if value is a valid enum raw value.
+ **/
+- (BOOL)isValidEnumValue:(int32_t)value;
+
+/** @return Name for the text format, or nil if not known. */
+- (nullable NSString *)textFormatName;
+
+@end
+
+/**
+ * Describes a proto enum.
+ **/
+@interface GPBEnumDescriptor : NSObject
+
+/** Name of the enum. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Function that validates that raw values are valid enum values. */
+@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
+
+/**
+ * Returns the enum value name for the given raw enum.
+ *
+ * @param number The raw enum value.
+ *
+ * @return The name of the enum value passed, or nil if not valid.
+ **/
+- (nullable NSString *)enumNameForValue:(int32_t)number;
+
+/**
+ * Gets the enum raw value for the given enum name.
+ *
+ * @param outValue A pointer where the value will be set.
+ * @param name The enum name for which to get the raw value.
+ *
+ * @return YES if a value was copied into the pointer, NO otherwise.
+ **/
+- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
+
+/**
+ * Returns the text format for the given raw enum value.
+ *
+ * @param number The raw enum value.
+ *
+ * @return The text format name for the raw enum value, or nil if not valid.
+ **/
+- (nullable NSString *)textFormatNameForValue:(int32_t)number;
+
+/**
+ * Gets the enum raw value for the given text format name.
+ *
+ * @param outValue A pointer where the value will be set.
+ * @param textFormatName The text format name for which to get the raw value.
+ *
+ * @return YES if a value was copied into the pointer, NO otherwise.
+ **/
+- (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName;
+
+@end
+
+/**
+ * Describes a proto extension.
+ **/
+@interface GPBExtensionDescriptor : NSObject<NSCopying>
+/** Field number under which the extension is stored. */
+@property(nonatomic, readonly) uint32_t fieldNumber;
+/** The containing message class, i.e. the class extended by this extension. */
+@property(nonatomic, readonly) Class containingMessageClass;
+/** Data type contained in the extension. */
+@property(nonatomic, readonly) GPBDataType dataType;
+/** Whether the extension is repeated. */
+@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
+/** Whether the extension is packable. */
+@property(nonatomic, readonly, getter=isPackable) BOOL packable;
+/** The class of the message if the extension is of message type. */
+@property(nonatomic, readonly, assign) Class msgClass;
+/** The singleton name for the extension. */
+@property(nonatomic, readonly) NSString *singletonName;
+/** The enum descriptor if the extension is of enum type. */
+@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
+/** The default value for the extension. */
+@property(nonatomic, readonly, nullable) id defaultValue;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBDescriptor.m b/third_party/protobuf/objectivec/GPBDescriptor.m
new file mode 100644
index 0000000000..0753a9485b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor.m
@@ -0,0 +1,1104 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBDescriptor_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBUtilities_PackagePrivate.h"
+#import "GPBWireFormat.h"
+#import "GPBMessage_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// The addresses of these variables are used as keys for objc_getAssociatedObject.
+static const char kTextFormatExtraValueKey = 0;
+static const char kParentClassNameValueKey = 0;
+static const char kClassNameSuffixKey = 0;
+
+// Utility function to generate selectors on the fly.
+static SEL SelFromStrings(const char *prefix, const char *middle,
+ const char *suffix, BOOL takesArg) {
+ if (prefix == NULL && suffix == NULL && !takesArg) {
+ return sel_getUid(middle);
+ }
+ const size_t prefixLen = prefix != NULL ? strlen(prefix) : 0;
+ const size_t middleLen = strlen(middle);
+ const size_t suffixLen = suffix != NULL ? strlen(suffix) : 0;
+ size_t totalLen =
+ prefixLen + middleLen + suffixLen + 1; // include space for null on end.
+ if (takesArg) {
+ totalLen += 1;
+ }
+ char buffer[totalLen];
+ if (prefix != NULL) {
+ memcpy(buffer, prefix, prefixLen);
+ memcpy(buffer + prefixLen, middle, middleLen);
+ buffer[prefixLen] = (char)toupper(buffer[prefixLen]);
+ } else {
+ memcpy(buffer, middle, middleLen);
+ }
+ if (suffix != NULL) {
+ memcpy(buffer + prefixLen + middleLen, suffix, suffixLen);
+ }
+ if (takesArg) {
+ buffer[totalLen - 2] = ':';
+ }
+ // Always null terminate it.
+ buffer[totalLen - 1] = 0;
+
+ SEL result = sel_getUid(buffer);
+ return result;
+}
+
+static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
+ NSArray *allMessageFields)
+ __attribute__((ns_returns_retained));
+
+static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
+ NSArray *allMessageFields) {
+ NSMutableArray *result = [[NSMutableArray alloc] init];
+ for (GPBFieldDescriptor *fieldDesc in allMessageFields) {
+ if (fieldDesc->description_->hasIndex == hasIndex) {
+ [result addObject:fieldDesc];
+ }
+ }
+ return result;
+}
+
+@implementation GPBDescriptor {
+ Class messageClass_;
+ GPBFileDescriptor *file_;
+ BOOL wireFormat_;
+}
+
+@synthesize messageClass = messageClass_;
+@synthesize fields = fields_;
+@synthesize oneofs = oneofs_;
+@synthesize extensionRanges = extensionRanges_;
+@synthesize extensionRangesCount = extensionRangesCount_;
+@synthesize file = file_;
+@synthesize wireFormat = wireFormat_;
+
++ (instancetype)
+ allocDescriptorForClass:(Class)messageClass
+ rootClass:(Class)rootClass
+ file:(GPBFileDescriptor *)file
+ fields:(void *)fieldDescriptions
+ fieldCount:(uint32_t)fieldCount
+ storageSize:(uint32_t)storageSize
+ flags:(GPBDescriptorInitializationFlags)flags {
+ // The rootClass is no longer used, but it is passed in to ensure it
+ // was started up during initialization also.
+ (void)rootClass;
+ NSMutableArray *fields = nil;
+ GPBFileSyntax syntax = file.syntax;
+ BOOL fieldsIncludeDefault =
+ (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
+
+ void *desc;
+ for (uint32_t i = 0; i < fieldCount; ++i) {
+ if (fields == nil) {
+ fields = [[NSMutableArray alloc] initWithCapacity:fieldCount];
+ }
+ // Need correctly typed pointer for array indexing below to work.
+ if (fieldsIncludeDefault) {
+ GPBMessageFieldDescriptionWithDefault *fieldDescWithDefault = fieldDescriptions;
+ desc = &(fieldDescWithDefault[i]);
+ } else {
+ GPBMessageFieldDescription *fieldDesc = fieldDescriptions;
+ desc = &(fieldDesc[i]);
+ }
+ GPBFieldDescriptor *fieldDescriptor =
+ [[GPBFieldDescriptor alloc] initWithFieldDescription:desc
+ includesDefault:fieldsIncludeDefault
+ syntax:syntax];
+ [fields addObject:fieldDescriptor];
+ [fieldDescriptor release];
+ }
+
+ BOOL wireFormat = (flags & GPBDescriptorInitializationFlag_WireFormat) != 0;
+ GPBDescriptor *descriptor = [[self alloc] initWithClass:messageClass
+ file:file
+ fields:fields
+ storageSize:storageSize
+ wireFormat:wireFormat];
+ [fields release];
+ return descriptor;
+}
+
+- (instancetype)initWithClass:(Class)messageClass
+ file:(GPBFileDescriptor *)file
+ fields:(NSArray *)fields
+ storageSize:(uint32_t)storageSize
+ wireFormat:(BOOL)wireFormat {
+ if ((self = [super init])) {
+ messageClass_ = messageClass;
+ file_ = file;
+ fields_ = [fields retain];
+ storageSize_ = storageSize;
+ wireFormat_ = wireFormat;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [fields_ release];
+ [oneofs_ release];
+ [super dealloc];
+}
+
+- (void)setupOneofs:(const char **)oneofNames
+ count:(uint32_t)count
+ firstHasIndex:(int32_t)firstHasIndex {
+ NSCAssert(firstHasIndex < 0, @"Should always be <0");
+ NSMutableArray *oneofs = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0, hasIndex = firstHasIndex; i < count; ++i, --hasIndex) {
+ const char *name = oneofNames[i];
+ NSArray *fieldsForOneof = NewFieldsArrayForHasIndex(hasIndex, fields_);
+ NSCAssert(fieldsForOneof.count > 0,
+ @"No fields for this oneof? (%s:%d)", name, hasIndex);
+ GPBOneofDescriptor *oneofDescriptor =
+ [[GPBOneofDescriptor alloc] initWithName:name fields:fieldsForOneof];
+ [oneofs addObject:oneofDescriptor];
+ [oneofDescriptor release];
+ [fieldsForOneof release];
+ }
+ oneofs_ = oneofs;
+}
+
+- (void)setupExtraTextInfo:(const char *)extraTextFormatInfo {
+ // Extra info is a compile time option, so skip the work if not needed.
+ if (extraTextFormatInfo) {
+ NSValue *extraInfoValue = [NSValue valueWithPointer:extraTextFormatInfo];
+ for (GPBFieldDescriptor *fieldDescriptor in fields_) {
+ if (fieldDescriptor->description_->flags & GPBFieldTextFormatNameCustom) {
+ objc_setAssociatedObject(fieldDescriptor, &kTextFormatExtraValueKey,
+ extraInfoValue,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ }
+ }
+}
+
+- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count {
+ extensionRanges_ = ranges;
+ extensionRangesCount_ = count;
+}
+
+- (void)setupContainingMessageClassName:(const char *)msgClassName {
+ // Note: Only fetch the class here, can't send messages to it because
+ // that could cause cycles back to this class within +initialize if
+ // two messages have each other in fields (i.e. - they build a graph).
+ NSAssert(objc_getClass(msgClassName), @"Class %s not defined", msgClassName);
+ NSValue *parentNameValue = [NSValue valueWithPointer:msgClassName];
+ objc_setAssociatedObject(self, &kParentClassNameValueKey,
+ parentNameValue,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+- (void)setupMessageClassNameSuffix:(NSString *)suffix {
+ if (suffix.length) {
+ objc_setAssociatedObject(self, &kClassNameSuffixKey,
+ suffix,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+}
+
+- (NSString *)name {
+ return NSStringFromClass(messageClass_);
+}
+
+- (GPBDescriptor *)containingType {
+ NSValue *parentNameValue =
+ objc_getAssociatedObject(self, &kParentClassNameValueKey);
+ if (!parentNameValue) {
+ return nil;
+ }
+ const char *parentName = [parentNameValue pointerValue];
+ Class parentClass = objc_getClass(parentName);
+ NSAssert(parentClass, @"Class %s not defined", parentName);
+ return [parentClass descriptor];
+}
+
+- (NSString *)fullName {
+ NSString *className = NSStringFromClass(self.messageClass);
+ GPBFileDescriptor *file = self.file;
+ NSString *objcPrefix = file.objcPrefix;
+ if (objcPrefix && ![className hasPrefix:objcPrefix]) {
+ NSAssert(0,
+ @"Class didn't have correct prefix? (%@ - %@)",
+ className, objcPrefix);
+ return nil;
+ }
+ GPBDescriptor *parent = self.containingType;
+
+ NSString *name = nil;
+ if (parent) {
+ NSString *parentClassName = NSStringFromClass(parent.messageClass);
+ // The generator will add _Class to avoid reserved words, drop it.
+ NSString *suffix = objc_getAssociatedObject(parent, &kClassNameSuffixKey);
+ if (suffix) {
+ if (![parentClassName hasSuffix:suffix]) {
+ NSAssert(0,
+ @"ParentMessage class didn't have correct suffix? (%@ - %@)",
+ className, suffix);
+ return nil;
+ }
+ parentClassName =
+ [parentClassName substringToIndex:(parentClassName.length - suffix.length)];
+ }
+ NSString *parentPrefix = [parentClassName stringByAppendingString:@"_"];
+ if (![className hasPrefix:parentPrefix]) {
+ NSAssert(0,
+ @"Class didn't have the correct parent name prefix? (%@ - %@)",
+ parentPrefix, className);
+ return nil;
+ }
+ name = [className substringFromIndex:parentPrefix.length];
+ } else {
+ name = [className substringFromIndex:objcPrefix.length];
+ }
+
+ // The generator will add _Class to avoid reserved words, drop it.
+ NSString *suffix = objc_getAssociatedObject(self, &kClassNameSuffixKey);
+ if (suffix) {
+ if (![name hasSuffix:suffix]) {
+ NSAssert(0,
+ @"Message class didn't have correct suffix? (%@ - %@)",
+ name, suffix);
+ return nil;
+ }
+ name = [name substringToIndex:(name.length - suffix.length)];
+ }
+
+ NSString *prefix = (parent != nil ? parent.fullName : file.package);
+ NSString *result;
+ if (prefix.length > 0) {
+ result = [NSString stringWithFormat:@"%@.%@", prefix, name];
+ } else {
+ result = name;
+ }
+ return result;
+}
+
+- (id)copyWithZone:(NSZone *)zone {
+#pragma unused(zone)
+ return [self retain];
+}
+
+- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if (GPBFieldNumber(descriptor) == fieldNumber) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBFieldDescriptor *)fieldWithName:(NSString *)name {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBOneofDescriptor *)oneofWithName:(NSString *)name {
+ for (GPBOneofDescriptor *descriptor in oneofs_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+@end
+
+@implementation GPBFileDescriptor {
+ NSString *package_;
+ NSString *objcPrefix_;
+ GPBFileSyntax syntax_;
+}
+
+@synthesize package = package_;
+@synthesize objcPrefix = objcPrefix_;
+@synthesize syntax = syntax_;
+
+- (instancetype)initWithPackage:(NSString *)package
+ objcPrefix:(NSString *)objcPrefix
+ syntax:(GPBFileSyntax)syntax {
+ self = [super init];
+ if (self) {
+ package_ = [package copy];
+ objcPrefix_ = [objcPrefix copy];
+ syntax_ = syntax;
+ }
+ return self;
+}
+
+- (instancetype)initWithPackage:(NSString *)package
+ syntax:(GPBFileSyntax)syntax {
+ self = [super init];
+ if (self) {
+ package_ = [package copy];
+ syntax_ = syntax;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [package_ release];
+ [objcPrefix_ release];
+ [super dealloc];
+}
+
+@end
+
+@implementation GPBOneofDescriptor
+
+@synthesize fields = fields_;
+
+- (instancetype)initWithName:(const char *)name fields:(NSArray *)fields {
+ self = [super init];
+ if (self) {
+ name_ = name;
+ fields_ = [fields retain];
+ for (GPBFieldDescriptor *fieldDesc in fields) {
+ fieldDesc->containingOneof_ = self;
+ }
+
+ caseSel_ = SelFromStrings(NULL, name, "OneOfCase", NO);
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [fields_ release];
+ [super dealloc];
+}
+
+- (NSString *)name {
+ return @(name_);
+}
+
+- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if (GPBFieldNumber(descriptor) == fieldNumber) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBFieldDescriptor *)fieldWithName:(NSString *)name {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+@end
+
+uint32_t GPBFieldTag(GPBFieldDescriptor *self) {
+ GPBMessageFieldDescription *description = self->description_;
+ GPBWireFormat format;
+ if ((description->flags & GPBFieldMapKeyMask) != 0) {
+ // Maps are repeated messages on the wire.
+ format = GPBWireFormatForType(GPBDataTypeMessage, NO);
+ } else {
+ format = GPBWireFormatForType(description->dataType,
+ ((description->flags & GPBFieldPacked) != 0));
+ }
+ return GPBWireFormatMakeTag(description->number, format);
+}
+
+uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
+ GPBMessageFieldDescription *description = self->description_;
+ NSCAssert((description->flags & GPBFieldRepeated) != 0,
+ @"Only valid on repeated fields");
+ GPBWireFormat format =
+ GPBWireFormatForType(description->dataType,
+ ((description->flags & GPBFieldPacked) == 0));
+ return GPBWireFormatMakeTag(description->number, format);
+}
+
+@implementation GPBFieldDescriptor {
+ GPBGenericValue defaultValue_;
+
+ // Message ivars
+ Class msgClass_;
+
+ // Enum ivars.
+ // If protos are generated with GenerateEnumDescriptors on then it will
+ // be a enumDescriptor, otherwise it will be a enumVerifier.
+ union {
+ GPBEnumDescriptor *enumDescriptor_;
+ GPBEnumValidationFunc enumVerifier_;
+ } enumHandling_;
+}
+
+@synthesize msgClass = msgClass_;
+@synthesize containingOneof = containingOneof_;
+
+- (instancetype)init {
+ // Throw an exception if people attempt to not use the designated initializer.
+ self = [super init];
+ if (self != nil) {
+ [self doesNotRecognizeSelector:_cmd];
+ self = nil;
+ }
+ return self;
+}
+
+- (instancetype)initWithFieldDescription:(void *)description
+ includesDefault:(BOOL)includesDefault
+ syntax:(GPBFileSyntax)syntax {
+ if ((self = [super init])) {
+ GPBMessageFieldDescription *coreDesc;
+ if (includesDefault) {
+ coreDesc = &(((GPBMessageFieldDescriptionWithDefault *)description)->core);
+ } else {
+ coreDesc = description;
+ }
+ description_ = coreDesc;
+ getSel_ = sel_getUid(coreDesc->name);
+ setSel_ = SelFromStrings("set", coreDesc->name, NULL, YES);
+
+ GPBDataType dataType = coreDesc->dataType;
+ BOOL isMessage = GPBDataTypeIsMessage(dataType);
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(self);
+
+ if (isMapOrArray) {
+ // map<>/repeated fields get a *Count property (inplace of a has*) to
+ // support checking if there are any entries without triggering
+ // autocreation.
+ hasOrCountSel_ = SelFromStrings(NULL, coreDesc->name, "_Count", NO);
+ } else {
+ // If there is a positive hasIndex, then:
+ // - All fields types for proto2 messages get has* selectors.
+ // - Only message fields for proto3 messages get has* selectors.
+ // Note: the positive check is to handle oneOfs, we can't check
+ // containingOneof_ because it isn't set until after initialization.
+ if ((coreDesc->hasIndex >= 0) &&
+ (coreDesc->hasIndex != GPBNoHasBit) &&
+ ((syntax != GPBFileSyntaxProto3) || isMessage)) {
+ hasOrCountSel_ = SelFromStrings("has", coreDesc->name, NULL, NO);
+ setHasSel_ = SelFromStrings("setHas", coreDesc->name, NULL, YES);
+ }
+ }
+
+ // Extra type specific data.
+ if (isMessage) {
+ const char *className = coreDesc->dataTypeSpecific.className;
+ // Note: Only fetch the class here, can't send messages to it because
+ // that could cause cycles back to this class within +initialize if
+ // two messages have each other in fields (i.e. - they build a graph).
+ msgClass_ = objc_getClass(className);
+ NSAssert(msgClass_, @"Class %s not defined", className);
+ } else if (dataType == GPBDataTypeEnum) {
+ if ((coreDesc->flags & GPBFieldHasEnumDescriptor) != 0) {
+ enumHandling_.enumDescriptor_ =
+ coreDesc->dataTypeSpecific.enumDescFunc();
+ } else {
+ enumHandling_.enumVerifier_ =
+ coreDesc->dataTypeSpecific.enumVerifier;
+ }
+ }
+
+ // Non map<>/repeated fields can have defaults in proto2 syntax.
+ if (!isMapOrArray && includesDefault) {
+ defaultValue_ = ((GPBMessageFieldDescriptionWithDefault *)description)->defaultValue;
+ if (dataType == GPBDataTypeBytes) {
+ // Data stored as a length prefixed (network byte order) c-string in
+ // descriptor structure.
+ const uint8_t *bytes = (const uint8_t *)defaultValue_.valueData;
+ if (bytes) {
+ uint32_t length = *((uint32_t *)bytes);
+ length = ntohl(length);
+ bytes += sizeof(length);
+ defaultValue_.valueData =
+ [[NSData alloc] initWithBytes:bytes length:length];
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (void)dealloc {
+ if (description_->dataType == GPBDataTypeBytes &&
+ !(description_->flags & GPBFieldRepeated)) {
+ [defaultValue_.valueData release];
+ }
+ [super dealloc];
+}
+
+- (GPBDataType)dataType {
+ return description_->dataType;
+}
+
+- (BOOL)hasDefaultValue {
+ return (description_->flags & GPBFieldHasDefaultValue) != 0;
+}
+
+- (uint32_t)number {
+ return description_->number;
+}
+
+- (NSString *)name {
+ return @(description_->name);
+}
+
+- (BOOL)isRequired {
+ return (description_->flags & GPBFieldRequired) != 0;
+}
+
+- (BOOL)isOptional {
+ return (description_->flags & GPBFieldOptional) != 0;
+}
+
+- (GPBFieldType)fieldType {
+ GPBFieldFlags flags = description_->flags;
+ if ((flags & GPBFieldRepeated) != 0) {
+ return GPBFieldTypeRepeated;
+ } else if ((flags & GPBFieldMapKeyMask) != 0) {
+ return GPBFieldTypeMap;
+ } else {
+ return GPBFieldTypeSingle;
+ }
+}
+
+- (GPBDataType)mapKeyDataType {
+ switch (description_->flags & GPBFieldMapKeyMask) {
+ case GPBFieldMapKeyInt32:
+ return GPBDataTypeInt32;
+ case GPBFieldMapKeyInt64:
+ return GPBDataTypeInt64;
+ case GPBFieldMapKeyUInt32:
+ return GPBDataTypeUInt32;
+ case GPBFieldMapKeyUInt64:
+ return GPBDataTypeUInt64;
+ case GPBFieldMapKeySInt32:
+ return GPBDataTypeSInt32;
+ case GPBFieldMapKeySInt64:
+ return GPBDataTypeSInt64;
+ case GPBFieldMapKeyFixed32:
+ return GPBDataTypeFixed32;
+ case GPBFieldMapKeyFixed64:
+ return GPBDataTypeFixed64;
+ case GPBFieldMapKeySFixed32:
+ return GPBDataTypeSFixed32;
+ case GPBFieldMapKeySFixed64:
+ return GPBDataTypeSFixed64;
+ case GPBFieldMapKeyBool:
+ return GPBDataTypeBool;
+ case GPBFieldMapKeyString:
+ return GPBDataTypeString;
+
+ default:
+ NSAssert(0, @"Not a map type");
+ return GPBDataTypeInt32; // For lack of anything better.
+ }
+}
+
+- (BOOL)isPackable {
+ return (description_->flags & GPBFieldPacked) != 0;
+}
+
+- (BOOL)isValidEnumValue:(int32_t)value {
+ NSAssert(description_->dataType == GPBDataTypeEnum,
+ @"Field Must be of type GPBDataTypeEnum");
+ if (description_->flags & GPBFieldHasEnumDescriptor) {
+ return enumHandling_.enumDescriptor_.enumVerifier(value);
+ } else {
+ return enumHandling_.enumVerifier_(value);
+ }
+}
+
+- (GPBEnumDescriptor *)enumDescriptor {
+ if (description_->flags & GPBFieldHasEnumDescriptor) {
+ return enumHandling_.enumDescriptor_;
+ } else {
+ return nil;
+ }
+}
+
+- (GPBGenericValue)defaultValue {
+ // Depends on the fact that defaultValue_ is initialized either to "0/nil" or
+ // to an actual defaultValue in our initializer.
+ GPBGenericValue value = defaultValue_;
+
+ if (!(description_->flags & GPBFieldRepeated)) {
+ // We special handle data and strings. If they are nil, we replace them
+ // with empty string/empty data.
+ GPBDataType type = description_->dataType;
+ if (type == GPBDataTypeBytes && value.valueData == nil) {
+ value.valueData = GPBEmptyNSData();
+ } else if (type == GPBDataTypeString && value.valueString == nil) {
+ value.valueString = @"";
+ }
+ }
+ return value;
+}
+
+- (NSString *)textFormatName {
+ if ((description_->flags & GPBFieldTextFormatNameCustom) != 0) {
+ NSValue *extraInfoValue =
+ objc_getAssociatedObject(self, &kTextFormatExtraValueKey);
+ // Support can be left out at generation time.
+ if (!extraInfoValue) {
+ return nil;
+ }
+ const uint8_t *extraTextFormatInfo = [extraInfoValue pointerValue];
+ return GPBDecodeTextFormatName(extraTextFormatInfo, GPBFieldNumber(self),
+ self.name);
+ }
+
+ // The logic here has to match SetCommonFieldVariables() from
+ // objectivec_field.cc in the proto compiler.
+ NSString *name = self.name;
+ NSUInteger len = [name length];
+
+ // Remove the "_p" added to reserved names.
+ if ([name hasSuffix:@"_p"]) {
+ name = [name substringToIndex:(len - 2)];
+ len = [name length];
+ }
+
+ // Remove "Array" from the end for repeated fields.
+ if (((description_->flags & GPBFieldRepeated) != 0) &&
+ [name hasSuffix:@"Array"]) {
+ name = [name substringToIndex:(len - 5)];
+ len = [name length];
+ }
+
+ // Groups vs. other fields.
+ if (description_->dataType == GPBDataTypeGroup) {
+ // Just capitalize the first letter.
+ unichar firstChar = [name characterAtIndex:0];
+ if (firstChar >= 'a' && firstChar <= 'z') {
+ NSString *firstCharString =
+ [NSString stringWithFormat:@"%C", (unichar)(firstChar - 'a' + 'A')];
+ NSString *result =
+ [name stringByReplacingCharactersInRange:NSMakeRange(0, 1)
+ withString:firstCharString];
+ return result;
+ }
+ return name;
+
+ } else {
+ // Undo the CamelCase.
+ NSMutableString *result = [NSMutableString stringWithCapacity:len];
+ for (uint32_t i = 0; i < len; i++) {
+ unichar c = [name characterAtIndex:i];
+ if (c >= 'A' && c <= 'Z') {
+ if (i > 0) {
+ [result appendFormat:@"_%C", (unichar)(c - 'A' + 'a')];
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ }
+ return result;
+ }
+}
+
+@end
+
+@implementation GPBEnumDescriptor {
+ NSString *name_;
+ // valueNames_ is a single c string with all of the value names appended
+ // together, each null terminated. -calcValueNameOffsets fills in
+ // nameOffsets_ with the offsets to allow quicker access to the individual
+ // names.
+ const char *valueNames_;
+ const int32_t *values_;
+ GPBEnumValidationFunc enumVerifier_;
+ const uint8_t *extraTextFormatInfo_;
+ uint32_t *nameOffsets_;
+ uint32_t valueCount_;
+}
+
+@synthesize name = name_;
+@synthesize enumVerifier = enumVerifier_;
+
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier {
+ GPBEnumDescriptor *descriptor = [[self alloc] initWithName:name
+ valueNames:valueNames
+ values:values
+ count:valueCount
+ enumVerifier:enumVerifier];
+ return descriptor;
+}
+
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier
+ extraTextFormatInfo:(const char *)extraTextFormatInfo {
+ // Call the common case.
+ GPBEnumDescriptor *descriptor = [self allocDescriptorForName:name
+ valueNames:valueNames
+ values:values
+ count:valueCount
+ enumVerifier:enumVerifier];
+ // Set the extra info.
+ descriptor->extraTextFormatInfo_ = (const uint8_t *)extraTextFormatInfo;
+ return descriptor;
+}
+
+- (instancetype)initWithName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier {
+ if ((self = [super init])) {
+ name_ = [name copy];
+ valueNames_ = valueNames;
+ values_ = values;
+ valueCount_ = valueCount;
+ enumVerifier_ = enumVerifier;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [name_ release];
+ if (nameOffsets_) free(nameOffsets_);
+ [super dealloc];
+}
+
+- (void)calcValueNameOffsets {
+ @synchronized(self) {
+ if (nameOffsets_ != NULL) {
+ return;
+ }
+ uint32_t *offsets = malloc(valueCount_ * sizeof(uint32_t));
+ const char *scan = valueNames_;
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ offsets[i] = (uint32_t)(scan - valueNames_);
+ while (*scan != '\0') ++scan;
+ ++scan; // Step over the null.
+ }
+ nameOffsets_ = offsets;
+ }
+}
+
+- (NSString *)enumNameForValue:(int32_t)number {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ if (values_[i] == number) {
+ const char *valueName = valueNames_ + nameOffsets_[i];
+ NSString *fullName = [NSString stringWithFormat:@"%@_%s", name_, valueName];
+ return fullName;
+ }
+ }
+ return nil;
+}
+
+- (BOOL)getValue:(int32_t *)outValue forEnumName:(NSString *)name {
+ // Must have the prefix.
+ NSUInteger prefixLen = name_.length + 1;
+ if ((name.length <= prefixLen) || ![name hasPrefix:name_] ||
+ ([name characterAtIndex:prefixLen - 1] != '_')) {
+ return NO;
+ }
+
+ // Skip over the prefix.
+ const char *nameAsCStr = [name UTF8String];
+ nameAsCStr += prefixLen;
+
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ // Find it.
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ const char *valueName = valueNames_ + nameOffsets_[i];
+ if (strcmp(nameAsCStr, valueName) == 0) {
+ if (outValue) {
+ *outValue = values_[i];
+ }
+ return YES;
+ }
+ }
+ return NO;
+}
+
+- (BOOL)getValue:(int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ int32_t value = values_[i];
+ NSString *valueTextFormatName = [self textFormatNameForValue:value];
+ if ([valueTextFormatName isEqual:textFormatName]) {
+ if (outValue) {
+ *outValue = value;
+ }
+ return YES;
+ }
+ }
+ return NO;
+}
+
+- (NSString *)textFormatNameForValue:(int32_t)number {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ // Find the EnumValue descriptor and its index.
+ BOOL foundIt = NO;
+ uint32_t valueDescriptorIndex;
+ for (valueDescriptorIndex = 0; valueDescriptorIndex < valueCount_;
+ ++valueDescriptorIndex) {
+ if (values_[valueDescriptorIndex] == number) {
+ foundIt = YES;
+ break;
+ }
+ }
+
+ if (!foundIt) {
+ return nil;
+ }
+
+ NSString *result = nil;
+ // Naming adds an underscore between enum name and value name, skip that also.
+ const char *valueName = valueNames_ + nameOffsets_[valueDescriptorIndex];
+ NSString *shortName = @(valueName);
+
+ // See if it is in the map of special format handling.
+ if (extraTextFormatInfo_) {
+ result = GPBDecodeTextFormatName(extraTextFormatInfo_,
+ (int32_t)valueDescriptorIndex, shortName);
+ }
+ // Logic here needs to match what objectivec_enum.cc does in the proto
+ // compiler.
+ if (result == nil) {
+ NSUInteger len = [shortName length];
+ NSMutableString *worker = [NSMutableString stringWithCapacity:len];
+ for (NSUInteger i = 0; i < len; i++) {
+ unichar c = [shortName characterAtIndex:i];
+ if (i > 0 && c >= 'A' && c <= 'Z') {
+ [worker appendString:@"_"];
+ }
+ [worker appendFormat:@"%c", toupper((char)c)];
+ }
+ result = worker;
+ }
+ return result;
+}
+
+@end
+
+@implementation GPBExtensionDescriptor {
+ GPBGenericValue defaultValue_;
+}
+
+@synthesize containingMessageClass = containingMessageClass_;
+
+- (instancetype)initWithExtensionDescription:
+ (GPBExtensionDescription *)description {
+ if ((self = [super init])) {
+ description_ = description;
+
+#if defined(DEBUG) && DEBUG
+ const char *className = description->messageOrGroupClassName;
+ if (className) {
+ NSAssert(objc_lookUpClass(className) != Nil,
+ @"Class %s not defined", className);
+ }
+#endif
+
+ if (description->extendedClass) {
+ Class containingClass = objc_lookUpClass(description->extendedClass);
+ NSAssert(containingClass, @"Class %s not defined",
+ description->extendedClass);
+ containingMessageClass_ = containingClass;
+ }
+
+ GPBDataType type = description_->dataType;
+ if (type == GPBDataTypeBytes) {
+ // Data stored as a length prefixed c-string in descriptor records.
+ const uint8_t *bytes =
+ (const uint8_t *)description->defaultValue.valueData;
+ if (bytes) {
+ uint32_t length = *((uint32_t *)bytes);
+ // The length is stored in network byte order.
+ length = ntohl(length);
+ bytes += sizeof(length);
+ defaultValue_.valueData =
+ [[NSData alloc] initWithBytes:bytes length:length];
+ }
+ } else if (type == GPBDataTypeMessage || type == GPBDataTypeGroup) {
+ // The default is looked up in -defaultValue instead since extensions
+ // aren't common, we avoid the hit startup hit and it avoid initialization
+ // order issues.
+ } else {
+ defaultValue_ = description->defaultValue;
+ }
+ }
+ return self;
+}
+
+- (void)dealloc {
+ if ((description_->dataType == GPBDataTypeBytes) &&
+ !GPBExtensionIsRepeated(description_)) {
+ [defaultValue_.valueData release];
+ }
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+#pragma unused(zone)
+ // Immutable.
+ return [self retain];
+}
+
+- (NSString *)singletonName {
+ return @(description_->singletonName);
+}
+
+- (const char *)singletonNameC {
+ return description_->singletonName;
+}
+
+- (uint32_t)fieldNumber {
+ return description_->fieldNumber;
+}
+
+- (GPBDataType)dataType {
+ return description_->dataType;
+}
+
+- (GPBWireFormat)wireType {
+ return GPBWireFormatForType(description_->dataType,
+ GPBExtensionIsPacked(description_));
+}
+
+- (GPBWireFormat)alternateWireType {
+ NSAssert(GPBExtensionIsRepeated(description_),
+ @"Only valid on repeated extensions");
+ return GPBWireFormatForType(description_->dataType,
+ !GPBExtensionIsPacked(description_));
+}
+
+- (BOOL)isRepeated {
+ return GPBExtensionIsRepeated(description_);
+}
+
+- (BOOL)isMap {
+ return (description_->options & GPBFieldMapKeyMask) != 0;
+}
+
+- (BOOL)isPackable {
+ return GPBExtensionIsPacked(description_);
+}
+
+- (Class)msgClass {
+ return objc_getClass(description_->messageOrGroupClassName);
+}
+
+- (GPBEnumDescriptor *)enumDescriptor {
+ if (description_->dataType == GPBDataTypeEnum) {
+ GPBEnumDescriptor *enumDescriptor = description_->enumDescriptorFunc();
+ return enumDescriptor;
+ }
+ return nil;
+}
+
+- (id)defaultValue {
+ if (GPBExtensionIsRepeated(description_)) {
+ return nil;
+ }
+
+ switch (description_->dataType) {
+ case GPBDataTypeBool:
+ return @(defaultValue_.valueBool);
+ case GPBDataTypeFloat:
+ return @(defaultValue_.valueFloat);
+ case GPBDataTypeDouble:
+ return @(defaultValue_.valueDouble);
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeSFixed32:
+ return @(defaultValue_.valueInt32);
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeSFixed64:
+ return @(defaultValue_.valueInt64);
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFixed32:
+ return @(defaultValue_.valueUInt32);
+ case GPBDataTypeUInt64:
+ case GPBDataTypeFixed64:
+ return @(defaultValue_.valueUInt64);
+ case GPBDataTypeBytes:
+ // Like message fields, the default is zero length data.
+ return (defaultValue_.valueData ? defaultValue_.valueData
+ : GPBEmptyNSData());
+ case GPBDataTypeString:
+ // Like message fields, the default is zero length string.
+ return (defaultValue_.valueString ? defaultValue_.valueString : @"");
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ return nil;
+ }
+}
+
+- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other {
+ int32_t selfNumber = description_->fieldNumber;
+ int32_t otherNumber = other->description_->fieldNumber;
+ if (selfNumber < otherNumber) {
+ return NSOrderedAscending;
+ } else if (selfNumber == otherNumber) {
+ return NSOrderedSame;
+ } else {
+ return NSOrderedDescending;
+ }
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h b/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h
new file mode 100644
index 0000000000..9173e7a2b1
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h
@@ -0,0 +1,329 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBDescriptor.h"
+#import "GPBWireFormat.h"
+
+// Describes attributes of the field.
+typedef NS_OPTIONS(uint16_t, GPBFieldFlags) {
+ GPBFieldNone = 0,
+ // These map to standard protobuf concepts.
+ GPBFieldRequired = 1 << 0,
+ GPBFieldRepeated = 1 << 1,
+ GPBFieldPacked = 1 << 2,
+ GPBFieldOptional = 1 << 3,
+ GPBFieldHasDefaultValue = 1 << 4,
+
+ // Indicates the field needs custom handling for the TextFormat name, if not
+ // set, the name can be derived from the ObjC name.
+ GPBFieldTextFormatNameCustom = 1 << 6,
+ // Indicates the field has an enum descriptor.
+ GPBFieldHasEnumDescriptor = 1 << 7,
+
+ // These are not standard protobuf concepts, they are specific to the
+ // Objective C runtime.
+
+ // These bits are used to mark the field as a map and what the key
+ // type is.
+ GPBFieldMapKeyMask = 0xF << 8,
+ GPBFieldMapKeyInt32 = 1 << 8,
+ GPBFieldMapKeyInt64 = 2 << 8,
+ GPBFieldMapKeyUInt32 = 3 << 8,
+ GPBFieldMapKeyUInt64 = 4 << 8,
+ GPBFieldMapKeySInt32 = 5 << 8,
+ GPBFieldMapKeySInt64 = 6 << 8,
+ GPBFieldMapKeyFixed32 = 7 << 8,
+ GPBFieldMapKeyFixed64 = 8 << 8,
+ GPBFieldMapKeySFixed32 = 9 << 8,
+ GPBFieldMapKeySFixed64 = 10 << 8,
+ GPBFieldMapKeyBool = 11 << 8,
+ GPBFieldMapKeyString = 12 << 8,
+};
+
+// NOTE: The structures defined here have their members ordered to minimize
+// their size. This directly impacts the size of apps since these exist per
+// field/extension.
+
+// Describes a single field in a protobuf as it is represented as an ivar.
+typedef struct GPBMessageFieldDescription {
+ // Name of ivar.
+ const char *name;
+ union {
+ const char *className; // Name for message class.
+ // For enums only: If EnumDescriptors are compiled in, it will be that,
+ // otherwise it will be the verifier.
+ GPBEnumDescriptorFunc enumDescFunc;
+ GPBEnumValidationFunc enumVerifier;
+ } dataTypeSpecific;
+ // The field number for the ivar.
+ uint32_t number;
+ // The index (in bits) into _has_storage_.
+ // >= 0: the bit to use for a value being set.
+ // = GPBNoHasBit(INT32_MAX): no storage used.
+ // < 0: in a oneOf, use a full int32 to record the field active.
+ int32_t hasIndex;
+ // Offset of the variable into it's structure struct.
+ uint32_t offset;
+ // Field flags. Use accessor functions below.
+ GPBFieldFlags flags;
+ // Data type of the ivar.
+ GPBDataType dataType;
+} GPBMessageFieldDescription;
+
+// Fields in messages defined in a 'proto2' syntax file can provide a default
+// value. This struct provides the default along with the field info.
+typedef struct GPBMessageFieldDescriptionWithDefault {
+ // Default value for the ivar.
+ GPBGenericValue defaultValue;
+
+ GPBMessageFieldDescription core;
+} GPBMessageFieldDescriptionWithDefault;
+
+// Describes attributes of the extension.
+typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) {
+ GPBExtensionNone = 0,
+ // These map to standard protobuf concepts.
+ GPBExtensionRepeated = 1 << 0,
+ GPBExtensionPacked = 1 << 1,
+ GPBExtensionSetWireFormat = 1 << 2,
+};
+
+// An extension
+typedef struct GPBExtensionDescription {
+ GPBGenericValue defaultValue;
+ const char *singletonName;
+ const char *extendedClass;
+ const char *messageOrGroupClassName;
+ GPBEnumDescriptorFunc enumDescriptorFunc;
+ int32_t fieldNumber;
+ GPBDataType dataType;
+ GPBExtensionOptions options;
+} GPBExtensionDescription;
+
+typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
+ GPBDescriptorInitializationFlag_None = 0,
+ GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0,
+ GPBDescriptorInitializationFlag_WireFormat = 1 << 1,
+};
+
+@interface GPBDescriptor () {
+ @package
+ NSArray *fields_;
+ NSArray *oneofs_;
+ uint32_t storageSize_;
+}
+
+// fieldDescriptions have to be long lived, they are held as raw pointers.
++ (instancetype)
+ allocDescriptorForClass:(Class)messageClass
+ rootClass:(Class)rootClass
+ file:(GPBFileDescriptor *)file
+ fields:(void *)fieldDescriptions
+ fieldCount:(uint32_t)fieldCount
+ storageSize:(uint32_t)storageSize
+ flags:(GPBDescriptorInitializationFlags)flags;
+
+- (instancetype)initWithClass:(Class)messageClass
+ file:(GPBFileDescriptor *)file
+ fields:(NSArray *)fields
+ storageSize:(uint32_t)storage
+ wireFormat:(BOOL)wireFormat;
+
+// Called right after init to provide extra information to avoid init having
+// an explosion of args. These pointers are recorded, so they are expected
+// to live for the lifetime of the app.
+- (void)setupOneofs:(const char **)oneofNames
+ count:(uint32_t)count
+ firstHasIndex:(int32_t)firstHasIndex;
+- (void)setupExtraTextInfo:(const char *)extraTextFormatInfo;
+- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count;
+- (void)setupContainingMessageClassName:(const char *)msgClassName;
+- (void)setupMessageClassNameSuffix:(NSString *)suffix;
+
+@end
+
+@interface GPBFileDescriptor ()
+- (instancetype)initWithPackage:(NSString *)package
+ objcPrefix:(NSString *)objcPrefix
+ syntax:(GPBFileSyntax)syntax;
+- (instancetype)initWithPackage:(NSString *)package
+ syntax:(GPBFileSyntax)syntax;
+@end
+
+@interface GPBOneofDescriptor () {
+ @package
+ const char *name_;
+ NSArray *fields_;
+ SEL caseSel_;
+}
+// name must be long lived.
+- (instancetype)initWithName:(const char *)name fields:(NSArray *)fields;
+@end
+
+@interface GPBFieldDescriptor () {
+ @package
+ GPBMessageFieldDescription *description_;
+ GPB_UNSAFE_UNRETAINED GPBOneofDescriptor *containingOneof_;
+
+ SEL getSel_;
+ SEL setSel_;
+ SEL hasOrCountSel_; // *Count for map<>/repeated fields, has* otherwise.
+ SEL setHasSel_;
+}
+
+// Single initializer
+// description has to be long lived, it is held as a raw pointer.
+- (instancetype)initWithFieldDescription:(void *)description
+ includesDefault:(BOOL)includesDefault
+ syntax:(GPBFileSyntax)syntax;
+@end
+
+@interface GPBEnumDescriptor ()
+// valueNames, values and extraTextFormatInfo have to be long lived, they are
+// held as raw pointers.
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier;
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier
+ extraTextFormatInfo:(const char *)extraTextFormatInfo;
+
+- (instancetype)initWithName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier;
+@end
+
+@interface GPBExtensionDescriptor () {
+ @package
+ GPBExtensionDescription *description_;
+}
+@property(nonatomic, readonly) GPBWireFormat wireType;
+
+// For repeated extensions, alternateWireType is the wireType with the opposite
+// value for the packable property. i.e. - if the extension was marked packed
+// it would be the wire type for unpacked; if the extension was marked unpacked,
+// it would be the wire type for packed.
+@property(nonatomic, readonly) GPBWireFormat alternateWireType;
+
+// description has to be long lived, it is held as a raw pointer.
+- (instancetype)initWithExtensionDescription:
+ (GPBExtensionDescription *)description;
+- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
+@end
+
+CF_EXTERN_C_BEGIN
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) {
+ return (field->description_->flags &
+ (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0;
+}
+
+GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) {
+ return field->description_->dataType;
+}
+
+GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) {
+ return field->description_->hasIndex;
+}
+
+GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) {
+ return field->description_->number;
+}
+
+#pragma clang diagnostic pop
+
+uint32_t GPBFieldTag(GPBFieldDescriptor *self);
+
+// For repeated fields, alternateWireType is the wireType with the opposite
+// value for the packable property. i.e. - if the field was marked packed it
+// would be the wire type for unpacked; if the field was marked unpacked, it
+// would be the wire type for packed.
+uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self);
+
+GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) {
+ return syntax != GPBFileSyntaxProto3;
+}
+
+GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) {
+ return syntax == GPBFileSyntaxProto3;
+}
+
+GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionRepeated) != 0;
+}
+
+GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionPacked) != 0;
+}
+
+GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionSetWireFormat) != 0;
+}
+
+// Helper for compile time assets.
+#ifndef GPBInternalCompileAssert
+ #if __has_feature(c_static_assert) || __has_extension(c_static_assert)
+ #define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg)
+ #else
+ // Pre-Xcode 7 support.
+ #define GPBInternalCompileAssertSymbolInner(line, msg) GPBInternalCompileAssert ## line ## __ ## msg
+ #define GPBInternalCompileAssertSymbol(line, msg) GPBInternalCompileAssertSymbolInner(line, msg)
+ #define GPBInternalCompileAssert(test, msg) \
+ typedef char GPBInternalCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
+ #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert)
+#endif // GPBInternalCompileAssert
+
+// Sanity check that there isn't padding between the field description
+// structures with and without a default.
+GPBInternalCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) ==
+ (sizeof(GPBGenericValue) +
+ sizeof(GPBMessageFieldDescription)),
+ DescriptionsWithDefault_different_size_than_expected);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBDictionary.h b/third_party/protobuf/objectivec/GPBDictionary.h
new file mode 100644
index 0000000000..9d674150e3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary.h
@@ -0,0 +1,8570 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+// Note on naming: for the classes holding numeric values, a more natural
+// naming of the method might be things like "-valueForKey:",
+// "-setValue:forKey:"; etc. But those selectors are also defined by Key Value
+// Coding (KVC) as categories on NSObject. So "overloading" the selectors with
+// other meanings can cause warnings (based on compiler settings), but more
+// importantly, some of those selector get called as KVC breaks up keypaths.
+// So if those selectors are used, using KVC will compile cleanly, but could
+// crash as it invokes those selectors with the wrong types of arguments.
+
+NS_ASSUME_NONNULL_BEGIN
+
+//%PDDM-EXPAND DECLARE_DICTIONARIES()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32 -> UInt32
+
+/**
+ * Class used for map fields of <uint32_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint32_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+/**
+ * Class used for map fields of <uint32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+/**
+ * Class used for map fields of <uint32_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint32_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+/**
+ * Class used for map fields of <uint32_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint32_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+/**
+ * Class used for map fields of <uint32_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint32_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+/**
+ * Class used for map fields of <uint32_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint32_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+/**
+ * Class used for map fields of <uint32_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint32_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+/**
+ * Class used for map fields of <uint32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint32_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(uint32_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+/**
+ * Class used for map fields of <uint32_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint32_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> UInt32
+
+/**
+ * Class used for map fields of <int32_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int32_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+/**
+ * Class used for map fields of <int32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+/**
+ * Class used for map fields of <int32_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int32_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+/**
+ * Class used for map fields of <int32_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int32_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+/**
+ * Class used for map fields of <int32_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int32_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Float
+
+/**
+ * Class used for map fields of <int32_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int32_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Double
+
+/**
+ * Class used for map fields of <int32_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int32_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+/**
+ * Class used for map fields of <int32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int32_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(int32_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Object
+
+/**
+ * Class used for map fields of <int32_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int32_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> UInt32
+
+/**
+ * Class used for map fields of <uint64_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint64_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+/**
+ * Class used for map fields of <uint64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+/**
+ * Class used for map fields of <uint64_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint64_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+/**
+ * Class used for map fields of <uint64_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint64_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+/**
+ * Class used for map fields of <uint64_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint64_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+/**
+ * Class used for map fields of <uint64_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint64_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+/**
+ * Class used for map fields of <uint64_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint64_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+/**
+ * Class used for map fields of <uint64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint64_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(uint64_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+/**
+ * Class used for map fields of <uint64_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint64_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> UInt32
+
+/**
+ * Class used for map fields of <int64_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int64_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+/**
+ * Class used for map fields of <int64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+/**
+ * Class used for map fields of <int64_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int64_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+/**
+ * Class used for map fields of <int64_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int64_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+/**
+ * Class used for map fields of <int64_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int64_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Float
+
+/**
+ * Class used for map fields of <int64_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int64_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Double
+
+/**
+ * Class used for map fields of <int64_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int64_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+/**
+ * Class used for map fields of <int64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int64_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(int64_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Object
+
+/**
+ * Class used for map fields of <int64_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int64_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> UInt32
+
+/**
+ * Class used for map fields of <BOOL, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolUInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(BOOL key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Int32
+
+/**
+ * Class used for map fields of <BOOL, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> UInt64
+
+/**
+ * Class used for map fields of <BOOL, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolUInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(BOOL key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Int64
+
+/**
+ * Class used for map fields of <BOOL, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(BOOL key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Bool
+
+/**
+ * Class used for map fields of <BOOL, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolBoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(BOOL key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Float
+
+/**
+ * Class used for map fields of <BOOL, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolFloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(BOOL key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Double
+
+/**
+ * Class used for map fields of <BOOL, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolDoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(BOOL key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Enum
+
+/**
+ * Class used for map fields of <BOOL, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolEnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(BOOL)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Object
+
+/**
+ * Class used for map fields of <BOOL, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(BOOL key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> UInt32
+
+/**
+ * Class used for map fields of <NSString, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringUInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(NSString *key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Int32
+
+/**
+ * Class used for map fields of <NSString, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> UInt64
+
+/**
+ * Class used for map fields of <NSString, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringUInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(NSString *key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Int64
+
+/**
+ * Class used for map fields of <NSString, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(NSString *key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Bool
+
+/**
+ * Class used for map fields of <NSString, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringBoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(NSString *key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Float
+
+/**
+ * Class used for map fields of <NSString, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringFloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(NSString *key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Double
+
+/**
+ * Class used for map fields of <NSString, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringDoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(NSString *key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Enum
+
+/**
+ * Class used for map fields of <NSString, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringEnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(NSString *key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(NSString *)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+//%PDDM-EXPAND-END DECLARE_DICTIONARIES()
+
+NS_ASSUME_NONNULL_END
+
+//%PDDM-DEFINE DECLARE_DICTIONARIES()
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt32, uint32_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int32, int32_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt64, uint64_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int64, int64_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Bool, BOOL)
+//%DICTIONARY_POD_INTERFACES_FOR_KEY(String, NSString, *, OBJECT)
+//%PDDM-DEFINE DICTIONARY_INTERFACES_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
+//%DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
+//%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, ObjectType)
+//%PDDM-DEFINE DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt32, uint32_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int32, int32_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt64, uint64_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int64, int64_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Bool, BOOL)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Float, float)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Double, double)
+//%DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Enum, int32_t)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
+//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, , POD, VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
+//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
+//%/**
+//% * Gets the value for the given key.
+//% *
+//% * @param value Pointer into which the value will be set, if found.
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return YES if the key was found and the value was copied, NO otherwise.
+//% **/
+//%- (BOOL)get##VNAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key;
+//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_TYPE, VNAME)
+//%/**
+//% * Fetches the object stored under the given key.
+//% *
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return The object if found, nil otherwise.
+//% **/
+//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key;
+//%PDDM-DEFINE VALUE_FOR_KEY_Enum(KEY_TYPE, VALUE_TYPE, VNAME)
+//%VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
+//%PDDM-DEFINE ARRAY_ARG_MODIFIERPOD()
+// Nothing
+//%PDDM-DEFINE ARRAY_ARG_MODIFIEREnum()
+// Nothing
+//%PDDM-DEFINE ARRAY_ARG_MODIFIEROBJECT()
+//%__nonnull GPB_UNSAFE_UNRETAINED ##
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary<__covariant VALUE_TYPE>
+//%PDDM-DEFINE DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%/**
+//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
+//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) : NSObject <NSCopying>
+//%
+//%/** Number of entries stored in this dictionary. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%
+//%/**
+//% * @return A newly instanced and empty dictionary.
+//% **/
+//%+ (instancetype)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the single entry given.
+//% *
+//% * @param ##VNAME_VAR The value to be placed in the dictionary.
+//% * @param key ##VNAME_VAR$S## The key under which to store the value.
+//% *
+//% * @return A newly instanced dictionary with the key and value in it.
+//% **/
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
+//% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries given.
+//% *
+//% * @param ##VNAME_VAR##s The values to be placed in the dictionary.
+//% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
+//% * @param count ##VNAME_VAR$S## The number of entries to store in the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the keys and values in it.
+//% **/
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% ##VNAME$S## count:(NSUInteger)count;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given capacity.
+//% *
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the given capacity.
+//% **/
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+//%
+//%/**
+//% * Initializes this dictionary, copying the given values and keys.
+//% *
+//% * @param ##VNAME_VAR##s The values to be placed in this dictionary.
+//% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
+//% * @param count ##VNAME_VAR$S## The number of elements to copy into the dictionary.
+//% *
+//% * @return A newly initialized dictionary with a copy of the values and keys.
+//% **/
+//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% ##VNAME$S## count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes this dictionary, copying the entries from the given dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to this dictionary.
+//% *
+//% * @return A newly initialized dictionary with the entries of the given dictionary.
+//% **/
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Initializes this dictionary with the requested capacity.
+//% *
+//% * @param numItems Number of items needed for this dictionary.
+//% *
+//% * @return A newly initialized dictionary with the requested capacity.
+//% **/
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems;
+//%
+//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%
+//%/**
+//% * Adds the keys and values from another dictionary.
+//% *
+//% * @param otherDictionary Dictionary containing entries to be added to this
+//% * dictionary.
+//% **/
+//%- (void)addEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
+//%
+//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, Enum)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%/**
+//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
+//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary : NSObject <NSCopying>
+//%
+//%/** Number of entries stored in this dictionary. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%/** The validation function to check if the enums are valid. */
+//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+//%
+//%/**
+//% * @return A newly instanced and empty dictionary.
+//% **/
+//%+ (instancetype)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given validation function.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% *
+//% * @return A newly instanced dictionary.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the single entry given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param rawValue The raw enum value to be placed in the dictionary.
+//% * @param key The key under which to store the value.
+//% *
+//% * @return A newly instanced dictionary with the key and value in it.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValue:(VALUE_TYPE)rawValue
+//% forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param values The raw enum values values to be placed in the dictionary.
+//% * @param keys The keys under which to store the values.
+//% * @param count The number of entries to store in the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the keys and values in it.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given capacity.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the given capacity.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems;
+//%
+//%/**
+//% * Initializes a dictionary with the given validation function.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% *
+//% * @return A newly initialized dictionary.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Initializes a dictionary with the entries given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param values The raw enum values values to be placed in the dictionary.
+//% * @param keys The keys under which to store the values.
+//% * @param count The number of entries to store in the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the keys and values in it.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Initializes a dictionary with the given capacity.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the given capacity.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems;
+//%
+//%// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+//%// is not a valid enumerator as defined by validationFunc. If the actual value is
+//%// desired, use "raw" version of the method.
+//%
+//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
+//%
+//%/**
+//% * Gets the raw enum value for the given key.
+//% *
+//% * @note This method bypass the validationFunc to enable the access of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param rawValue Pointer into which the value will be set, if found.
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return YES if the key was found and the value was copied, NO otherwise.
+//% **/
+//%- (BOOL)getRawValue:(nullable VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Enumerates the keys and values on this dictionary with the given block.
+//% *
+//% * @note This method bypass the validationFunc to enable the access of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param block The block to enumerate with.
+//% * **key**: The key for the current entry.
+//% * **rawValue**: The value for the current entry
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateKeysAndRawValuesUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE rawValue, BOOL *stop))block;
+//%
+//%/**
+//% * Adds the keys and raw enum values from another dictionary.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param otherDictionary Dictionary containing entries to be added to this
+//% * dictionary.
+//% **/
+//%- (void)addRawEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
+//%
+//%// If value is not a valid enumerator as defined by validationFunc, these
+//%// methods will assert in debug, and will log in release and assign the value
+//%// to the default value. Use the rawValue methods below to assign non enumerator
+//%// values.
+//%
+//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_TYPE, VNAME)
+//%
+//%/**
+//% * Enumerates the keys and values on this dictionary with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **key**: ##VNAME_VAR$S## The key for the current entry.
+//% * **VNAME_VAR**: The value for the current entry
+//% * **stop**: ##VNAME_VAR$S## A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block;
+
+//%PDDM-DEFINE DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%/**
+//% * Sets the value for the given key.
+//% *
+//% * @param ##VNAME_VAR The value to set.
+//% * @param key ##VNAME_VAR$S## The key under which to store the value.
+//% **/
+//%- (void)set##VNAME##:(VALUE_TYPE)##VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%DICTIONARY_EXTRA_MUTABLE_METHODS_##VHELPER(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+//%/**
+//% * Removes the entry for the given key.
+//% *
+//% * @param aKey Key to be removed from this dictionary.
+//% **/
+//%- (void)remove##VNAME##ForKey:(KEY_TYPE##KisP$S##KisP)aKey;
+//%
+//%/**
+//% * Removes all entries in this dictionary.
+//% **/
+//%- (void)removeAll;
+
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_POD(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+// Empty
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_OBJECT(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+// Empty
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_Enum(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+//%
+//%/**
+//% * Sets the raw enum value for the given key.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param rawValue The raw enum value to set.
+//% * @param key The key under which to store the raw enum value.
+//% **/
+//%- (void)setRawValue:(VALUE_TYPE)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
diff --git a/third_party/protobuf/objectivec/GPBDictionary.m b/third_party/protobuf/objectivec/GPBDictionary.m
new file mode 100644
index 0000000000..1c67c680e9
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary.m
@@ -0,0 +1,13627 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBDictionary_PackagePrivate.h"
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// ------------------------------ NOTE ------------------------------
+// At the moment, this is all using NSNumbers in NSDictionaries under
+// the hood, but it is all hidden so we can come back and optimize
+// with direct CFDictionary usage later. The reason that wasn't
+// done yet is needing to support 32bit iOS builds. Otherwise
+// it would be pretty simple to store all this data in CFDictionaries
+// directly.
+// ------------------------------------------------------------------
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Used to include code only visible to specific versions of the static
+// analyzer. Useful for wrapping code that only exists to silence the analyzer.
+// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
+// END_APPLE_BUILD_VERSION using:
+// xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
+// Example usage:
+// #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
+#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
+ (defined(__clang_analyzer__) && \
+ (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
+ __apple_build_version__ <= END_APPLE_BUILD_VERSION))
+
+enum {
+ kMapKeyFieldNumber = 1,
+ kMapValueFieldNumber = 2,
+};
+
+static BOOL DictDefault_IsValidValue(int32_t value) {
+ // Anything but the bad value marker is allowed.
+ return (value != kGPBUnrecognizedEnumeratorValue);
+}
+
+//%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% return 0;
+//% }
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% }
+//%}
+//%
+//%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
+//% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% return 0;
+//% }
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
+//% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% }
+//%}
+//%
+//%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
+//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
+//% #pragma unused(dataType) // For when asserts are off in release.
+//% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
+//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
+//% #pragma unused(dataType) // For when asserts are off in release.
+//% [stream write##VALUE_NAME##:fieldNum value:value];
+//%}
+//%
+//%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
+//%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
+//%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
+//%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
+//%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
+//%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
+//%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
+//%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
+//%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
+//%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
+//%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
+//%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
+// This block of code is generated, do not edit it directly.
+
+static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt32) {
+ return GPBComputeInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSInt32) {
+ return GPBComputeSInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSFixed32) {
+ return GPBComputeSFixed32Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt32) {
+ [stream writeInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSInt32) {
+ [stream writeSInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSFixed32) {
+ [stream writeSFixed32:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt32) {
+ return GPBComputeUInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeFixed32) {
+ return GPBComputeFixed32Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt32) {
+ [stream writeUInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeFixed32) {
+ [stream writeFixed32:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt64) {
+ return GPBComputeInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSInt64) {
+ return GPBComputeSInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSFixed64) {
+ return GPBComputeSFixed64Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt64) {
+ [stream writeInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSInt64) {
+ [stream writeSInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSFixed64) {
+ [stream writeSFixed64:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt64) {
+ return GPBComputeUInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeFixed64) {
+ return GPBComputeFixed64Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt64) {
+ [stream writeUInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeFixed64) {
+ [stream writeFixed64:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeBoolSize(fieldNum, value);
+}
+
+static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeBool:fieldNum value:value];
+}
+
+static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeEnumSize(fieldNum, value);
+}
+
+static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeEnum:fieldNum value:value];
+}
+
+static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeFloatSize(fieldNum, value);
+}
+
+static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeFloat:fieldNum value:value];
+}
+
+static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeDoubleSize(fieldNum, value);
+}
+
+static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeDouble:fieldNum value:value];
+}
+
+static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeStringSize(fieldNum, value);
+}
+
+static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeString:fieldNum value:value];
+}
+
+static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeMessage) {
+ return GPBComputeMessageSize(fieldNum, value);
+ } else if (dataType == GPBDataTypeString) {
+ return GPBComputeStringSize(fieldNum, value);
+ } else if (dataType == GPBDataTypeBytes) {
+ return GPBComputeBytesSize(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeMessage) {
+ [stream writeMessage:fieldNum value:value];
+ } else if (dataType == GPBDataTypeString) {
+ [stream writeString:fieldNum value:value];
+ } else if (dataType == GPBDataTypeBytes) {
+ [stream writeBytes:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
+
+size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
+ GPBDataType mapValueType = GPBGetFieldDataType(field);
+ __block size_t result = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
+ msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * dict.count;
+ return result;
+}
+
+void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
+ NSDictionary *dict,
+ GPBFieldDescriptor *field) {
+ NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
+ GPBDataType mapValueType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
+ msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
+
+ // Write the size and fields.
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ [outputStream writeString:kMapKeyFieldNumber value:key];
+ WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
+ }];
+}
+
+BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
+ NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
+ NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
+ #pragma unused(field) // For when asserts are off in release.
+ for (GPBMessage *msg in [dict objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+// Note: if the type is an object, it the retain pass back to the caller.
+static void ReadValue(GPBCodedInputStream *stream,
+ GPBGenericValue *valueToFill,
+ GPBDataType type,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field) {
+ switch (type) {
+ case GPBDataTypeBool:
+ valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
+ break;
+ case GPBDataTypeFixed32:
+ valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
+ break;
+ case GPBDataTypeSFixed32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
+ break;
+ case GPBDataTypeFloat:
+ valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
+ break;
+ case GPBDataTypeFixed64:
+ valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
+ break;
+ case GPBDataTypeSFixed64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
+ break;
+ case GPBDataTypeDouble:
+ valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
+ break;
+ case GPBDataTypeInt32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
+ break;
+ case GPBDataTypeInt64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadInt32(&stream->state_);
+ break;
+ case GPBDataTypeSInt32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
+ break;
+ case GPBDataTypeSInt64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
+ break;
+ case GPBDataTypeUInt32:
+ valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
+ break;
+ case GPBDataTypeUInt64:
+ valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
+ break;
+ case GPBDataTypeBytes:
+ [valueToFill->valueData release];
+ valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
+ break;
+ case GPBDataTypeString:
+ [valueToFill->valueString release];
+ valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
+ break;
+ case GPBDataTypeMessage: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [stream readMessage:message extensionRegistry:registry];
+ [valueToFill->valueMessage release];
+ valueToFill->valueMessage = message;
+ break;
+ }
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"Can't happen");
+ break;
+ case GPBDataTypeEnum:
+ valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
+ break;
+ }
+}
+
+void GPBDictionaryReadEntry(id mapDictionary,
+ GPBCodedInputStream *stream,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field,
+ GPBMessage *parentMessage) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+
+ GPBGenericValue key;
+ GPBGenericValue value;
+ // Zero them (but pick up any enum default for proto2).
+ key.valueString = value.valueString = nil;
+ if (valueDataType == GPBDataTypeEnum) {
+ value = field.defaultValue;
+ }
+
+ GPBCodedInputStreamState *state = &stream->state_;
+ uint32_t keyTag =
+ GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
+ uint32_t valueTag =
+ GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
+
+ BOOL hitError = NO;
+ while (YES) {
+ uint32_t tag = GPBCodedInputStreamReadTag(state);
+ if (tag == keyTag) {
+ ReadValue(stream, &key, keyDataType, registry, field);
+ } else if (tag == valueTag) {
+ ReadValue(stream, &value, valueDataType, registry, field);
+ } else if (tag == 0) {
+ // zero signals EOF / limit reached
+ break;
+ } else { // Unknown
+ if (![stream skipField:tag]){
+ hitError = YES;
+ break;
+ }
+ }
+ }
+
+ if (!hitError) {
+ // Handle the special defaults and/or missing key/value.
+ if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
+ key.valueString = [@"" retain];
+ }
+ if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ value.valueString = [@"" retain];
+ break;
+ case GPBDataTypeBytes:
+ value.valueData = [GPBEmptyNSData() retain];
+ break;
+#if defined(__clang_analyzer__)
+ case GPBDataTypeGroup:
+ // Maps can't really have Groups as the value type, but this case is needed
+ // so the analyzer won't report the posibility of send nil in for the value
+ // in the NSMutableDictionary case below.
+#endif
+ case GPBDataTypeMessage: {
+ value.valueMessage = [[field.msgClass alloc] init];
+ break;
+ }
+ default:
+ // Nothing
+ break;
+ }
+#pragma clang diagnostic pop
+ }
+
+ if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
+#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
+ // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
+ // be raised as needed for new Xcodes.
+ //
+ // This is only needed on a "shallow" analyze; on a "deep" analyze, the
+ // existing code path gets this correct. In shallow, the analyzer decides
+ // GPBDataTypeIsObject(valueDataType) is both false and true on a single
+ // path through this function, allowing nil to be used for the
+ // setObject:forKey:.
+ if (value.valueString == nil) {
+ value.valueString = [@"" retain];
+ }
+#endif
+ // mapDictionary is an NSMutableDictionary
+ [(NSMutableDictionary *)mapDictionary setObject:value.valueString
+ forKey:key.valueString];
+ } else {
+ if (valueDataType == GPBDataTypeEnum) {
+ if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
+ [field isValidEnumValue:value.valueEnum]) {
+ [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
+ } else {
+ NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
+ forKey:&key
+ keyDataType:keyDataType];
+ [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
+ }
+ } else {
+ [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
+ }
+ }
+ }
+
+ if (GPBDataTypeIsObject(keyDataType)) {
+ [key.valueString release];
+ }
+ if (GPBDataTypeIsObject(valueDataType)) {
+ [value.valueString release];
+ }
+}
+
+//
+// Macros for the common basic cases.
+//
+
+//%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
+//%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
+//%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
+
+//%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
+//%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
+
+//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
+
+//%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
+//% @package
+//% NSMutableDictionary *_dictionary;
+//%}
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
+//% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR
+//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:&key
+//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s
+//% KEY_NAME$S VALUE_NAME$S forKeys:keys
+//% KEY_NAME$S VALUE_NAME$S count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithCapacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% _dictionary = [[NSMutableDictionary alloc] init];
+//% if (count && VNAME_VAR##s && keys) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//%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])];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
+//%
+//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%
+//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
+//% @package
+//% NSMutableDictionary *_dictionary;
+//% GPBEnumValidationFunc _validationFunc;
+//%}
+//%
+//%@synthesize validationFunc = _validationFunc;
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWithValidationFunction:NULL
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+//% return [[[self alloc] initWithValidationFunction:func
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValue:(VALUE_TYPE)rawValue
+//% forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func
+//% KEY_NAME$S VALUE_NAME$S rawValues:&rawValue
+//% KEY_NAME$S VALUE_NAME$S forKeys:&key
+//% KEY_NAME$S VALUE_NAME$S count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE [])rawValues
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func
+//% KEY_NAME$S VALUE_NAME$S rawValues:rawValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:keys
+//% KEY_NAME$S VALUE_NAME$S count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE [])rawValues
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% _dictionary = [[NSMutableDictionary alloc] init];
+//% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+//% if (count && rawValues && keys) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWithValidationFunction:dictionary.validationFunc
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0];
+//% if (self) {
+//% if (dictionary) {
+//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
+//%
+//%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && value) {
+//% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
+//% if (!_validationFunc(result)) {
+//% result = kGPBUnrecognizedEnumeratorValue;
+//% }
+//% *value = result;
+//% }
+//% return (wrapped != NULL);
+//%}
+//%
+//%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && rawValue) {
+//% *rawValue = UNWRAP##VALUE_NAME(wrapped);
+//% }
+//% return (wrapped != NULL);
+//%}
+//%
+//%- (void)enumerateKeysAndEnumsUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
+//% GPBEnumValidationFunc func = _validationFunc;
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue,
+//% BOOL *stop) {
+//% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
+//% if (!func(unwrapped)) {
+//% unwrapped = kGPBUnrecognizedEnumeratorValue;
+//% }
+//% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop);
+//% }];
+//%}
+//%
+//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
+//%
+//%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
+//% value];
+//% }
+//%
+//% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [_dictionary release];
+//% [super dealloc];
+//%}
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
+//% return NO;
+//% }
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
+//% return [_dictionary isEqual:otherDictionary->_dictionary];
+//%}
+//%
+//%- (NSUInteger)hash {
+//% return _dictionary.count;
+//%}
+//%
+//%- (NSString *)description {
+//% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+//%}
+//%
+//%- (NSUInteger)count {
+//% return _dictionary.count;
+//%}
+//%
+//%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u,
+//% BOOL *stop) {
+//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), stop);
+//% }];
+//%}
+//%
+//%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+//% NSUInteger count = _dictionary.count;
+//% if (count == 0) {
+//% return 0;
+//% }
+//%
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% GPBDataType keyDataType = field.mapKeyDataType;
+//% __block size_t result = 0;
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u##,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+//% }];
+//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+//% result += tagSize * count;
+//% return result;
+//%}
+//%
+//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+//% asField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% GPBDataType keyDataType = field.mapKeyDataType;
+//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% // Write the tag.
+//% [outputStream writeInt32NoTag:tag];
+//% // Write the size of the message.
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% [outputStream writeInt32NoTag:(int32_t)msgSize];
+//% // Write the fields.
+//% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% }];
+//%}
+//%
+//%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
+//%}
+//%
+//%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
+//% #pragma unused(stop)
+//% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
+//% }];
+//%}
+//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
+//%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
+//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
+//% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
+//%}
+//%
+//%- (void)removeAll {
+//% [_dictionary removeAllObjects];
+//%}
+
+//
+// Custom Generation for Bool keys
+//
+
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
+
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
+//%#pragma mark - Bool -> VALUE_NAME
+//%
+//%@implementation GPBBool##VALUE_NAME##Dictionary {
+//% @package
+//% VALUE_TYPE _values[2];
+//%BOOL_DICT_HAS_STORAGE_##HELPER()}
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)VNAME_VAR
+//% ##VNAME$S## forKey:(BOOL)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR
+//% VALUE_NAME$S ##VNAME$S## forKeys:&key
+//% VALUE_NAME$S ##VNAME$S## count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const BOOL [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s
+//% VALUE_NAME$S ##VNAME$S## forKeys:keys
+//% VALUE_NAME$S ##VNAME$S## count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithCapacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%BOOL_DICT_DEALLOC##HELPER()
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
+//% return NO;
+//% }
+//% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
+//% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
+//% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
+//% return NO;
+//% }
+//% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
+//% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
+//% return NO;
+//% }
+//% return YES;
+//%}
+//%
+//%- (NSUInteger)hash {
+//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
+//%}
+//%
+//%- (NSString *)description {
+//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+//% if (BOOL_DICT_W_HAS##HELPER(0, )) {
+//% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
+//% }
+//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
+//% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
+//% }
+//% [result appendString:@" }"];
+//% return result;
+//%}
+//%
+//%- (NSUInteger)count {
+//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
+//%}
+//%
+//%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
+//%
+//%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+//% if (BOOL_DICT_HAS##HELPER(0, )) {
+//% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
+//% }
+//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
+//% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
+//% }
+//%}
+//%
+//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
+//% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
+//% BOOL stop = NO;
+//% if (BOOL_DICT_HAS##HELPER(0, )) {
+//% block(NO, _values[0], &stop);
+//% }
+//% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
+//% block(YES, _values[1], &stop);
+//% }
+//%}
+//%
+//%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% NSUInteger count = 0;
+//% size_t result = 0;
+//% for (int i = 0; i < 2; ++i) {
+//% if (BOOL_DICT_HAS##HELPER(i, )) {
+//% ++count;
+//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+//% }
+//% }
+//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+//% result += tagSize * count;
+//% return result;
+//%}
+//%
+//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+//% asField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+//% for (int i = 0; i < 2; ++i) {
+//% if (BOOL_DICT_HAS##HELPER(i, )) {
+//% // Write the tag.
+//% [outputStream writeInt32NoTag:tag];
+//% // Write the size of the message.
+//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+//% [outputStream writeInt32NoTag:(int32_t)msgSize];
+//% // Write the fields.
+//% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+//% }
+//% }
+//%}
+//%
+//%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%@end
+//%
+
+
+//
+// Helpers for PODs
+//
+
+//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && value) {
+//% *value = UNWRAP##VALUE_NAME(wrapped);
+//% }
+//% return (wrapped != NULL);
+//%}
+//%PDDM-DEFINE WRAPPEDPOD(VALUE)
+//%@(VALUE)
+//%PDDM-DEFINE UNWRAPUInt32(VALUE)
+//%[VALUE unsignedIntValue]
+//%PDDM-DEFINE UNWRAPInt32(VALUE)
+//%[VALUE intValue]
+//%PDDM-DEFINE UNWRAPUInt64(VALUE)
+//%[VALUE unsignedLongLongValue]
+//%PDDM-DEFINE UNWRAPInt64(VALUE)
+//%[VALUE longLongValue]
+//%PDDM-DEFINE UNWRAPBool(VALUE)
+//%[VALUE boolValue]
+//%PDDM-DEFINE UNWRAPFloat(VALUE)
+//%[VALUE floatValue]
+//%PDDM-DEFINE UNWRAPDouble(VALUE)
+//%[VALUE doubleValue]
+//%PDDM-DEFINE UNWRAPEnum(VALUE)
+//%[VALUE intValue]
+//%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
+//%[NSString stringWithFormat:@"%u", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
+//%[NSString stringWithFormat:@"%d", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
+//%[NSString stringWithFormat:@"%llu", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
+//%[NSString stringWithFormat:@"%lld", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
+//%(VALUE ? @"true" : @"false")
+//%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
+//%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
+//%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
+//%@(VALUE)
+//%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
+//%NSNumber *
+//%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
+//%VAL1 != VAL2
+//%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
+//%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
+//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
+//% forKey:(GPBGenericValue *)key
+//% keyDataType:(GPBDataType)keyDataType {
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+//% NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+//% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+//% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
+//% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+//% [outputStream release];
+//% return data;
+//%}
+//%
+//%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
+//%value##VALUE_NAME
+//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
+// Empty
+//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
+// Empty
+
+//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
+//% BOOL _valueSet[2];
+//%
+//%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
+//%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
+//% ##VALUE_NAME$S## forKeys:(const BOOL [])keys
+//% ##VALUE_NAME$S## count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% int idx = keys[i] ? 1 : 0;
+//% _values[idx] = values[i];
+//% _valueSet[idx] = YES;
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (dictionary->_valueSet[i]) {
+//% _values[i] = dictionary->_values[i];
+//% _valueSet[i] = YES;
+//% }
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
+//%#if !defined(NS_BLOCK_ASSERTIONS)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [super dealloc];
+//%}
+//%#endif // !defined(NS_BLOCK_ASSERTIONS)
+//%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
+//%BOOL_DICT_HASPOD(IDX, REF)
+//%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
+//%REF##_valueSet[IDX]
+//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
+//%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
+//% int idx = (key ? 1 : 0);
+//% if (_valueSet[idx]) {
+//% if (value) {
+//% *value = _values[idx];
+//% }
+//% return YES;
+//% }
+//% return NO;
+//%}
+//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
+//%- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% int idx = (key->valueBool ? 1 : 0);
+//% _values[idx] = value->value##VALUE_NAME;
+//% _valueSet[idx] = YES;
+//%}
+//%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
+//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (otherDictionary->_valueSet[i]) {
+//% _valueSet[i] = YES;
+//% _values[i] = otherDictionary->_values[i];
+//% }
+//% }
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
+//% int idx = (key ? 1 : 0);
+//% _values[idx] = value;
+//% _valueSet[idx] = YES;
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
+//% _valueSet[aKey ? 1 : 0] = NO;
+//%}
+//%
+//%- (void)removeAll {
+//% _valueSet[0] = NO;
+//% _valueSet[1] = NO;
+//%}
+//%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
+//%STR_FORMAT_##VALUE_NAME()
+//%PDDM-DEFINE STR_FORMAT_UInt32()
+//%%u
+//%PDDM-DEFINE STR_FORMAT_Int32()
+//%%d
+//%PDDM-DEFINE STR_FORMAT_UInt64()
+//%%llu
+//%PDDM-DEFINE STR_FORMAT_Int64()
+//%%lld
+//%PDDM-DEFINE STR_FORMAT_Bool()
+//%%d
+//%PDDM-DEFINE STR_FORMAT_Float()
+//%%f
+//%PDDM-DEFINE STR_FORMAT_Double()
+//%%lf
+
+//
+// Helpers for Objects
+//
+
+//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
+//% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% return result;
+//%}
+//%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
+//%VALUE
+//%PDDM-DEFINE UNWRAPString(VALUE)
+//%VALUE
+//%PDDM-DEFINE UNWRAPObject(VALUE)
+//%VALUE
+//%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
+//%VALUE
+//%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
+//%VALUE
+//%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
+//%ENUM_TYPEOBJECT_##TYPE()
+//%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
+//%NSString *
+//%PDDM-DEFINE ENUM_TYPEOBJECT_id()
+//%id ##
+//%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
+//%![VAL1 isEqual:VAL2]
+//%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
+//%- (BOOL)isInitialized {
+//% for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+//% if (!msg.initialized) {
+//% return NO;
+//% }
+//% }
+//% return YES;
+//%}
+//%
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+//% GPBMessage *msg,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% GPBMessage *copiedMsg = [msg copyWithZone:zone];
+//% [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+//% [copiedMsg release];
+//% }];
+//% return newDict;
+//%}
+//%
+//%
+//%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
+//%- (BOOL)isInitialized {
+//% if (_values[0] && ![_values[0] isInitialized]) {
+//% return NO;
+//% }
+//% if (_values[1] && ![_values[1] isInitialized]) {
+//% return NO;
+//% }
+//% return YES;
+//%}
+//%
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% for (int i = 0; i < 2; ++i) {
+//% if (_values[i] != nil) {
+//% newDict->_values[i] = [_values[i] copyWithZone:zone];
+//% }
+//% }
+//% return newDict;
+//%}
+//%
+//%
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
+//%valueString
+//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
+//%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
+//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
+//%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
+//%##EXTRA_INDENT$S## }
+//%
+//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
+//%##EXTRA_INDENT$S## if (!##KEY_NAME) {
+//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
+//%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
+//%##EXTRA_INDENT$S## }
+//%
+
+//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
+// Empty
+//%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
+//% forKeys:(const BOOL [])keys
+//% count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% if (!objects[i]) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"Attempting to add nil object to a Dictionary"];
+//% }
+//% int idx = keys[i] ? 1 : 0;
+//% [_values[idx] release];
+//% _values[idx] = (VALUE_TYPE)[objects[i] retain];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWithObjects:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% _values[0] = [dictionary->_values[0] retain];
+//% _values[1] = [dictionary->_values[1] retain];
+//% }
+//% }
+//% return self;
+//%}
+//%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [_values[0] release];
+//% [_values[1] release];
+//% [super dealloc];
+//%}
+//%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
+//%(BOOL_DICT_HASOBJECT(IDX, REF))
+//%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
+//%REF##_values[IDX] != nil
+//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (VALUE_TYPE)objectForKey:(BOOL)key {
+//% return _values[key ? 1 : 0];
+//%}
+//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
+//%- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% int idx = (key->valueBool ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = [value->valueString retain];
+//%}
+
+//%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (otherDictionary->_values[i] != nil) {
+//% [_values[i] release];
+//% _values[i] = [otherDictionary->_values[i] retain];
+//% }
+//% }
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
+//% if (!object) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"Attempting to add nil object to a Dictionary"];
+//% }
+//% int idx = (key ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = [object retain];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)removeObjectForKey:(BOOL)aKey {
+//% int idx = (aKey ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = nil;
+//%}
+//%
+//%- (void)removeAll {
+//% for (int i = 0; i < 2; ++i) {
+//% [_values[i] release];
+//% _values[i] = nil;
+//% }
+//%}
+//%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
+//%%@
+
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32 -> UInt32
+
+@implementation GPBUInt32UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint32_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+@implementation GPBUInt32Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+@implementation GPBUInt32UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint32_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+@implementation GPBUInt32Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint32_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+@implementation GPBUInt32BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint32_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+@implementation GPBUInt32FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint32_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+@implementation GPBUInt32DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint32_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+@implementation GPBUInt32EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey unsignedIntValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(uint32_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+@implementation GPBUInt32ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint32_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBUInt32ObjectDictionary *newDict =
+ [[GPBUInt32ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], object);
+ }];
+}
+
+- (id)objectForKey:(uint32_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(uint32_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32 -> UInt32
+
+@implementation GPBInt32UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int32_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+@implementation GPBInt32Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+@implementation GPBInt32UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int32_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+@implementation GPBInt32Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int32_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+@implementation GPBInt32BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
+ return NO;
+ }
+ GPBInt32BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int32_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Float
+
+@implementation GPBInt32FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
+ return NO;
+ }
+ GPBInt32FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int32_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Double
+
+@implementation GPBInt32DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBInt32DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int32_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+@implementation GPBInt32EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
+ return NO;
+ }
+ GPBInt32EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey intValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(int32_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - Int32 -> Object
+
+@implementation GPBInt32ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBInt32ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int32_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey intValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBInt32ObjectDictionary *newDict =
+ [[GPBInt32ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], object);
+ }];
+}
+
+- (id)objectForKey:(int32_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(int32_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64 -> UInt32
+
+@implementation GPBUInt64UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint64_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+@implementation GPBUInt64Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+@implementation GPBUInt64UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint64_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+@implementation GPBUInt64Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint64_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+@implementation GPBUInt64BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint64_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+@implementation GPBUInt64FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint64_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+@implementation GPBUInt64DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint64_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+@implementation GPBUInt64EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey unsignedLongLongValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(uint64_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+@implementation GPBUInt64ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint64_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBUInt64ObjectDictionary *newDict =
+ [[GPBUInt64ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], object);
+ }];
+}
+
+- (id)objectForKey:(uint64_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(uint64_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64 -> UInt32
+
+@implementation GPBInt64UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int64_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+@implementation GPBInt64Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+@implementation GPBInt64UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int64_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+@implementation GPBInt64Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int64_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+@implementation GPBInt64BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
+ return NO;
+ }
+ GPBInt64BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int64_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Float
+
+@implementation GPBInt64FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
+ return NO;
+ }
+ GPBInt64FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int64_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Double
+
+@implementation GPBInt64DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBInt64DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int64_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+@implementation GPBInt64EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
+ return NO;
+ }
+ GPBInt64EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey longLongValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(int64_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - Int64 -> Object
+
+@implementation GPBInt64ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBInt64ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int64_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey longLongValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBInt64ObjectDictionary *newDict =
+ [[GPBInt64ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], object);
+ }];
+}
+
+- (id)objectForKey:(int64_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(int64_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - String -> UInt32
+
+@implementation GPBStringUInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBStringUInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(NSString *key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Int32
+
+@implementation GPBStringInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBStringInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> UInt64
+
+@implementation GPBStringUInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBStringUInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(NSString *key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Int64
+
+@implementation GPBStringInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBStringInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(NSString *key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Bool
+
+@implementation GPBStringBoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
+ return NO;
+ }
+ GPBStringBoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(NSString *key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Float
+
+@implementation GPBStringFloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
+ return NO;
+ }
+ GPBStringFloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(NSString *key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Double
+
+@implementation GPBStringDoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
+ return NO;
+ }
+ GPBStringDoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(NSString *key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Enum
+
+@implementation GPBStringEnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
+ return NO;
+ }
+ GPBStringEnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(aKey, unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+//%PDDM-EXPAND-END (5 expansions)
+
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt32
+
+@implementation GPBBoolUInt32Dictionary {
+ @package
+ uint32_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolUInt32Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %u", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %u", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueUInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(BOOL key, uint32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int32
+
+@implementation GPBBoolInt32Dictionary {
+ @package
+ int32_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolInt32Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt64
+
+@implementation GPBBoolUInt64Dictionary {
+ @package
+ uint64_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolUInt64Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %llu", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %llu", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueUInt64;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(BOOL key, uint64_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int64
+
+@implementation GPBBoolInt64Dictionary {
+ @package
+ int64_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolInt64Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %lld", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %lld", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt64;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(BOOL key, int64_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Bool
+
+@implementation GPBBoolBoolDictionary {
+ @package
+ BOOL _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
+ return NO;
+ }
+ GPBBoolBoolDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueBool;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", (_values[0] ? @"true" : @"false"));
+ }
+ if (_valueSet[1]) {
+ block(@"true", (_values[1] ? @"true" : @"false"));
+ }
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(BOOL key, BOOL value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Float
+
+@implementation GPBBoolFloatDictionary {
+ @package
+ float _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
+ return NO;
+ }
+ GPBBoolFloatDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %f", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %f", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getFloat:(float *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueFloat;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(BOOL key, float value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Double
+
+@implementation GPBBoolDoubleDictionary {
+ @package
+ double _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
+ return NO;
+ }
+ GPBBoolDoubleDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %lf", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %lf", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getDouble:(double *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueDouble;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(BOOL key, double value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Object
+
+@implementation GPBBoolObjectDictionary {
+ @package
+ id _values[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ int idx = keys[i] ? 1 : 0;
+ [_values[idx] release];
+ _values[idx] = (id)[objects[i] retain];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ _values[0] = [dictionary->_values[0] retain];
+ _values[1] = [dictionary->_values[1] retain];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_values[0] release];
+ [_values[1] release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
+ return NO;
+ }
+ GPBBoolObjectDictionary *otherDictionary = other;
+ if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
+ ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
+ return NO;
+ }
+ if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
+ ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if ((_values[0] != nil)) {
+ [result appendFormat:@"NO: %@", _values[0]];
+ }
+ if ((_values[1] != nil)) {
+ [result appendFormat:@"YES: %@", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
+}
+
+- (id)objectForKey:(BOOL)key {
+ return _values[key ? 1 : 0];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = [value->valueString retain];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_values[0] != nil) {
+ block(@"false", _values[0]);
+ }
+ if ((_values[1] != nil)) {
+ block(@"true", _values[1]);
+ }
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(BOOL key, id object, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_values[0] != nil) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && (_values[1] != nil)) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (BOOL)isInitialized {
+ if (_values[0] && ![_values[0] isInitialized]) {
+ return NO;
+ }
+ if (_values[1] && ![_values[1] isInitialized]) {
+ return NO;
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBBoolObjectDictionary *newDict =
+ [[GPBBoolObjectDictionary alloc] init];
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ newDict->_values[i] = [_values[i] copyWithZone:zone];
+ }
+ }
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_values[i] != nil) {
+ [_values[i] release];
+ _values[i] = [otherDictionary->_values[i] retain];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(BOOL)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ int idx = (key ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = [object retain];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(BOOL)aKey {
+ int idx = (aKey ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = nil;
+}
+
+- (void)removeAll {
+ for (int i = 0; i < 2; ++i) {
+ [_values[i] release];
+ _values[i] = nil;
+ }
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+#pragma mark - Bool -> Enum
+
+@implementation GPBBoolEnumDictionary {
+ @package
+ GPBEnumValidationFunc _validationFunc;
+ int32_t _values[2];
+ BOOL _valueSet[2];
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = rawValues[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+#pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
+ return NO;
+ }
+ GPBBoolEnumDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ int32_t result = _values[idx];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (rawValue) {
+ *rawValue = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block {
+ BOOL stop = NO;
+ GPBEnumValidationFunc func = _validationFunc;
+ int32_t validatedValue;
+ if (_valueSet[0]) {
+ validatedValue = _values[0];
+ if (!func(validatedValue)) {
+ validatedValue = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(NO, validatedValue, &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ validatedValue = _values[1];
+ if (!func(validatedValue)) {
+ validatedValue = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(YES, validatedValue, &stop);
+ }
+}
+
+//%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
+// This block of code is generated, do not edit it directly.
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+
+//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", @(_values[0]));
+ }
+ if (_valueSet[1]) {
+ block(@"true", @(_values[1]));
+ }
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setEnum:(int32_t)value forKey:(BOOL)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = rawValue;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+#pragma mark - NSDictionary Subclass
+
+@implementation GPBAutocreatedDictionary {
+ NSMutableDictionary *_dictionary;
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+#pragma mark Required NSDictionary overrides
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const id<NSCopying> [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
+ forKeys:keys
+ count:count];
+ }
+ return self;
+}
+
+- (NSUInteger)count {
+ return [_dictionary count];
+}
+
+- (id)objectForKey:(id)aKey {
+ return [_dictionary objectForKey:aKey];
+}
+
+- (NSEnumerator *)keyEnumerator {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ return [_dictionary keyEnumerator];
+}
+
+#pragma mark Required NSMutableDictionary overrides
+
+// Only need to call GPBAutocreatedDictionaryModified() when adding things
+// since we only autocreate empty dictionaries.
+
+- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ [_dictionary setObject:anObject forKey:aKey];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(id)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+#pragma mark Extra things hooked
+
+- (id)copyWithZone:(NSZone *)zone {
+ if (_dictionary == nil) {
+ return [[NSMutableDictionary allocWithZone:zone] init];
+ }
+ return [_dictionary copyWithZone:zone];
+}
+
+- (id)mutableCopyWithZone:(NSZone *)zone {
+ if (_dictionary == nil) {
+ return [[NSMutableDictionary allocWithZone:zone] init];
+ }
+ return [_dictionary mutableCopyWithZone:zone];
+}
+
+// Not really needed, but subscripting is likely common enough it doesn't hurt
+// to ensure it goes directly to the real NSMutableDictionary.
+- (id)objectForKeyedSubscript:(id)key {
+ return [_dictionary objectForKeyedSubscript:key];
+}
+
+// Not really needed, but subscripting is likely common enough it doesn't hurt
+// to ensure it goes directly to the real NSMutableDictionary.
+- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ [_dictionary setObject:obj forKeyedSubscript:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key,
+ id obj,
+ BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:block];
+}
+
+- (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(id key,
+ id obj,
+ BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h b/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h
new file mode 100644
index 0000000000..7b921e8ec7
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h
@@ -0,0 +1,488 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBDictionary.h"
+
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionRegistry;
+@class GPBFieldDescriptor;
+
+@protocol GPBDictionaryInternalsProtocol
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field;
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key;
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
+@end
+
+//%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME)
+//%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object)
+//%PDDM-DEFINE DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt32, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int32, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt64, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int64, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Bool, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Float, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Double, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Enum, Enum)
+
+//%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
+//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
+//% @package
+//% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+//%}
+//%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
+//%
+
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
+// Empty
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
+//%- (BOOL)isInitialized;
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone
+//% __attribute__((ns_returns_retained));
+//%
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
+//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
+//% forKey:(GPBGenericValue *)key
+//% keyDataType:(GPBDataType)keyDataType;
+//%
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+//%PDDM-EXPAND-END (6 expansions)
+
+#pragma mark - NSDictionary Subclass
+
+@interface GPBAutocreatedDictionary : NSMutableDictionary {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Helpers
+
+CF_EXTERN_C_BEGIN
+
+// Helper to compute size when an NSDictionary is used for the map instead
+// of a custom type.
+size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to write out when an NSDictionary is used for the map instead
+// of a custom type.
+void GPBDictionaryWriteToStreamInternalHelper(
+ GPBCodedOutputStream *outputStream, NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to check message initialization when an NSDictionary is used for
+// the map instead of a custom type.
+BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to read a map instead.
+void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field,
+ GPBMessage *parentMessage);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBExtensionInternals.h b/third_party/protobuf/objectivec/GPBExtensionInternals.h
new file mode 100644
index 0000000000..2b980aefa4
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionInternals.h
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBDescriptor.h"
+
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionRegistry;
+
+void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
+ BOOL isPackedOnStream,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *message);
+
+size_t GPBComputeExtensionSerializedSizeIncludingTag(
+ GPBExtensionDescriptor *extension, id value);
+
+void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension,
+ id value,
+ GPBCodedOutputStream *output);
diff --git a/third_party/protobuf/objectivec/GPBExtensionInternals.m b/third_party/protobuf/objectivec/GPBExtensionInternals.m
new file mode 100644
index 0000000000..290c82a1bb
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionInternals.m
@@ -0,0 +1,391 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBExtensionInternals.h"
+
+#import <objc/runtime.h>
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *existingValue)
+ __attribute__((ns_returns_retained));
+
+GPB_INLINE size_t DataTypeSize(GPBDataType dataType) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (dataType) {
+ case GPBDataTypeBool:
+ return 1;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeFloat:
+ return 4;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeDouble:
+ return 8;
+ default:
+ return 0;
+ }
+#pragma clang diagnostic pop
+}
+
+static size_t ComputePBSerializedSizeNoTagOfObject(GPBDataType dataType, id object) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##SizeNoTag([(NSNumber *)object ACCESSOR]);
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##SizeNoTag(object);
+ switch (dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Message)
+ FIELD_CASE2(Group)
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static size_t ComputeSerializedSizeIncludingTagOfObject(
+ GPBExtensionDescription *description, id object) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##Size(description->fieldNumber, \
+ [(NSNumber *)object ACCESSOR]);
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##Size(description->fieldNumber, object);
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Group)
+ case GPBDataTypeMessage:
+ if (GPBExtensionIsWireFormat(description)) {
+ return GPBComputeMessageSetExtensionSize(description->fieldNumber,
+ object);
+ } else {
+ return GPBComputeMessageSize(description->fieldNumber, object);
+ }
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static size_t ComputeSerializedSizeIncludingTagOfArray(
+ GPBExtensionDescription *description, NSArray *values) {
+ if (GPBExtensionIsPacked(description)) {
+ size_t size = 0;
+ size_t typeSize = DataTypeSize(description->dataType);
+ if (typeSize != 0) {
+ size = values.count * typeSize;
+ } else {
+ for (id value in values) {
+ size +=
+ ComputePBSerializedSizeNoTagOfObject(description->dataType, value);
+ }
+ }
+ return size + GPBComputeTagSize(description->fieldNumber) +
+ GPBComputeRawVarint32SizeForInteger(size);
+ } else {
+ size_t size = 0;
+ for (id value in values) {
+ size += ComputeSerializedSizeIncludingTagOfObject(description, value);
+ }
+ return size;
+ }
+}
+
+static void WriteObjectIncludingTagToCodedOutputStream(
+ id object, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE:description->fieldNumber \
+ value:[(NSNumber *)object ACCESSOR]]; \
+ return;
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE:description->fieldNumber value:object]; \
+ return;
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Group)
+ case GPBDataTypeMessage:
+ if (GPBExtensionIsWireFormat(description)) {
+ [output writeMessageSetExtension:description->fieldNumber value:object];
+ } else {
+ [output writeMessage:description->fieldNumber value:object];
+ }
+ return;
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static void WriteObjectNoTagToCodedOutputStream(
+ id object, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE##NoTag:[(NSNumber *)object ACCESSOR]]; \
+ return;
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE##NoTag:object]; \
+ return;
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Message)
+ case GPBDataTypeGroup:
+ [output writeGroupNoTag:description->fieldNumber value:object];
+ return;
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static void WriteArrayIncludingTagsToCodedOutputStream(
+ NSArray *values, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+ if (GPBExtensionIsPacked(description)) {
+ [output writeTag:description->fieldNumber
+ format:GPBWireFormatLengthDelimited];
+ size_t dataSize = 0;
+ size_t typeSize = DataTypeSize(description->dataType);
+ if (typeSize != 0) {
+ dataSize = values.count * typeSize;
+ } else {
+ for (id value in values) {
+ dataSize +=
+ ComputePBSerializedSizeNoTagOfObject(description->dataType, value);
+ }
+ }
+ [output writeRawVarintSizeTAs32:dataSize];
+ for (id value in values) {
+ WriteObjectNoTagToCodedOutputStream(value, description, output);
+ }
+ } else {
+ for (id value in values) {
+ WriteObjectIncludingTagToCodedOutputStream(value, description, output);
+ }
+ }
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
+ BOOL isPackedOnStream,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *message) {
+ GPBExtensionDescription *description = extension->description_;
+ GPBCodedInputStreamState *state = &input->state_;
+ if (isPackedOnStream) {
+ NSCAssert(GPBExtensionIsRepeated(description),
+ @"How was it packed if it isn't repeated?");
+ int32_t length = GPBCodedInputStreamReadInt32(state);
+ size_t limit = GPBCodedInputStreamPushLimit(state, length);
+ while (GPBCodedInputStreamBytesUntilLimit(state) > 0) {
+ id value = NewSingleValueFromInputStream(extension,
+ input,
+ extensionRegistry,
+ nil);
+ [message addExtension:extension value:value];
+ [value release];
+ }
+ GPBCodedInputStreamPopLimit(state, limit);
+ } else {
+ id existingValue = nil;
+ BOOL isRepeated = GPBExtensionIsRepeated(description);
+ if (!isRepeated && GPBDataTypeIsMessage(description->dataType)) {
+ existingValue = [message getExistingExtension:extension];
+ }
+ id value = NewSingleValueFromInputStream(extension,
+ input,
+ extensionRegistry,
+ existingValue);
+ if (isRepeated) {
+ [message addExtension:extension value:value];
+ } else {
+ [message setExtension:extension value:value];
+ }
+ [value release];
+ }
+}
+
+void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension,
+ id value,
+ GPBCodedOutputStream *output) {
+ GPBExtensionDescription *description = extension->description_;
+ if (GPBExtensionIsRepeated(description)) {
+ WriteArrayIncludingTagsToCodedOutputStream(value, description, output);
+ } else {
+ WriteObjectIncludingTagToCodedOutputStream(value, description, output);
+ }
+}
+
+size_t GPBComputeExtensionSerializedSizeIncludingTag(
+ GPBExtensionDescriptor *extension, id value) {
+ GPBExtensionDescription *description = extension->description_;
+ if (GPBExtensionIsRepeated(description)) {
+ return ComputeSerializedSizeIncludingTagOfArray(description, value);
+ } else {
+ return ComputeSerializedSizeIncludingTagOfObject(description, value);
+ }
+}
+
+// Note that this returns a retained value intentionally.
+static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *existingValue) {
+ GPBExtensionDescription *description = extension->description_;
+ GPBCodedInputStreamState *state = &input->state_;
+ switch (description->dataType) {
+ case GPBDataTypeBool: return [[NSNumber alloc] initWithBool:GPBCodedInputStreamReadBool(state)];
+ case GPBDataTypeFixed32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadFixed32(state)];
+ case GPBDataTypeSFixed32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSFixed32(state)];
+ case GPBDataTypeFloat: return [[NSNumber alloc] initWithFloat:GPBCodedInputStreamReadFloat(state)];
+ case GPBDataTypeFixed64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadFixed64(state)];
+ case GPBDataTypeSFixed64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSFixed64(state)];
+ case GPBDataTypeDouble: return [[NSNumber alloc] initWithDouble:GPBCodedInputStreamReadDouble(state)];
+ case GPBDataTypeInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadInt32(state)];
+ case GPBDataTypeInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadInt64(state)];
+ case GPBDataTypeSInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSInt32(state)];
+ case GPBDataTypeSInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSInt64(state)];
+ case GPBDataTypeUInt32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadUInt32(state)];
+ case GPBDataTypeUInt64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadUInt64(state)];
+ case GPBDataTypeBytes: return GPBCodedInputStreamReadRetainedBytes(state);
+ case GPBDataTypeString: return GPBCodedInputStreamReadRetainedString(state);
+ case GPBDataTypeEnum: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadEnum(state)];
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ GPBMessage *message;
+ if (existingValue) {
+ message = [existingValue retain];
+ } else {
+ GPBDescriptor *decriptor = [extension.msgClass descriptor];
+ message = [[decriptor.messageClass alloc] init];
+ }
+
+ if (description->dataType == GPBDataTypeGroup) {
+ [input readGroup:description->fieldNumber
+ message:message
+ extensionRegistry:extensionRegistry];
+ } else {
+ // description->dataType == GPBDataTypeMessage
+ if (GPBExtensionIsWireFormat(description)) {
+ // For MessageSet fields the message length will have already been
+ // read.
+ [message mergeFromCodedInputStream:input
+ extensionRegistry:extensionRegistry];
+ } else {
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ }
+ }
+
+ return message;
+ }
+ }
+
+ return nil;
+}
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBExtensionRegistry.h b/third_party/protobuf/objectivec/GPBExtensionRegistry.h
new file mode 100644
index 0000000000..d79632d28b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionRegistry.h
@@ -0,0 +1,87 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBDescriptor;
+@class GPBExtensionDescriptor;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * A table of known extensions, searchable by name or field number. When
+ * parsing a protocol message that might have extensions, you must provide a
+ * GPBExtensionRegistry in which you have registered any extensions that you
+ * want to be able to parse. Otherwise, those extensions will just be treated
+ * like unknown fields.
+ *
+ * The *Root classes provide `+extensionRegistry` for the extensions defined
+ * in a given file *and* all files it imports. You can also create a
+ * GPBExtensionRegistry, and merge those registries to handle parsing
+ * extensions defined from non overlapping files.
+ *
+ * ```
+ * GPBExtensionRegistry *registry = [[MyProtoFileRoot extensionRegistry] copy];
+ * [registry addExtension:[OtherMessage neededExtension]]; // Not in MyProtoFile
+ * NSError *parseError;
+ * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError];
+ * ```
+ **/
+@interface GPBExtensionRegistry : NSObject<NSCopying>
+
+/**
+ * Adds the given GPBExtensionDescriptor to this registry.
+ *
+ * @param extension The extension description to add.
+ **/
+- (void)addExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Adds all the extensions from another registry to this registry.
+ *
+ * @param registry The registry to merge into this registry.
+ **/
+- (void)addExtensions:(GPBExtensionRegistry *)registry;
+
+/**
+ * Looks for the extension registered for the given field number on a given
+ * GPBDescriptor.
+ *
+ * @param descriptor The descriptor to look for a registered extension on.
+ * @param fieldNumber The field number of the extension to look for.
+ *
+ * @return The registered GPBExtensionDescriptor or nil if none was found.
+ **/
+- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
+ fieldNumber:(NSInteger)fieldNumber;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBExtensionRegistry.m b/third_party/protobuf/objectivec/GPBExtensionRegistry.m
new file mode 100644
index 0000000000..65534b67af
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionRegistry.m
@@ -0,0 +1,131 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBExtensionRegistry.h"
+
+#import "GPBBootstrap.h"
+#import "GPBDescriptor.h"
+
+@implementation GPBExtensionRegistry {
+ NSMutableDictionary *mutableClassMap_;
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ mutableClassMap_ = [[NSMutableDictionary alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [mutableClassMap_ release];
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ GPBExtensionRegistry *result = [[[self class] allocWithZone:zone] init];
+ if (result && mutableClassMap_.count) {
+ [result->mutableClassMap_ addEntriesFromDictionary:mutableClassMap_];
+ }
+ return result;
+}
+
+- (CFMutableDictionaryRef)extensionMapForContainingMessageClass:
+ (Class)containingMessageClass {
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)
+ [mutableClassMap_ objectForKey:containingMessageClass];
+ if (extensionMap == nil) {
+ // Use a custom dictionary here because the keys are numbers and conversion
+ // back and forth from NSNumber isn't worth the cost.
+ extensionMap = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL,
+ &kCFTypeDictionaryValueCallBacks);
+ [mutableClassMap_ setObject:(id)extensionMap
+ forKey:(id<NSCopying>)containingMessageClass];
+ }
+ return extensionMap;
+}
+
+- (void)addExtension:(GPBExtensionDescriptor *)extension {
+ if (extension == nil) {
+ return;
+ }
+
+ Class containingMessageClass = extension.containingMessageClass;
+ CFMutableDictionaryRef extensionMap =
+ [self extensionMapForContainingMessageClass:containingMessageClass];
+ ssize_t key = extension.fieldNumber;
+ CFDictionarySetValue(extensionMap, (const void *)key, extension);
+}
+
+- (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
+ fieldNumber:(NSInteger)fieldNumber {
+ Class messageClass = descriptor.messageClass;
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)
+ [mutableClassMap_ objectForKey:messageClass];
+ ssize_t key = fieldNumber;
+ GPBExtensionDescriptor *result =
+ (extensionMap
+ ? CFDictionaryGetValue(extensionMap, (const void *)key)
+ : nil);
+ return result;
+}
+
+static void CopyKeyValue(const void *key, const void *value, void *context) {
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)context;
+ CFDictionarySetValue(extensionMap, key, value);
+}
+
+- (void)addExtensions:(GPBExtensionRegistry *)registry {
+ if (registry == nil) {
+ // In the case where there are no extensions just ignore.
+ return;
+ }
+ NSMutableDictionary *otherClassMap = registry->mutableClassMap_;
+ [otherClassMap enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL * stop) {
+#pragma unused(stop)
+ Class containingMessageClass = key;
+ CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value;
+
+ CFMutableDictionaryRef extensionMap =
+ [self extensionMapForContainingMessageClass:containingMessageClass];
+
+ CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap);
+ }];
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBMessage.h b/third_party/protobuf/objectivec/GPBMessage.h
new file mode 100644
index 0000000000..2c325ba85b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage.h
@@ -0,0 +1,461 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBBootstrap.h"
+
+@class GPBDescriptor;
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionDescriptor;
+@class GPBExtensionRegistry;
+@class GPBFieldDescriptor;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+/** NSError domain used for errors. */
+extern NSString *const GPBMessageErrorDomain;
+
+/** Error codes for NSErrors originated in GPBMessage. */
+typedef NS_ENUM(NSInteger, GPBMessageErrorCode) {
+ /** Uncategorized error. */
+ GPBMessageErrorCodeOther = -100,
+ /** Message couldn't be serialized because it is missing required fields. */
+ GPBMessageErrorCodeMissingRequiredField = -101,
+};
+
+/**
+ * Key under which the GPBMessage error's reason is stored inside the userInfo
+ * dictionary.
+ **/
+extern NSString *const GPBErrorReasonKey;
+
+CF_EXTERN_C_END
+
+/**
+ * Base class that each generated message subclasses from.
+ *
+ * @note @c NSCopying support is a "deep copy", in that all sub objects are
+ * copied. Just like you wouldn't want a UIView/NSView trying to
+ * exist in two places, you don't want a sub message to be a property
+ * property of two other messages.
+ *
+ * @note While the class support NSSecureCoding, if the message has any
+ * extensions, they will end up reloaded in @c unknownFields as there is
+ * no way for the @c NSCoding plumbing to pass through a
+ * @c GPBExtensionRegistry. To support extensions, instead of passing the
+ * calls off to the Message, simple store the result of @c data, and then
+ * when loading, fetch the data and use
+ * @c +parseFromData:extensionRegistry:error: to provide an extension
+ * registry.
+ **/
+@interface GPBMessage : NSObject<NSSecureCoding, NSCopying>
+
+// If you add an instance method/property to this class that may conflict with
+// fields declared in protos, you need to update objective_helpers.cc. The main
+// cases are methods that take no arguments, or setFoo:/hasFoo: type methods.
+
+/**
+ * The set of unknown fields for this message.
+ *
+ * Only messages from proto files declared with "proto2" syntax support unknown
+ * fields. For "proto3" syntax, any unknown fields found while parsing are
+ * dropped.
+ **/
+@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields;
+
+/**
+ * Whether the message, along with all submessages, have the required fields
+ * set. This is only applicable for files declared with "proto2" syntax, as
+ * there are no required fields for "proto3" syntax.
+ **/
+@property(nonatomic, readonly, getter=isInitialized) BOOL initialized;
+
+/**
+ * @return An autoreleased message with the default values set.
+ **/
++ (instancetype)message;
+
+/**
+ * Creates a new instance by parsing the provided data. This method should be
+ * sent to the generated message class that the data should be interpreted as.
+ * If there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param errorPtr An optional error pointer to fill in with a failure reason if
+ * the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note Unlike the parseFrom... methods, this never checks to see if all of
+ * the required fields are set. So this method can be used to reload
+ * messages that may not be complete.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param errorPtr An optional error pointer to fill in with a failure reason if
+ * the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note Unlike the parseFrom... methods, this never checks to see if all of
+ * the required fields are set. So this method can be used to reload
+ * messages that may not be complete.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Parses the given data as this message's class, and merges those values into
+ * this message.
+ *
+ * @param data The binary representation of the message to merge.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ *
+ * @exception GPBCodedInputStreamException Exception thrown when parsing was
+ * unsuccessful.
+ **/
+- (void)mergeFromData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+
+/**
+ * Merges the fields from another message (of the same type) into this
+ * message.
+ *
+ * @param other Message to merge into this message.
+ **/
+- (void)mergeFrom:(GPBMessage *)other;
+
+/**
+ * Writes out the message to the given coded output stream.
+ *
+ * @param output The coded output stream into which to write the message.
+ **/
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
+
+/**
+ * Writes out the message to the given output stream.
+ *
+ * @param output The output stream into which to write the message.
+ **/
+- (void)writeToOutputStream:(NSOutputStream *)output;
+
+/**
+ * Writes out a varint for the message size followed by the the message to
+ * the given output stream.
+ *
+ * @param output The coded output stream into which to write the message.
+ **/
+- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output;
+
+/**
+ * Writes out a varint for the message size followed by the the message to
+ * the given output stream.
+ *
+ * @param output The output stream into which to write the message.
+ **/
+- (void)writeDelimitedToOutputStream:(NSOutputStream *)output;
+
+/**
+ * Serializes the message to an NSData.
+ *
+ * If there is an error while generating the data, nil is returned.
+ *
+ * @note This value is not cached, so if you are using it repeatedly, cache
+ * it yourself.
+ *
+ * @note In DEBUG ONLY, the message is also checked for all required field,
+ * if one is missing, nil will be returned.
+ *
+ * @return The binary representation of the message.
+ **/
+- (nullable NSData *)data;
+
+/**
+ * Serializes a varint with the message size followed by the message data,
+ * returning that as an NSData.
+ *
+ * @note This value is not cached, so if you are using it repeatedly, it is
+ * recommended to keep a local copy.
+ *
+ * @return The binary representation of the size along with the message.
+ **/
+- (NSData *)delimitedData;
+
+/**
+ * Calculates the size of the object if it were serialized.
+ *
+ * This is not a cached value. If you are following a pattern like this:
+ *
+ * ```
+ * size_t size = [aMsg serializedSize];
+ * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)];
+ * [foo writeSize:size];
+ * [foo appendData:[aMsg data]];
+ * ```
+ *
+ * you would be better doing:
+ *
+ * ```
+ * NSData *data = [aMsg data];
+ * NSUInteger size = [aMsg length];
+ * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)];
+ * [foo writeSize:size];
+ * [foo appendData:data];
+ * ```
+ *
+ * @return The size of the message in it's binary representation.
+ **/
+- (size_t)serializedSize;
+
+/**
+ * @return The descriptor for the message class.
+ **/
++ (GPBDescriptor *)descriptor;
+
+/**
+ * Return the descriptor for the message.
+ **/
+- (GPBDescriptor *)descriptor;
+
+/**
+ * @return An array with the extension descriptors that are currently set on the
+ * message.
+ **/
+- (NSArray *)extensionsCurrentlySet;
+
+/**
+ * Checks whether there is an extension set on the message which matches the
+ * given extension descriptor.
+ *
+ * @param extension Extension descriptor to check if it's set on the message.
+ *
+ * @return Whether the extension is currently set on the message.
+ **/
+- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension;
+
+/*
+ * Fetches the given extension's value for this message.
+ *
+ * Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for
+ * repeated fields. If the extension is a Message one will be auto created for
+ * you and returned similar to fields.
+ *
+ * @param extension The extension descriptor of the extension to fetch.
+ *
+ * @return The extension matching the given descriptor, or nil if none found.
+ **/
+- (nullable id)getExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Sets the given extension's value for this message. This only applies for
+ * single field extensions (i.e. - not repeated fields).
+ *
+ * Extensions use boxed values (NSNumbers).
+ *
+ * @param extension The extension descriptor under which to set the value.
+ * @param value The value to be set as the extension.
+ **/
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ value:(nullable id)value;
+
+/**
+ * Adds the given value to the extension for this message. This only applies
+ * to repeated field extensions. If the field is a repeated POD type, the value
+ * should be an NSNumber.
+ *
+ * @param extension The extension descriptor under which to add the value.
+ * @param value The value to be added to the repeated extension.
+ **/
+- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value;
+
+/**
+ * Replaces the value at the given index with the given value for the extension
+ * on this message. This only applies to repeated field extensions. If the field
+ * is a repeated POD type, the value is should be an NSNumber.
+ *
+ * @param extension The extension descriptor under which to replace the value.
+ * @param index The index of the extension to be replaced.
+ * @param value The value to be replaced in the repeated extension.
+ **/
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ index:(NSUInteger)index
+ value:(id)value;
+
+/**
+ * Clears the given extension for this message.
+ *
+ * @param extension The extension descriptor to be cleared from this message.
+ **/
+- (void)clearExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Resets all of the fields of this message to their default values.
+ **/
+- (void)clear;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBMessage.m b/third_party/protobuf/objectivec/GPBMessage.m
new file mode 100644
index 0000000000..58a10fdb9b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage.m
@@ -0,0 +1,3243 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBMessage_PackagePrivate.h"
+
+#import <objc/runtime.h>
+#import <objc/message.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBExtensionInternals.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBRootObject_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+NSString *const GPBMessageErrorDomain =
+ GPBNSStringifySymbol(GPBMessageErrorDomain);
+
+NSString *const GPBErrorReasonKey = @"Reason";
+
+static NSString *const kGPBDataCoderKey = @"GPBData";
+
+//
+// PLEASE REMEMBER:
+//
+// This is the base class for *all* messages generated, so any selector defined,
+// *public* or *private* could end up colliding with a proto message field. So
+// avoid using selectors that could match a property, use C functions to hide
+// them, etc.
+//
+
+@interface GPBMessage () {
+ @package
+ GPBUnknownFieldSet *unknownFields_;
+ NSMutableDictionary *extensionMap_;
+ NSMutableDictionary *autocreatedExtensionMap_;
+
+ // If the object was autocreated, we remember the creator so that if we get
+ // mutated, we can inform the creator to make our field visible.
+ GPBMessage *autocreator_;
+ GPBFieldDescriptor *autocreatorField_;
+ GPBExtensionDescriptor *autocreatorExtension_;
+}
+@end
+
+static id CreateArrayForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator)
+ __attribute__((ns_returns_retained));
+static id GetOrCreateArrayIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+static id CreateMapForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator)
+ __attribute__((ns_returns_retained));
+static id GetOrCreateMapIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap,
+ NSZone *zone)
+ __attribute__((ns_returns_retained));
+
+#ifdef DEBUG
+static NSError *MessageError(NSInteger code, NSDictionary *userInfo) {
+ return [NSError errorWithDomain:GPBMessageErrorDomain
+ code:code
+ userInfo:userInfo];
+}
+#endif
+
+static NSError *ErrorFromException(NSException *exception) {
+ NSError *error = nil;
+
+ if ([exception.name isEqual:GPBCodedInputStreamException]) {
+ NSDictionary *exceptionInfo = exception.userInfo;
+ error = exceptionInfo[GPBCodedInputStreamUnderlyingErrorKey];
+ }
+
+ if (!error) {
+ NSString *reason = exception.reason;
+ NSDictionary *userInfo = nil;
+ if ([reason length]) {
+ userInfo = @{ GPBErrorReasonKey : reason };
+ }
+
+ error = [NSError errorWithDomain:GPBMessageErrorDomain
+ code:GPBMessageErrorCodeOther
+ userInfo:userInfo];
+ }
+ return error;
+}
+
+static void CheckExtension(GPBMessage *self,
+ GPBExtensionDescriptor *extension) {
+ if ([self class] != extension.containingMessageClass) {
+ [NSException
+ raise:NSInvalidArgumentException
+ format:@"Extension %@ used on wrong class (%@ instead of %@)",
+ extension.singletonName,
+ [self class], extension.containingMessageClass];
+ }
+}
+
+static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap,
+ NSZone *zone) {
+ if (extensionMap.count == 0) {
+ return nil;
+ }
+ NSMutableDictionary *result = [[NSMutableDictionary allocWithZone:zone]
+ initWithCapacity:extensionMap.count];
+
+ for (GPBExtensionDescriptor *extension in extensionMap) {
+ id value = [extensionMap objectForKey:extension];
+ BOOL isMessageExtension = GPBExtensionIsMessage(extension);
+
+ if (extension.repeated) {
+ if (isMessageExtension) {
+ NSMutableArray *list =
+ [[NSMutableArray alloc] initWithCapacity:[value count]];
+ for (GPBMessage *listValue in value) {
+ GPBMessage *copiedValue = [listValue copyWithZone:zone];
+ [list addObject:copiedValue];
+ [copiedValue release];
+ }
+ [result setObject:list forKey:extension];
+ [list release];
+ } else {
+ NSMutableArray *copiedValue = [value mutableCopyWithZone:zone];
+ [result setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ }
+ } else {
+ if (isMessageExtension) {
+ GPBMessage *copiedValue = [value copyWithZone:zone];
+ [result setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ } else {
+ [result setObject:value forKey:extension];
+ }
+ }
+ }
+
+ return result;
+}
+
+static id CreateArrayForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator) {
+ id result;
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBBoolArray alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt32Array alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt32Array alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt64Array alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt64Array alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBFloatArray alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBDoubleArray alloc] init];
+ break;
+
+ case GPBDataTypeEnum:
+ result = [[GPBEnumArray alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ if (autocreator) {
+ result = [[GPBAutocreatedArray alloc] init];
+ } else {
+ result = [[NSMutableArray alloc] init];
+ }
+ break;
+ }
+
+ if (autocreator) {
+ if (GPBDataTypeIsObject(fieldDataType)) {
+ GPBAutocreatedArray *autoArray = result;
+ autoArray->_autocreator = autocreator;
+ } else {
+ GPBInt32Array *gpbArray = result;
+ gpbArray->_autocreator = autocreator;
+ }
+ }
+
+ return result;
+}
+
+static id CreateMapForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator) {
+ id result;
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ switch (keyDataType) {
+ case GPBDataTypeBool:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBBoolBoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBBoolUInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBBoolInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBBoolUInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBBoolInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBBoolFloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBBoolDoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBBoolEnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBBoolObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBUInt32BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt32UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBUInt32Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt32UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBUInt32Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBUInt32FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBUInt32DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBUInt32EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBUInt32ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBInt32BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBInt32UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt32Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBInt32UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt32Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBInt32FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBInt32DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBInt32EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBInt32ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBUInt64BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt64UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBUInt64Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt64UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBUInt64Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBUInt64FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBUInt64DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBUInt64EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBUInt64ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBInt64BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBInt64UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt64Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBInt64UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt64Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBInt64FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBInt64DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBInt64EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBInt64ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeString:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBStringBoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBStringUInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBStringInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBStringUInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBStringInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBStringFloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBStringDoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBStringEnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ if (autocreator) {
+ result = [[GPBAutocreatedDictionary alloc] init];
+ } else {
+ result = [[NSMutableDictionary alloc] init];
+ }
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+
+ case GPBDataTypeFloat:
+ case GPBDataTypeDouble:
+ case GPBDataTypeEnum:
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+
+ if (autocreator) {
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ GPBAutocreatedDictionary *autoDict = result;
+ autoDict->_autocreator = autocreator;
+ } else {
+ GPBInt32Int32Dictionary *gpbDict = result;
+ gpbDict->_autocreator = autocreator;
+ }
+ }
+
+ return result;
+}
+
+#if !defined(__clang_analyzer__)
+// These functions are blocked from the analyzer because the analyzer sees the
+// GPBSetRetainedObjectIvarWithFieldInternal() call as consuming the array/map,
+// so use of the array/map after the call returns is flagged as a use after
+// free.
+// But GPBSetRetainedObjectIvarWithFieldInternal() is "consuming" the retain
+// count be holding onto the object (it is transfering it), the object is
+// still valid after returning from the call. The other way to avoid this
+// would be to add a -retain/-autorelease, but that would force every
+// repeated/map field parsed into the autorelease pool which is both a memory
+// and performance hit.
+
+static id GetOrCreateArrayIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ // No lock needed, this is called from places expecting to mutate
+ // so no threading protection is needed.
+ array = CreateArrayForField(field, nil);
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, array, syntax);
+ }
+ return array;
+}
+
+// This is like GPBGetObjectIvarWithField(), but for arrays, it should
+// only be used to wire the method into the class.
+static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ // Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ array = CreateArrayForField(field, self);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, array);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ }
+ return array;
+}
+
+static id GetOrCreateMapIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ // No lock needed, this is called from places expecting to mutate
+ // so no threading protection is needed.
+ dict = CreateMapForField(field, nil);
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, dict, syntax);
+ }
+ return dict;
+}
+
+// This is like GPBGetObjectIvarWithField(), but for maps, it should
+// only be used to wire the method into the class.
+static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ // Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ dict = CreateMapForField(field, self);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, dict);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ }
+ return dict;
+}
+
+#endif // !defined(__clang_analyzer__)
+
+GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass,
+ GPBMessage *autocreator,
+ GPBFieldDescriptor *field) {
+ GPBMessage *message = [[msgClass alloc] init];
+ message->autocreator_ = autocreator;
+ message->autocreatorField_ = [field retain];
+ return message;
+}
+
+static GPBMessage *CreateMessageWithAutocreatorForExtension(
+ Class msgClass, GPBMessage *autocreator, GPBExtensionDescriptor *extension)
+ __attribute__((ns_returns_retained));
+
+static GPBMessage *CreateMessageWithAutocreatorForExtension(
+ Class msgClass, GPBMessage *autocreator,
+ GPBExtensionDescriptor *extension) {
+ GPBMessage *message = [[msgClass alloc] init];
+ message->autocreator_ = autocreator;
+ message->autocreatorExtension_ = [extension retain];
+ return message;
+}
+
+BOOL GPBWasMessageAutocreatedBy(GPBMessage *message, GPBMessage *parent) {
+ return (message->autocreator_ == parent);
+}
+
+void GPBBecomeVisibleToAutocreator(GPBMessage *self) {
+ // Message objects that are implicitly created by accessing a message field
+ // are initially not visible via the hasX selector. This method makes them
+ // visible.
+ if (self->autocreator_) {
+ // This will recursively make all parent messages visible until it reaches a
+ // super-creator that's visible.
+ if (self->autocreatorField_) {
+ GPBFileSyntax syntax = [self->autocreator_ descriptor].file.syntax;
+ GPBSetObjectIvarWithFieldInternal(self->autocreator_,
+ self->autocreatorField_, self, syntax);
+ } else {
+ [self->autocreator_ setExtension:self->autocreatorExtension_ value:self];
+ }
+ }
+}
+
+void GPBAutocreatedArrayModified(GPBMessage *self, id array) {
+ // When one of our autocreated arrays adds elements, make it visible.
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ id curArray = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (curArray == array) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ GPBAutocreatedArray *autoArray = array;
+ autoArray->_autocreator = nil;
+ } else {
+ GPBInt32Array *gpbArray = array;
+ gpbArray->_autocreator = nil;
+ }
+ GPBBecomeVisibleToAutocreator(self);
+ return;
+ }
+ }
+ }
+ NSCAssert(NO, @"Unknown autocreated %@ for %@.", [array class], self);
+}
+
+void GPBAutocreatedDictionaryModified(GPBMessage *self, id dictionary) {
+ // When one of our autocreated dicts adds elements, make it visible.
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.fieldType == GPBFieldTypeMap) {
+ id curDict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (curDict == dictionary) {
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBFieldDataTypeIsObject(field)) {
+ GPBAutocreatedDictionary *autoDict = dictionary;
+ autoDict->_autocreator = nil;
+ } else {
+ GPBInt32Int32Dictionary *gpbDict = dictionary;
+ gpbDict->_autocreator = nil;
+ }
+ GPBBecomeVisibleToAutocreator(self);
+ return;
+ }
+ }
+ }
+ NSCAssert(NO, @"Unknown autocreated %@ for %@.", [dictionary class], self);
+}
+
+void GPBClearMessageAutocreator(GPBMessage *self) {
+ if ((self == nil) || !self->autocreator_) {
+ return;
+ }
+
+#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
+ // Either the autocreator must have its "has" flag set to YES, or it must be
+ // NO and not equal to ourselves.
+ BOOL autocreatorHas =
+ (self->autocreatorField_
+ ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_)
+ : [self->autocreator_ hasExtension:self->autocreatorExtension_]);
+ GPBMessage *autocreatorFieldValue =
+ (self->autocreatorField_
+ ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_,
+ self->autocreatorField_)
+ : [self->autocreator_->autocreatedExtensionMap_
+ objectForKey:self->autocreatorExtension_]);
+ NSCAssert(autocreatorHas || autocreatorFieldValue != self,
+ @"Cannot clear autocreator because it still refers to self, self: %@.",
+ self);
+
+#endif // DEBUG && !defined(NS_BLOCK_ASSERTIONS)
+
+ self->autocreator_ = nil;
+ [self->autocreatorField_ release];
+ self->autocreatorField_ = nil;
+ [self->autocreatorExtension_ release];
+ self->autocreatorExtension_ = nil;
+}
+
+static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
+ if (!self->unknownFields_) {
+ self->unknownFields_ = [[GPBUnknownFieldSet alloc] init];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+ return self->unknownFields_;
+}
+
+@implementation GPBMessage
+
++ (void)initialize {
+ Class pbMessageClass = [GPBMessage class];
+ if ([self class] == pbMessageClass) {
+ // This is here to start up the "base" class descriptor.
+ [self descriptor];
+ // Message shares extension method resolving with GPBRootObject so insure
+ // it is started up at the same time.
+ (void)[GPBRootObject class];
+ } else if ([self superclass] == pbMessageClass) {
+ // This is here to start up all the "message" subclasses. Just needs to be
+ // done for the messages, not any of the subclasses.
+ // This must be done in initialize to enforce thread safety of start up of
+ // the protocol buffer library.
+ // Note: The generated code for -descriptor calls
+ // +[GPBDescriptor allocDescriptorForClass:...], passing the GPBRootObject
+ // subclass for the file. That call chain is what ensures that *Root class
+ // is started up to support extension resolution off the message class
+ // (+resolveClassMethod: below) in a thread safe manner.
+ [self descriptor];
+ }
+}
+
++ (instancetype)allocWithZone:(NSZone *)zone {
+ // Override alloc to allocate our classes with the additional storage
+ // required for the instance variables.
+ GPBDescriptor *descriptor = [self descriptor];
+ return NSAllocateObject(self, descriptor->storageSize_, zone);
+}
+
++ (instancetype)alloc {
+ return [self allocWithZone:nil];
+}
+
++ (GPBDescriptor *)descriptor {
+ // This is thread safe because it is called from +initialize.
+ static GPBDescriptor *descriptor = NULL;
+ static GPBFileDescriptor *fileDescriptor = NULL;
+ if (!descriptor) {
+ // Use a dummy file that marks it as proto2 syntax so when used generically
+ // it supports unknowns/etc.
+ fileDescriptor =
+ [[GPBFileDescriptor alloc] initWithPackage:@"internal"
+ syntax:GPBFileSyntaxProto2];
+
+ descriptor = [GPBDescriptor allocDescriptorForClass:[GPBMessage class]
+ rootClass:Nil
+ file:fileDescriptor
+ fields:NULL
+ fieldCount:0
+ storageSize:0
+ flags:0];
+ }
+ return descriptor;
+}
+
++ (instancetype)message {
+ return [[[self alloc] init] autorelease];
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ messageStorage_ = (GPBMessage_StoragePtr)(
+ ((uint8_t *)self) + class_getInstanceSize([self class]));
+ }
+
+ return self;
+}
+
+- (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr {
+ return [self initWithData:data extensionRegistry:nil error:errorPtr];
+}
+
+- (instancetype)initWithData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ if ((self = [self init])) {
+ @try {
+ [self mergeFromData:data extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (self && !self.initialized) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ }
+ return self;
+}
+
+- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ if ((self = [self init])) {
+ @try {
+ [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (self && !self.initialized) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self internalClear:NO];
+ NSCAssert(!autocreator_, @"Autocreator was not cleared before dealloc.");
+ if (readOnlySemaphore_) {
+ dispatch_release(readOnlySemaphore_);
+ }
+ [super dealloc];
+}
+
+- (void)copyFieldsInto:(GPBMessage *)message
+ zone:(NSZone *)zone
+ descriptor:(GPBDescriptor *)descriptor {
+ // Copy all the storage...
+ memcpy(message->messageStorage_, messageStorage_, descriptor->storageSize_);
+
+ GPBFileSyntax syntax = descriptor.file.syntax;
+
+ // Loop over the fields doing fixup...
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ id value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (value) {
+ // We need to copy the array/map, but the catch is for message fields,
+ // we also need to ensure all the messages as those need copying also.
+ id newValue;
+ if (GPBFieldDataTypeIsMessage(field)) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ NSArray *existingArray = (NSArray *)value;
+ NSMutableArray *newArray =
+ [[NSMutableArray alloc] initWithCapacity:existingArray.count];
+ newValue = newArray;
+ for (GPBMessage *msg in existingArray) {
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newArray addObject:copiedMsg];
+ [copiedMsg release];
+ }
+ } else {
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ // Map is an NSDictionary.
+ NSDictionary *existingDict = value;
+ NSMutableDictionary *newDict = [[NSMutableDictionary alloc]
+ initWithCapacity:existingDict.count];
+ newValue = newDict;
+ [existingDict enumerateKeysAndObjectsUsingBlock:^(NSString *key,
+ GPBMessage *msg,
+ BOOL *stop) {
+#pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict setObject:copiedMsg forKey:key];
+ [copiedMsg release];
+ }];
+ } else {
+ // Is one of the GPB*ObjectDictionary classes. Type doesn't
+ // matter, just need one to invoke the selector.
+ GPBInt32ObjectDictionary *existingDict = value;
+ newValue = [existingDict deepCopyWithZone:zone];
+ }
+ }
+ } else {
+ // Not messages (but is a map/array)...
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ // NSArray
+ newValue = [value mutableCopyWithZone:zone];
+ } else {
+ // GPB*Array
+ newValue = [value copyWithZone:zone];
+ }
+ } else {
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ // NSDictionary
+ newValue = [value mutableCopyWithZone:zone];
+ } else {
+ // Is one of the GPB*Dictionary classes. Type doesn't matter,
+ // just need one to invoke the selector.
+ GPBInt32Int32Dictionary *existingDict = value;
+ newValue = [existingDict copyWithZone:zone];
+ }
+ }
+ }
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ }
+ } else if (GPBFieldDataTypeIsMessage(field)) {
+ // For object types, if we have a value, copy it. If we don't,
+ // zero it to remove the pointer to something that was autocreated
+ // (and the ptr just got memcpyed).
+ if (GPBGetHasIvarField(self, field)) {
+ GPBMessage *value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBMessage *newValue = [value copyWithZone:zone];
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ } else {
+ uint8_t *storage = (uint8_t *)message->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ *typePtr = NULL;
+ }
+ } else if (GPBFieldDataTypeIsObject(field) &&
+ GPBGetHasIvarField(self, field)) {
+ // A set string/data value (message picked off above), copy it.
+ id value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ id newValue = [value copyWithZone:zone];
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ } else {
+ // memcpy took care of the rest of the primitive fields if they were set.
+ }
+ } // for (field in descriptor->fields_)
+}
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBMessage *result = [[descriptor.messageClass allocWithZone:zone] init];
+
+ [self copyFieldsInto:result zone:zone descriptor:descriptor];
+ // Make immutable copies of the extra bits.
+ result->unknownFields_ = [unknownFields_ copyWithZone:zone];
+ result->extensionMap_ = CloneExtensionMap(extensionMap_, zone);
+ return result;
+}
+
+- (void)clear {
+ [self internalClear:YES];
+}
+
+- (void)internalClear:(BOOL)zeroStorage {
+ GPBDescriptor *descriptor = [self descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ id arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (arrayOrMap) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ if ([arrayOrMap isKindOfClass:[GPBAutocreatedArray class]]) {
+ GPBAutocreatedArray *autoArray = arrayOrMap;
+ if (autoArray->_autocreator == self) {
+ autoArray->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Array.
+ GPBInt32Array *gpbArray = arrayOrMap;
+ if (gpbArray->_autocreator == self) {
+ gpbArray->_autocreator = nil;
+ }
+ }
+ } else {
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBFieldDataTypeIsObject(field)) {
+ if ([arrayOrMap isKindOfClass:[GPBAutocreatedDictionary class]]) {
+ GPBAutocreatedDictionary *autoDict = arrayOrMap;
+ if (autoDict->_autocreator == self) {
+ autoDict->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Dictionary.
+ GPBInt32Int32Dictionary *gpbDict = arrayOrMap;
+ if (gpbDict->_autocreator == self) {
+ gpbDict->_autocreator = nil;
+ }
+ }
+ }
+ [arrayOrMap release];
+ }
+ } else if (GPBFieldDataTypeIsMessage(field)) {
+ GPBClearAutocreatedMessageIvarWithField(self, field);
+ GPBMessage *value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [value release];
+ } else if (GPBFieldDataTypeIsObject(field) &&
+ GPBGetHasIvarField(self, field)) {
+ id value = GPBGetObjectIvarWithField(self, field);
+ [value release];
+ }
+ }
+
+ // GPBClearMessageAutocreator() expects that its caller has already been
+ // removed from autocreatedExtensionMap_ so we set to nil first.
+ NSArray *autocreatedValues = [autocreatedExtensionMap_ allValues];
+ [autocreatedExtensionMap_ release];
+ autocreatedExtensionMap_ = nil;
+
+ // Since we're clearing all of our extensions, make sure that we clear the
+ // autocreator on any that we've created so they no longer refer to us.
+ for (GPBMessage *value in autocreatedValues) {
+ NSCAssert(GPBWasMessageAutocreatedBy(value, self),
+ @"Autocreated extension does not refer back to self.");
+ GPBClearMessageAutocreator(value);
+ }
+
+ [extensionMap_ release];
+ extensionMap_ = nil;
+ [unknownFields_ release];
+ unknownFields_ = nil;
+
+ // Note that clearing does not affect autocreator_. If we are being cleared
+ // because of a dealloc, then autocreator_ should be nil anyway. If we are
+ // being cleared because someone explicitly clears us, we don't want to
+ // sever our relationship with our autocreator.
+
+ if (zeroStorage) {
+ memset(messageStorage_, 0, descriptor->storageSize_);
+ }
+}
+
+- (BOOL)isInitialized {
+ GPBDescriptor *descriptor = [self descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.isRequired) {
+ if (!GPBGetHasIvarField(self, field)) {
+ return NO;
+ }
+ }
+ if (GPBFieldDataTypeIsMessage(field)) {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ if (field.isRequired) {
+ GPBMessage *message = GPBGetMessageMessageField(self, field);
+ if (!message.initialized) {
+ return NO;
+ }
+ } else {
+ NSAssert(field.isOptional,
+ @"%@: Single message field %@ not required or optional?",
+ [self class], field.name);
+ if (GPBGetHasIvarField(self, field)) {
+ GPBMessage *message = GPBGetMessageMessageField(self, field);
+ if (!message.initialized) {
+ return NO;
+ }
+ }
+ }
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ for (GPBMessage *message in array) {
+ if (!message.initialized) {
+ return NO;
+ }
+ }
+ } else { // fieldType == GPBFieldTypeMap
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ NSDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (map && !GPBDictionaryIsInitializedInternalHelper(map, field)) {
+ return NO;
+ }
+ } else {
+ // Real type is GPB*ObjectDictionary, exact type doesn't matter.
+ GPBInt32ObjectDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (map && ![map isInitialized]) {
+ return NO;
+ }
+ }
+ }
+ }
+ }
+
+ __block BOOL result = YES;
+ [extensionMap_
+ enumerateKeysAndObjectsUsingBlock:^(GPBExtensionDescriptor *extension,
+ id obj,
+ BOOL *stop) {
+ if (GPBExtensionIsMessage(extension)) {
+ if (extension.isRepeated) {
+ for (GPBMessage *msg in obj) {
+ if (!msg.initialized) {
+ result = NO;
+ *stop = YES;
+ break;
+ }
+ }
+ } else {
+ GPBMessage *asMsg = obj;
+ if (!asMsg.initialized) {
+ result = NO;
+ *stop = YES;
+ }
+ }
+ }
+ }];
+ return result;
+}
+
+- (GPBDescriptor *)descriptor {
+ return [[self class] descriptor];
+}
+
+- (NSData *)data {
+#ifdef DEBUG
+ if (!self.initialized) {
+ return nil;
+ }
+#endif
+ NSMutableData *data = [NSMutableData dataWithLength:[self serializedSize]];
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ @try {
+ [self writeToCodedOutputStream:stream];
+ }
+ @catch (NSException *exception) {
+ // This really shouldn't happen. The only way writeToCodedOutputStream:
+ // could throw is if something in the library has a bug and the
+ // serializedSize was wrong.
+#ifdef DEBUG
+ NSLog(@"%@: Internal exception while building message data: %@",
+ [self class], exception);
+#endif
+ data = nil;
+ }
+ [stream release];
+ return data;
+}
+
+- (NSData *)delimitedData {
+ size_t serializedSize = [self serializedSize];
+ size_t varintSize = GPBComputeRawVarint32SizeForInteger(serializedSize);
+ NSMutableData *data =
+ [NSMutableData dataWithLength:(serializedSize + varintSize)];
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ @try {
+ [self writeDelimitedToCodedOutputStream:stream];
+ }
+ @catch (NSException *exception) {
+ // This really shouldn't happen. The only way writeToCodedOutputStream:
+ // could throw is if something in the library has a bug and the
+ // serializedSize was wrong.
+#ifdef DEBUG
+ NSLog(@"%@: Internal exception while building message delimitedData: %@",
+ [self class], exception);
+#endif
+ // If it happens, truncate.
+ data.length = 0;
+ }
+ [stream release];
+ return data;
+}
+
+- (void)writeToOutputStream:(NSOutputStream *)output {
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithOutputStream:output];
+ [self writeToCodedOutputStream:stream];
+ [stream release];
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output {
+ GPBDescriptor *descriptor = [self descriptor];
+ NSArray *fieldsArray = descriptor->fields_;
+ NSUInteger fieldCount = fieldsArray.count;
+ const GPBExtensionRange *extensionRanges = descriptor.extensionRanges;
+ NSUInteger extensionRangesCount = descriptor.extensionRangesCount;
+ for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) {
+ if (i == fieldCount) {
+ [self writeExtensionsToCodedOutputStream:output
+ range:extensionRanges[j++]];
+ } else if (j == extensionRangesCount ||
+ GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) {
+ [self writeField:fieldsArray[i++] toCodedOutputStream:output];
+ } else {
+ [self writeExtensionsToCodedOutputStream:output
+ range:extensionRanges[j++]];
+ }
+ }
+ if (descriptor.isWireFormat) {
+ [unknownFields_ writeAsMessageSetTo:output];
+ } else {
+ [unknownFields_ writeToCodedOutputStream:output];
+ }
+}
+
+- (void)writeDelimitedToOutputStream:(NSOutputStream *)output {
+ GPBCodedOutputStream *codedOutput =
+ [[GPBCodedOutputStream alloc] initWithOutputStream:output];
+ [self writeDelimitedToCodedOutputStream:codedOutput];
+ [codedOutput release];
+}
+
+- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output {
+ [output writeRawVarintSizeTAs32:[self serializedSize]];
+ [self writeToCodedOutputStream:output];
+}
+
+- (void)writeField:(GPBFieldDescriptor *)field
+ toCodedOutputStream:(GPBCodedOutputStream *)output {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ BOOL has = GPBGetHasIvarField(self, field);
+ if (!has) {
+ return;
+ }
+ }
+ uint32_t fieldNumber = GPBFieldNumber(field);
+
+//%PDDM-DEFINE FIELD_CASE(TYPE, REAL_TYPE)
+//%FIELD_CASE_FULL(TYPE, REAL_TYPE, REAL_TYPE)
+//%PDDM-DEFINE FIELD_CASE_FULL(TYPE, REAL_TYPE, ARRAY_TYPE)
+//% case GPBDataType##TYPE:
+//% if (fieldType == GPBFieldTypeRepeated) {
+//% uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+//% GPB##ARRAY_TYPE##Array *array =
+//% GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [output write##TYPE##Array:fieldNumber values:array tag:tag];
+//% } else if (fieldType == GPBFieldTypeSingle) {
+//% [output write##TYPE:fieldNumber
+//% TYPE$S value:GPBGetMessage##REAL_TYPE##Field(self, field)];
+//% } else { // fieldType == GPBFieldTypeMap
+//% // Exact type here doesn't matter.
+//% GPBInt32##ARRAY_TYPE##Dictionary *dict =
+//% GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [dict writeToCodedOutputStream:output asField:field];
+//% }
+//% break;
+//%
+//%PDDM-DEFINE FIELD_CASE2(TYPE)
+//% case GPBDataType##TYPE:
+//% if (fieldType == GPBFieldTypeRepeated) {
+//% NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [output write##TYPE##Array:fieldNumber values:array];
+//% } else if (fieldType == GPBFieldTypeSingle) {
+//% // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+//% // again.
+//% [output write##TYPE:fieldNumber
+//% TYPE$S value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+//% } else { // fieldType == GPBFieldTypeMap
+//% // Exact type here doesn't matter.
+//% id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% GPBDataType mapKeyDataType = field.mapKeyDataType;
+//% if (mapKeyDataType == GPBDataTypeString) {
+//% GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+//% } else {
+//% [dict writeToCodedOutputStream:output asField:field];
+//% }
+//% }
+//% break;
+//%
+
+ switch (GPBGetFieldDataType(field)) {
+
+//%PDDM-EXPAND FIELD_CASE(Bool, Bool)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeBool:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBBoolArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeBoolArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeBool:fieldNumber
+ value:GPBGetMessageBoolField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32BoolDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Fixed32, UInt32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFixed32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFixed32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFixed32:fieldNumber
+ value:GPBGetMessageUInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SFixed32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSFixed32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSFixed32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSFixed32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Float, Float)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFloat:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBFloatArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFloatArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFloat:fieldNumber
+ value:GPBGetMessageFloatField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32FloatDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Fixed64, UInt64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFixed64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFixed64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFixed64:fieldNumber
+ value:GPBGetMessageUInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SFixed64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSFixed64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSFixed64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSFixed64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Double, Double)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeDouble:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBDoubleArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeDoubleArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeDouble:fieldNumber
+ value:GPBGetMessageDoubleField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32DoubleDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Int32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeInt32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Int64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeInt64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SInt32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSInt32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SInt64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSInt64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(UInt32, UInt32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeUInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeUInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeUInt32:fieldNumber
+ value:GPBGetMessageUInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(UInt64, UInt64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeUInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeUInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeUInt64:fieldNumber
+ value:GPBGetMessageUInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE_FULL(Enum, Int32, Enum)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeEnum:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBEnumArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeEnumArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeEnum:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32EnumDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Bytes)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeBytes:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeBytesArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeBytes:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(String)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeString:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeStringArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeString:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Message)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeMessage:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeMessageArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeMessage:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Group)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeGroup:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeGroupArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeGroup:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND-END (18 expansions)
+ }
+}
+
+#pragma mark - Extensions
+
+- (id)getExtension:(GPBExtensionDescriptor *)extension {
+ CheckExtension(self, extension);
+ id value = [extensionMap_ objectForKey:extension];
+ if (value != nil) {
+ return value;
+ }
+
+ // No default for repeated.
+ if (extension.isRepeated) {
+ return nil;
+ }
+ // Non messages get their default.
+ if (!GPBExtensionIsMessage(extension)) {
+ return extension.defaultValue;
+ }
+
+ // Check for an autocreated value.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ value = [autocreatedExtensionMap_ objectForKey:extension];
+ if (!value) {
+ // Auto create the message extensions to match normal fields.
+ value = CreateMessageWithAutocreatorForExtension(extension.msgClass, self,
+ extension);
+
+ if (autocreatedExtensionMap_ == nil) {
+ autocreatedExtensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ // We can't simply call setExtension here because that would clear the new
+ // value's autocreator.
+ [autocreatedExtensionMap_ setObject:value forKey:extension];
+ [value release];
+ }
+
+ dispatch_semaphore_signal(readOnlySemaphore_);
+ return value;
+}
+
+- (id)getExistingExtension:(GPBExtensionDescriptor *)extension {
+ // This is an internal method so we don't need to call CheckExtension().
+ return [extensionMap_ objectForKey:extension];
+}
+
+- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension {
+#if defined(DEBUG) && DEBUG
+ CheckExtension(self, extension);
+#endif // DEBUG
+ return nil != [extensionMap_ objectForKey:extension];
+}
+
+- (NSArray *)extensionsCurrentlySet {
+ return [extensionMap_ allKeys];
+}
+
+- (void)writeExtensionsToCodedOutputStream:(GPBCodedOutputStream *)output
+ range:(GPBExtensionRange)range {
+ NSArray *sortedExtensions = [[extensionMap_ allKeys]
+ sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
+ uint32_t start = range.start;
+ uint32_t end = range.end;
+ for (GPBExtensionDescriptor *extension in sortedExtensions) {
+ uint32_t fieldNumber = extension.fieldNumber;
+ if (fieldNumber >= start && fieldNumber < end) {
+ id value = [extensionMap_ objectForKey:extension];
+ GPBWriteExtensionValueToOutputStream(extension, value, output);
+ }
+ }
+}
+
+- (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value {
+ if (!value) {
+ [self clearExtension:extension];
+ return;
+ }
+
+ CheckExtension(self, extension);
+
+ if (extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call addExtension() for repeated types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ // This pointless cast is for CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION.
+ // Without it, the compiler complains we're passing an id nullable when
+ // setObject:forKey: requires a id nonnull for the value. The check for
+ // !value at the start of the method ensures it isn't nil, but the check
+ // isn't smart enough to realize that.
+ [extensionMap_ setObject:(id)value forKey:extension];
+
+ GPBExtensionDescriptor *descriptor = extension;
+
+ if (GPBExtensionIsMessage(descriptor) && !descriptor.isRepeated) {
+ GPBMessage *autocreatedValue =
+ [[autocreatedExtensionMap_ objectForKey:extension] retain];
+ // Must remove from the map before calling GPBClearMessageAutocreator() so
+ // that GPBClearMessageAutocreator() knows its safe to clear.
+ [autocreatedExtensionMap_ removeObjectForKey:extension];
+ GPBClearMessageAutocreator(autocreatedValue);
+ [autocreatedValue release];
+ }
+
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value {
+ CheckExtension(self, extension);
+
+ if (!extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call setExtension() for singular types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+ NSMutableArray *list = [extensionMap_ objectForKey:extension];
+ if (list == nil) {
+ list = [NSMutableArray array];
+ [extensionMap_ setObject:list forKey:extension];
+ }
+
+ [list addObject:value];
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ index:(NSUInteger)idx
+ value:(id)value {
+ CheckExtension(self, extension);
+
+ if (!extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call setExtension() for singular types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ NSMutableArray *list = [extensionMap_ objectForKey:extension];
+
+ [list replaceObjectAtIndex:idx withObject:value];
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)clearExtension:(GPBExtensionDescriptor *)extension {
+ CheckExtension(self, extension);
+
+ // Only become visible if there was actually a value to clear.
+ if ([extensionMap_ objectForKey:extension]) {
+ [extensionMap_ removeObjectForKey:extension];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+}
+
+#pragma mark - mergeFrom
+
+- (void)mergeFromData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
+ [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
+ [input checkLastTagWas:0];
+ [input release];
+}
+
+#pragma mark - mergeDelimitedFrom
+
+- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBCodedInputStreamState *state = &input->state_;
+ if (GPBCodedInputStreamIsAtEnd(state)) {
+ return;
+ }
+ NSData *data = GPBCodedInputStreamReadRetainedBytesNoCopy(state);
+ if (data == nil) {
+ return;
+ }
+ [self mergeFromData:data extensionRegistry:extensionRegistry];
+ [data release];
+}
+
+#pragma mark - Parse From Data Support
+
++ (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr {
+ return [self parseFromData:data extensionRegistry:nil error:errorPtr];
+}
+
++ (instancetype)parseFromData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ return [[[self alloc] initWithData:data
+ extensionRegistry:extensionRegistry
+ error:errorPtr] autorelease];
+}
+
++ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ return
+ [[[self alloc] initWithCodedInputStream:input
+ extensionRegistry:extensionRegistry
+ error:errorPtr] autorelease];
+}
+
+#pragma mark - Parse Delimited From Data Support
+
++ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ GPBMessage *message = [[[self alloc] init] autorelease];
+ @try {
+ [message mergeDelimitedFromCodedInputStream:input
+ extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ message = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (message && !message.initialized) {
+ message = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ return message;
+}
+
+#pragma mark - Unknown Field Support
+
+- (GPBUnknownFieldSet *)unknownFields {
+ return unknownFields_;
+}
+
+- (void)setUnknownFields:(GPBUnknownFieldSet *)unknownFields {
+ if (unknownFields != unknownFields_) {
+ [unknownFields_ release];
+ unknownFields_ = [unknownFields copy];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+}
+
+- (void)parseMessageSet:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ uint32_t typeId = 0;
+ NSData *rawBytes = nil;
+ GPBExtensionDescriptor *extension = nil;
+ GPBCodedInputStreamState *state = &input->state_;
+ while (true) {
+ uint32_t tag = GPBCodedInputStreamReadTag(state);
+ if (tag == 0) {
+ break;
+ }
+
+ if (tag == GPBWireFormatMessageSetTypeIdTag) {
+ typeId = GPBCodedInputStreamReadUInt32(state);
+ if (typeId != 0) {
+ extension = [extensionRegistry extensionForDescriptor:[self descriptor]
+ fieldNumber:typeId];
+ }
+ } else if (tag == GPBWireFormatMessageSetMessageTag) {
+ rawBytes =
+ [GPBCodedInputStreamReadRetainedBytesNoCopy(state) autorelease];
+ } else {
+ if (![input skipField:tag]) {
+ break;
+ }
+ }
+ }
+
+ [input checkLastTagWas:GPBWireFormatMessageSetItemEndTag];
+
+ if (rawBytes != nil && typeId != 0) {
+ if (extension != nil) {
+ GPBCodedInputStream *newInput =
+ [[GPBCodedInputStream alloc] initWithData:rawBytes];
+ GPBExtensionMergeFromInputStream(extension,
+ extension.packable,
+ newInput,
+ extensionRegistry,
+ self);
+ [newInput release];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeMessageSetMessage:typeId data:rawBytes];
+ }
+ }
+}
+
+- (BOOL)parseUnknownField:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ tag:(uint32_t)tag {
+ GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag);
+ int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag);
+
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBExtensionDescriptor *extension =
+ [extensionRegistry extensionForDescriptor:descriptor
+ fieldNumber:fieldNumber];
+ if (extension == nil) {
+ if (descriptor.wireFormat && GPBWireFormatMessageSetItemTag == tag) {
+ [self parseMessageSet:input extensionRegistry:extensionRegistry];
+ return YES;
+ }
+ } else {
+ if (extension.wireType == wireType) {
+ GPBExtensionMergeFromInputStream(extension,
+ extension.packable,
+ input,
+ extensionRegistry,
+ self);
+ return YES;
+ }
+ // Primitive, repeated types can be packed on unpacked on the wire, and are
+ // parsed either way.
+ if ([extension isRepeated] &&
+ !GPBDataTypeIsObject(extension->description_->dataType) &&
+ (extension.alternateWireType == wireType)) {
+ GPBExtensionMergeFromInputStream(extension,
+ !extension.packable,
+ input,
+ extensionRegistry,
+ self);
+ return YES;
+ }
+ }
+ if ([GPBUnknownFieldSet isFieldTag:tag]) {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ return [unknownFields mergeFieldFrom:tag input:input];
+ } else {
+ return NO;
+ }
+}
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields addUnknownMapEntry:fieldNum value:data];
+}
+
+#pragma mark - MergeFromCodedInputStream Support
+
+static void MergeSingleFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(&input->state_); \
+ GPBSet##FUNC_TYPE##IvarWithFieldInternal(self, field, val, syntax); \
+ break; \
+ }
+#define CASE_SINGLE_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id val = GPBCodedInputStreamReadRetained##NAME(&input->state_); \
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, val, syntax); \
+ break; \
+ }
+ CASE_SINGLE_POD(Bool, BOOL, Bool)
+ CASE_SINGLE_POD(Fixed32, uint32_t, UInt32)
+ CASE_SINGLE_POD(SFixed32, int32_t, Int32)
+ CASE_SINGLE_POD(Float, float, Float)
+ CASE_SINGLE_POD(Fixed64, uint64_t, UInt64)
+ CASE_SINGLE_POD(SFixed64, int64_t, Int64)
+ CASE_SINGLE_POD(Double, double, Double)
+ CASE_SINGLE_POD(Int32, int32_t, Int32)
+ CASE_SINGLE_POD(Int64, int64_t, Int64)
+ CASE_SINGLE_POD(SInt32, int32_t, Int32)
+ CASE_SINGLE_POD(SInt64, int64_t, Int64)
+ CASE_SINGLE_POD(UInt32, uint32_t, UInt32)
+ CASE_SINGLE_POD(UInt64, uint64_t, UInt64)
+ CASE_SINGLE_OBJECT(Bytes)
+ CASE_SINGLE_OBJECT(String)
+#undef CASE_SINGLE_POD
+#undef CASE_SINGLE_OBJECT
+
+ case GPBDataTypeMessage: {
+ if (GPBGetHasIvarField(self, field)) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has
+ // check again.
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ } else {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message, syntax);
+ }
+ break;
+ }
+
+ case GPBDataTypeGroup: {
+ if (GPBGetHasIvarField(self, field)) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has
+ // check again.
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ } else {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message, syntax);
+ }
+ break;
+ }
+
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(&input->state_);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ GPBSetInt32IvarWithFieldInternal(self, field, val, syntax);
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ }
+ } // switch
+}
+
+static void MergeRepeatedPackedFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ GPBCodedInputStreamState *state = &input->state_;
+ id genericArray = GetOrCreateArrayIvarWithField(self, field, syntax);
+ int32_t length = GPBCodedInputStreamReadInt32(state);
+ size_t limit = GPBCodedInputStreamPushLimit(state, length);
+ while (GPBCodedInputStreamBytesUntilLimit(state) > 0) {
+ switch (fieldDataType) {
+#define CASE_REPEATED_PACKED_POD(NAME, TYPE, ARRAY_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(state); \
+ [(GPB##ARRAY_TYPE##Array *)genericArray addValue:val]; \
+ break; \
+ }
+ CASE_REPEATED_PACKED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_PACKED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_PACKED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(Float, float, Float)
+ CASE_REPEATED_PACKED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_PACKED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(Double, double, Double)
+ CASE_REPEATED_PACKED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_PACKED_POD(UInt64, uint64_t, UInt64)
+#undef CASE_REPEATED_PACKED_POD
+
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"Non primitive types can't be packed");
+ break;
+
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(state);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ [(GPBEnumArray*)genericArray addRawValue:val];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ break;
+ }
+ } // switch
+ } // while(BytesUntilLimit() > 0)
+ GPBCodedInputStreamPopLimit(state, limit);
+}
+
+static void MergeRepeatedNotPackedFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBCodedInputStreamState *state = &input->state_;
+ id genericArray = GetOrCreateArrayIvarWithField(self, field, syntax);
+ switch (GPBGetFieldDataType(field)) {
+#define CASE_REPEATED_NOT_PACKED_POD(NAME, TYPE, ARRAY_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(state); \
+ [(GPB##ARRAY_TYPE##Array *)genericArray addValue:val]; \
+ break; \
+ }
+#define CASE_REPEATED_NOT_PACKED_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id val = GPBCodedInputStreamReadRetained##NAME(state); \
+ [(NSMutableArray*)genericArray addObject:val]; \
+ [val release]; \
+ break; \
+ }
+ CASE_REPEATED_NOT_PACKED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_NOT_PACKED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_NOT_PACKED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(Float, float, Float)
+ CASE_REPEATED_NOT_PACKED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_NOT_PACKED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(Double, double, Double)
+ CASE_REPEATED_NOT_PACKED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_NOT_PACKED_POD(UInt64, uint64_t, UInt64)
+ CASE_REPEATED_NOT_PACKED_OBJECT(Bytes)
+ CASE_REPEATED_NOT_PACKED_OBJECT(String)
+#undef CASE_REPEATED_NOT_PACKED_POD
+#undef CASE_NOT_PACKED_OBJECT
+ case GPBDataTypeMessage: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ [(NSMutableArray*)genericArray addObject:message];
+ [message release];
+ break;
+ }
+ case GPBDataTypeGroup: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ [(NSMutableArray*)genericArray addObject:message];
+ [message release];
+ break;
+ }
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(state);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ [(GPBEnumArray*)genericArray addRawValue:val];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ break;
+ }
+ } // switch
+}
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ GPBCodedInputStreamState *state = &input->state_;
+ uint32_t tag = 0;
+ NSUInteger startingIndex = 0;
+ NSArray *fields = descriptor->fields_;
+ NSUInteger numFields = fields.count;
+ while (YES) {
+ BOOL merged = NO;
+ tag = GPBCodedInputStreamReadTag(state);
+ if (tag == 0) {
+ break; // Reached end.
+ }
+ for (NSUInteger i = 0; i < numFields; ++i) {
+ if (startingIndex >= numFields) startingIndex = 0;
+ GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
+ if (GPBFieldTag(fieldDescriptor) == tag) {
+ GPBFieldType fieldType = fieldDescriptor.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, syntax,
+ input, extensionRegistry);
+ // Well formed protos will only have a single field once, advance
+ // the starting index to the next field.
+ startingIndex += 1;
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ if (fieldDescriptor.isPackable) {
+ MergeRepeatedPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input);
+ // Well formed protos will only have a repeated field that is
+ // packed once, advance the starting index to the next field.
+ startingIndex += 1;
+ } else {
+ MergeRepeatedNotPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input, extensionRegistry);
+ }
+ } else { // fieldType == GPBFieldTypeMap
+ // GPB*Dictionary or NSDictionary, exact type doesn't matter at this
+ // point.
+ id map = GetOrCreateMapIvarWithField(self, fieldDescriptor, syntax);
+ [input readMapEntry:map
+ extensionRegistry:extensionRegistry
+ field:fieldDescriptor
+ parentMessage:self];
+ }
+ merged = YES;
+ break;
+ } else {
+ startingIndex += 1;
+ }
+ } // for(i < numFields)
+
+ if (!merged && (tag != 0)) {
+ // Primitive, repeated types can be packed on unpacked on the wire, and
+ // are parsed either way. The above loop covered tag in the preferred
+ // for, so this need to check the alternate form.
+ for (NSUInteger i = 0; i < numFields; ++i) {
+ if (startingIndex >= numFields) startingIndex = 0;
+ GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
+ if ((fieldDescriptor.fieldType == GPBFieldTypeRepeated) &&
+ !GPBFieldDataTypeIsObject(fieldDescriptor) &&
+ (GPBFieldAlternateTag(fieldDescriptor) == tag)) {
+ BOOL alternateIsPacked = !fieldDescriptor.isPackable;
+ if (alternateIsPacked) {
+ MergeRepeatedPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input);
+ // Well formed protos will only have a repeated field that is
+ // packed once, advance the starting index to the next field.
+ startingIndex += 1;
+ } else {
+ MergeRepeatedNotPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input, extensionRegistry);
+ }
+ merged = YES;
+ break;
+ } else {
+ startingIndex += 1;
+ }
+ }
+ }
+
+ if (!merged) {
+ if (tag == 0) {
+ // zero signals EOF / limit reached
+ return;
+ } else {
+ if (GPBPreserveUnknownFields(syntax)) {
+ if (![self parseUnknownField:input
+ extensionRegistry:extensionRegistry
+ tag:tag]) {
+ // it's an endgroup tag
+ return;
+ }
+ } else {
+ if (![input skipField:tag]) {
+ return;
+ }
+ }
+ }
+ } // if(!merged)
+
+ } // while(YES)
+}
+
+#pragma mark - MergeFrom Support
+
+- (void)mergeFrom:(GPBMessage *)other {
+ Class selfClass = [self class];
+ Class otherClass = [other class];
+ if (!([selfClass isSubclassOfClass:otherClass] ||
+ [otherClass isSubclassOfClass:selfClass])) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Classes must match %@ != %@", selfClass, otherClass];
+ }
+
+ // We assume something will be done and become visible.
+ GPBBecomeVisibleToAutocreator(self);
+
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ int32_t hasIndex = GPBFieldHasIndex(field);
+ uint32_t fieldNumber = GPBFieldNumber(field);
+ if (!GPBGetHasIvar(other, hasIndex, fieldNumber)) {
+ // Other doesn't have the field set, on to the next.
+ continue;
+ }
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+ case GPBDataTypeBool:
+ GPBSetBoolIvarWithFieldInternal(
+ self, field, GPBGetMessageBoolField(other, field), syntax);
+ break;
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ GPBSetInt32IvarWithFieldInternal(
+ self, field, GPBGetMessageInt32Field(other, field), syntax);
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ GPBSetUInt32IvarWithFieldInternal(
+ self, field, GPBGetMessageUInt32Field(other, field), syntax);
+ break;
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ GPBSetInt64IvarWithFieldInternal(
+ self, field, GPBGetMessageInt64Field(other, field), syntax);
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ GPBSetUInt64IvarWithFieldInternal(
+ self, field, GPBGetMessageUInt64Field(other, field), syntax);
+ break;
+ case GPBDataTypeFloat:
+ GPBSetFloatIvarWithFieldInternal(
+ self, field, GPBGetMessageFloatField(other, field), syntax);
+ break;
+ case GPBDataTypeDouble:
+ GPBSetDoubleIvarWithFieldInternal(
+ self, field, GPBGetMessageDoubleField(other, field), syntax);
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeString: {
+ id otherVal = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ GPBSetObjectIvarWithFieldInternal(self, field, otherVal, syntax);
+ break;
+ }
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ id otherVal = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (GPBGetHasIvar(self, hasIndex, fieldNumber)) {
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [message mergeFrom:otherVal];
+ } else {
+ GPBMessage *message = [otherVal copy];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message,
+ syntax);
+ }
+ break;
+ }
+ } // switch()
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ // In the case of a list, they need to be appended, and there is no
+ // _hasIvar to worry about setting.
+ id otherArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (otherArray) {
+ GPBDataType fieldDataType = field->description_->dataType;
+ if (GPBDataTypeIsObject(fieldDataType)) {
+ NSMutableArray *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addObjectsFromArray:otherArray];
+ } else if (fieldDataType == GPBDataTypeEnum) {
+ GPBEnumArray *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addRawValuesFromArray:otherArray];
+ } else {
+ // The array type doesn't matter, that all implment
+ // -addValuesFromArray:.
+ GPBInt32Array *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addValuesFromArray:otherArray];
+ }
+ }
+ } else { // fieldType = GPBFieldTypeMap
+ // In the case of a map, they need to be merged, and there is no
+ // _hasIvar to worry about setting.
+ id otherDict = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (otherDict) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = field->description_->dataType;
+ if (GPBDataTypeIsObject(keyDataType) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ NSMutableDictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addEntriesFromDictionary:otherDict];
+ } else if (valueDataType == GPBDataTypeEnum) {
+ // The exact type doesn't matter, just need to know it is a
+ // GPB*EnumDictionary.
+ GPBInt32EnumDictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addRawEntriesFromDictionary:otherDict];
+ } else {
+ // The exact type doesn't matter, they all implement
+ // -addEntriesFromDictionary:.
+ GPBInt32Int32Dictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addEntriesFromDictionary:otherDict];
+ }
+ }
+ } // if (fieldType)..else if...else
+ } // for(fields)
+
+ // Unknown fields.
+ if (!unknownFields_) {
+ [self setUnknownFields:other.unknownFields];
+ } else {
+ [unknownFields_ mergeUnknownFields:other.unknownFields];
+ }
+
+ // Extensions
+
+ if (other->extensionMap_.count == 0) {
+ return;
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ =
+ CloneExtensionMap(other->extensionMap_, NSZoneFromPointer(self));
+ } else {
+ for (GPBExtensionDescriptor *extension in other->extensionMap_) {
+ id otherValue = [other->extensionMap_ objectForKey:extension];
+ id value = [extensionMap_ objectForKey:extension];
+ BOOL isMessageExtension = GPBExtensionIsMessage(extension);
+
+ if (extension.repeated) {
+ NSMutableArray *list = value;
+ if (list == nil) {
+ list = [[NSMutableArray alloc] init];
+ [extensionMap_ setObject:list forKey:extension];
+ [list release];
+ }
+ if (isMessageExtension) {
+ for (GPBMessage *otherListValue in otherValue) {
+ GPBMessage *copiedValue = [otherListValue copy];
+ [list addObject:copiedValue];
+ [copiedValue release];
+ }
+ } else {
+ [list addObjectsFromArray:otherValue];
+ }
+ } else {
+ if (isMessageExtension) {
+ if (value) {
+ [(GPBMessage *)value mergeFrom:(GPBMessage *)otherValue];
+ } else {
+ GPBMessage *copiedValue = [otherValue copy];
+ [extensionMap_ setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ }
+ } else {
+ [extensionMap_ setObject:otherValue forKey:extension];
+ }
+ }
+
+ if (isMessageExtension && !extension.isRepeated) {
+ GPBMessage *autocreatedValue =
+ [[autocreatedExtensionMap_ objectForKey:extension] retain];
+ // Must remove from the map before calling GPBClearMessageAutocreator()
+ // so that GPBClearMessageAutocreator() knows its safe to clear.
+ [autocreatedExtensionMap_ removeObjectForKey:extension];
+ GPBClearMessageAutocreator(autocreatedValue);
+ [autocreatedValue release];
+ }
+ }
+ }
+}
+
+#pragma mark - isEqual: & hash Support
+
+- (BOOL)isEqual:(id)other {
+ if (other == self) {
+ return YES;
+ }
+ if (![other isKindOfClass:[self class]] &&
+ ![self isKindOfClass:[other class]]) {
+ return NO;
+ }
+
+ GPBMessage *otherMsg = other;
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ uint8_t *selfStorage = (uint8_t *)messageStorage_;
+ uint8_t *otherStorage = (uint8_t *)otherMsg->messageStorage_;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ // In the case of a list or map, there is no _hasIvar to worry about.
+ // NOTE: These are NSArray/GPB*Array or NSDictionary/GPB*Dictionary, but
+ // the type doesn't really matter as the objects all support -count and
+ // -isEqual:.
+ NSArray *resultMapOrArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ NSArray *otherMapOrArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ // nil and empty are equal
+ if (resultMapOrArray.count != 0 || otherMapOrArray.count != 0) {
+ if (![resultMapOrArray isEqual:otherMapOrArray]) {
+ return NO;
+ }
+ }
+ } else { // Single field
+ int32_t hasIndex = GPBFieldHasIndex(field);
+ uint32_t fieldNum = GPBFieldNumber(field);
+ BOOL selfHas = GPBGetHasIvar(self, hasIndex, fieldNum);
+ BOOL otherHas = GPBGetHasIvar(other, hasIndex, fieldNum);
+ if (selfHas != otherHas) {
+ return NO; // Differing has values, not equal.
+ }
+ if (!selfHas) {
+ // Same has values, was no, nothing else to check for this field.
+ continue;
+ }
+ // Now compare the values.
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ size_t fieldOffset = field->description_->offset;
+ switch (fieldDataType) {
+ case GPBDataTypeBool: {
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL selfValue = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ BOOL otherValue = GPBGetHasIvar(other, (int32_t)(fieldOffset), 0);
+ if (selfValue != otherValue) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFloat: {
+ GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ // These are all 32bit, signed/unsigned doesn't matter for equality.
+ uint32_t *selfValPtr = (uint32_t *)&selfStorage[fieldOffset];
+ uint32_t *otherValPtr = (uint32_t *)&otherStorage[fieldOffset];
+ if (*selfValPtr != *otherValPtr) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ case GPBDataTypeDouble: {
+ GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ // These are all 64bit, signed/unsigned doesn't matter for equality.
+ uint64_t *selfValPtr = (uint64_t *)&selfStorage[fieldOffset];
+ uint64_t *otherValPtr = (uint64_t *)&otherStorage[fieldOffset];
+ if (*selfValPtr != *otherValPtr) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ // Type doesn't matter here, they all implement -isEqual:.
+ id *selfValPtr = (id *)&selfStorage[fieldOffset];
+ id *otherValPtr = (id *)&otherStorage[fieldOffset];
+ if (![*selfValPtr isEqual:*otherValPtr]) {
+ return NO;
+ }
+ break;
+ }
+ } // switch()
+ } // if(mapOrArray)...else
+ } // for(fields)
+
+ // nil and empty are equal
+ if (extensionMap_.count != 0 || otherMsg->extensionMap_.count != 0) {
+ if (![extensionMap_ isEqual:otherMsg->extensionMap_]) {
+ return NO;
+ }
+ }
+
+ // nil and empty are equal
+ GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_;
+ if ([unknownFields_ countOfFields] != 0 ||
+ [otherUnknowns countOfFields] != 0) {
+ if (![unknownFields_ isEqual:otherUnknowns]) {
+ return NO;
+ }
+ }
+
+ return YES;
+}
+
+// It is very difficult to implement a generic hash for ProtoBuf messages that
+// will perform well. If you need hashing on your ProtoBufs (eg you are using
+// them as dictionary keys) you will probably want to implement a ProtoBuf
+// message specific hash as a category on your protobuf class. Do not make it a
+// category on GPBMessage as you will conflict with this hash, and will possibly
+// override hash for all generated protobufs. A good implementation of hash will
+// be really fast, so we would recommend only hashing protobufs that have an
+// identifier field of some kind that you can easily hash. If you implement
+// hash, we would strongly recommend overriding isEqual: in your category as
+// well, as the default implementation of isEqual: is extremely slow, and may
+// drastically affect performance in large sets.
+- (NSUInteger)hash {
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ const NSUInteger prime = 19;
+ uint8_t *storage = (uint8_t *)messageStorage_;
+
+ // Start with the descriptor and then mix it with some instance info.
+ // Hopefully that will give a spread based on classes and what fields are set.
+ NSUInteger result = (NSUInteger)descriptor;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ // Exact type doesn't matter, just check if there are any elements.
+ NSArray *mapOrArray = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ NSUInteger count = mapOrArray.count;
+ if (count) {
+ // NSArray/NSDictionary use count, use the field number and the count.
+ result = prime * result + GPBFieldNumber(field);
+ result = prime * result + count;
+ }
+ } else if (GPBGetHasIvarField(self, field)) {
+ // Just using the field number seemed simple/fast, but then a small
+ // message class where all the same fields are always set (to different
+ // things would end up all with the same hash, so pull in some data).
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ size_t fieldOffset = field->description_->offset;
+ switch (fieldDataType) {
+ case GPBDataTypeBool: {
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL value = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ result = prime * result + value;
+ break;
+ }
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFloat: {
+ GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ // These are all 32bit, just mix it in.
+ uint32_t *valPtr = (uint32_t *)&storage[fieldOffset];
+ result = prime * result + *valPtr;
+ break;
+ }
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ case GPBDataTypeDouble: {
+ GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ // These are all 64bit, just mix what fits into an NSUInteger in.
+ uint64_t *valPtr = (uint64_t *)&storage[fieldOffset];
+ result = prime * result + (NSUInteger)(*valPtr);
+ break;
+ }
+ case GPBDataTypeBytes:
+ case GPBDataTypeString: {
+ // Type doesn't matter here, they both implement -hash:.
+ id *valPtr = (id *)&storage[fieldOffset];
+ result = prime * result + [*valPtr hash];
+ break;
+ }
+
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ GPBMessage **valPtr = (GPBMessage **)&storage[fieldOffset];
+ // Could call -hash on the sub message, but that could recurse pretty
+ // deep; follow the lead of NSArray/NSDictionary and don't really
+ // recurse for hash, instead use the field number and the descriptor
+ // of the sub message. Yes, this could suck for a bunch of messages
+ // where they all only differ in the sub messages, but if you are
+ // using a message with sub messages for something that needs -hash,
+ // odds are you are also copying them as keys, and that deep copy
+ // will also suck.
+ result = prime * result + GPBFieldNumber(field);
+ result = prime * result + (NSUInteger)[[*valPtr class] descriptor];
+ break;
+ }
+ } // switch()
+ }
+ }
+
+ // Unknowns and extensions are not included.
+
+ return result;
+}
+
+#pragma mark - Description Support
+
+- (NSString *)description {
+ NSString *textFormat = GPBTextFormatForMessage(self, @" ");
+ NSString *description = [NSString
+ stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat];
+ return description;
+}
+
+#if defined(DEBUG) && DEBUG
+
+// Xcode 5.1 added support for custom quick look info.
+// https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomClassDisplay_in_QuickLook/CH01-quick_look_for_custom_objects/CH01-quick_look_for_custom_objects.html#//apple_ref/doc/uid/TP40014001-CH2-SW1
+- (id)debugQuickLookObject {
+ return GPBTextFormatForMessage(self, nil);
+}
+
+#endif // DEBUG
+
+#pragma mark - SerializedSize
+
+- (size_t)serializedSize {
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ size_t result = 0;
+
+ // Has check is done explicitly, so GPBGetObjectIvarWithFieldNoAutocreate()
+ // avoids doing the has check again.
+
+ // Fields.
+ for (GPBFieldDescriptor *fieldDescriptor in descriptor->fields_) {
+ GPBFieldType fieldType = fieldDescriptor.fieldType;
+ GPBDataType fieldDataType = GPBGetFieldDataType(fieldDescriptor);
+
+ // Single Fields
+ if (fieldType == GPBFieldTypeSingle) {
+ BOOL selfHas = GPBGetHasIvarField(self, fieldDescriptor);
+ if (!selfHas) {
+ continue; // Nothing to do.
+ }
+
+ uint32_t fieldNumber = GPBFieldNumber(fieldDescriptor);
+
+ switch (fieldDataType) {
+#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE fieldVal = GPBGetMessage##FUNC_TYPE##Field(self, fieldDescriptor); \
+ result += GPBCompute##NAME##Size(fieldNumber, fieldVal); \
+ break; \
+ }
+#define CASE_SINGLE_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id fieldVal = GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); \
+ result += GPBCompute##NAME##Size(fieldNumber, fieldVal); \
+ break; \
+ }
+ CASE_SINGLE_POD(Bool, BOOL, Bool)
+ CASE_SINGLE_POD(Fixed32, uint32_t, UInt32)
+ CASE_SINGLE_POD(SFixed32, int32_t, Int32)
+ CASE_SINGLE_POD(Float, float, Float)
+ CASE_SINGLE_POD(Fixed64, uint64_t, UInt64)
+ CASE_SINGLE_POD(SFixed64, int64_t, Int64)
+ CASE_SINGLE_POD(Double, double, Double)
+ CASE_SINGLE_POD(Int32, int32_t, Int32)
+ CASE_SINGLE_POD(Int64, int64_t, Int64)
+ CASE_SINGLE_POD(SInt32, int32_t, Int32)
+ CASE_SINGLE_POD(SInt64, int64_t, Int64)
+ CASE_SINGLE_POD(UInt32, uint32_t, UInt32)
+ CASE_SINGLE_POD(UInt64, uint64_t, UInt64)
+ CASE_SINGLE_OBJECT(Bytes)
+ CASE_SINGLE_OBJECT(String)
+ CASE_SINGLE_OBJECT(Message)
+ CASE_SINGLE_OBJECT(Group)
+ CASE_SINGLE_POD(Enum, int32_t, Int32)
+#undef CASE_SINGLE_POD
+#undef CASE_SINGLE_OBJECT
+ }
+
+ // Repeated Fields
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ id genericArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ NSUInteger count = [genericArray count];
+ if (count == 0) {
+ continue; // Nothing to add.
+ }
+ __block size_t dataSize = 0;
+
+ switch (fieldDataType) {
+#define CASE_REPEATED_POD(NAME, TYPE, ARRAY_TYPE) \
+ CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, )
+#define CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ARRAY_ACCESSOR_NAME) \
+ case GPBDataType##NAME: { \
+ GPB##ARRAY_TYPE##Array *array = genericArray; \
+ [array enumerate##ARRAY_ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { \
+ _Pragma("unused(idx, stop)"); \
+ dataSize += GPBCompute##NAME##SizeNoTag(value); \
+ }]; \
+ break; \
+ }
+#define CASE_REPEATED_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ for (id value in genericArray) { \
+ dataSize += GPBCompute##NAME##SizeNoTag(value); \
+ } \
+ break; \
+ }
+ CASE_REPEATED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_POD(Float, float, Float)
+ CASE_REPEATED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_POD(Double, double, Double)
+ CASE_REPEATED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_POD(UInt64, uint64_t, UInt64)
+ CASE_REPEATED_OBJECT(Bytes)
+ CASE_REPEATED_OBJECT(String)
+ CASE_REPEATED_OBJECT(Message)
+ CASE_REPEATED_OBJECT(Group)
+ CASE_REPEATED_POD_EXTRA(Enum, int32_t, Enum, Raw)
+#undef CASE_REPEATED_POD
+#undef CASE_REPEATED_POD_EXTRA
+#undef CASE_REPEATED_OBJECT
+ } // switch
+ result += dataSize;
+ size_t tagSize = GPBComputeTagSize(GPBFieldNumber(fieldDescriptor));
+ if (fieldDataType == GPBDataTypeGroup) {
+ // Groups have both a start and an end tag.
+ tagSize *= 2;
+ }
+ if (fieldDescriptor.isPackable) {
+ result += tagSize;
+ result += GPBComputeSizeTSizeAsInt32NoTag(dataSize);
+ } else {
+ result += count * tagSize;
+ }
+
+ // Map<> Fields
+ } else { // fieldType == GPBFieldTypeMap
+ if (GPBDataTypeIsObject(fieldDataType) &&
+ (fieldDescriptor.mapKeyDataType == GPBDataTypeString)) {
+ // If key type was string, then the map is an NSDictionary.
+ NSDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ if (map) {
+ result += GPBDictionaryComputeSizeInternalHelper(map, fieldDescriptor);
+ }
+ } else {
+ // Type will be GPB*GroupDictionary, exact type doesn't matter.
+ GPBInt32Int32Dictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ result += [map computeSerializedSizeAsField:fieldDescriptor];
+ }
+ }
+ } // for(fields)
+
+ // Add any unknown fields.
+ if (descriptor.wireFormat) {
+ result += [unknownFields_ serializedSizeAsMessageSet];
+ } else {
+ result += [unknownFields_ serializedSize];
+ }
+
+ // Add any extensions.
+ for (GPBExtensionDescriptor *extension in extensionMap_) {
+ id value = [extensionMap_ objectForKey:extension];
+ result += GPBComputeExtensionSerializedSizeIncludingTag(extension, value);
+ }
+
+ return result;
+}
+
+#pragma mark - Resolve Methods Support
+
+typedef struct ResolveIvarAccessorMethodResult {
+ IMP impToAdd;
+ SEL encodingSelector;
+} ResolveIvarAccessorMethodResult;
+
+static void ResolveIvarGet(GPBFieldDescriptor *field,
+ ResolveIvarAccessorMethodResult *result) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_GET(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj) { \
+ return GPBGetMessage##TRUE_NAME##Field(obj, field); \
+ }); \
+ result->encodingSelector = @selector(get##NAME); \
+ break; \
+ }
+#define CASE_GET_OBJECT(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj) { \
+ return GPBGetObjectIvarWithField(obj, field); \
+ }); \
+ result->encodingSelector = @selector(get##NAME); \
+ break; \
+ }
+ CASE_GET(Bool, BOOL, Bool)
+ CASE_GET(Fixed32, uint32_t, UInt32)
+ CASE_GET(SFixed32, int32_t, Int32)
+ CASE_GET(Float, float, Float)
+ CASE_GET(Fixed64, uint64_t, UInt64)
+ CASE_GET(SFixed64, int64_t, Int64)
+ CASE_GET(Double, double, Double)
+ CASE_GET(Int32, int32_t, Int32)
+ CASE_GET(Int64, int64_t, Int64)
+ CASE_GET(SInt32, int32_t, Int32)
+ CASE_GET(SInt64, int64_t, Int64)
+ CASE_GET(UInt32, uint32_t, UInt32)
+ CASE_GET(UInt64, uint64_t, UInt64)
+ CASE_GET_OBJECT(Bytes, id, Object)
+ CASE_GET_OBJECT(String, id, Object)
+ CASE_GET_OBJECT(Message, id, Object)
+ CASE_GET_OBJECT(Group, id, Object)
+ CASE_GET(Enum, int32_t, Enum)
+#undef CASE_GET
+ }
+}
+
+static void ResolveIvarSet(GPBFieldDescriptor *field,
+ GPBFileSyntax syntax,
+ ResolveIvarAccessorMethodResult *result) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_SET(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj, TYPE value) { \
+ return GPBSet##TRUE_NAME##IvarWithFieldInternal(obj, field, value, syntax); \
+ }); \
+ result->encodingSelector = @selector(set##NAME:); \
+ break; \
+ }
+ CASE_SET(Bool, BOOL, Bool)
+ CASE_SET(Fixed32, uint32_t, UInt32)
+ CASE_SET(SFixed32, int32_t, Int32)
+ CASE_SET(Float, float, Float)
+ CASE_SET(Fixed64, uint64_t, UInt64)
+ CASE_SET(SFixed64, int64_t, Int64)
+ CASE_SET(Double, double, Double)
+ CASE_SET(Int32, int32_t, Int32)
+ CASE_SET(Int64, int64_t, Int64)
+ CASE_SET(SInt32, int32_t, Int32)
+ CASE_SET(SInt64, int64_t, Int64)
+ CASE_SET(UInt32, uint32_t, UInt32)
+ CASE_SET(UInt64, uint64_t, UInt64)
+ CASE_SET(Bytes, id, Object)
+ CASE_SET(String, id, Object)
+ CASE_SET(Message, id, Object)
+ CASE_SET(Group, id, Object)
+ CASE_SET(Enum, int32_t, Enum)
+#undef CASE_SET
+ }
+}
+
++ (BOOL)resolveInstanceMethod:(SEL)sel {
+ const GPBDescriptor *descriptor = [self descriptor];
+ if (!descriptor) {
+ return NO;
+ }
+
+ // NOTE: hasOrCountSel_/setHasSel_ will be NULL if the field for the given
+ // message should not have has support (done in GPBDescriptor.m), so there is
+ // no need for checks here to see if has*/setHas* are allowed.
+
+ ResolveIvarAccessorMethodResult result = {NULL, NULL};
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(field);
+ if (!isMapOrArray) {
+ // Single fields.
+ if (sel == field->getSel_) {
+ ResolveIvarGet(field, &result);
+ break;
+ } else if (sel == field->setSel_) {
+ ResolveIvarSet(field, descriptor.file.syntax, &result);
+ break;
+ } else if (sel == field->hasOrCountSel_) {
+ int32_t index = GPBFieldHasIndex(field);
+ uint32_t fieldNum = GPBFieldNumber(field);
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GPBGetHasIvar(obj, index, fieldNum);
+ });
+ result.encodingSelector = @selector(getBool);
+ break;
+ } else if (sel == field->setHasSel_) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj, BOOL value) {
+ if (value) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: %@ can only be set to NO (to clear field).",
+ [obj class],
+ NSStringFromSelector(field->setHasSel_)];
+ }
+ GPBClearMessageField(obj, field);
+ });
+ result.encodingSelector = @selector(setBool:);
+ break;
+ } else {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof && (sel == oneof->caseSel_)) {
+ int32_t index = GPBFieldHasIndex(field);
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GPBGetHasOneof(obj, index);
+ });
+ result.encodingSelector = @selector(getEnum);
+ break;
+ }
+ }
+ } else {
+ // map<>/repeated fields.
+ if (sel == field->getSel_) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GetArrayIvarWithField(obj, field);
+ });
+ } else {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GetMapIvarWithField(obj, field);
+ });
+ }
+ result.encodingSelector = @selector(getArray);
+ break;
+ } else if (sel == field->setSel_) {
+ // Local for syntax so the block can directly capture it and not the
+ // full lookup.
+ const GPBFileSyntax syntax = descriptor.file.syntax;
+ result.impToAdd = imp_implementationWithBlock(^(id obj, id value) {
+ return GPBSetObjectIvarWithFieldInternal(obj, field, value, syntax);
+ });
+ result.encodingSelector = @selector(setArray:);
+ break;
+ } else if (sel == field->hasOrCountSel_) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ // Type doesn't matter, all *Array and *Dictionary types support
+ // -count.
+ NSArray *arrayOrMap =
+ GPBGetObjectIvarWithFieldNoAutocreate(obj, field);
+ return [arrayOrMap count];
+ });
+ result.encodingSelector = @selector(getArrayCount);
+ break;
+ }
+ }
+ }
+ if (result.impToAdd) {
+ const char *encoding =
+ GPBMessageEncodingForSelector(result.encodingSelector, YES);
+ Class msgClass = descriptor.messageClass;
+ BOOL methodAdded = class_addMethod(msgClass, sel, result.impToAdd, encoding);
+ // class_addMethod() is documented as also failing if the method was already
+ // added; so we check if the method is already there and return success so
+ // the method dispatch will still happen. Why would it already be added?
+ // Two threads could cause the same method to be bound at the same time,
+ // but only one will actually bind it; the other still needs to return true
+ // so things will dispatch.
+ if (!methodAdded) {
+ methodAdded = GPBClassHasSel(msgClass, sel);
+ }
+ return methodAdded;
+ }
+ return [super resolveInstanceMethod:sel];
+}
+
++ (BOOL)resolveClassMethod:(SEL)sel {
+ // Extensions scoped to a Message and looked up via class methods.
+ if (GPBResolveExtensionClassMethod(self, sel)) {
+ return YES;
+ }
+ return [super resolveClassMethod:sel];
+}
+
+#pragma mark - NSCoding Support
+
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)aDecoder {
+ self = [self init];
+ if (self) {
+ NSData *data =
+ [aDecoder decodeObjectOfClass:[NSData class] forKey:kGPBDataCoderKey];
+ if (data.length) {
+ [self mergeFromData:data extensionRegistry:nil];
+ }
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)aCoder {
+ NSData *data = [self data];
+ if (data.length) {
+ [aCoder encodeObject:data forKey:kGPBDataCoderKey];
+ }
+}
+
+#pragma mark - KVC Support
+
++ (BOOL)accessInstanceVariablesDirectly {
+ // Make sure KVC doesn't use instance variables.
+ return NO;
+}
+
+@end
+
+#pragma mark - Messages from GPBUtilities.h but defined here for access to helpers.
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeRepeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a repeated field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateArrayIvarWithField(self, field, syntax);
+}
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeMap) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a map<> field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateMapIvarWithField(self, field, syntax);
+}
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h b/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h
new file mode 100644
index 0000000000..9324cf8d5e
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h
@@ -0,0 +1,150 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBMessage.h"
+
+#import <libkern/OSAtomic.h>
+
+#import "GPBBootstrap.h"
+
+typedef struct GPBMessage_Storage {
+ uint32_t _has_storage_[0];
+} GPBMessage_Storage;
+
+typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
+
+@interface GPBMessage () {
+ @package
+ // NOTE: Because of the +allocWithZone code using NSAllocateObject(),
+ // this structure should ideally always be kept pointer aligned where the
+ // real storage starts is also pointer aligned. The compiler/runtime already
+ // do this, but it may not be documented.
+
+ // A pointer to the actual fields of the subclasses. The actual structure
+ // pointed to by this pointer will depend on the subclass.
+ // All of the actual structures will start the same as
+ // GPBMessage_Storage with _has_storage__ as the first field.
+ // Kept public because static functions need to access it.
+ GPBMessage_StoragePtr messageStorage_;
+
+ // A lock to provide mutual exclusion from internal data that can be modified
+ // by *read* operations such as getters (autocreation of message fields and
+ // message extensions, not setting of values). Used to guarantee thread safety
+ // for concurrent reads on the message.
+ // NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
+ // pointed out that they are vulnerable to live locking on iOS in cases of
+ // priority inversion:
+ // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
+ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
+ // Use of readOnlySemaphore_ must be prefaced by a call to
+ // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows
+ // readOnlySemaphore_ to be only created when actually needed.
+ dispatch_once_t readOnlySemaphoreCreationOnce_;
+ dispatch_semaphore_t readOnlySemaphore_;
+}
+
+// Gets an extension value without autocreating the result if not found. (i.e.
+// returns nil if the extension is not set)
+- (id)getExistingExtension:(GPBExtensionDescriptor *)extension;
+
+// Parses a message of this type from the input and merges it with this
+// message.
+//
+// Warning: This does not verify that all required fields are present in
+// the input message.
+// Note: The caller should call
+// -[CodedInputStream checkLastTagWas:] after calling this to
+// verify that the last tag seen was the appropriate end-group tag,
+// or zero for EOF.
+// NOTE: This will throw if there is an error while parsing.
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+
+// Parses the next delimited message of this type from the input and merges it
+// with this message.
+- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry;
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;
+
+@end
+
+CF_EXTERN_C_BEGIN
+
+
+// Call this before using the readOnlySemaphore_. This ensures it is created only once.
+NS_INLINE void GPBPrepareReadOnlySemaphore(GPBMessage *self) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Starting on Xcode 8.3, the static analyzer complains that the dispatch_once_t
+// variable passed to dispatch_once should not be allocated on the heap or
+// stack. Given that the semaphore is also an instance variable of the message,
+// both variables are cleared at the same time, so this is safe.
+#if !defined(__clang_analyzer__)
+ dispatch_once(&self->readOnlySemaphoreCreationOnce_, ^{
+ self->readOnlySemaphore_ = dispatch_semaphore_create(1);
+ });
+#endif // !defined(__clang_analyzer__)
+
+#pragma clang diagnostic pop
+}
+
+// Returns a new instance that was automatically created by |autocreator| for
+// its field |field|.
+GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass,
+ GPBMessage *autocreator,
+ GPBFieldDescriptor *field)
+ __attribute__((ns_returns_retained));
+
+// Returns whether |message| autocreated this message. This is NO if the message
+// was not autocreated by |message| or if it has been mutated since
+// autocreation.
+BOOL GPBWasMessageAutocreatedBy(GPBMessage *message, GPBMessage *parent);
+
+// Call this when you mutate a message. It will cause the message to become
+// visible to its autocreator.
+void GPBBecomeVisibleToAutocreator(GPBMessage *self);
+
+// Call this when an array/dictionary is mutated so the parent message that
+// autocreated it can react.
+void GPBAutocreatedArrayModified(GPBMessage *self, id array);
+void GPBAutocreatedDictionaryModified(GPBMessage *self, id dictionary);
+
+// Clear the autocreator, if any. Asserts if the autocreator still has an
+// autocreated reference to this message.
+void GPBClearMessageAutocreator(GPBMessage *self);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers.h b/third_party/protobuf/objectivec/GPBProtocolBuffers.h
new file mode 100644
index 0000000000..68d8854eb8
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers.h
@@ -0,0 +1,76 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBBootstrap.h"
+
+#import "GPBArray.h"
+#import "GPBCodedInputStream.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBDescriptor.h"
+#import "GPBDictionary.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBMessage.h"
+#import "GPBRootObject.h"
+#import "GPBUnknownField.h"
+#import "GPBUnknownFieldSet.h"
+#import "GPBUtilities.h"
+#import "GPBWellKnownTypes.h"
+#import "GPBWireFormat.h"
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+// Well-known proto types
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/Api.pbobjc.h>
+ #import <Protobuf/Duration.pbobjc.h>
+ #import <Protobuf/Empty.pbobjc.h>
+ #import <Protobuf/FieldMask.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+ #import <Protobuf/Struct.pbobjc.h>
+ #import <Protobuf/Timestamp.pbobjc.h>
+ #import <Protobuf/Type.pbobjc.h>
+ #import <Protobuf/Wrappers.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/Api.pbobjc.h"
+ #import "google/protobuf/Duration.pbobjc.h"
+ #import "google/protobuf/Empty.pbobjc.h"
+ #import "google/protobuf/FieldMask.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+ #import "google/protobuf/Struct.pbobjc.h"
+ #import "google/protobuf/Timestamp.pbobjc.h"
+ #import "google/protobuf/Type.pbobjc.h"
+ #import "google/protobuf/Wrappers.pbobjc.h"
+#endif
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers.m b/third_party/protobuf/objectivec/GPBProtocolBuffers.m
new file mode 100644
index 0000000000..d04c8be155
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers.m
@@ -0,0 +1,66 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// If you want to build protocol buffers in your own project without adding the
+// project dependency, you can just add this file.
+
+
+// This warning seems to treat code differently when it is #imported than when
+// it is inline in the file. GPBDictionary.m compiles cleanly in other targets,
+// but when #imported here it triggers a bunch of warnings that don't make
+// much sense, and don't trigger when compiled directly. So we shut off the
+// warnings here.
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+
+#import "GPBArray.m"
+#import "GPBCodedInputStream.m"
+#import "GPBCodedOutputStream.m"
+#import "GPBDescriptor.m"
+#import "GPBDictionary.m"
+#import "GPBExtensionInternals.m"
+#import "GPBExtensionRegistry.m"
+#import "GPBMessage.m"
+#import "GPBRootObject.m"
+#import "GPBUnknownField.m"
+#import "GPBUnknownFieldSet.m"
+#import "GPBUtilities.m"
+#import "GPBWellKnownTypes.m"
+#import "GPBWireFormat.m"
+
+#import "google/protobuf/Any.pbobjc.m"
+#import "google/protobuf/Api.pbobjc.m"
+#import "google/protobuf/Duration.pbobjc.m"
+#import "google/protobuf/Empty.pbobjc.m"
+#import "google/protobuf/FieldMask.pbobjc.m"
+#import "google/protobuf/SourceContext.pbobjc.m"
+#import "google/protobuf/Struct.pbobjc.m"
+#import "google/protobuf/Timestamp.pbobjc.m"
+#import "google/protobuf/Type.pbobjc.m"
+#import "google/protobuf/Wrappers.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h b/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h
new file mode 100644
index 0000000000..fea75b93bc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This header is meant to only be used by the generated source, it should not
+// be included in code using protocol buffers.
+
+#import "GPBProtocolBuffers.h"
+
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBExtensionInternals.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBRootObject_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
diff --git a/third_party/protobuf/objectivec/GPBRootObject.h b/third_party/protobuf/objectivec/GPBRootObject.h
new file mode 100644
index 0000000000..d2e2aebfcc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject.h
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBExtensionRegistry;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Every generated proto file defines a local "Root" class that exposes a
+ * GPBExtensionRegistry for all the extensions defined by that file and
+ * the files it depends on.
+ **/
+@interface GPBRootObject : NSObject
+
+/**
+ * @return An extension registry for the given file and all the files it depends
+ * on.
+ **/
++ (GPBExtensionRegistry *)extensionRegistry;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBRootObject.m b/third_party/protobuf/objectivec/GPBRootObject.m
new file mode 100644
index 0000000000..585d205a21
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject.m
@@ -0,0 +1,237 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBRootObject_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import <CoreFoundation/CoreFoundation.h>
+
+#import "GPBDescriptor.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+@interface GPBExtensionDescriptor (GPBRootObject)
+// Get singletonName as a c string.
+- (const char *)singletonNameC;
+@end
+
+@implementation GPBRootObject
+
+// Taken from http://www.burtleburtle.net/bob/hash/doobs.html
+// Public Domain
+static uint32_t jenkins_one_at_a_time_hash(const char *key) {
+ uint32_t hash = 0;
+ for (uint32_t i = 0; key[i] != '\0'; ++i) {
+ hash += key[i];
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ }
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+ return hash;
+}
+
+// Key methods for our custom CFDictionary.
+// Note that the dictionary lasts for the lifetime of our app, so no need
+// to worry about deallocation. All of the items are added to it at
+// startup, and so the keys don't need to be retained/released.
+// Keys are NULL terminated char *.
+static const void *GPBRootExtensionKeyRetain(CFAllocatorRef allocator,
+ const void *value) {
+#pragma unused(allocator)
+ return value;
+}
+
+static void GPBRootExtensionKeyRelease(CFAllocatorRef allocator,
+ const void *value) {
+#pragma unused(allocator)
+#pragma unused(value)
+}
+
+static CFStringRef GPBRootExtensionCopyKeyDescription(const void *value) {
+ const char *key = (const char *)value;
+ return CFStringCreateWithCString(kCFAllocatorDefault, key,
+ kCFStringEncodingUTF8);
+}
+
+static Boolean GPBRootExtensionKeyEqual(const void *value1,
+ const void *value2) {
+ const char *key1 = (const char *)value1;
+ const char *key2 = (const char *)value2;
+ return strcmp(key1, key2) == 0;
+}
+
+static CFHashCode GPBRootExtensionKeyHash(const void *value) {
+ const char *key = (const char *)value;
+ return jenkins_one_at_a_time_hash(key);
+}
+
+// NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
+// pointed out that they are vulnerable to live locking on iOS in cases of
+// priority inversion:
+// http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
+// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
+static dispatch_semaphore_t gExtensionSingletonDictionarySemaphore;
+static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
+static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL;
+
++ (void)initialize {
+ // Ensure the global is started up.
+ if (!gExtensionSingletonDictionary) {
+ gExtensionSingletonDictionarySemaphore = dispatch_semaphore_create(1);
+ CFDictionaryKeyCallBacks keyCallBacks = {
+ // See description above for reason for using custom dictionary.
+ 0,
+ GPBRootExtensionKeyRetain,
+ GPBRootExtensionKeyRelease,
+ GPBRootExtensionCopyKeyDescription,
+ GPBRootExtensionKeyEqual,
+ GPBRootExtensionKeyHash,
+ };
+ gExtensionSingletonDictionary =
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &keyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ gDefaultExtensionRegistry = [[GPBExtensionRegistry alloc] init];
+ }
+
+ if ([self superclass] == [GPBRootObject class]) {
+ // This is here to start up all the per file "Root" subclasses.
+ // This must be done in initialize to enforce thread safety of start up of
+ // the protocol buffer library.
+ [self extensionRegistry];
+ }
+}
+
++ (GPBExtensionRegistry *)extensionRegistry {
+ // Is overridden in all the subclasses that provide extensions to provide the
+ // per class one.
+ return gDefaultExtensionRegistry;
+}
+
++ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field {
+ const char *key = [field singletonNameC];
+ dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore,
+ DISPATCH_TIME_FOREVER);
+ CFDictionarySetValue(gExtensionSingletonDictionary, key, field);
+ dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+}
+
+static id ExtensionForName(id self, SEL _cmd) {
+ // Really fast way of doing "classname_selName".
+ // This came up as a hotspot (creation of NSString *) when accessing a
+ // lot of extensions.
+ const char *selName = sel_getName(_cmd);
+ if (selName[0] == '_') {
+ return nil; // Apple internal selector.
+ }
+ size_t selNameLen = 0;
+ while (1) {
+ char c = selName[selNameLen];
+ if (c == '\0') { // String end.
+ break;
+ }
+ if (c == ':') {
+ return nil; // Selector took an arg, not one of the runtime methods.
+ }
+ ++selNameLen;
+ }
+
+ const char *className = class_getName(self);
+ size_t classNameLen = strlen(className);
+ char key[classNameLen + selNameLen + 2];
+ memcpy(key, className, classNameLen);
+ key[classNameLen] = '_';
+ memcpy(&key[classNameLen + 1], selName, selNameLen);
+ key[classNameLen + 1 + selNameLen] = '\0';
+
+ // NOTE: Even though this method is called from another C function,
+ // gExtensionSingletonDictionarySemaphore and gExtensionSingletonDictionary
+ // will always be initialized. This is because this call flow is just to
+ // lookup the Extension, meaning the code is calling an Extension class
+ // message on a Message or Root class. This guarantees that the class was
+ // initialized and Message classes ensure their Root was also initialized.
+ NSAssert(gExtensionSingletonDictionary, @"Startup order broken!");
+
+ dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore,
+ DISPATCH_TIME_FOREVER);
+ id extension = (id)CFDictionaryGetValue(gExtensionSingletonDictionary, key);
+ // We can't remove the key from the dictionary here (as an optimization),
+ // two threads could have gone into +resolveClassMethod: for the same method,
+ // and ended up here; there's no way to ensure both return YES without letting
+ // both try to wire in the method.
+ dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+ return extension;
+}
+
+BOOL GPBResolveExtensionClassMethod(Class self, SEL sel) {
+ // Another option would be to register the extensions with the class at
+ // globallyRegisterExtension:
+ // Timing the two solutions, this solution turned out to be much faster
+ // and reduced startup time, and runtime memory.
+ // The advantage to globallyRegisterExtension is that it would reduce the
+ // size of the protos somewhat because the singletonNameC wouldn't need
+ // to include the class name. For a class with a lot of extensions it
+ // can add up. You could also significantly reduce the code complexity of this
+ // file.
+ id extension = ExtensionForName(self, sel);
+ if (extension != nil) {
+ const char *encoding =
+ GPBMessageEncodingForSelector(@selector(getClassValue), NO);
+ Class metaClass = objc_getMetaClass(class_getName(self));
+ IMP imp = imp_implementationWithBlock(^(id obj) {
+#pragma unused(obj)
+ return extension;
+ });
+ BOOL methodAdded = class_addMethod(metaClass, sel, imp, encoding);
+ // class_addMethod() is documented as also failing if the method was already
+ // added; so we check if the method is already there and return success so
+ // the method dispatch will still happen. Why would it already be added?
+ // Two threads could cause the same method to be bound at the same time,
+ // but only one will actually bind it; the other still needs to return true
+ // so things will dispatch.
+ if (!methodAdded) {
+ methodAdded = GPBClassHasSel(metaClass, sel);
+ }
+ return methodAdded;
+ }
+ return NO;
+}
+
+
++ (BOOL)resolveClassMethod:(SEL)sel {
+ if (GPBResolveExtensionClassMethod(self, sel)) {
+ return YES;
+ }
+ return [super resolveClassMethod:sel];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h b/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h
new file mode 100644
index 0000000000..3c8f09c896
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h
@@ -0,0 +1,46 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRootObject.h"
+
+@class GPBExtensionDescriptor;
+
+@interface GPBRootObject ()
+
+// Globally register.
++ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field;
+
+@end
+
+// Returns YES if the selector was resolved and added to the class,
+// NO otherwise.
+BOOL GPBResolveExtensionClassMethod(Class self, SEL sel);
diff --git a/third_party/protobuf/objectivec/GPBRuntimeTypes.h b/third_party/protobuf/objectivec/GPBRuntimeTypes.h
new file mode 100644
index 0000000000..4d552060b0
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRuntimeTypes.h
@@ -0,0 +1,144 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBBootstrap.h"
+
+@class GPBEnumDescriptor;
+@class GPBMessage;
+@class GPBInt32Array;
+
+/**
+ * Verifies that a given value can be represented by an enum type.
+ * */
+typedef BOOL (*GPBEnumValidationFunc)(int32_t);
+
+/**
+ * Fetches an EnumDescriptor.
+ * */
+typedef GPBEnumDescriptor *(*GPBEnumDescriptorFunc)(void);
+
+/**
+ * Magic value used at runtime to indicate an enum value that wasn't know at
+ * compile time.
+ * */
+enum {
+ kGPBUnrecognizedEnumeratorValue = (int32_t)0xFBADBEEF,
+};
+
+/**
+ * A union for storing all possible Protobuf values. Note that owner is
+ * responsible for memory management of object types.
+ * */
+typedef union {
+ BOOL valueBool;
+ int32_t valueInt32;
+ int64_t valueInt64;
+ uint32_t valueUInt32;
+ uint64_t valueUInt64;
+ float valueFloat;
+ double valueDouble;
+ GPB_UNSAFE_UNRETAINED NSData *valueData;
+ GPB_UNSAFE_UNRETAINED NSString *valueString;
+ GPB_UNSAFE_UNRETAINED GPBMessage *valueMessage;
+ int32_t valueEnum;
+} GPBGenericValue;
+
+/**
+ * Enum listing the possible data types that a field can contain.
+ *
+ * @note Do not change the order of this enum (or add things to it) without
+ * thinking about it very carefully. There are several things that depend
+ * on the order.
+ * */
+typedef NS_ENUM(uint8_t, GPBDataType) {
+ /** Field contains boolean value(s). */
+ GPBDataTypeBool = 0,
+ /** Field contains unsigned 4 byte value(s). */
+ GPBDataTypeFixed32,
+ /** Field contains signed 4 byte value(s). */
+ GPBDataTypeSFixed32,
+ /** Field contains float value(s). */
+ GPBDataTypeFloat,
+ /** Field contains unsigned 8 byte value(s). */
+ GPBDataTypeFixed64,
+ /** Field contains signed 8 byte value(s). */
+ GPBDataTypeSFixed64,
+ /** Field contains double value(s). */
+ GPBDataTypeDouble,
+ /**
+ * Field contains variable length value(s). Inefficient for encoding negative
+ * numbers – if your field is likely to have negative values, use
+ * GPBDataTypeSInt32 instead.
+ **/
+ GPBDataTypeInt32,
+ /**
+ * Field contains variable length value(s). Inefficient for encoding negative
+ * numbers – if your field is likely to have negative values, use
+ * GPBDataTypeSInt64 instead.
+ **/
+ GPBDataTypeInt64,
+ /** Field contains signed variable length integer value(s). */
+ GPBDataTypeSInt32,
+ /** Field contains signed variable length integer value(s). */
+ GPBDataTypeSInt64,
+ /** Field contains unsigned variable length integer value(s). */
+ GPBDataTypeUInt32,
+ /** Field contains unsigned variable length integer value(s). */
+ GPBDataTypeUInt64,
+ /** Field contains an arbitrary sequence of bytes. */
+ GPBDataTypeBytes,
+ /** Field contains UTF-8 encoded or 7-bit ASCII text. */
+ GPBDataTypeString,
+ /** Field contains message type(s). */
+ GPBDataTypeMessage,
+ /** Field contains message type(s). */
+ GPBDataTypeGroup,
+ /** Field contains enum value(s). */
+ GPBDataTypeEnum,
+};
+
+enum {
+ /**
+ * A count of the number of types in GPBDataType. Separated out from the
+ * GPBDataType enum to avoid warnings regarding not handling GPBDataType_Count
+ * in switch statements.
+ **/
+ GPBDataType_Count = GPBDataTypeEnum + 1
+};
+
+/** An extension range. */
+typedef struct GPBExtensionRange {
+ /** Inclusive. */
+ uint32_t start;
+ /** Exclusive. */
+ uint32_t end;
+} GPBExtensionRange;
diff --git a/third_party/protobuf/objectivec/GPBUnknownField.h b/third_party/protobuf/objectivec/GPBUnknownField.h
new file mode 100644
index 0000000000..a135cc2031
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField.h
@@ -0,0 +1,96 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBCodedOutputStream;
+@class GPBUInt32Array;
+@class GPBUInt64Array;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+/**
+ * Store an unknown field. These are used in conjunction with
+ * GPBUnknownFieldSet.
+ **/
+@interface GPBUnknownField : NSObject<NSCopying>
+
+/** The field number the data is stored under. */
+@property(nonatomic, readonly, assign) int32_t number;
+
+/** An array of varint values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt64Array *varintList;
+
+/** An array of fixed32 values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List;
+
+/** An array of fixed64 values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List;
+
+/** An array of data values for this field. */
+@property(nonatomic, readonly, strong) NSArray<NSData*> *lengthDelimitedList;
+
+/** An array of groups of values for this field. */
+@property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet*> *groupList;
+
+/**
+ * Add a value to the varintList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addVarint:(uint64_t)value;
+/**
+ * Add a value to the fixed32List.
+ *
+ * @param value The value to add.
+ **/
+- (void)addFixed32:(uint32_t)value;
+/**
+ * Add a value to the fixed64List.
+ *
+ * @param value The value to add.
+ **/
+- (void)addFixed64:(uint64_t)value;
+/**
+ * Add a value to the lengthDelimitedList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addLengthDelimited:(NSData *)value;
+/**
+ * Add a value to the groupList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addGroup:(GPBUnknownFieldSet *)value;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBUnknownField.m b/third_party/protobuf/objectivec/GPBUnknownField.m
new file mode 100644
index 0000000000..30efe7563b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField.m
@@ -0,0 +1,334 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUnknownField_PackagePrivate.h"
+
+#import "GPBArray.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+
+@implementation GPBUnknownField {
+ @protected
+ int32_t number_;
+ GPBUInt64Array *mutableVarintList_;
+ GPBUInt32Array *mutableFixed32List_;
+ GPBUInt64Array *mutableFixed64List_;
+ NSMutableArray<NSData*> *mutableLengthDelimitedList_;
+ NSMutableArray<GPBUnknownFieldSet*> *mutableGroupList_;
+}
+
+@synthesize number = number_;
+@synthesize varintList = mutableVarintList_;
+@synthesize fixed32List = mutableFixed32List_;
+@synthesize fixed64List = mutableFixed64List_;
+@synthesize lengthDelimitedList = mutableLengthDelimitedList_;
+@synthesize groupList = mutableGroupList_;
+
+- (instancetype)initWithNumber:(int32_t)number {
+ if ((self = [super init])) {
+ number_ = number;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [mutableVarintList_ release];
+ [mutableFixed32List_ release];
+ [mutableFixed64List_ release];
+ [mutableLengthDelimitedList_ release];
+ [mutableGroupList_ release];
+
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBUnknownField *result =
+ [[GPBUnknownField allocWithZone:zone] initWithNumber:number_];
+ result->mutableFixed32List_ = [mutableFixed32List_ copyWithZone:zone];
+ result->mutableFixed64List_ = [mutableFixed64List_ copyWithZone:zone];
+ result->mutableLengthDelimitedList_ =
+ [mutableLengthDelimitedList_ copyWithZone:zone];
+ result->mutableVarintList_ = [mutableVarintList_ copyWithZone:zone];
+ if (mutableGroupList_.count) {
+ result->mutableGroupList_ = [[NSMutableArray allocWithZone:zone]
+ initWithCapacity:mutableGroupList_.count];
+ for (GPBUnknownFieldSet *group in mutableGroupList_) {
+ GPBUnknownFieldSet *copied = [group copyWithZone:zone];
+ [result->mutableGroupList_ addObject:copied];
+ [copied release];
+ }
+ }
+ return result;
+}
+
+- (BOOL)isEqual:(id)object {
+ if (self == object) return YES;
+ if (![object isKindOfClass:[GPBUnknownField class]]) return NO;
+ GPBUnknownField *field = (GPBUnknownField *)object;
+ BOOL equalVarint =
+ (mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) ||
+ [mutableVarintList_ isEqual:field->mutableVarintList_];
+ if (!equalVarint) return NO;
+ BOOL equalFixed32 = (mutableFixed32List_.count == 0 &&
+ field->mutableFixed32List_.count == 0) ||
+ [mutableFixed32List_ isEqual:field->mutableFixed32List_];
+ if (!equalFixed32) return NO;
+ BOOL equalFixed64 = (mutableFixed64List_.count == 0 &&
+ field->mutableFixed64List_.count == 0) ||
+ [mutableFixed64List_ isEqual:field->mutableFixed64List_];
+ if (!equalFixed64) return NO;
+ BOOL equalLDList =
+ (mutableLengthDelimitedList_.count == 0 &&
+ field->mutableLengthDelimitedList_.count == 0) ||
+ [mutableLengthDelimitedList_ isEqual:field->mutableLengthDelimitedList_];
+ if (!equalLDList) return NO;
+ BOOL equalGroupList =
+ (mutableGroupList_.count == 0 && field->mutableGroupList_.count == 0) ||
+ [mutableGroupList_ isEqual:field->mutableGroupList_];
+ if (!equalGroupList) return NO;
+ return YES;
+}
+
+- (NSUInteger)hash {
+ // Just mix the hashes of the possible sub arrays.
+ const int prime = 31;
+ NSUInteger result = prime + [mutableVarintList_ hash];
+ result = prime * result + [mutableFixed32List_ hash];
+ result = prime * result + [mutableFixed64List_ hash];
+ result = prime * result + [mutableLengthDelimitedList_ hash];
+ result = prime * result + [mutableGroupList_ hash];
+ return result;
+}
+
+- (void)writeToOutput:(GPBCodedOutputStream *)output {
+ NSUInteger count = mutableVarintList_.count;
+ if (count > 0) {
+ [output writeUInt64Array:number_ values:mutableVarintList_ tag:0];
+ }
+ count = mutableFixed32List_.count;
+ if (count > 0) {
+ [output writeFixed32Array:number_ values:mutableFixed32List_ tag:0];
+ }
+ count = mutableFixed64List_.count;
+ if (count > 0) {
+ [output writeFixed64Array:number_ values:mutableFixed64List_ tag:0];
+ }
+ count = mutableLengthDelimitedList_.count;
+ if (count > 0) {
+ [output writeBytesArray:number_ values:mutableLengthDelimitedList_];
+ }
+ count = mutableGroupList_.count;
+ if (count > 0) {
+ [output writeUnknownGroupArray:number_ values:mutableGroupList_];
+ }
+}
+
+- (size_t)serializedSize {
+ __block size_t result = 0;
+ int32_t number = number_;
+ [mutableVarintList_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeUInt64Size(number, value);
+ }];
+
+ [mutableFixed32List_
+ enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeFixed32Size(number, value);
+ }];
+
+ [mutableFixed64List_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeFixed64Size(number, value);
+ }];
+
+ for (NSData *data in mutableLengthDelimitedList_) {
+ result += GPBComputeBytesSize(number, data);
+ }
+
+ for (GPBUnknownFieldSet *set in mutableGroupList_) {
+ result += GPBComputeUnknownGroupSize(number, set);
+ }
+
+ return result;
+}
+
+- (void)writeAsMessageSetExtensionToOutput:(GPBCodedOutputStream *)output {
+ for (NSData *data in mutableLengthDelimitedList_) {
+ [output writeRawMessageSetExtension:number_ value:data];
+ }
+}
+
+- (size_t)serializedSizeAsMessageSetExtension {
+ size_t result = 0;
+ for (NSData *data in mutableLengthDelimitedList_) {
+ result += GPBComputeRawMessageSetExtensionSize(number_, data);
+ }
+ return result;
+}
+
+- (NSString *)description {
+ NSMutableString *description = [NSMutableString
+ stringWithFormat:@"<%@ %p>: Field: %d {\n", [self class], self, number_];
+ [mutableVarintList_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%llu\n", value];
+ }];
+
+ [mutableFixed32List_
+ enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%u\n", value];
+ }];
+
+ [mutableFixed64List_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%llu\n", value];
+ }];
+
+ for (NSData *data in mutableLengthDelimitedList_) {
+ [description appendFormat:@"\t%@\n", data];
+ }
+
+ for (GPBUnknownFieldSet *set in mutableGroupList_) {
+ [description appendFormat:@"\t%@\n", set];
+ }
+ [description appendString:@"}"];
+ return description;
+}
+
+- (void)mergeFromField:(GPBUnknownField *)other {
+ GPBUInt64Array *otherVarintList = other.varintList;
+ if (otherVarintList.count > 0) {
+ if (mutableVarintList_ == nil) {
+ mutableVarintList_ = [otherVarintList copy];
+ } else {
+ [mutableVarintList_ addValuesFromArray:otherVarintList];
+ }
+ }
+
+ GPBUInt32Array *otherFixed32List = other.fixed32List;
+ if (otherFixed32List.count > 0) {
+ if (mutableFixed32List_ == nil) {
+ mutableFixed32List_ = [otherFixed32List copy];
+ } else {
+ [mutableFixed32List_ addValuesFromArray:otherFixed32List];
+ }
+ }
+
+ GPBUInt64Array *otherFixed64List = other.fixed64List;
+ if (otherFixed64List.count > 0) {
+ if (mutableFixed64List_ == nil) {
+ mutableFixed64List_ = [otherFixed64List copy];
+ } else {
+ [mutableFixed64List_ addValuesFromArray:otherFixed64List];
+ }
+ }
+
+ NSArray *otherLengthDelimitedList = other.lengthDelimitedList;
+ if (otherLengthDelimitedList.count > 0) {
+ if (mutableLengthDelimitedList_ == nil) {
+ mutableLengthDelimitedList_ = [otherLengthDelimitedList mutableCopy];
+ } else {
+ [mutableLengthDelimitedList_
+ addObjectsFromArray:otherLengthDelimitedList];
+ }
+ }
+
+ NSArray *otherGroupList = other.groupList;
+ if (otherGroupList.count > 0) {
+ if (mutableGroupList_ == nil) {
+ mutableGroupList_ =
+ [[NSMutableArray alloc] initWithCapacity:otherGroupList.count];
+ }
+ // Make our own mutable copies.
+ for (GPBUnknownFieldSet *group in otherGroupList) {
+ GPBUnknownFieldSet *copied = [group copy];
+ [mutableGroupList_ addObject:copied];
+ [copied release];
+ }
+ }
+}
+
+- (void)addVarint:(uint64_t)value {
+ if (mutableVarintList_ == nil) {
+ mutableVarintList_ = [[GPBUInt64Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableVarintList_ addValue:value];
+ }
+}
+
+- (void)addFixed32:(uint32_t)value {
+ if (mutableFixed32List_ == nil) {
+ mutableFixed32List_ =
+ [[GPBUInt32Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableFixed32List_ addValue:value];
+ }
+}
+
+- (void)addFixed64:(uint64_t)value {
+ if (mutableFixed64List_ == nil) {
+ mutableFixed64List_ =
+ [[GPBUInt64Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableFixed64List_ addValue:value];
+ }
+}
+
+- (void)addLengthDelimited:(NSData *)value {
+ if (mutableLengthDelimitedList_ == nil) {
+ mutableLengthDelimitedList_ =
+ [[NSMutableArray alloc] initWithObjects:&value count:1];
+ } else {
+ [mutableLengthDelimitedList_ addObject:value];
+ }
+}
+
+- (void)addGroup:(GPBUnknownFieldSet *)value {
+ if (mutableGroupList_ == nil) {
+ mutableGroupList_ = [[NSMutableArray alloc] initWithObjects:&value count:1];
+ } else {
+ [mutableGroupList_ addObject:value];
+ }
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet.h b/third_party/protobuf/objectivec/GPBUnknownFieldSet.h
new file mode 100644
index 0000000000..1b5f24f392
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet.h
@@ -0,0 +1,82 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBUnknownField;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * A collection of unknown fields. Fields parsed from the binary representation
+ * of a message that are unknown end up in an instance of this set. This only
+ * applies for files declared with the "proto2" syntax. Files declared with the
+ * "proto3" syntax discard the unknown values.
+ **/
+@interface GPBUnknownFieldSet : NSObject<NSCopying>
+
+/**
+ * Tests to see if the given field number has a value.
+ *
+ * @param number The field number to check.
+ *
+ * @return YES if there is an unknown field for the given field number.
+ **/
+- (BOOL)hasField:(int32_t)number;
+
+/**
+ * Fetches the GPBUnknownField for the given field number.
+ *
+ * @param number The field number to look up.
+ *
+ * @return The GPBUnknownField or nil if none found.
+ **/
+- (nullable GPBUnknownField *)getField:(int32_t)number;
+
+/**
+ * @return The number of fields in this set.
+ **/
+- (NSUInteger)countOfFields;
+
+/**
+ * Adds the given field to the set.
+ *
+ * @param field The field to add to the set.
+ **/
+- (void)addField:(GPBUnknownField *)field;
+
+/**
+ * @return An array of the GPBUnknownFields sorted by the field numbers.
+ **/
+- (NSArray<GPBUnknownField *> *)sortedFields;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet.m b/third_party/protobuf/objectivec/GPBUnknownFieldSet.m
new file mode 100644
index 0000000000..a7335f050b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet.m
@@ -0,0 +1,395 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUtilities.h"
+#import "GPBWireFormat.h"
+
+#pragma mark Helpers
+
+static void checkNumber(int32_t number) {
+ if (number == 0) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Zero is not a valid field number."];
+ }
+}
+
+@implementation GPBUnknownFieldSet {
+ @package
+ CFMutableDictionaryRef fields_;
+}
+
+static void CopyWorker(const void *key, const void *value, void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBUnknownFieldSet *result = context;
+
+ GPBUnknownField *copied = [field copy];
+ [result addField:copied];
+ [copied release];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBUnknownFieldSet *result = [[GPBUnknownFieldSet allocWithZone:zone] init];
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, CopyWorker, result);
+ }
+ return result;
+}
+
+- (void)dealloc {
+ if (fields_) {
+ CFRelease(fields_);
+ }
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)object {
+ BOOL equal = NO;
+ if ([object isKindOfClass:[GPBUnknownFieldSet class]]) {
+ GPBUnknownFieldSet *set = (GPBUnknownFieldSet *)object;
+ if ((fields_ == NULL) && (set->fields_ == NULL)) {
+ equal = YES;
+ } else if ((fields_ != NULL) && (set->fields_ != NULL)) {
+ equal = CFEqual(fields_, set->fields_);
+ }
+ }
+ return equal;
+}
+
+- (NSUInteger)hash {
+ // Return the hash of the fields dictionary (or just some value).
+ if (fields_) {
+ return CFHash(fields_);
+ }
+ return (NSUInteger)[GPBUnknownFieldSet class];
+}
+
+#pragma mark - Public Methods
+
+- (BOOL)hasField:(int32_t)number {
+ ssize_t key = number;
+ return fields_ ? (CFDictionaryGetValue(fields_, (void *)key) != nil) : NO;
+}
+
+- (GPBUnknownField *)getField:(int32_t)number {
+ ssize_t key = number;
+ GPBUnknownField *result =
+ fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
+ return result;
+}
+
+- (NSUInteger)countOfFields {
+ return fields_ ? CFDictionaryGetCount(fields_) : 0;
+}
+
+- (NSArray *)sortedFields {
+ if (!fields_) return [NSArray array];
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ GPBUnknownField *values[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
+ (const void **)values);
+ struct GPBFieldPair {
+ ssize_t key;
+ GPBUnknownField *value;
+ } pairs[count];
+ for (size_t i = 0; i < count; ++i) {
+ pairs[i].key = keys[i];
+ pairs[i].value = values[i];
+ };
+ qsort_b(pairs, count, sizeof(struct GPBFieldPair),
+ ^(const void *first, const void *second) {
+ const struct GPBFieldPair *a = first;
+ const struct GPBFieldPair *b = second;
+ return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1);
+ });
+ for (size_t i = 0; i < count; ++i) {
+ values[i] = pairs[i].value;
+ };
+ return [NSArray arrayWithObjects:values count:count];
+}
+
+#pragma mark - Internal Methods
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output {
+ if (!fields_) return;
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ GPBUnknownField *values[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
+ (const void **)values);
+ if (count > 1) {
+ struct GPBFieldPair {
+ ssize_t key;
+ GPBUnknownField *value;
+ } pairs[count];
+
+ for (size_t i = 0; i < count; ++i) {
+ pairs[i].key = keys[i];
+ pairs[i].value = values[i];
+ };
+ qsort_b(pairs, count, sizeof(struct GPBFieldPair),
+ ^(const void *first, const void *second) {
+ const struct GPBFieldPair *a = first;
+ const struct GPBFieldPair *b = second;
+ return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1);
+ });
+ for (size_t i = 0; i < count; ++i) {
+ GPBUnknownField *value = pairs[i].value;
+ [value writeToOutput:output];
+ }
+ } else {
+ [values[0] writeToOutput:output];
+ }
+}
+
+- (NSString *)description {
+ NSMutableString *description = [NSMutableString
+ stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self];
+ NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" ");
+ [description appendString:textFormat];
+ [description appendString:@"}"];
+ return description;
+}
+
+static void GPBUnknownFieldSetSerializedSize(const void *key, const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ size_t *result = context;
+ *result += [field serializedSize];
+}
+
+- (size_t)serializedSize {
+ size_t result = 0;
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize,
+ &result);
+ }
+ return result;
+}
+
+static void GPBUnknownFieldSetWriteAsMessageSetTo(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBCodedOutputStream *output = context;
+ [field writeAsMessageSetExtensionToOutput:output];
+}
+
+- (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output {
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo,
+ output);
+ }
+}
+
+static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ size_t *result = context;
+ *result += [field serializedSizeAsMessageSetExtension];
+}
+
+- (size_t)serializedSizeAsMessageSet {
+ size_t result = 0;
+ if (fields_) {
+ CFDictionaryApplyFunction(
+ fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result);
+ }
+ return result;
+}
+
+- (NSData *)data {
+ NSMutableData *data = [NSMutableData dataWithLength:self.serializedSize];
+ GPBCodedOutputStream *output =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ [self writeToCodedOutputStream:output];
+ [output release];
+ return data;
+}
+
++ (BOOL)isFieldTag:(int32_t)tag {
+ return GPBWireFormatGetTagWireType(tag) != GPBWireFormatEndGroup;
+}
+
+- (void)addField:(GPBUnknownField *)field {
+ int32_t number = [field number];
+ checkNumber(number);
+ if (!fields_) {
+ // Use a custom dictionary here because the keys are numbers and conversion
+ // back and forth from NSNumber isn't worth the cost.
+ fields_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL,
+ &kCFTypeDictionaryValueCallBacks);
+ }
+ ssize_t key = number;
+ CFDictionarySetValue(fields_, (const void *)key, field);
+}
+
+- (GPBUnknownField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create {
+ ssize_t key = number;
+ GPBUnknownField *existing =
+ fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil;
+ if (!existing && create) {
+ existing = [[GPBUnknownField alloc] initWithNumber:number];
+ // This retains existing.
+ [self addField:existing];
+ [existing release];
+ }
+ return existing;
+}
+
+static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBUnknownFieldSet *self = context;
+
+ int32_t number = [field number];
+ checkNumber(number);
+ GPBUnknownField *oldField = [self mutableFieldForNumber:number create:NO];
+ if (oldField) {
+ [oldField mergeFromField:field];
+ } else {
+ // Merge only comes from GPBMessage's mergeFrom:, so it means we are on
+ // mutable message and are an mutable instance, so make sure we need
+ // mutable fields.
+ GPBUnknownField *fieldCopy = [field copy];
+ [self addField:fieldCopy];
+ [fieldCopy release];
+ }
+}
+
+- (void)mergeUnknownFields:(GPBUnknownFieldSet *)other {
+ if (other && other->fields_) {
+ CFDictionaryApplyFunction(other->fields_,
+ GPBUnknownFieldSetMergeUnknownFields, self);
+ }
+}
+
+- (void)mergeFromData:(NSData *)data {
+ GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
+ [self mergeFromCodedInputStream:input];
+ [input checkLastTagWas:0];
+ [input release];
+}
+
+- (void)mergeVarintField:(int32_t)number value:(int32_t)value {
+ checkNumber(number);
+ [[self mutableFieldForNumber:number create:YES] addVarint:value];
+}
+
+- (BOOL)mergeFieldFrom:(int32_t)tag input:(GPBCodedInputStream *)input {
+ NSAssert(GPBWireFormatIsValidTag(tag), @"Got passed an invalid tag");
+ int32_t number = GPBWireFormatGetTagFieldNumber(tag);
+ GPBCodedInputStreamState *state = &input->state_;
+ switch (GPBWireFormatGetTagWireType(tag)) {
+ case GPBWireFormatVarint: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addVarint:GPBCodedInputStreamReadInt64(state)];
+ return YES;
+ }
+ case GPBWireFormatFixed64: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addFixed64:GPBCodedInputStreamReadFixed64(state)];
+ return YES;
+ }
+ case GPBWireFormatLengthDelimited: {
+ NSData *data = GPBCodedInputStreamReadRetainedBytes(state);
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addLengthDelimited:data];
+ [data release];
+ return YES;
+ }
+ case GPBWireFormatStartGroup: {
+ GPBUnknownFieldSet *unknownFieldSet = [[GPBUnknownFieldSet alloc] init];
+ [input readUnknownGroup:number message:unknownFieldSet];
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addGroup:unknownFieldSet];
+ [unknownFieldSet release];
+ return YES;
+ }
+ case GPBWireFormatEndGroup:
+ return NO;
+ case GPBWireFormatFixed32: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addFixed32:GPBCodedInputStreamReadFixed32(state)];
+ return YES;
+ }
+ }
+}
+
+- (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData {
+ [[self mutableFieldForNumber:number create:YES]
+ addLengthDelimited:messageData];
+}
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
+ GPBUnknownField *field = [self mutableFieldForNumber:fieldNum create:YES];
+ [field addLengthDelimited:data];
+}
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input {
+ while (YES) {
+ int32_t tag = GPBCodedInputStreamReadTag(&input->state_);
+ if (tag == 0 || ![self mergeFieldFrom:tag input:input]) {
+ break;
+ }
+ }
+}
+
+- (void)getTags:(int32_t *)tags {
+ if (!fields_) return;
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys, NULL);
+ for (size_t i = 0; i < count; ++i) {
+ tags[i] = (int32_t)keys[i];
+ }
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h
new file mode 100644
index 0000000000..e27127ad1d
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h
@@ -0,0 +1,61 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUnknownFieldSet.h"
+
+@class GPBCodedOutputStream;
+@class GPBCodedInputStream;
+
+@interface GPBUnknownFieldSet ()
+
++ (BOOL)isFieldTag:(int32_t)tag;
+
+- (NSData *)data;
+
+- (size_t)serializedSize;
+- (size_t)serializedSizeAsMessageSet;
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
+- (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output;
+
+- (void)mergeUnknownFields:(GPBUnknownFieldSet *)other;
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input;
+- (void)mergeFromData:(NSData *)data;
+
+- (void)mergeVarintField:(int32_t)number value:(int32_t)value;
+- (BOOL)mergeFieldFrom:(int32_t)tag input:(GPBCodedInputStream *)input;
+- (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData;
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h
new file mode 100644
index 0000000000..1fbce0f954
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUnknownField.h"
+
+@class GPBCodedOutputStream;
+
+@interface GPBUnknownField ()
+
+- (instancetype)initWithNumber:(int32_t)number;
+
+- (void)writeToOutput:(GPBCodedOutputStream *)output;
+- (size_t)serializedSize;
+
+- (void)writeAsMessageSetExtensionToOutput:(GPBCodedOutputStream *)output;
+- (size_t)serializedSizeAsMessageSetExtension;
+
+- (void)mergeFromField:(GPBUnknownField *)other;
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUtilities.h b/third_party/protobuf/objectivec/GPBUtilities.h
new file mode 100644
index 0000000000..5464dfb356
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities.h
@@ -0,0 +1,539 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBArray.h"
+#import "GPBMessage.h"
+#import "GPBRuntimeTypes.h"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Generates a string that should be a valid "TextFormat" for the C++ version
+ * of Protocol Buffers.
+ *
+ * @param message The message to generate from.
+ * @param lineIndent A string to use as the prefix for all lines generated. Can
+ * be nil if no extra indent is needed.
+ *
+ * @return An NSString with the TextFormat of the message.
+ **/
+NSString *GPBTextFormatForMessage(GPBMessage *message,
+ NSString * __nullable lineIndent);
+
+/**
+ * Generates a string that should be a valid "TextFormat" for the C++ version
+ * of Protocol Buffers.
+ *
+ * @param unknownSet The unknown field set to generate from.
+ * @param lineIndent A string to use as the prefix for all lines generated. Can
+ * be nil if no extra indent is needed.
+ *
+ * @return An NSString with the TextFormat of the unknown field set.
+ **/
+NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
+ NSString * __nullable lineIndent);
+
+/**
+ * Checks if the given field number is set on a message.
+ *
+ * @param self The message to check.
+ * @param fieldNumber The field number to check.
+ *
+ * @return YES if the field number is set on the given message.
+ **/
+BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
+
+/**
+ * Checks if the given field is set on a message.
+ *
+ * @param self The message to check.
+ * @param field The field to check.
+ *
+ * @return YES if the field is set on the given message.
+ **/
+BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Clears the given field for the given message.
+ *
+ * @param self The message for which to clear the field.
+ * @param field The field to clear.
+ **/
+void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
+
+//%PDDM-EXPAND GPB_ACCESSORS()
+// This block of code is generated, do not edit it directly.
+
+
+//
+// Get/Set a given field from/to a message.
+//
+
+// Single Fields
+
+/**
+ * Gets the value of a bytes field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a bytes field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
+
+/**
+ * Gets the value of a string field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a string field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
+
+/**
+ * Gets the value of a message field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a message field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
+
+/**
+ * Gets the value of a group field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a group field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
+
+/**
+ * Gets the value of a bool field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a bool field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
+
+/**
+ * Gets the value of an int32 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an int32 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
+
+/**
+ * Gets the value of an uint32 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an uint32 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
+
+/**
+ * Gets the value of an int64 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an int64 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
+
+/**
+ * Gets the value of an uint64 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an uint64 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
+
+/**
+ * Gets the value of a float field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a float field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
+
+/**
+ * Gets the value of a double field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a double field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
+
+/**
+ * Gets the given enum field of a message. For proto3, if the value isn't a
+ * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
+ * GPBGetMessageRawEnumField will bypass the check and return whatever value
+ * was set.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ *
+ * @return The enum value for the given field.
+ **/
+int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Set the given enum field of a message. You can only set values that are
+ * members of the enum.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The enum value to set in the field.
+ **/
+void GPBSetMessageEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value);
+
+/**
+ * Get the given enum field of a message. No check is done to ensure the value
+ * was defined in the enum.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ *
+ * @return The raw enum value for the given field.
+ **/
+int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Set the given enum field of a message. You can set the value to anything,
+ * even a value that is not a member of the enum.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The raw enum value to set in the field.
+ **/
+void GPBSetMessageRawEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value);
+
+// Repeated Fields
+
+/**
+ * Gets the value of a repeated field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The repeated field to get.
+ *
+ * @return A GPB*Array or an NSMutableArray based on the field's type.
+ **/
+id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a repeated field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param array A GPB*Array or NSMutableArray based on the field's type.
+ **/
+void GPBSetMessageRepeatedField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id array);
+
+// Map Fields
+
+/**
+ * Gets the value of a map<> field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The repeated field to get.
+ *
+ * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
+ **/
+id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a map<> field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
+ * field's type.
+ **/
+void GPBSetMessageMapField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id dictionary);
+
+//%PDDM-EXPAND-END GPB_ACCESSORS()
+
+/**
+ * Returns an empty NSData to assign to byte fields when you wish to assign them
+ * to empty. Prevents allocating a lot of little [NSData data] objects.
+ **/
+NSData *GPBEmptyNSData(void) __attribute__((pure));
+
+/**
+ * Drops the `unknownFields` from the given message and from all sub message.
+ **/
+void GPBMessageDropUnknownFieldsRecursively(GPBMessage *message);
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+
+//%PDDM-DEFINE GPB_ACCESSORS()
+//%
+//%//
+//%// Get/Set a given field from/to a message.
+//%//
+//%
+//%// Single Fields
+//%
+//%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
+//%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
+//%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
+//%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
+//%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
+//%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
+//%GPB_ACCESSOR_SINGLE(Float, float, )
+//%GPB_ACCESSOR_SINGLE(Double, double, )
+//%/**
+//% * Gets the given enum field of a message. For proto3, if the value isn't a
+//% * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
+//% * GPBGetMessageRawEnumField will bypass the check and return whatever value
+//% * was set.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% *
+//% * @return The enum value for the given field.
+//% **/
+//%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Set the given enum field of a message. You can only set values that are
+//% * members of the enum.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The enum value to set in the field.
+//% **/
+//%void GPBSetMessageEnumField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% int32_t value);
+//%
+//%/**
+//% * Get the given enum field of a message. No check is done to ensure the value
+//% * was defined in the enum.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% *
+//% * @return The raw enum value for the given field.
+//% **/
+//%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Set the given enum field of a message. You can set the value to anything,
+//% * even a value that is not a member of the enum.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The raw enum value to set in the field.
+//% **/
+//%void GPBSetMessageRawEnumField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% int32_t value);
+//%
+//%// Repeated Fields
+//%
+//%/**
+//% * Gets the value of a repeated field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The repeated field to get.
+//% *
+//% * @return A GPB*Array or an NSMutableArray based on the field's type.
+//% **/
+//%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a repeated field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param array A GPB*Array or NSMutableArray based on the field's type.
+//% **/
+//%void GPBSetMessageRepeatedField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% id array);
+//%
+//%// Map Fields
+//%
+//%/**
+//% * Gets the value of a map<> field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The repeated field to get.
+//% *
+//% * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
+//% **/
+//%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a map<> field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
+//% * field's type.
+//% **/
+//%void GPBSetMessageMapField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% id dictionary);
+//%
+
+//%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
+//%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
+//%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
+//%/**
+//% * Gets the value of a##AN NAME$L field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% **/
+//%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a##AN NAME$L field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The to set in the field.
+//% **/
+//%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
+//%
diff --git a/third_party/protobuf/objectivec/GPBUtilities.m b/third_party/protobuf/objectivec/GPBUtilities.m
new file mode 100644
index 0000000000..5029ec73b3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities.m
@@ -0,0 +1,1923 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUtilities_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField.h"
+#import "GPBUnknownFieldSet.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+static void AppendTextFormatForMessage(GPBMessage *message,
+ NSMutableString *toStr,
+ NSString *lineIndent);
+
+NSData *GPBEmptyNSData(void) {
+ static dispatch_once_t onceToken;
+ static NSData *defaultNSData = nil;
+ dispatch_once(&onceToken, ^{
+ defaultNSData = [[NSData alloc] init];
+ });
+ return defaultNSData;
+}
+
+void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) {
+ if (!initialMessage) {
+ return;
+ }
+
+ // Use an array as a list to process to avoid recursion.
+ NSMutableArray *todo = [NSMutableArray arrayWithObject:initialMessage];
+
+ while (todo.count) {
+ GPBMessage *msg = todo.lastObject;
+ [todo removeLastObject];
+
+ // Clear unknowns.
+ msg.unknownFields = nil;
+
+ // Handle the message fields.
+ GPBDescriptor *descriptor = [[msg class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (!GPBFieldDataTypeIsMessage(field)) {
+ continue;
+ }
+ switch (field.fieldType) {
+ case GPBFieldTypeSingle:
+ if (GPBGetHasIvarField(msg, field)) {
+ GPBMessage *fieldMessage = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ [todo addObject:fieldMessage];
+ }
+ break;
+
+ case GPBFieldTypeRepeated: {
+ NSArray *fieldMessages = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ if (fieldMessages.count) {
+ [todo addObjectsFromArray:fieldMessages];
+ }
+ break;
+ }
+
+ case GPBFieldTypeMap: {
+ id rawFieldMap = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ switch (field.mapKeyDataType) {
+ case GPBDataTypeBool:
+ [(GPBBoolObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ BOOL key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ [(GPBUInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ uint32_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ [(GPBInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ int32_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ [(GPBUInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ uint64_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ [(GPBInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ int64_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeString:
+ [(NSDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ NSString * _Nonnull key, GPBMessage * _Nonnull obj, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:obj];
+ }];
+ break;
+ case GPBDataTypeFloat:
+ case GPBDataTypeDouble:
+ case GPBDataTypeEnum:
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ NSCAssert(NO, @"Aren't valid key types.");
+ }
+ break;
+ } // switch(field.mapKeyDataType)
+ } // switch(field.fieldType)
+ } // for(fields)
+
+ // Handle any extensions holding messages.
+ for (GPBExtensionDescriptor *extension in [msg extensionsCurrentlySet]) {
+ if (!GPBDataTypeIsMessage(extension.dataType)) {
+ continue;
+ }
+ if (extension.isRepeated) {
+ NSArray *extMessages = [msg getExtension:extension];
+ [todo addObjectsFromArray:extMessages];
+ } else {
+ GPBMessage *extMessage = [msg getExtension:extension];
+ [todo addObject:extMessage];
+ }
+ } // for(extensionsCurrentlySet)
+
+ } // while(todo.count)
+}
+
+
+// -- About Version Checks --
+// There's actually 3 places these checks all come into play:
+// 1. When the generated source is compile into .o files, the header check
+// happens. This is checking the protoc used matches the library being used
+// when making the .o.
+// 2. Every place a generated proto header is included in a developer's code,
+// the header check comes into play again. But this time it is checking that
+// the current library headers being used still support/match the ones for
+// the generated code.
+// 3. At runtime the final check here (GPBCheckRuntimeVersionsInternal), is
+// called from the generated code passing in values captured when the
+// generated code's .o was made. This checks that at runtime the generated
+// code and runtime library match.
+
+void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
+ // NOTE: This is passing the value captured in the compiled code to check
+ // against the values captured when the runtime support was compiled. This
+ // ensures the library code isn't in a different framework/library that
+ // was generated with a non matching version.
+ if (GOOGLE_PROTOBUF_OBJC_VERSION < objcRuntimeVersion) {
+ // Library is too old for headers.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Linked to ProtocolBuffer runtime version %d,"
+ @" but code compiled needing atleast %d!",
+ GOOGLE_PROTOBUF_OBJC_VERSION, objcRuntimeVersion];
+ }
+ if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
+ // Headers are too old for library.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Proto generation source compiled against runtime"
+ @" version %d, but this version of the runtime only"
+ @" supports back to %d!",
+ objcRuntimeVersion,
+ GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
+ }
+}
+
+// This api is no longer used for version checks. 30001 is the last version
+// using this old versioning model. When that support is removed, this function
+// can be removed (along with the declaration in GPBUtilities_PackagePrivate.h).
+void GPBCheckRuntimeVersionInternal(int32_t version) {
+ GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION == 30001,
+ time_to_remove_this_old_version_shim);
+ if (version != GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Linked to ProtocolBuffer runtime version %d,"
+ @" but code compiled with version %d!",
+ GOOGLE_PROTOBUF_OBJC_GEN_VERSION, version];
+ }
+}
+
+BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber];
+ return GPBMessageHasFieldSet(self, field);
+}
+
+BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field) {
+ if (self == nil || field == nil) return NO;
+
+ // Repeated/Map don't use the bit, they check the count.
+ if (GPBFieldIsMapOrArray(field)) {
+ // Array/map type doesn't matter, since GPB*Array/NSArray and
+ // GPB*Dictionary/NSDictionary all support -count;
+ NSArray *arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ return (arrayOrMap.count > 0);
+ } else {
+ return GPBGetHasIvarField(self, field);
+ }
+}
+
+void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field) {
+ // If not set, nothing to do.
+ if (!GPBGetHasIvarField(self, field)) {
+ return;
+ }
+
+ if (GPBFieldStoresObject(field)) {
+ // Object types are handled slightly differently, they need to be released.
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ [*typePtr release];
+ *typePtr = nil;
+ } else {
+ // POD types just need to clear the has bit as the Get* method will
+ // fetch the default when needed.
+ }
+ GPBSetHasIvarField(self, field, NO);
+}
+
+BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) {
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+ if (idx < 0) {
+ NSCAssert(fieldNumber != 0, @"Invalid field number.");
+ BOOL hasIvar = (self->messageStorage_->_has_storage_[-idx] == fieldNumber);
+ return hasIvar;
+ } else {
+ NSCAssert(idx != GPBNoHasBit, @"Invalid has bit.");
+ uint32_t byteIndex = idx / 32;
+ uint32_t bitMask = (1 << (idx % 32));
+ BOOL hasIvar =
+ (self->messageStorage_->_has_storage_[byteIndex] & bitMask) ? YES : NO;
+ return hasIvar;
+ }
+}
+
+uint32_t GPBGetHasOneof(GPBMessage *self, int32_t idx) {
+ NSCAssert(idx < 0, @"%@: invalid index (%d) for oneof.",
+ [self class], idx);
+ uint32_t result = self->messageStorage_->_has_storage_[-idx];
+ return result;
+}
+
+void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
+ BOOL value) {
+ if (idx < 0) {
+ NSCAssert(fieldNumber != 0, @"Invalid field number.");
+ uint32_t *has_storage = self->messageStorage_->_has_storage_;
+ has_storage[-idx] = (value ? fieldNumber : 0);
+ } else {
+ NSCAssert(idx != GPBNoHasBit, @"Invalid has bit.");
+ uint32_t *has_storage = self->messageStorage_->_has_storage_;
+ uint32_t byte = idx / 32;
+ uint32_t bitMask = (1 << (idx % 32));
+ if (value) {
+ has_storage[byte] |= bitMask;
+ } else {
+ has_storage[byte] &= ~bitMask;
+ }
+ }
+}
+
+void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
+ int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) {
+ uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex);
+ if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) {
+ // Do nothing/nothing set in the oneof.
+ return;
+ }
+
+ // Like GPBClearMessageField(), free the memory if an objecttype is set,
+ // pod types don't need to do anything.
+ GPBFieldDescriptor *fieldSet = [oneof fieldWithNumber:fieldNumberSet];
+ NSCAssert(fieldSet,
+ @"%@: oneof set to something (%u) not in the oneof?",
+ [self class], fieldNumberSet);
+ if (fieldSet && GPBFieldStoresObject(fieldSet)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[fieldSet->description_->offset];
+ [*typePtr release];
+ *typePtr = nil;
+ }
+
+ // Set to nothing stored in the oneof.
+ // (field number doesn't matter since setting to nothing).
+ GPBSetHasIvar(self, oneofHasIndex, 1, NO);
+}
+
+#pragma mark - IVar accessors
+
+//%PDDM-DEFINE IVAR_POD_ACCESSORS_DEFN(NAME, TYPE)
+//%TYPE GPBGetMessage##NAME##Field(GPBMessage *self,
+//% TYPE$S NAME$S GPBFieldDescriptor *field) {
+//% if (GPBGetHasIvarField(self, field)) {
+//% uint8_t *storage = (uint8_t *)self->messageStorage_;
+//% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
+//% return *typePtr;
+//% } else {
+//% return field.defaultValue.value##NAME;
+//% }
+//%}
+//%
+//%// Only exists for public api, no core code should use this.
+//%void GPBSetMessage##NAME##Field(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value) {
+//% if (self == nil || field == nil) return;
+//% GPBFileSyntax syntax = [self descriptor].file.syntax;
+//% GPBSet##NAME##IvarWithFieldInternal(self, field, value, syntax);
+//%}
+//%
+//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value,
+//% NAME$S GPBFileSyntax syntax) {
+//% GPBOneofDescriptor *oneof = field->containingOneof_;
+//% if (oneof) {
+//% GPBMessageFieldDescription *fieldDesc = field->description_;
+//% GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+//% }
+//% NSCAssert(self->messageStorage_ != NULL,
+//% @"%@: All messages should have storage (from init)",
+//% [self class]);
+//%#if defined(__clang_analyzer__)
+//% if (self->messageStorage_ == NULL) return;
+//%#endif
+//% uint8_t *storage = (uint8_t *)self->messageStorage_;
+//% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
+//% *typePtr = value;
+//% // proto2: any value counts as having been set; proto3, it
+//% // has to be a non zero value or be in a oneof.
+//% BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+//% || (value != (TYPE)0)
+//% || (field->containingOneof_ != NULL));
+//% GPBSetHasIvarField(self, field, hasValue);
+//% GPBBecomeVisibleToAutocreator(self);
+//%}
+//%
+//%PDDM-DEFINE IVAR_ALIAS_DEFN_OBJECT(NAME, TYPE)
+//%// Only exists for public api, no core code should use this.
+//%TYPE *GPBGetMessage##NAME##Field(GPBMessage *self,
+//% TYPE$S NAME$S GPBFieldDescriptor *field) {
+//% return (TYPE *)GPBGetObjectIvarWithField(self, field);
+//%}
+//%
+//%// Only exists for public api, no core code should use this.
+//%void GPBSetMessage##NAME##Field(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE *value) {
+//% GPBSetObjectIvarWithField(self, field, (id)value);
+//%}
+//%
+
+// Object types are handled slightly differently, they need to be released
+// and retained.
+
+void GPBSetAutocreatedRetainedObjectIvarWithField(
+ GPBMessage *self, GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed)) value) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ NSCAssert(*typePtr == NULL, @"Can't set autocreated object more than once.");
+ *typePtr = value;
+}
+
+void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ return;
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ GPBMessage *oldValue = *typePtr;
+ *typePtr = NULL;
+ GPBClearMessageAutocreator(oldValue);
+ [oldValue release];
+}
+
+// This exists only for briging some aliased types, nothing else should use it.
+static void GPBSetObjectIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field, id value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
+ syntax);
+}
+
+void GPBSetObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, id value,
+ GPBFileSyntax syntax) {
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
+ syntax);
+}
+
+void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id value, GPBFileSyntax syntax) {
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ GPBDataType fieldType = GPBGetFieldDataType(field);
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(field);
+ BOOL fieldIsMessage = GPBDataTypeIsMessage(fieldType);
+#ifdef DEBUG
+ if (value == nil && !isMapOrArray && !fieldIsMessage &&
+ field.hasDefaultValue) {
+ // Setting a message to nil is an obvious way to "clear" the value
+ // as there is no way to set a non-empty default value for messages.
+ //
+ // For Strings and Bytes that have default values set it is not clear what
+ // should be done when their value is set to nil. Is the intention just to
+ // clear the set value and reset to default, or is the intention to set the
+ // value to the empty string/data? Arguments can be made for both cases.
+ // 'nil' has been abused as a replacement for an empty string/data in ObjC.
+ // We decided to be consistent with all "object" types and clear the has
+ // field, and fall back on the default value. The warning below will only
+ // appear in debug, but the could should be changed so the intention is
+ // clear.
+ NSString *hasSel = NSStringFromSelector(field->hasOrCountSel_);
+ NSString *propName = field.name;
+ NSString *className = self.descriptor.name;
+ NSLog(@"warning: '%@.%@ = nil;' is not clearly defined for fields with "
+ @"default values. Please use '%@.%@ = %@' if you want to set it to "
+ @"empty, or call '%@.%@ = NO' to reset it to it's default value of "
+ @"'%@'. Defaulting to resetting default value.",
+ className, propName, className, propName,
+ (fieldType == GPBDataTypeString) ? @"@\"\"" : @"GPBEmptyNSData()",
+ className, hasSel, field.defaultValue.valueString);
+ // Note: valueString, depending on the type, it could easily be
+ // valueData/valueMessage.
+ }
+#endif // DEBUG
+ if (!isMapOrArray) {
+ // Non repeated/map can be in an oneof, clear any existing value from the
+ // oneof.
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ // Clear "has" if they are being set to nil.
+ BOOL setHasValue = (value != nil);
+ // Under proto3, Bytes & String fields get cleared by resetting them to
+ // their default (empty) values, so if they are set to something of length
+ // zero, they are being cleared.
+ if ((syntax == GPBFileSyntaxProto3) && !fieldIsMessage &&
+ ([value length] == 0)) {
+ // Except, if the field was in a oneof, then it still gets recorded as
+ // having been set so the state of the oneof can be serialized back out.
+ if (!oneof) {
+ setHasValue = NO;
+ }
+ if (setHasValue) {
+ NSCAssert(value != nil, @"Should never be setting has for nil");
+ } else {
+ // The value passed in was retained, it must be released since we
+ // aren't saving anything in the field.
+ [value release];
+ value = nil;
+ }
+ }
+ GPBSetHasIvarField(self, field, setHasValue);
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+
+ id oldValue = *typePtr;
+
+ *typePtr = value;
+
+ if (oldValue) {
+ if (isMapOrArray) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ // If the old array was autocreated by us, then clear it.
+ if (GPBDataTypeIsObject(fieldType)) {
+ if ([oldValue isKindOfClass:[GPBAutocreatedArray class]]) {
+ GPBAutocreatedArray *autoArray = oldValue;
+ if (autoArray->_autocreator == self) {
+ autoArray->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Array.
+ GPBInt32Array *gpbArray = oldValue;
+ if (gpbArray->_autocreator == self) {
+ gpbArray->_autocreator = nil;
+ }
+ }
+ } else { // GPBFieldTypeMap
+ // If the old map was autocreated by us, then clear it.
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(fieldType)) {
+ if ([oldValue isKindOfClass:[GPBAutocreatedDictionary class]]) {
+ GPBAutocreatedDictionary *autoDict = oldValue;
+ if (autoDict->_autocreator == self) {
+ autoDict->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Dictionary.
+ GPBInt32Int32Dictionary *gpbDict = oldValue;
+ if (gpbDict->_autocreator == self) {
+ gpbDict->_autocreator = nil;
+ }
+ }
+ }
+ } else if (fieldIsMessage) {
+ // If the old message value was autocreated by us, then clear it.
+ GPBMessage *oldMessageValue = oldValue;
+ if (GPBWasMessageAutocreatedBy(oldMessageValue, self)) {
+ GPBClearMessageAutocreator(oldMessageValue);
+ }
+ }
+ [oldValue release];
+ }
+
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (self->messageStorage_ == nil) {
+ return nil;
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ return *typePtr;
+}
+
+id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ NSCAssert(!GPBFieldIsMapOrArray(field), @"Shouldn't get here");
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ return *typePtr;
+ }
+ // Not set...
+
+ // Non messages (string/data), get their default.
+ if (!GPBFieldDataTypeIsMessage(field)) {
+ return field.defaultValue.valueMessage;
+ }
+
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ GPBMessage *result = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!result) {
+ // For non repeated messages, create the object, set it and return it.
+ // This object will not initially be visible via GPBGetHasIvar, so
+ // we save its creator so it can become visible if it's mutated later.
+ result = GPBCreateMessageWithAutocreator(field.msgClass, self, field);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, result);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ return GPBGetEnumIvarWithFieldInternal(self, field, syntax);
+}
+
+int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ int32_t result = GPBGetMessageInt32Field(self, field);
+ // If this is presevering unknown enums, make sure the value is valid before
+ // returning it.
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) &&
+ ![field isValidEnumValue:result]) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field,
+ int32_t value) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, int32_t value,
+ GPBFileSyntax syntax) {
+ // Don't allow in unknown values. Proto3 can use the Raw method.
+ if (![field isValidEnumValue:value]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Attempt to set an unknown enum value (%d)",
+ [self class], field.name, value];
+ }
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+// Only exists for public api, no core code should use this.
+int32_t GPBGetMessageRawEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ int32_t result = GPBGetMessageInt32Field(self, field);
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field,
+ int32_t value) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+BOOL GPBGetMessageBoolField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ // Bools are stored in the has bits to avoid needing explicit space in the
+ // storage structure.
+ // (the field number passed to the HasIvar helper doesn't really matter
+ // since the offset is never negative)
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ return GPBGetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number);
+ } else {
+ return field.defaultValue.valueBool;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageBoolField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetBoolIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value,
+ GPBFileSyntax syntax) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+
+ // Bools are stored in the has bits to avoid needing explicit space in the
+ // storage structure.
+ // (the field number passed to the HasIvar helper doesn't really matter since
+ // the offset is never negative)
+ GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
+
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (BOOL)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+int32_t GPBGetMessageInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueInt32;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (int32_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+uint32_t GPBGetMessageUInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueUInt32;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageUInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetUInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (uint32_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+int64_t GPBGetMessageInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueInt64;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt64IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (int64_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+uint64_t GPBGetMessageUInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueUInt64;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageUInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetUInt64IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (uint64_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Float, float)
+// This block of code is generated, do not edit it directly.
+
+float GPBGetMessageFloatField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ float *typePtr = (float *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueFloat;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageFloatField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetFloatIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ float *typePtr = (float *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (float)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Double, double)
+// This block of code is generated, do not edit it directly.
+
+double GPBGetMessageDoubleField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ double *typePtr = (double *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueDouble;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageDoubleField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetDoubleIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ double *typePtr = (double *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (double)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND-END (6 expansions)
+
+// Aliases are function calls that are virtually the same.
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(String, NSString)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+NSString *GPBGetMessageStringField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (NSString *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageStringField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ NSString *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Bytes, NSData)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+NSData *GPBGetMessageBytesField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (NSData *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageBytesField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ NSData *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Message, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+GPBMessage *GPBGetMessageMessageField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (GPBMessage *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageMessageField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBMessage *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Group, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+GPBMessage *GPBGetMessageGroupField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (GPBMessage *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageGroupField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBMessage *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND-END (4 expansions)
+
+// GPBGetMessageRepeatedField is defined in GPBMessage.m
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeRepeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a repeated field.",
+ [self class], field.name];
+ }
+ Class expectedClass = Nil;
+ switch (GPBGetFieldDataType(field)) {
+ case GPBDataTypeBool:
+ expectedClass = [GPBBoolArray class];
+ break;
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ expectedClass = [GPBInt32Array class];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ expectedClass = [GPBUInt32Array class];
+ break;
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ expectedClass = [GPBInt64Array class];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ expectedClass = [GPBUInt64Array class];
+ break;
+ case GPBDataTypeFloat:
+ expectedClass = [GPBFloatArray class];
+ break;
+ case GPBDataTypeDouble:
+ expectedClass = [GPBDoubleArray class];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ expectedClass = [NSMutableArray class];
+ break;
+ case GPBDataTypeEnum:
+ expectedClass = [GPBEnumArray class];
+ break;
+ }
+ if (array && ![array isKindOfClass:expectedClass]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Expected %@ object, got %@.",
+ [self class], field.name, expectedClass, [array class]];
+ }
+#endif
+ GPBSetObjectIvarWithField(self, field, array);
+}
+
+#if defined(DEBUG) && DEBUG
+static NSString *TypeToStr(GPBDataType dataType) {
+ switch (dataType) {
+ case GPBDataTypeBool:
+ return @"Bool";
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ return @"Int32";
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ return @"UInt32";
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ return @"Int64";
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ return @"UInt64";
+ case GPBDataTypeFloat:
+ return @"Float";
+ case GPBDataTypeDouble:
+ return @"Double";
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return @"Object";
+ case GPBDataTypeEnum:
+ return @"Bool";
+ }
+}
+#endif
+
+// GPBGetMessageMapField is defined in GPBMessage.m
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field,
+ id dictionary) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeMap) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a map<> field.",
+ [self class], field.name];
+ }
+ if (dictionary) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSString *keyStr = TypeToStr(keyDataType);
+ NSString *valueStr = TypeToStr(valueDataType);
+ if (keyDataType == GPBDataTypeString) {
+ keyStr = @"String";
+ }
+ Class expectedClass = Nil;
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ expectedClass = [NSMutableDictionary class];
+ } else {
+ NSString *className =
+ [NSString stringWithFormat:@"GPB%@%@Dictionary", keyStr, valueStr];
+ expectedClass = NSClassFromString(className);
+ NSCAssert(expectedClass, @"Missing a class (%@)?", expectedClass);
+ }
+ if (![dictionary isKindOfClass:expectedClass]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Expected %@ object, got %@.",
+ [self class], field.name, expectedClass,
+ [dictionary class]];
+ }
+ }
+#endif
+ GPBSetObjectIvarWithField(self, field, dictionary);
+}
+
+#pragma mark - Misc Dynamic Runtime Utils
+
+const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel) {
+ Protocol *protocol =
+ objc_getProtocol(GPBStringifySymbol(GPBMessageSignatureProtocol));
+ struct objc_method_description description =
+ protocol_getMethodDescription(protocol, selector, NO, instanceSel);
+ return description.types;
+}
+
+#pragma mark - Text Format Support
+
+static void AppendStringEscaped(NSString *toPrint, NSMutableString *destStr) {
+ [destStr appendString:@"\""];
+ NSUInteger len = [toPrint length];
+ for (NSUInteger i = 0; i < len; ++i) {
+ unichar aChar = [toPrint characterAtIndex:i];
+ switch (aChar) {
+ case '\n': [destStr appendString:@"\\n"]; break;
+ case '\r': [destStr appendString:@"\\r"]; break;
+ case '\t': [destStr appendString:@"\\t"]; break;
+ case '\"': [destStr appendString:@"\\\""]; break;
+ case '\'': [destStr appendString:@"\\\'"]; break;
+ case '\\': [destStr appendString:@"\\\\"]; break;
+ default:
+ // This differs slightly from the C++ code in that the C++ doesn't
+ // generate UTF8; it looks at the string in UTF8, but escapes every
+ // byte > 0x7E.
+ if (aChar < 0x20) {
+ [destStr appendFormat:@"\\%d%d%d",
+ (aChar / 64), ((aChar % 64) / 8), (aChar % 8)];
+ } else {
+ [destStr appendFormat:@"%C", aChar];
+ }
+ break;
+ }
+ }
+ [destStr appendString:@"\""];
+}
+
+static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) {
+ const char *src = (const char *)[buffer bytes];
+ size_t srcLen = [buffer length];
+ [destStr appendString:@"\""];
+ for (const char *srcEnd = src + srcLen; src < srcEnd; src++) {
+ switch (*src) {
+ case '\n': [destStr appendString:@"\\n"]; break;
+ case '\r': [destStr appendString:@"\\r"]; break;
+ case '\t': [destStr appendString:@"\\t"]; break;
+ case '\"': [destStr appendString:@"\\\""]; break;
+ case '\'': [destStr appendString:@"\\\'"]; break;
+ case '\\': [destStr appendString:@"\\\\"]; break;
+ default:
+ if (isprint(*src)) {
+ [destStr appendFormat:@"%c", *src];
+ } else {
+ // NOTE: doing hex means you have to worry about the letter after
+ // the hex being another hex char and forcing that to be escaped, so
+ // use octal to keep it simple.
+ [destStr appendFormat:@"\\%03o", (uint8_t)(*src)];
+ }
+ break;
+ }
+ }
+ [destStr appendString:@"\""];
+}
+
+static void AppendTextFormatForMapMessageField(
+ id map, GPBFieldDescriptor *field, NSMutableString *toStr,
+ NSString *lineIndent, NSString *fieldName, NSString *lineEnding) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ BOOL isMessageValue = GPBDataTypeIsMessage(valueDataType);
+
+ NSString *msgStartFirst =
+ [NSString stringWithFormat:@"%@%@ {%@\n", lineIndent, fieldName, lineEnding];
+ NSString *msgStart =
+ [NSString stringWithFormat:@"%@%@ {\n", lineIndent, fieldName];
+ NSString *msgEnd = [NSString stringWithFormat:@"%@}\n", lineIndent];
+
+ NSString *keyLine = [NSString stringWithFormat:@"%@ key: ", lineIndent];
+ NSString *valueLine = [NSString stringWithFormat:@"%@ value%s ", lineIndent,
+ (isMessageValue ? "" : ":")];
+
+ __block BOOL isFirst = YES;
+
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ // map is an NSDictionary.
+ NSDictionary *dict = map;
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
+ #pragma unused(stop)
+ [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
+ isFirst = NO;
+
+ [toStr appendString:keyLine];
+ AppendStringEscaped(key, toStr);
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:valueLine];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ AppendStringEscaped(value, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString(value, toStr);
+ break;
+
+ case GPBDataTypeMessage:
+ [toStr appendString:@"{\n"];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(value, toStr, subIndent);
+ [toStr appendFormat:@"%@ }", lineIndent];
+ break;
+
+ default:
+ NSCAssert(NO, @"Can't happen");
+ break;
+ }
+#pragma clang diagnostic pop
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:msgEnd];
+ }];
+ } else {
+ // map is one of the GPB*Dictionary classes, type doesn't matter.
+ GPBInt32Int32Dictionary *dict = map;
+ [dict enumerateForTextFormat:^(id keyObj, id valueObj) {
+ [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
+ isFirst = NO;
+
+ // Key always is a NSString.
+ if (keyDataType == GPBDataTypeString) {
+ [toStr appendString:keyLine];
+ AppendStringEscaped(keyObj, toStr);
+ [toStr appendString:@"\n"];
+ } else {
+ [toStr appendFormat:@"%@%@\n", keyLine, keyObj];
+ }
+
+ [toStr appendString:valueLine];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ AppendStringEscaped(valueObj, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString(valueObj, toStr);
+ break;
+
+ case GPBDataTypeMessage:
+ [toStr appendString:@"{\n"];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(valueObj, toStr, subIndent);
+ [toStr appendFormat:@"%@ }", lineIndent];
+ break;
+
+ case GPBDataTypeEnum: {
+ int32_t enumValue = [valueObj intValue];
+ NSString *valueStr = nil;
+ GPBEnumDescriptor *descriptor = field.enumDescriptor;
+ if (descriptor) {
+ valueStr = [descriptor textFormatNameForValue:enumValue];
+ }
+ if (valueStr) {
+ [toStr appendString:valueStr];
+ } else {
+ [toStr appendFormat:@"%d", enumValue];
+ }
+ break;
+ }
+
+ default:
+ NSCAssert(valueDataType != GPBDataTypeGroup, @"Can't happen");
+ // Everything else is a NSString.
+ [toStr appendString:valueObj];
+ break;
+ }
+#pragma clang diagnostic pop
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:msgEnd];
+ }];
+ }
+}
+
+static void AppendTextFormatForMessageField(GPBMessage *message,
+ GPBFieldDescriptor *field,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ id arrayOrMap;
+ NSUInteger count;
+ GPBFieldType fieldType = field.fieldType;
+ switch (fieldType) {
+ case GPBFieldTypeSingle:
+ arrayOrMap = nil;
+ count = (GPBGetHasIvarField(message, field) ? 1 : 0);
+ break;
+
+ case GPBFieldTypeRepeated:
+ // Will be NSArray or GPB*Array, type doesn't matter, they both
+ // implement count.
+ arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(message, field);
+ count = [(NSArray *)arrayOrMap count];
+ break;
+
+ case GPBFieldTypeMap: {
+ // Will be GPB*Dictionary or NSMutableDictionary, type doesn't matter,
+ // they both implement count.
+ arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(message, field);
+ count = [(NSDictionary *)arrayOrMap count];
+ break;
+ }
+ }
+
+ if (count == 0) {
+ // Nothing to print, out of here.
+ return;
+ }
+
+ NSString *lineEnding = @"";
+
+ // If the name can't be reversed or support for extra info was turned off,
+ // this can return nil.
+ NSString *fieldName = [field textFormatName];
+ if ([fieldName length] == 0) {
+ fieldName = [NSString stringWithFormat:@"%u", GPBFieldNumber(field)];
+ // If there is only one entry, put the objc name as a comment, other wise
+ // add it before the repeated values.
+ if (count > 1) {
+ [toStr appendFormat:@"%@# %@\n", lineIndent, field.name];
+ } else {
+ lineEnding = [NSString stringWithFormat:@" # %@", field.name];
+ }
+ }
+
+ if (fieldType == GPBFieldTypeMap) {
+ AppendTextFormatForMapMessageField(arrayOrMap, field, toStr, lineIndent,
+ fieldName, lineEnding);
+ return;
+ }
+
+ id array = arrayOrMap;
+ const BOOL isRepeated = (array != nil);
+
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ BOOL isMessageField = GPBDataTypeIsMessage(fieldDataType);
+ for (NSUInteger j = 0; j < count; ++j) {
+ // Start the line.
+ [toStr appendFormat:@"%@%@%s ", lineIndent, fieldName,
+ (isMessageField ? "" : ":")];
+
+ // The value.
+ switch (fieldDataType) {
+#define FIELD_CASE(GPBDATATYPE, CTYPE, REAL_TYPE, ...) \
+ case GPBDataType##GPBDATATYPE: { \
+ CTYPE v = (isRepeated ? [(GPB##REAL_TYPE##Array *)array valueAtIndex:j] \
+ : GPBGetMessage##REAL_TYPE##Field(message, field)); \
+ [toStr appendFormat:__VA_ARGS__, v]; \
+ break; \
+ }
+
+ FIELD_CASE(Int32, int32_t, Int32, @"%d")
+ FIELD_CASE(SInt32, int32_t, Int32, @"%d")
+ FIELD_CASE(SFixed32, int32_t, Int32, @"%d")
+ FIELD_CASE(UInt32, uint32_t, UInt32, @"%u")
+ FIELD_CASE(Fixed32, uint32_t, UInt32, @"%u")
+ FIELD_CASE(Int64, int64_t, Int64, @"%lld")
+ FIELD_CASE(SInt64, int64_t, Int64, @"%lld")
+ FIELD_CASE(SFixed64, int64_t, Int64, @"%lld")
+ FIELD_CASE(UInt64, uint64_t, UInt64, @"%llu")
+ FIELD_CASE(Fixed64, uint64_t, UInt64, @"%llu")
+ FIELD_CASE(Float, float, Float, @"%.*g", FLT_DIG)
+ FIELD_CASE(Double, double, Double, @"%.*lg", DBL_DIG)
+
+#undef FIELD_CASE
+
+ case GPBDataTypeEnum: {
+ int32_t v = (isRepeated ? [(GPBEnumArray *)array rawValueAtIndex:j]
+ : GPBGetMessageInt32Field(message, field));
+ NSString *valueStr = nil;
+ GPBEnumDescriptor *descriptor = field.enumDescriptor;
+ if (descriptor) {
+ valueStr = [descriptor textFormatNameForValue:v];
+ }
+ if (valueStr) {
+ [toStr appendString:valueStr];
+ } else {
+ [toStr appendFormat:@"%d", v];
+ }
+ break;
+ }
+
+ case GPBDataTypeBool: {
+ BOOL v = (isRepeated ? [(GPBBoolArray *)array valueAtIndex:j]
+ : GPBGetMessageBoolField(message, field));
+ [toStr appendString:(v ? @"true" : @"false")];
+ break;
+ }
+
+ case GPBDataTypeString: {
+ NSString *v = (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetMessageStringField(message, field));
+ AppendStringEscaped(v, toStr);
+ break;
+ }
+
+ case GPBDataTypeBytes: {
+ NSData *v = (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetMessageBytesField(message, field));
+ AppendBufferAsString(v, toStr);
+ break;
+ }
+
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ GPBMessage *v =
+ (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetObjectIvarWithField(message, field));
+ [toStr appendFormat:@"{%@\n", lineEnding];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(v, toStr, subIndent);
+ [toStr appendFormat:@"%@}", lineIndent];
+ lineEnding = @"";
+ break;
+ }
+
+ } // switch(fieldDataType)
+
+ // End the line.
+ [toStr appendFormat:@"%@\n", lineEnding];
+
+ } // for(count)
+}
+
+static void AppendTextFormatForMessageExtensionRange(GPBMessage *message,
+ NSArray *activeExtensions,
+ GPBExtensionRange range,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ uint32_t start = range.start;
+ uint32_t end = range.end;
+ for (GPBExtensionDescriptor *extension in activeExtensions) {
+ uint32_t fieldNumber = extension.fieldNumber;
+ if (fieldNumber < start) {
+ // Not there yet.
+ continue;
+ }
+ if (fieldNumber > end) {
+ // Done.
+ break;
+ }
+
+ id rawExtValue = [message getExtension:extension];
+ BOOL isRepeated = extension.isRepeated;
+
+ NSUInteger numValues = 1;
+ NSString *lineEnding = @"";
+ if (isRepeated) {
+ numValues = [(NSArray *)rawExtValue count];
+ }
+
+ NSString *singletonName = extension.singletonName;
+ if (numValues == 1) {
+ lineEnding = [NSString stringWithFormat:@" # [%@]", singletonName];
+ } else {
+ [toStr appendFormat:@"%@# [%@]\n", lineIndent, singletonName];
+ }
+
+ GPBDataType extDataType = extension.dataType;
+ for (NSUInteger j = 0; j < numValues; ++j) {
+ id curValue = (isRepeated ? [rawExtValue objectAtIndex:j] : rawExtValue);
+
+ // Start the line.
+ [toStr appendFormat:@"%@%u%s ", lineIndent, fieldNumber,
+ (GPBDataTypeIsMessage(extDataType) ? "" : ":")];
+
+ // The value.
+ switch (extDataType) {
+#define FIELD_CASE(GPBDATATYPE, CTYPE, NUMSELECTOR, ...) \
+ case GPBDataType##GPBDATATYPE: { \
+ CTYPE v = [(NSNumber *)curValue NUMSELECTOR]; \
+ [toStr appendFormat:__VA_ARGS__, v]; \
+ break; \
+ }
+
+ FIELD_CASE(Int32, int32_t, intValue, @"%d")
+ FIELD_CASE(SInt32, int32_t, intValue, @"%d")
+ FIELD_CASE(SFixed32, int32_t, unsignedIntValue, @"%d")
+ FIELD_CASE(UInt32, uint32_t, unsignedIntValue, @"%u")
+ FIELD_CASE(Fixed32, uint32_t, unsignedIntValue, @"%u")
+ FIELD_CASE(Int64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(SInt64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(SFixed64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(UInt64, uint64_t, unsignedLongLongValue, @"%llu")
+ FIELD_CASE(Fixed64, uint64_t, unsignedLongLongValue, @"%llu")
+ FIELD_CASE(Float, float, floatValue, @"%.*g", FLT_DIG)
+ FIELD_CASE(Double, double, doubleValue, @"%.*lg", DBL_DIG)
+ // TODO: Add a comment with the enum name from enum descriptors
+ // (might not be real value, so leave it as a comment, ObjC compiler
+ // name mangles differently). Doesn't look like we actually generate
+ // an enum descriptor reference like we do for normal fields, so this
+ // will take a compiler change.
+ FIELD_CASE(Enum, int32_t, intValue, @"%d")
+
+#undef FIELD_CASE
+
+ case GPBDataTypeBool:
+ [toStr appendString:([(NSNumber *)curValue boolValue] ? @"true"
+ : @"false")];
+ break;
+
+ case GPBDataTypeString:
+ AppendStringEscaped(curValue, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString((NSData *)curValue, toStr);
+ break;
+
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ [toStr appendFormat:@"{%@\n", lineEnding];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(curValue, toStr, subIndent);
+ [toStr appendFormat:@"%@}", lineIndent];
+ lineEnding = @"";
+ break;
+ }
+
+ } // switch(extDataType)
+
+ } // for(numValues)
+
+ // End the line.
+ [toStr appendFormat:@"%@\n", lineEnding];
+
+ } // for..in(activeExtensions)
+}
+
+static void AppendTextFormatForMessage(GPBMessage *message,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ GPBDescriptor *descriptor = [message descriptor];
+ NSArray *fieldsArray = descriptor->fields_;
+ NSUInteger fieldCount = fieldsArray.count;
+ const GPBExtensionRange *extensionRanges = descriptor.extensionRanges;
+ NSUInteger extensionRangesCount = descriptor.extensionRangesCount;
+ NSArray *activeExtensions = [[message extensionsCurrentlySet]
+ sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
+ for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) {
+ if (i == fieldCount) {
+ AppendTextFormatForMessageExtensionRange(
+ message, activeExtensions, extensionRanges[j++], toStr, lineIndent);
+ } else if (j == extensionRangesCount ||
+ GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) {
+ AppendTextFormatForMessageField(message, fieldsArray[i++], toStr,
+ lineIndent);
+ } else {
+ AppendTextFormatForMessageExtensionRange(
+ message, activeExtensions, extensionRanges[j++], toStr, lineIndent);
+ }
+ }
+
+ NSString *unknownFieldsStr =
+ GPBTextFormatForUnknownFieldSet(message.unknownFields, lineIndent);
+ if ([unknownFieldsStr length] > 0) {
+ [toStr appendFormat:@"%@# --- Unknown fields ---\n", lineIndent];
+ [toStr appendString:unknownFieldsStr];
+ }
+}
+
+NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent) {
+ if (message == nil) return @"";
+ if (lineIndent == nil) lineIndent = @"";
+
+ NSMutableString *buildString = [NSMutableString string];
+ AppendTextFormatForMessage(message, buildString, lineIndent);
+ return buildString;
+}
+
+NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
+ NSString *lineIndent) {
+ if (unknownSet == nil) return @"";
+ if (lineIndent == nil) lineIndent = @"";
+
+ NSMutableString *result = [NSMutableString string];
+ for (GPBUnknownField *field in [unknownSet sortedFields]) {
+ int32_t fieldNumber = [field number];
+
+#define PRINT_LOOP(PROPNAME, CTYPE, FORMAT) \
+ [field.PROPNAME \
+ enumerateValuesWithBlock:^(CTYPE value, NSUInteger idx, BOOL * stop) { \
+ _Pragma("unused(idx, stop)"); \
+ [result \
+ appendFormat:@"%@%d: " #FORMAT "\n", lineIndent, fieldNumber, value]; \
+ }];
+
+ PRINT_LOOP(varintList, uint64_t, %llu);
+ PRINT_LOOP(fixed32List, uint32_t, 0x%X);
+ PRINT_LOOP(fixed64List, uint64_t, 0x%llX);
+
+#undef PRINT_LOOP
+
+ // NOTE: C++ version of TextFormat tries to parse this as a message
+ // and print that if it succeeds.
+ for (NSData *data in field.lengthDelimitedList) {
+ [result appendFormat:@"%@%d: ", lineIndent, fieldNumber];
+ AppendBufferAsString(data, result);
+ [result appendString:@"\n"];
+ }
+
+ for (GPBUnknownFieldSet *subUnknownSet in field.groupList) {
+ [result appendFormat:@"%@%d: {\n", lineIndent, fieldNumber];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ NSString *subUnknwonSetStr =
+ GPBTextFormatForUnknownFieldSet(subUnknownSet, subIndent);
+ [result appendString:subUnknwonSetStr];
+ [result appendFormat:@"%@}\n", lineIndent];
+ }
+ }
+ return result;
+}
+
+// Helpers to decode a varint. Not using GPBCodedInputStream version because
+// that needs a state object, and we don't want to create an input stream out
+// of the data.
+GPB_INLINE int8_t ReadRawByteFromData(const uint8_t **data) {
+ int8_t result = *((int8_t *)(*data));
+ ++(*data);
+ return result;
+}
+
+static int32_t ReadRawVarint32FromData(const uint8_t **data) {
+ int8_t tmp = ReadRawByteFromData(data);
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int32_t result = tmp & 0x7f;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = ReadRawByteFromData(data)) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (ReadRawByteFromData(data) >= 0) {
+ return result;
+ }
+ }
+ [NSException raise:NSParseErrorException
+ format:@"Unable to read varint32"];
+ }
+ }
+ }
+ }
+ return result;
+}
+
+NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key,
+ NSString *inputStr) {
+ // decodData form:
+ // varint32: num entries
+ // for each entry:
+ // varint32: key
+ // bytes*: decode data
+ //
+ // decode data one of two forms:
+ // 1: a \0 followed by the string followed by an \0
+ // 2: bytecodes to transform an input into the right thing, ending with \0
+ //
+ // the bytes codes are of the form:
+ // 0xabbccccc
+ // 0x0 (all zeros), end.
+ // a - if set, add an underscore
+ // bb - 00 ccccc bytes as is
+ // bb - 10 ccccc upper first, as is on rest, ccccc byte total
+ // bb - 01 ccccc lower first, as is on rest, ccccc byte total
+ // bb - 11 ccccc all upper, ccccc byte total
+
+ if (!decodeData || !inputStr) {
+ return nil;
+ }
+
+ // Find key
+ const uint8_t *scan = decodeData;
+ int32_t numEntries = ReadRawVarint32FromData(&scan);
+ BOOL foundKey = NO;
+ while (!foundKey && (numEntries > 0)) {
+ --numEntries;
+ int32_t dataKey = ReadRawVarint32FromData(&scan);
+ if (dataKey == key) {
+ foundKey = YES;
+ } else {
+ // If it is a inlined string, it will start with \0; if it is bytecode it
+ // will start with a code. So advance one (skipping the inline string
+ // marker), and then loop until reaching the end marker (\0).
+ ++scan;
+ while (*scan != 0) ++scan;
+ // Now move past the end marker.
+ ++scan;
+ }
+ }
+
+ if (!foundKey) {
+ return nil;
+ }
+
+ // Decode
+
+ if (*scan == 0) {
+ // Inline string. Move over the marker, and NSString can take it as
+ // UTF8.
+ ++scan;
+ NSString *result = [NSString stringWithUTF8String:(const char *)scan];
+ return result;
+ }
+
+ NSMutableString *result =
+ [NSMutableString stringWithCapacity:[inputStr length]];
+
+ const uint8_t kAddUnderscore = 0b10000000;
+ const uint8_t kOpMask = 0b01100000;
+ // const uint8_t kOpAsIs = 0b00000000;
+ const uint8_t kOpFirstUpper = 0b01000000;
+ const uint8_t kOpFirstLower = 0b00100000;
+ const uint8_t kOpAllUpper = 0b01100000;
+ const uint8_t kSegmentLenMask = 0b00011111;
+
+ NSInteger i = 0;
+ for (; *scan != 0; ++scan) {
+ if (*scan & kAddUnderscore) {
+ [result appendString:@"_"];
+ }
+ int segmentLen = *scan & kSegmentLenMask;
+ uint8_t decodeOp = *scan & kOpMask;
+
+ // Do op specific handling of the first character.
+ if (decodeOp == kOpFirstUpper) {
+ unichar c = [inputStr characterAtIndex:i];
+ [result appendFormat:@"%c", toupper((char)c)];
+ ++i;
+ --segmentLen;
+ } else if (decodeOp == kOpFirstLower) {
+ unichar c = [inputStr characterAtIndex:i];
+ [result appendFormat:@"%c", tolower((char)c)];
+ ++i;
+ --segmentLen;
+ }
+ // else op == kOpAsIs || op == kOpAllUpper
+
+ // Now pull over the rest of the length for this segment.
+ for (int x = 0; x < segmentLen; ++x) {
+ unichar c = [inputStr characterAtIndex:(i + x)];
+ if (decodeOp == kOpAllUpper) {
+ [result appendFormat:@"%c", toupper((char)c)];
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ }
+ i += segmentLen;
+ }
+
+ return result;
+}
+
+#pragma clang diagnostic pop
+
+BOOL GPBClassHasSel(Class aClass, SEL sel) {
+ // NOTE: We have to use class_copyMethodList, all other runtime method
+ // lookups actually also resolve the method implementation and this
+ // is called from within those methods.
+
+ BOOL result = NO;
+ unsigned int methodCount = 0;
+ Method *methodList = class_copyMethodList(aClass, &methodCount);
+ for (unsigned int i = 0; i < methodCount; ++i) {
+ SEL methodSelector = method_getName(methodList[i]);
+ if (methodSelector == sel) {
+ result = YES;
+ break;
+ }
+ }
+ free(methodList);
+ return result;
+}
+
+#pragma mark - GPBMessageSignatureProtocol
+
+// A series of selectors that are used solely to get @encoding values
+// for them by the dynamic protobuf runtime code. An object using the protocol
+// needs to be declared for the protocol to be valid at runtime.
+@interface GPBMessageSignatureProtocol : NSObject<GPBMessageSignatureProtocol>
+@end
+@implementation GPBMessageSignatureProtocol
+@end
diff --git a/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h
new file mode 100644
index 0000000000..16859d4875
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h
@@ -0,0 +1,350 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUtilities.h"
+
+#import "GPBDescriptor_PackagePrivate.h"
+
+// Macros for stringifying library symbols. These are used in the generated
+// PB descriptor classes wherever a library symbol name is represented as a
+// string. See README.google for more information.
+#define GPBStringify(S) #S
+#define GPBStringifySymbol(S) GPBStringify(S)
+
+#define GPBNSStringify(S) @#S
+#define GPBNSStringifySymbol(S) GPBNSStringify(S)
+
+// Constant to internally mark when there is no has bit.
+#define GPBNoHasBit INT32_MAX
+
+CF_EXTERN_C_BEGIN
+
+// These two are used to inject a runtime check for version mismatch into the
+// generated sources to make sure they are linked with a supporting runtime.
+void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion);
+GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS() {
+ // NOTE: By being inline here, this captures the value from the library's
+ // headers at the time the generated code was compiled.
+#if defined(DEBUG) && DEBUG
+ GPBCheckRuntimeVersionSupport(GOOGLE_PROTOBUF_OBJC_VERSION);
+#endif
+}
+
+// Legacy version of the checks, remove when GOOGLE_PROTOBUF_OBJC_GEN_VERSION
+// goes away (see more info in GPBBootstrap.h).
+void GPBCheckRuntimeVersionInternal(int32_t version);
+GPB_INLINE void GPBDebugCheckRuntimeVersion() {
+#if defined(DEBUG) && DEBUG
+ GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION);
+#endif
+}
+
+// Conversion functions for de/serializing floating point types.
+
+GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) {
+ union { double f; int64_t i; } u;
+ u.f = v;
+ return u.i;
+}
+
+GPB_INLINE int32_t GPBConvertFloatToInt32(float v) {
+ union { float f; int32_t i; } u;
+ u.f = v;
+ return u.i;
+}
+
+GPB_INLINE double GPBConvertInt64ToDouble(int64_t v) {
+ union { double f; int64_t i; } u;
+ u.i = v;
+ return u.f;
+}
+
+GPB_INLINE float GPBConvertInt32ToFloat(int32_t v) {
+ union { float f; int32_t i; } u;
+ u.i = v;
+ return u.f;
+}
+
+GPB_INLINE int32_t GPBLogicalRightShift32(int32_t value, int32_t spaces) {
+ return (int32_t)((uint32_t)(value) >> spaces);
+}
+
+GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) {
+ return (int64_t)((uint64_t)(value) >> spaces);
+}
+
+// Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers
+// into values that can be efficiently encoded with varint. (Otherwise,
+// negative values must be sign-extended to 64 bits to be varint encoded,
+// thus always taking 10 bytes on the wire.)
+GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) {
+ return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(n) & 1));
+}
+
+// Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers
+// into values that can be efficiently encoded with varint. (Otherwise,
+// negative values must be sign-extended to 64 bits to be varint encoded,
+// thus always taking 10 bytes on the wire.)
+GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) {
+ return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n) & 1));
+}
+
+// Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers
+// into values that can be efficiently encoded with varint. (Otherwise,
+// negative values must be sign-extended to 64 bits to be varint encoded,
+// thus always taking 10 bytes on the wire.)
+GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) {
+ // Note: the right-shift must be arithmetic
+ return (uint32_t)((n << 1) ^ (n >> 31));
+}
+
+// Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers
+// into values that can be efficiently encoded with varint. (Otherwise,
+// negative values must be sign-extended to 64 bits to be varint encoded,
+// thus always taking 10 bytes on the wire.)
+GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) {
+ // Note: the right-shift must be arithmetic
+ return (uint64_t)((n << 1) ^ (n >> 63));
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) {
+ switch (type) {
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+GPB_INLINE BOOL GPBDataTypeIsMessage(GPBDataType type) {
+ switch (type) {
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+GPB_INLINE BOOL GPBFieldDataTypeIsMessage(GPBFieldDescriptor *field) {
+ return GPBDataTypeIsMessage(field->description_->dataType);
+}
+
+GPB_INLINE BOOL GPBFieldDataTypeIsObject(GPBFieldDescriptor *field) {
+ return GPBDataTypeIsObject(field->description_->dataType);
+}
+
+GPB_INLINE BOOL GPBExtensionIsMessage(GPBExtensionDescriptor *ext) {
+ return GPBDataTypeIsMessage(ext->description_->dataType);
+}
+
+// The field is an array/map or it has an object value.
+GPB_INLINE BOOL GPBFieldStoresObject(GPBFieldDescriptor *field) {
+ GPBMessageFieldDescription *desc = field->description_;
+ if ((desc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0) {
+ return YES;
+ }
+ return GPBDataTypeIsObject(desc->dataType);
+}
+
+BOOL GPBGetHasIvar(GPBMessage *self, int32_t index, uint32_t fieldNumber);
+void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
+ BOOL value);
+uint32_t GPBGetHasOneof(GPBMessage *self, int32_t index);
+
+GPB_INLINE BOOL
+GPBGetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ return GPBGetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number);
+}
+GPB_INLINE void GPBSetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field,
+ BOOL value) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, value);
+}
+
+void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
+ int32_t oneofHasIndex, uint32_t fieldNumberNotToClear);
+
+#pragma clang diagnostic pop
+
+//%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE)
+//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value,
+//% NAME$S GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Float, float)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Double, double)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Enum, int32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND-END (8 expansions)
+
+int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+
+id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+
+void GPBSetObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, id value,
+ GPBFileSyntax syntax);
+void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed))
+ value,
+ GPBFileSyntax syntax);
+
+// GPBGetObjectIvarWithField will automatically create the field (message) if
+// it doesn't exist. GPBGetObjectIvarWithFieldNoAutocreate will return nil.
+id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self,
+ GPBFieldDescriptor *field);
+
+void GPBSetAutocreatedRetainedObjectIvarWithField(
+ GPBMessage *self, GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed)) value);
+
+// Clears and releases the autocreated message ivar, if it's autocreated. If
+// it's not set as autocreated, this method does nothing.
+void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field);
+
+// Returns an Objective C encoding for |selector|. |instanceSel| should be
+// YES if it's an instance selector (as opposed to a class selector).
+// |selector| must be a selector from MessageSignatureProtocol.
+const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel);
+
+// Helper for text format name encoding.
+// decodeData is the data describing the sepecial decodes.
+// key and inputString are the input that needs decoding.
+NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key,
+ NSString *inputString);
+
+// A series of selectors that are used solely to get @encoding values
+// for them by the dynamic protobuf runtime code. See
+// GPBMessageEncodingForSelector for details.
+@protocol GPBMessageSignatureProtocol
+@optional
+
+#define GPB_MESSAGE_SIGNATURE_ENTRY(TYPE, NAME) \
+ -(TYPE)get##NAME; \
+ -(void)set##NAME : (TYPE)value; \
+ -(TYPE)get##NAME##AtIndex : (NSUInteger)index;
+
+GPB_MESSAGE_SIGNATURE_ENTRY(BOOL, Bool)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, Fixed32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SFixed32)
+GPB_MESSAGE_SIGNATURE_ENTRY(float, Float)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, Fixed64)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SFixed64)
+GPB_MESSAGE_SIGNATURE_ENTRY(double, Double)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Int32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, Int64)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SInt32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SInt64)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, UInt32)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, UInt64)
+GPB_MESSAGE_SIGNATURE_ENTRY(NSData *, Bytes)
+GPB_MESSAGE_SIGNATURE_ENTRY(NSString *, String)
+GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Message)
+GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Group)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Enum)
+
+#undef GPB_MESSAGE_SIGNATURE_ENTRY
+
+- (id)getArray;
+- (NSUInteger)getArrayCount;
+- (void)setArray:(NSArray *)array;
++ (id)getClassValue;
+@end
+
+BOOL GPBClassHasSel(Class aClass, SEL sel);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBWellKnownTypes.h b/third_party/protobuf/objectivec/GPBWellKnownTypes.h
new file mode 100644
index 0000000000..04df417889
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWellKnownTypes.h
@@ -0,0 +1,245 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/Duration.pbobjc.h>
+ #import <Protobuf/Timestamp.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/Duration.pbobjc.h"
+ #import "google/protobuf/Timestamp.pbobjc.h"
+#endif
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Errors
+
+/** NSError domain used for errors. */
+extern NSString *const GPBWellKnownTypesErrorDomain;
+
+/** Error code for NSError with GPBWellKnownTypesErrorDomain. */
+typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) {
+ /** The type_url could not be computed for the requested GPBMessage class. */
+ GPBWellKnownTypesErrorCodeFailedToComputeTypeURL = -100,
+ /** type_url in a Any doesn’t match that of the requested GPBMessage class. */
+ GPBWellKnownTypesErrorCodeTypeURLMismatch = -101,
+};
+
+#pragma mark - GPBTimestamp
+
+/**
+ * Category for GPBTimestamp to work with standard Foundation time/date types.
+ **/
+@interface GPBTimestamp (GBPWellKnownTypes)
+
+/** The NSDate representation of this GPBTimestamp. */
+@property(nonatomic, readwrite, strong) NSDate *date;
+
+/**
+ * The NSTimeInterval representation of this GPBTimestamp.
+ *
+ * @note: Not all second/nanos combinations can be represented in a
+ * NSTimeInterval, so getting this could be a lossy transform.
+ **/
+@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970;
+
+/**
+ * Initializes a GPBTimestamp with the given NSDate.
+ *
+ * @param date The date to configure the GPBTimestamp with.
+ *
+ * @return A newly initialized GPBTimestamp.
+ **/
+- (instancetype)initWithDate:(NSDate *)date;
+
+/**
+ * Initializes a GPBTimestamp with the given NSTimeInterval.
+ *
+ * @param timeIntervalSince1970 Time interval to configure the GPBTimestamp with.
+ *
+ * @return A newly initialized GPBTimestamp.
+ **/
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970;
+
+@end
+
+#pragma mark - GPBDuration
+
+/**
+ * Category for GPBDuration to work with standard Foundation time type.
+ **/
+@interface GPBDuration (GBPWellKnownTypes)
+
+/**
+ * The NSTimeInterval representation of this GPBDuration.
+ *
+ * @note: Not all second/nanos combinations can be represented in a
+ * NSTimeInterval, so getting this could be a lossy transform.
+ **/
+@property(nonatomic, readwrite) NSTimeInterval timeInterval;
+
+/**
+ * Initializes a GPBDuration with the given NSTimeInterval.
+ *
+ * @param timeInterval Time interval to configure the GPBDuration with.
+ *
+ * @return A newly initialized GPBDuration.
+ **/
+- (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval;
+
+// These next two methods are deprecated because GBPDuration has no need of a
+// "base" time. The older methods were about symmetry with GBPTimestamp, but
+// the unix epoch usage is too confusing.
+
+/** Deprecated, use timeInterval instead. */
+@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970
+ __attribute__((deprecated("Use timeInterval")));
+/** Deprecated, use initWithTimeInterval: instead. */
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970
+ __attribute__((deprecated("Use initWithTimeInterval:")));
+
+@end
+
+#pragma mark - GPBAny
+
+/**
+ * Category for GPBAny to help work with the message within the object.
+ **/
+@interface GPBAny (GBPWellKnownTypes)
+
+/**
+ * Convenience method to create a GPBAny containing the serialized message.
+ * This uses type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
++ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Convenience method to create a GPBAny containing the serialized message.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
++ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes a GPBAny to contain the serialized message. This uses
+ * type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
+- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes a GPBAny to contain the serialized message.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
+- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Packs the serialized message into this GPBAny. This uses
+ * type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return Whether the packing was successful or not.
+ */
+- (BOOL)packWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Packs the serialized message into this GPBAny.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return Whether the packing was successful or not.
+ */
+- (BOOL)packWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Unpacks the serialized message as if it was an instance of the given class.
+ *
+ * @note When checking type_url, the base URL is not checked, only the fully
+ * qualified name.
+ *
+ * @param messageClass The class to use to deserialize the contained message.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return An instance of the given class populated with the contained data, or
+ * nil on failure.
+ */
+- (nullable GPBMessage *)unpackMessageClass:(Class)messageClass
+ error:(NSError **)errorPtr;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBWellKnownTypes.m b/third_party/protobuf/objectivec/GPBWellKnownTypes.m
new file mode 100644
index 0000000000..2808afeb23
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWellKnownTypes.m
@@ -0,0 +1,272 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Importing sources here to force the linker to include our category methods in
+// the static library. If these were compiled separately, the category methods
+// below would be stripped by the linker.
+
+#import "GPBWellKnownTypes.h"
+
+#import "GPBUtilities_PackagePrivate.h"
+
+NSString *const GPBWellKnownTypesErrorDomain =
+ GPBNSStringifySymbol(GPBWellKnownTypesErrorDomain);
+
+static NSString *kTypePrefixGoogleApisCom = @"type.googleapis.com/";
+
+static NSTimeInterval TimeIntervalFromSecondsAndNanos(int64_t seconds,
+ int32_t nanos) {
+ return seconds + (NSTimeInterval)nanos / 1e9;
+}
+
+static int32_t SecondsAndNanosFromTimeInterval(NSTimeInterval time,
+ int64_t *outSeconds,
+ BOOL nanosMustBePositive) {
+ NSTimeInterval seconds;
+ NSTimeInterval nanos = modf(time, &seconds);
+
+ if (nanosMustBePositive && (nanos < 0)) {
+ // Per Timestamp.proto, nanos is non-negative and "Negative second values with
+ // fractions must still have non-negative nanos values that count forward in
+ // time. Must be from 0 to 999,999,999 inclusive."
+ --seconds;
+ nanos = 1.0 + nanos;
+ }
+
+ nanos *= 1e9;
+ *outSeconds = (int64_t)seconds;
+ return (int32_t)nanos;
+}
+
+static NSString *BuildTypeURL(NSString *typeURLPrefix, NSString *fullName) {
+ if (typeURLPrefix.length == 0) {
+ return fullName;
+ }
+
+ if ([typeURLPrefix hasSuffix:@"/"]) {
+ return [typeURLPrefix stringByAppendingString:fullName];
+ }
+
+ return [NSString stringWithFormat:@"%@/%@", typeURLPrefix, fullName];
+}
+
+static NSString *ParseTypeFromURL(NSString *typeURLString) {
+ NSRange range = [typeURLString rangeOfString:@"/" options:NSBackwardsSearch];
+ if ((range.location == NSNotFound) ||
+ (NSMaxRange(range) == typeURLString.length)) {
+ return nil;
+ }
+ NSString *result = [typeURLString substringFromIndex:range.location + 1];
+ return result;
+}
+
+#pragma mark - GPBTimestamp
+
+@implementation GPBTimestamp (GBPWellKnownTypes)
+
+- (instancetype)initWithDate:(NSDate *)date {
+ return [self initWithTimeIntervalSince1970:date.timeIntervalSince1970];
+}
+
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ if ((self = [super init])) {
+ int64_t seconds;
+ int32_t nanos = SecondsAndNanosFromTimeInterval(
+ timeIntervalSince1970, &seconds, YES);
+ self.seconds = seconds;
+ self.nanos = nanos;
+ }
+ return self;
+}
+
+- (NSDate *)date {
+ return [NSDate dateWithTimeIntervalSince1970:self.timeIntervalSince1970];
+}
+
+- (void)setDate:(NSDate *)date {
+ self.timeIntervalSince1970 = date.timeIntervalSince1970;
+}
+
+- (NSTimeInterval)timeIntervalSince1970 {
+ return TimeIntervalFromSecondsAndNanos(self.seconds, self.nanos);
+}
+
+- (void)setTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ int64_t seconds;
+ int32_t nanos =
+ SecondsAndNanosFromTimeInterval(timeIntervalSince1970, &seconds, YES);
+ self.seconds = seconds;
+ self.nanos = nanos;
+}
+
+@end
+
+#pragma mark - GPBDuration
+
+@implementation GPBDuration (GBPWellKnownTypes)
+
+- (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval {
+ if ((self = [super init])) {
+ int64_t seconds;
+ int32_t nanos = SecondsAndNanosFromTimeInterval(
+ timeInterval, &seconds, NO);
+ self.seconds = seconds;
+ self.nanos = nanos;
+ }
+ return self;
+}
+
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ return [self initWithTimeInterval:timeIntervalSince1970];
+}
+
+- (NSTimeInterval)timeInterval {
+ return TimeIntervalFromSecondsAndNanos(self.seconds, self.nanos);
+}
+
+- (void)setTimeInterval:(NSTimeInterval)timeInterval {
+ int64_t seconds;
+ int32_t nanos =
+ SecondsAndNanosFromTimeInterval(timeInterval, &seconds, NO);
+ self.seconds = seconds;
+ self.nanos = nanos;
+}
+
+- (NSTimeInterval)timeIntervalSince1970 {
+ return self.timeInterval;
+}
+
+- (void)setTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ self.timeInterval = timeIntervalSince1970;
+}
+
+@end
+
+#pragma mark - GPBAny
+
+@implementation GPBAny (GBPWellKnownTypes)
+
++ (instancetype)anyWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self anyWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
++ (instancetype)anyWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ return [[[self alloc] initWithMessage:message
+ typeURLPrefix:typeURLPrefix
+ error:errorPtr] autorelease];
+}
+
+- (instancetype)initWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self initWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
+- (instancetype)initWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ self = [self init];
+ if (self) {
+ if (![self packWithMessage:message
+ typeURLPrefix:typeURLPrefix
+ error:errorPtr]) {
+ [self release];
+ self = nil;
+ }
+ }
+ return self;
+}
+
+- (BOOL)packWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self packWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
+- (BOOL)packWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ NSString *fullName = [message descriptor].fullName;
+ if (fullName.length == 0) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL
+ userInfo:nil];
+ }
+ return NO;
+ }
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ self.typeURL = BuildTypeURL(typeURLPrefix, fullName);
+ self.value = message.data;
+ return YES;
+}
+
+- (GPBMessage *)unpackMessageClass:(Class)messageClass
+ error:(NSError **)errorPtr {
+ NSString *fullName = [messageClass descriptor].fullName;
+ if (fullName.length == 0) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL
+ userInfo:nil];
+ }
+ return nil;
+ }
+
+ NSString *expectedFullName = ParseTypeFromURL(self.typeURL);
+ if ((expectedFullName == nil) || ![expectedFullName isEqual:fullName]) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeTypeURLMismatch
+ userInfo:nil];
+ }
+ return nil;
+ }
+
+ // Any is proto3, which means no extensions, so this assumes anything put
+ // within an any also won't need extensions. A second helper could be added
+ // if needed.
+ return [messageClass parseFromData:self.value
+ error:errorPtr];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBWireFormat.h b/third_party/protobuf/objectivec/GPBWireFormat.h
new file mode 100644
index 0000000000..c5941a3824
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWireFormat.h
@@ -0,0 +1,73 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBRuntimeTypes.h"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+typedef enum {
+ GPBWireFormatVarint = 0,
+ GPBWireFormatFixed64 = 1,
+ GPBWireFormatLengthDelimited = 2,
+ GPBWireFormatStartGroup = 3,
+ GPBWireFormatEndGroup = 4,
+ GPBWireFormatFixed32 = 5,
+} GPBWireFormat;
+
+enum {
+ GPBWireFormatMessageSetItem = 1,
+ GPBWireFormatMessageSetTypeId = 2,
+ GPBWireFormatMessageSetMessage = 3
+};
+
+uint32_t GPBWireFormatMakeTag(uint32_t fieldNumber, GPBWireFormat wireType)
+ __attribute__((const));
+GPBWireFormat GPBWireFormatGetTagWireType(uint32_t tag) __attribute__((const));
+uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) __attribute__((const));
+BOOL GPBWireFormatIsValidTag(uint32_t tag) __attribute__((const));
+
+GPBWireFormat GPBWireFormatForType(GPBDataType dataType, BOOL isPacked)
+ __attribute__((const));
+
+#define GPBWireFormatMessageSetItemTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetItem, GPBWireFormatStartGroup))
+#define GPBWireFormatMessageSetItemEndTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetItem, GPBWireFormatEndGroup))
+#define GPBWireFormatMessageSetTypeIdTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetTypeId, GPBWireFormatVarint))
+#define GPBWireFormatMessageSetMessageTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetMessage, \
+ GPBWireFormatLengthDelimited))
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBWireFormat.m b/third_party/protobuf/objectivec/GPBWireFormat.m
new file mode 100644
index 0000000000..860a339f9a
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWireFormat.m
@@ -0,0 +1,85 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBWireFormat.h"
+
+#import "GPBUtilities_PackagePrivate.h"
+
+enum {
+ GPBWireFormatTagTypeBits = 3,
+ GPBWireFormatTagTypeMask = 7 /* = (1 << GPBWireFormatTagTypeBits) - 1 */,
+};
+
+uint32_t GPBWireFormatMakeTag(uint32_t fieldNumber, GPBWireFormat wireType) {
+ return (fieldNumber << GPBWireFormatTagTypeBits) | wireType;
+}
+
+GPBWireFormat GPBWireFormatGetTagWireType(uint32_t tag) {
+ return (GPBWireFormat)(tag & GPBWireFormatTagTypeMask);
+}
+
+uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) {
+ return GPBLogicalRightShift32(tag, GPBWireFormatTagTypeBits);
+}
+
+BOOL GPBWireFormatIsValidTag(uint32_t tag) {
+ uint32_t formatBits = (tag & GPBWireFormatTagTypeMask);
+ // The valid GPBWireFormat* values are 0-5, anything else is not a valid tag.
+ BOOL result = (formatBits <= 5);
+ return result;
+}
+
+GPBWireFormat GPBWireFormatForType(GPBDataType type, BOOL isPacked) {
+ if (isPacked) {
+ return GPBWireFormatLengthDelimited;
+ }
+
+ static const GPBWireFormat format[GPBDataType_Count] = {
+ GPBWireFormatVarint, // GPBDataTypeBool
+ GPBWireFormatFixed32, // GPBDataTypeFixed32
+ GPBWireFormatFixed32, // GPBDataTypeSFixed32
+ GPBWireFormatFixed32, // GPBDataTypeFloat
+ GPBWireFormatFixed64, // GPBDataTypeFixed64
+ GPBWireFormatFixed64, // GPBDataTypeSFixed64
+ GPBWireFormatFixed64, // GPBDataTypeDouble
+ GPBWireFormatVarint, // GPBDataTypeInt32
+ GPBWireFormatVarint, // GPBDataTypeInt64
+ GPBWireFormatVarint, // GPBDataTypeSInt32
+ GPBWireFormatVarint, // GPBDataTypeSInt64
+ GPBWireFormatVarint, // GPBDataTypeUInt32
+ GPBWireFormatVarint, // GPBDataTypeUInt64
+ GPBWireFormatLengthDelimited, // GPBDataTypeBytes
+ GPBWireFormatLengthDelimited, // GPBDataTypeString
+ GPBWireFormatLengthDelimited, // GPBDataTypeMessage
+ GPBWireFormatStartGroup, // GPBDataTypeGroup
+ GPBWireFormatVarint // GPBDataTypeEnum
+ };
+ return format[type];
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..919d007642
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
@@ -0,0 +1,994 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 47;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */; };
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */; };
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */; };
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4BF0F94F99000A0C422 /* GPBMessage.m */; };
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */; };
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E60F94F99000A0C422 /* GPBUtilities.m */; };
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */; };
+ 8B210CCE159383D60032D72D /* golden_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCD159383D60032D72D /* golden_message */; };
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCF159386920032D72D /* golden_packed_fields_message */; };
+ 8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */; };
+ 8B4248D21A927E1500BC1EC6 /* GPBWellKnownTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */; };
+ 8B4248DC1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */; };
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; };
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; };
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; };
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; };
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; };
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */; };
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */; };
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F401DC2D1A8D444600FCC765 /* GPBArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC2B1A8D444600FCC765 /* GPBArray.m */; };
+ F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */; };
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; };
+ F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */; };
+ F4353D231ABB1537005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D211ABB1537005A6198 /* GPBDictionary.m */; };
+ F4353D341AC06F10005A6198 /* GPBDictionaryTests+Bool.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */; };
+ F4353D351AC06F10005A6198 /* GPBDictionaryTests+Int32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */; };
+ F4353D361AC06F10005A6198 /* GPBDictionaryTests+Int64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */; };
+ F4353D371AC06F10005A6198 /* GPBDictionaryTests+String.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */; };
+ F4353D381AC06F10005A6198 /* GPBDictionaryTests+UInt32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */; };
+ F4353D391AC06F10005A6198 /* GPBDictionaryTests+UInt64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */; };
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */; };
+ F4487C4D1A9F8E0200531423 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F4487C521A9F8E4D00531423 /* GPBProtocolBuffers.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */; };
+ F4487C751AADF7F500531423 /* GPBMessageTests+Runtime.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */; };
+ F4487C7F1AAF62CD00531423 /* GPBMessageTests+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */; };
+ F4487C831AAF6AB300531423 /* GPBMessageTests+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */; };
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */; };
+ F45E57C71AE6DC6A000B7D99 /* text_format_map_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */; };
+ F47476E51D21A524007C7B1A /* Duration.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */; };
+ F47476E61D21A524007C7B1A /* Timestamp.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */; };
+ F4B51B1E1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */; };
+ F4C4B9E41E1D976300D3B61D /* GPBDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */; };
+ F4E675971B21D0000054530B /* Any.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675871B21D0000054530B /* Any.pbobjc.m */; };
+ F4E675991B21D0000054530B /* Api.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675891B21D0000054530B /* Api.pbobjc.m */; };
+ F4E6759B1B21D0000054530B /* Empty.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758B1B21D0000054530B /* Empty.pbobjc.m */; };
+ F4E6759D1B21D0000054530B /* FieldMask.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */; };
+ F4E6759F1B21D0000054530B /* SourceContext.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */; };
+ F4E675A11B21D0000054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675911B21D0000054530B /* Struct.pbobjc.m */; };
+ F4E675A31B21D0000054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675931B21D0000054530B /* Type.pbobjc.m */; };
+ F4E675A51B21D0000054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675951B21D0000054530B /* Wrappers.pbobjc.m */; };
+ F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 7461B52D0F94FAF800A0C422;
+ remoteInfo = ProtocolBuffers;
+ };
+ F45BBC181B0CE3D7002D064D /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = F45BBC141B0CE3C6002D064D;
+ remoteInfo = "Compile Unittest Protos";
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBConcurrencyTests.m; sourceTree = "<group>"; };
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor_PackagePrivate.h; sourceTree = "<group>"; };
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBMessage_PackagePrivate.h; sourceTree = "<group>"; };
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTests-Info.plist"; sourceTree = "<group>"; };
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBBootstrap.h; sourceTree = "<group>"; };
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream.h; sourceTree = "<group>"; };
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GPBCodedInputStream.m; sourceTree = "<group>"; };
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream.h; sourceTree = "<group>"; };
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStream.m; sourceTree = "<group>"; };
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBExtensionRegistry.h; sourceTree = "<group>"; };
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionRegistry.m; sourceTree = "<group>"; };
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField.h; sourceTree = "<group>"; };
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownField.m; sourceTree = "<group>"; };
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBMessage.h; sourceTree = "<group>"; };
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessage.m; sourceTree = "<group>"; };
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers.h; sourceTree = "<group>"; };
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet.h; sourceTree = "<group>"; };
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSet.m; sourceTree = "<group>"; };
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUtilities.h; sourceTree = "<group>"; };
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilities.m; sourceTree = "<group>"; };
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWireFormat.h; sourceTree = "<group>"; };
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = "<group>"; };
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = "<group>"; };
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = "<group>"; };
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = "<group>"; };
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = "<group>"; };
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = "<group>"; };
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSetTest.m; sourceTree = "<group>"; };
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilitiesTests.m; sourceTree = "<group>"; };
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormatTests.m; sourceTree = "<group>"; };
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc.proto; sourceTree = "<group>"; };
+ 8B210CCD159383D60032D72D /* golden_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_message; sourceTree = "<group>"; };
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_packed_fields_message; sourceTree = "<group>"; };
+ 8B4248B81A8C254000BC1EC6 /* protobuf */ = {isa = PBXFileReference; lastKnownFileType = text; name = protobuf; path = ../../Intermediates/ProtocolBuffers_OSX.build/DerivedSources/protos/google/protobuf; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B4248B91A8C256900BC1EC6 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = "<group>"; };
+ 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPBSwiftTests.swift; sourceTree = "<group>"; };
+ 8B4248CF1A927E1500BC1EC6 /* GPBWellKnownTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWellKnownTypes.h; sourceTree = "<group>"; };
+ 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypes.m; sourceTree = "<group>"; };
+ 8B4248D31A92826400BC1EC6 /* Duration.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Duration.pbobjc.h; path = google/protobuf/Duration.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Duration.pbobjc.m; path = google/protobuf/Duration.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248D51A92826400BC1EC6 /* Timestamp.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Timestamp.pbobjc.h; path = google/protobuf/Timestamp.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Timestamp.pbobjc.m; path = google/protobuf/Timestamp.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
+ 8B42494C1A92A16600BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
+ 8B42494D1A92A16600BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = "<group>"; };
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = "<group>"; };
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = "<group>"; };
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = "<group>"; };
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = "<group>"; };
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = "<group>"; };
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = "<group>"; };
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = "<group>"; };
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = "<group>"; };
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = "<group>"; };
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
+ F401DC2A1A8D444600FCC765 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
+ F401DC2B1A8D444600FCC765 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
+ F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = "<group>"; };
+ F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = "<group>"; };
+ F4353D201ABB1537005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = "<group>"; };
+ F4353D211ABB1537005A6198 /* GPBDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionary.m; sourceTree = "<group>"; };
+ F4353D2C1AC06F10005A6198 /* GPBDictionaryTests.pddm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GPBDictionaryTests.pddm; sourceTree = "<group>"; };
+ F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Bool.m"; sourceTree = "<group>"; };
+ F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int32.m"; sourceTree = "<group>"; };
+ F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int64.m"; sourceTree = "<group>"; };
+ F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+String.m"; sourceTree = "<group>"; };
+ F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt32.m"; sourceTree = "<group>"; };
+ F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt64.m"; sourceTree = "<group>"; };
+ F43725911AC9832D004DCAFB /* GPBDictionary_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDictionary_PackagePrivate.h; sourceTree = "<group>"; };
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_unittest_data.txt; sourceTree = "<group>"; };
+ F4411BE71AF12FD700324B4A /* GPBArray_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBArray_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTestSingleSourceBuild.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Runtime.m"; sourceTree = "<group>"; };
+ F4487C781AADFB3100531423 /* unittest_runtime_proto2.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto2.proto; sourceTree = "<group>"; };
+ F4487C791AADFB3200531423 /* unittest_runtime_proto3.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto3.proto; sourceTree = "<group>"; };
+ F4487C7C1AAE06AC00531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; };
+ F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; };
+ F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; };
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; };
+ F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; };
+ F4AC9E1D1A8BEB3500BD6E83 /* unittest_cycle.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_cycle.proto; sourceTree = "<group>"; };
+ F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPBObjectiveCPlusPlusTest.mm; sourceTree = "<group>"; };
+ F4B6B8AF1A9CC98000892426 /* GPBUnknownField_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B21A9CCBDA00892426 /* GPBUnknownFieldSet_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B61A9CD1DE00892426 /* GPBExtensionInternals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBExtensionInternals.h; sourceTree = "<group>"; };
+ F4B6B8B81A9CD1DE00892426 /* GPBRootObject_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRootObject_PackagePrivate.h; sourceTree = "<group>"; };
+ F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionaryTests.m; sourceTree = "<group>"; };
+ F4CF31701B162ED800BD9B06 /* unittest_objc_startup.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc_startup.proto; sourceTree = "<group>"; };
+ F4E675861B21D0000054530B /* Any.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Any.pbobjc.h; path = google/protobuf/Any.pbobjc.h; sourceTree = "<group>"; };
+ F4E675871B21D0000054530B /* Any.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Any.pbobjc.m; path = google/protobuf/Any.pbobjc.m; sourceTree = "<group>"; };
+ F4E675881B21D0000054530B /* Api.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Api.pbobjc.h; path = google/protobuf/Api.pbobjc.h; sourceTree = "<group>"; };
+ F4E675891B21D0000054530B /* Api.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Api.pbobjc.m; path = google/protobuf/Api.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758A1B21D0000054530B /* Empty.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Empty.pbobjc.h; path = google/protobuf/Empty.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758B1B21D0000054530B /* Empty.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Empty.pbobjc.m; path = google/protobuf/Empty.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758C1B21D0000054530B /* FieldMask.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FieldMask.pbobjc.h; path = google/protobuf/FieldMask.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FieldMask.pbobjc.m; path = google/protobuf/FieldMask.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758E1B21D0000054530B /* SourceContext.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SourceContext.pbobjc.h; path = google/protobuf/SourceContext.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SourceContext.pbobjc.m; path = google/protobuf/SourceContext.pbobjc.m; sourceTree = "<group>"; };
+ F4E675901B21D0000054530B /* Struct.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Struct.pbobjc.h; path = google/protobuf/Struct.pbobjc.h; sourceTree = "<group>"; };
+ F4E675911B21D0000054530B /* Struct.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Struct.pbobjc.m; path = google/protobuf/Struct.pbobjc.m; sourceTree = "<group>"; };
+ F4E675921B21D0000054530B /* Type.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Type.pbobjc.h; path = google/protobuf/Type.pbobjc.h; sourceTree = "<group>"; };
+ F4E675931B21D0000054530B /* Type.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Type.pbobjc.m; path = google/protobuf/Type.pbobjc.m; sourceTree = "<group>"; };
+ F4E675941B21D0000054530B /* Wrappers.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Wrappers.pbobjc.h; path = google/protobuf/Wrappers.pbobjc.h; sourceTree = "<group>"; };
+ F4E675951B21D0000054530B /* Wrappers.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Wrappers.pbobjc.m; path = google/protobuf/Wrappers.pbobjc.m; sourceTree = "<group>"; };
+ F4E675A61B21D05C0054530B /* any.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = any.proto; path = ../src/google/protobuf/any.proto; sourceTree = "<group>"; };
+ F4E675A71B21D05C0054530B /* api.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = api.proto; path = ../src/google/protobuf/api.proto; sourceTree = "<group>"; };
+ F4E675A81B21D05C0054530B /* empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = empty.proto; path = ../src/google/protobuf/empty.proto; sourceTree = "<group>"; };
+ F4E675A91B21D05C0054530B /* field_mask.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = field_mask.proto; path = ../src/google/protobuf/field_mask.proto; sourceTree = "<group>"; };
+ F4E675AA1B21D05C0054530B /* source_context.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = source_context.proto; path = ../src/google/protobuf/source_context.proto; sourceTree = "<group>"; };
+ F4E675AB1B21D05C0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
+ F4E675AC1B21D05C0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
+ F4E675AD1B21D05C0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
+ F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 7461B52C0F94FAF800A0C422 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */,
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C4C1A9F8E0200531423 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C4D1A9F8E0200531423 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 080E96DDFE201D6D7F000001 /* Core Source */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */,
+ F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */,
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */,
+ 7461B3C50F94F84100A0C422 /* Extensions */,
+ 7461B4850F94F96600A0C422 /* Fields */,
+ 7461B4860F94F96B00A0C422 /* IO */,
+ 7461B5150F94FA7300A0C422 /* Messages */,
+ 8BCF334414ED727300BC5317 /* Support */,
+ 29B97315FDCFA39411CA2CEA /* Generated */,
+ );
+ name = "Core Source";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */,
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */,
+ F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
+ isa = PBXGroup;
+ children = (
+ 080E96DDFE201D6D7F000001 /* Core Source */,
+ 7461B6940F94FDDD00A0C422 /* Tests */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = CustomTemplate;
+ sourceTree = "<group>";
+ };
+ 29B97315FDCFA39411CA2CEA /* Generated */ = {
+ isa = PBXGroup;
+ children = (
+ F4E675861B21D0000054530B /* Any.pbobjc.h */,
+ F4E675871B21D0000054530B /* Any.pbobjc.m */,
+ F4E675A61B21D05C0054530B /* any.proto */,
+ F4E675881B21D0000054530B /* Api.pbobjc.h */,
+ F4E675891B21D0000054530B /* Api.pbobjc.m */,
+ F4E675A71B21D05C0054530B /* api.proto */,
+ 8B4248D31A92826400BC1EC6 /* Duration.pbobjc.h */,
+ 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */,
+ 8B42494C1A92A16600BC1EC6 /* duration.proto */,
+ F4E6758A1B21D0000054530B /* Empty.pbobjc.h */,
+ F4E6758B1B21D0000054530B /* Empty.pbobjc.m */,
+ F4E675A81B21D05C0054530B /* empty.proto */,
+ F4E675A91B21D05C0054530B /* field_mask.proto */,
+ F4E6758C1B21D0000054530B /* FieldMask.pbobjc.h */,
+ F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */,
+ F4E675AA1B21D05C0054530B /* source_context.proto */,
+ F4E6758E1B21D0000054530B /* SourceContext.pbobjc.h */,
+ F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */,
+ F4E675901B21D0000054530B /* Struct.pbobjc.h */,
+ F4E675911B21D0000054530B /* Struct.pbobjc.m */,
+ F4E675AB1B21D05C0054530B /* struct.proto */,
+ 8B4248D51A92826400BC1EC6 /* Timestamp.pbobjc.h */,
+ 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */,
+ 8B42494D1A92A16600BC1EC6 /* timestamp.proto */,
+ F4E675921B21D0000054530B /* Type.pbobjc.h */,
+ F4E675931B21D0000054530B /* Type.pbobjc.m */,
+ F4E675AC1B21D05C0054530B /* type.proto */,
+ F4E675941B21D0000054530B /* Wrappers.pbobjc.h */,
+ F4E675951B21D0000054530B /* Wrappers.pbobjc.m */,
+ F4E675AD1B21D05C0054530B /* wrappers.proto */,
+ );
+ name = Generated;
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 1D30AB110D05D00D00671497 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 7461B3C50F94F84100A0C422 /* Extensions */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B61A9CD1DE00892426 /* GPBExtensionInternals.h */,
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */,
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */,
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */,
+ F4B6B8B81A9CD1DE00892426 /* GPBRootObject_PackagePrivate.h */,
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */,
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */,
+ );
+ name = Extensions;
+ sourceTree = "<group>";
+ };
+ 7461B4850F94F96600A0C422 /* Fields */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8AF1A9CC98000892426 /* GPBUnknownField_PackagePrivate.h */,
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */,
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */,
+ F4B6B8B21A9CCBDA00892426 /* GPBUnknownFieldSet_PackagePrivate.h */,
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */,
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */,
+ );
+ name = Fields;
+ sourceTree = "<group>";
+ };
+ 7461B4860F94F96B00A0C422 /* IO */ = {
+ isa = PBXGroup;
+ children = (
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */,
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */,
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */,
+ F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */,
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */,
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */,
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */,
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */,
+ );
+ name = IO;
+ sourceTree = "<group>";
+ };
+ 7461B5150F94FA7300A0C422 /* Messages */ = {
+ isa = PBXGroup;
+ children = (
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */,
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */,
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */,
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */,
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */,
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */,
+ );
+ name = Messages;
+ sourceTree = "<group>";
+ };
+ 7461B6940F94FDDD00A0C422 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ 8B4248B81A8C254000BC1EC6 /* protobuf */,
+ 8B210CCD159383D60032D72D /* golden_message */,
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */,
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */,
+ F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */,
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */,
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */,
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */,
+ F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */,
+ F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */,
+ F4353D2C1AC06F10005A6198 /* GPBDictionaryTests.pddm */,
+ F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */,
+ F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */,
+ F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */,
+ F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */,
+ F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */,
+ F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */,
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
+ F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */,
+ F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */,
+ F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */,
+ F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */,
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */,
+ 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */,
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */,
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */,
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */,
+ F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */,
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */,
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
+ 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */,
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
+ F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */,
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
+ F4AC9E1D1A8BEB3500BD6E83 /* unittest_cycle.proto */,
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */,
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */,
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */,
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */,
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */,
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */,
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */,
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */,
+ F4CF31701B162ED800BD9B06 /* unittest_objc_startup.proto */,
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */,
+ F4487C781AADFB3100531423 /* unittest_runtime_proto2.proto */,
+ F4487C791AADFB3200531423 /* unittest_runtime_proto3.proto */,
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */,
+ 8B4248B91A8C256900BC1EC6 /* UnitTests-Bridging-Header.h */,
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */,
+ );
+ path = Tests;
+ sourceTree = "<group>";
+ };
+ 8BCF334414ED727300BC5317 /* Support */ = {
+ isa = PBXGroup;
+ children = (
+ F4411BE71AF12FD700324B4A /* GPBArray_PackagePrivate.h */,
+ F401DC2A1A8D444600FCC765 /* GPBArray.h */,
+ F401DC2B1A8D444600FCC765 /* GPBArray.m */,
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */,
+ F43725911AC9832D004DCAFB /* GPBDictionary_PackagePrivate.h */,
+ F4353D201ABB1537005A6198 /* GPBDictionary.h */,
+ F4353D211ABB1537005A6198 /* GPBDictionary.m */,
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */,
+ F4487C7C1AAE06AC00531423 /* GPBUtilities_PackagePrivate.h */,
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */,
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */,
+ 8B4248CF1A927E1500BC1EC6 /* GPBWellKnownTypes.h */,
+ 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */,
+ );
+ name = Support;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 7461B52A0F94FAF800A0C422 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C391A9F8E0200531423 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+ F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "$(ACTION)";
+ buildConfigurationList = F45BBC171B0CE3C6002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */;
+ buildPhases = (
+ );
+ buildToolPath = DevTools/compile_testing_protos.sh;
+ dependencies = (
+ );
+ name = "Compile Unittest Protos";
+ passBuildSettingsInEnvironment = 1;
+ productName = "Compile Unittest Protos";
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */;
+ buildPhases = (
+ 7461B52A0F94FAF800A0C422 /* Headers */,
+ 7461B52B0F94FAF800A0C422 /* Sources */,
+ 7461B52C0F94FAF800A0C422 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = ProtocolBuffers;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
+ buildPhases = (
+ F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */,
+ 8BBEA4A1147C727100C4ADB7 /* Resources */,
+ 8BBEA4A2147C727100C4ADB7 /* Sources */,
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */,
+ F45BBC191B0CE3D7002D064D /* PBXTargetDependency */,
+ );
+ name = UnitTests;
+ productName = UnitTests;
+ productReference = 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */;
+ productType = "com.apple.product-type.bundle.unit-test";
+ };
+ F4487C381A9F8E0200531423 /* TestSingleSourceBuild */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4487C4E1A9F8E0200531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */;
+ buildPhases = (
+ F4487C391A9F8E0200531423 /* Headers */,
+ F4487C3D1A9F8E0200531423 /* Sources */,
+ F4487C4C1A9F8E0200531423 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = TestSingleSourceBuild;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastSwiftUpdateCheck = 0710;
+ LastTestingUpgradeCheck = 0600;
+ LastUpgradeCheck = 0800;
+ TargetAttributes = {
+ 8BBEA4A5147C727100C4ADB7 = {
+ LastSwiftMigration = 0800;
+ TestTargetID = 8B9A5EA41831993600A9D33B;
+ };
+ F45BBC141B0CE3C6002D064D = {
+ CreatedOnToolsVersion = 6.3.2;
+ };
+ };
+ };
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_OSX" */;
+ compatibilityVersion = "Xcode 6.3";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */,
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */,
+ F4487C381A9F8E0200531423 /* TestSingleSourceBuild */,
+ F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8BBEA4A1147C727100C4ADB7 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B210CCE159383D60032D72D /* golden_message in Resources */,
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
+ F45E57C71AE6DC6A000B7D99 /* text_format_map_unittest_data.txt in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Script: Check Runtime Stamps";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 7461B52B0F94FAF800A0C422 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
+ F4E6759B1B21D0000054530B /* Empty.pbobjc.m in Sources */,
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */,
+ F401DC2D1A8D444600FCC765 /* GPBArray.m in Sources */,
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */,
+ F4E6759D1B21D0000054530B /* FieldMask.pbobjc.m in Sources */,
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */,
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */,
+ F47476E51D21A524007C7B1A /* Duration.pbobjc.m in Sources */,
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */,
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */,
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */,
+ F4E675991B21D0000054530B /* Api.pbobjc.m in Sources */,
+ F4E6759F1B21D0000054530B /* SourceContext.pbobjc.m in Sources */,
+ F4353D231ABB1537005A6198 /* GPBDictionary.m in Sources */,
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */,
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */,
+ F4E675971B21D0000054530B /* Any.pbobjc.m in Sources */,
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */,
+ 8B4248D21A927E1500BC1EC6 /* GPBWellKnownTypes.m in Sources */,
+ F4E675A31B21D0000054530B /* Type.pbobjc.m in Sources */,
+ F4E675A11B21D0000054530B /* Struct.pbobjc.m in Sources */,
+ F4E675A51B21D0000054530B /* Wrappers.pbobjc.m in Sources */,
+ F47476E61D21A524007C7B1A /* Timestamp.pbobjc.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A2147C727100C4ADB7 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */,
+ F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */,
+ F4353D361AC06F10005A6198 /* GPBDictionaryTests+Int64.m in Sources */,
+ F4353D391AC06F10005A6198 /* GPBDictionaryTests+UInt64.m in Sources */,
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */,
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */,
+ F4B51B1E1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
+ F4487C7F1AAF62CD00531423 /* GPBMessageTests+Serialization.m in Sources */,
+ 8B4248DC1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m in Sources */,
+ F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */,
+ F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */,
+ 8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */,
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
+ F4487C751AADF7F500531423 /* GPBMessageTests+Runtime.m in Sources */,
+ F4353D351AC06F10005A6198 /* GPBDictionaryTests+Int32.m in Sources */,
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */,
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */,
+ F4353D341AC06F10005A6198 /* GPBDictionaryTests+Bool.m in Sources */,
+ F4487C831AAF6AB300531423 /* GPBMessageTests+Merge.m in Sources */,
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */,
+ F4353D371AC06F10005A6198 /* GPBDictionaryTests+String.m in Sources */,
+ F4353D381AC06F10005A6198 /* GPBDictionaryTests+UInt32.m in Sources */,
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */,
+ F4C4B9E41E1D976300D3B61D /* GPBDictionaryTests.m in Sources */,
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */,
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C3D1A9F8E0200531423 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C521A9F8E4D00531423 /* GPBProtocolBuffers.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */;
+ targetProxy = 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */;
+ };
+ F45BBC191B0CE3D7002D064D /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */;
+ targetProxy = F45BBC181B0CE3D7002D064D /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+ 7461B52F0F94FAFA00A0C422 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ };
+ name = Debug;
+ };
+ 7461B5300F94FAFA00A0C422 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ };
+ name = Release;
+ };
+ 8BBEA4A7147C727100C4ADB7 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Debug;
+ };
+ 8BBEA4A8147C727100C4ADB7 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ MACOSX_DEPLOYMENT_TARGET = 10.9;
+ ONLY_ACTIVE_ARCH = YES;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = macosx;
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ MACOSX_DEPLOYMENT_TARGET = 10.9;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = macosx;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Release;
+ };
+ F4487C4F1A9F8E0200531423 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ };
+ name = Debug;
+ };
+ F4487C501A9F8E0200531423 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ };
+ name = Release;
+ };
+ F45BBC151B0CE3C6002D064D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ F45BBC161B0CE3C6002D064D /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7461B52F0F94FAFA00A0C422 /* Debug */,
+ 7461B5300F94FAFA00A0C422 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8BBEA4A7147C727100C4ADB7 /* Debug */,
+ 8BBEA4A8147C727100C4ADB7 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_OSX" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4487C4E1A9F8E0200531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4487C4F1A9F8E0200531423 /* Debug */,
+ F4487C501A9F8E0200531423 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F45BBC171B0CE3C6002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F45BBC151B0CE3C6002D064D /* Debug */,
+ F45BBC161B0CE3C6002D064D /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..888be4da13
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:ProtocolBuffers_OSX.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
new file mode 100644
index 0000000000..08de0be8d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
+ <false/>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
new file mode 100644
index 0000000000..2f6181316a
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
@@ -0,0 +1,335 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "CodedInputStreamTests">
+ </Test>
+ <Test
+ Identifier = "CodedOutputStreamTests">
+ </Test>
+ <Test
+ Identifier = "ConcurrencyTests">
+ </Test>
+ <Test
+ Identifier = "DescriptorTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBridgeTests">
+ </Test>
+ <Test
+ Identifier = "GPBDoubleArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayCustomTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBFloatArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBObjectiveCPlusPlusTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBTestCase">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "MessageMergeTests">
+ </Test>
+ <Test
+ Identifier = "MessageRuntimeTests">
+ </Test>
+ <Test
+ Identifier = "MessageSerializationTests">
+ </Test>
+ <Test
+ Identifier = "MessageTests">
+ </Test>
+ <Test
+ Identifier = "UnknownFieldSetTest">
+ </Test>
+ <Test
+ Identifier = "UtilitiesTests">
+ </Test>
+ <Test
+ Identifier = "WellKnownTypesTest">
+ </Test>
+ <Test
+ Identifier = "WireFormatTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Release">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
new file mode 100644
index 0000000000..b1243b79b2
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "NO">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4487C381A9F8E0200531423"
+ BuildableName = "libTestSingleSourceBuild.a"
+ BlueprintName = "TestSingleSourceBuild"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "NO"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ codeCoverageEnabled = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "PerfTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..64fc45c0e2
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
@@ -0,0 +1,1167 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 47;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */; };
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */; };
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */; };
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4BF0F94F99000A0C422 /* GPBMessage.m */; };
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */; };
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E60F94F99000A0C422 /* GPBUtilities.m */; };
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */; };
+ 8B210CCE159383D60032D72D /* golden_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCD159383D60032D72D /* golden_message */; };
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCF159386920032D72D /* golden_packed_fields_message */; };
+ 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */; };
+ 8B4248E41A929C8900BC1EC6 /* GPBWellKnownTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */; };
+ 8B4248E61A929C9900BC1EC6 /* GPBWellKnownTypesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */; };
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
+ 8B9742331A89D19F00DCE92C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */; };
+ 8B9742431A8AAA7800DCE92C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */; };
+ 8B9A5EA61831993600A9D33B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 8B9A5EA81831993600A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; };
+ 8B9A5EAE1831993600A9D33B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */; };
+ 8B9A5EB41831993600A9D33B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B9A5EB31831993600A9D33B /* AppDelegate.m */; };
+ 8B9A5EB61831993600A9D33B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8B9A5EB51831993600A9D33B /* Images.xcassets */; };
+ 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; };
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; };
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; };
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; };
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; };
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; };
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */; };
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */; };
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */; };
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; };
+ F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */; };
+ F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D251ABB156F005A6198 /* GPBDictionary.m */; };
+ F4353D421AC06F31005A6198 /* GPBDictionaryTests+Bool.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */; };
+ F4353D431AC06F31005A6198 /* GPBDictionaryTests+Int32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */; };
+ F4353D441AC06F31005A6198 /* GPBDictionaryTests+Int64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */; };
+ F4353D451AC06F31005A6198 /* GPBDictionaryTests+String.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */; };
+ F4353D461AC06F31005A6198 /* GPBDictionaryTests+UInt32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */; };
+ F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */; };
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */; };
+ F4487C6A1A9F8F8100531423 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F4487C6F1A9F8FFF00531423 /* GPBProtocolBuffers.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */; };
+ F4487C731A9F906200531423 /* GPBArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C711A9F906200531423 /* GPBArray.m */; };
+ F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */; };
+ F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */; };
+ F4487C851AAF6AC500531423 /* GPBMessageTests+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */; };
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */; };
+ F45E57C91AE6DC98000B7D99 /* text_format_map_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */; };
+ F47476E91D21A537007C7B1A /* Duration.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */; };
+ F47476EA1D21A537007C7B1A /* Timestamp.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */; };
+ F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */; };
+ F4C4B9E71E1D97BF00D3B61D /* GPBDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */; };
+ F4E675D01B21D1620054530B /* Any.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675B71B21D1440054530B /* Any.pbobjc.m */; };
+ F4E675D11B21D1620054530B /* Api.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675B91B21D1440054530B /* Api.pbobjc.m */; };
+ F4E675D21B21D1620054530B /* Empty.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675BC1B21D1440054530B /* Empty.pbobjc.m */; };
+ F4E675D31B21D1620054530B /* FieldMask.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */; };
+ F4E675D41B21D1620054530B /* SourceContext.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */; };
+ F4E675D51B21D1620054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C21B21D1440054530B /* Struct.pbobjc.m */; };
+ F4E675D61B21D1620054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C51B21D1440054530B /* Type.pbobjc.m */; };
+ F4E675D71B21D1620054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */; };
+ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 8B9A5ED01831994600A9D33B /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 8B9A5EA41831993600A9D33B;
+ remoteInfo = iOSTestHarness;
+ };
+ 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 7461B52D0F94FAF800A0C422;
+ remoteInfo = ProtocolBuffers;
+ };
+ F45BBC121B0CDBBA002D064D /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = F45BBC0E1B0CDB50002D064D;
+ remoteInfo = "Compile Unittest Protos";
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBConcurrencyTests.m; sourceTree = "<group>"; };
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor_PackagePrivate.h; sourceTree = "<group>"; };
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBMessage_PackagePrivate.h; sourceTree = "<group>"; };
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTests-Info.plist"; sourceTree = "<group>"; };
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBBootstrap.h; sourceTree = "<group>"; };
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream.h; sourceTree = "<group>"; };
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GPBCodedInputStream.m; sourceTree = "<group>"; };
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream.h; sourceTree = "<group>"; };
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStream.m; sourceTree = "<group>"; };
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBExtensionRegistry.h; sourceTree = "<group>"; };
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionRegistry.m; sourceTree = "<group>"; };
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField.h; sourceTree = "<group>"; };
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownField.m; sourceTree = "<group>"; };
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBMessage.h; sourceTree = "<group>"; };
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessage.m; sourceTree = "<group>"; };
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers.h; sourceTree = "<group>"; };
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet.h; sourceTree = "<group>"; };
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSet.m; sourceTree = "<group>"; };
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUtilities.h; sourceTree = "<group>"; };
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilities.m; sourceTree = "<group>"; };
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWireFormat.h; sourceTree = "<group>"; };
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = "<group>"; };
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = "<group>"; };
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = "<group>"; };
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = "<group>"; };
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = "<group>"; };
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = "<group>"; };
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSetTest.m; sourceTree = "<group>"; };
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilitiesTests.m; sourceTree = "<group>"; };
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormatTests.m; sourceTree = "<group>"; };
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc.proto; sourceTree = "<group>"; };
+ 8B210CCD159383D60032D72D /* golden_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_message; sourceTree = "<group>"; };
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_packed_fields_message; sourceTree = "<group>"; };
+ 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = "<group>"; };
+ 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPBSwiftTests.swift; sourceTree = "<group>"; };
+ 8B4248B71A8BDD9600BC1EC6 /* protobuf */ = {isa = PBXFileReference; lastKnownFileType = text; name = protobuf; path = ../../Intermediates/ProtocolBuffers_iOS.build/DerivedSources/protos/google/protobuf; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B4248DD1A929C7D00BC1EC6 /* Duration.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Duration.pbobjc.h; path = google/protobuf/Duration.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Duration.pbobjc.m; path = google/protobuf/Duration.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Timestamp.pbobjc.m; path = google/protobuf/Timestamp.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248E11A929C8900BC1EC6 /* GPBWellKnownTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWellKnownTypes.h; sourceTree = "<group>"; };
+ 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypes.m; sourceTree = "<group>"; };
+ 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
+ 8B4249481A92A02300BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
+ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = "<group>"; };
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = "<group>"; };
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = "<group>"; };
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = "<group>"; };
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = "<group>"; };
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = "<group>"; };
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = "<group>"; };
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = "<group>"; };
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = "<group>"; };
+ 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
+ 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+ 8B9A5E9F1831913D00A9D33B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSTestHarness.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B9A5EAB1831993600A9D33B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ 8B9A5EAD1831993600A9D33B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 8B9A5EB31831993600A9D33B /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 8B9A5EB51831993600A9D33B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = "<group>"; };
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
+ F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = "<group>"; };
+ F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = "<group>"; };
+ F4353D241ABB156F005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = "<group>"; };
+ F4353D251ABB156F005A6198 /* GPBDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionary.m; sourceTree = "<group>"; };
+ F4353D3A1AC06F31005A6198 /* GPBDictionaryTests.pddm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GPBDictionaryTests.pddm; sourceTree = "<group>"; };
+ F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Bool.m"; sourceTree = "<group>"; };
+ F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int32.m"; sourceTree = "<group>"; };
+ F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int64.m"; sourceTree = "<group>"; };
+ F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+String.m"; sourceTree = "<group>"; };
+ F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt32.m"; sourceTree = "<group>"; };
+ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt64.m"; sourceTree = "<group>"; };
+ F43725921AC9835D004DCAFB /* GPBDictionary_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDictionary_PackagePrivate.h; sourceTree = "<group>"; };
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_unittest_data.txt; sourceTree = "<group>"; };
+ F4411BE81AF1301700324B4A /* GPBArray_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBArray_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTestSingleSourceBuild.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4487C701A9F906200531423 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
+ F4487C711A9F906200531423 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
+ F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Runtime.m"; sourceTree = "<group>"; };
+ F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto2.proto; sourceTree = "<group>"; };
+ F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto3.proto; sourceTree = "<group>"; };
+ F4487C7D1AAE06C500531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; };
+ F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; };
+ F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; };
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; };
+ F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; };
+ F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_cycle.proto; sourceTree = "<group>"; };
+ F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPBObjectiveCPlusPlusTest.mm; sourceTree = "<group>"; };
+ F4B6B8B01A9CC99500892426 /* GPBUnknownField_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B11A9CCBBB00892426 /* GPBUnknownFieldSet_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B31A9CD1C600892426 /* GPBExtensionInternals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBExtensionInternals.h; sourceTree = "<group>"; };
+ F4B6B8B51A9CD1C600892426 /* GPBRootObject_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRootObject_PackagePrivate.h; sourceTree = "<group>"; };
+ F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionaryTests.m; sourceTree = "<group>"; };
+ F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc_startup.proto; sourceTree = "<group>"; };
+ F4E675B61B21D1440054530B /* Any.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Any.pbobjc.h; path = google/protobuf/Any.pbobjc.h; sourceTree = "<group>"; };
+ F4E675B71B21D1440054530B /* Any.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Any.pbobjc.m; path = google/protobuf/Any.pbobjc.m; sourceTree = "<group>"; };
+ F4E675B81B21D1440054530B /* Api.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Api.pbobjc.h; path = google/protobuf/Api.pbobjc.h; sourceTree = "<group>"; };
+ F4E675B91B21D1440054530B /* Api.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Api.pbobjc.m; path = google/protobuf/Api.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BB1B21D1440054530B /* Empty.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Empty.pbobjc.h; path = google/protobuf/Empty.pbobjc.h; sourceTree = "<group>"; };
+ F4E675BC1B21D1440054530B /* Empty.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Empty.pbobjc.m; path = google/protobuf/Empty.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BD1B21D1440054530B /* FieldMask.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FieldMask.pbobjc.h; path = google/protobuf/FieldMask.pbobjc.h; sourceTree = "<group>"; };
+ F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FieldMask.pbobjc.m; path = google/protobuf/FieldMask.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BF1B21D1440054530B /* SourceContext.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SourceContext.pbobjc.h; path = google/protobuf/SourceContext.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SourceContext.pbobjc.m; path = google/protobuf/SourceContext.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C11B21D1440054530B /* Struct.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Struct.pbobjc.h; path = google/protobuf/Struct.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C21B21D1440054530B /* Struct.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Struct.pbobjc.m; path = google/protobuf/Struct.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C31B21D1440054530B /* Timestamp.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Timestamp.pbobjc.h; path = google/protobuf/Timestamp.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C41B21D1440054530B /* Type.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Type.pbobjc.h; path = google/protobuf/Type.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C51B21D1440054530B /* Type.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Type.pbobjc.m; path = google/protobuf/Type.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C61B21D1440054530B /* Wrappers.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Wrappers.pbobjc.h; path = google/protobuf/Wrappers.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Wrappers.pbobjc.m; path = google/protobuf/Wrappers.pbobjc.m; sourceTree = "<group>"; };
+ F4E675D81B21D1DE0054530B /* any.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = any.proto; path = ../src/google/protobuf/any.proto; sourceTree = "<group>"; };
+ F4E675D91B21D1DE0054530B /* api.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = api.proto; path = ../src/google/protobuf/api.proto; sourceTree = "<group>"; };
+ F4E675DA1B21D1DE0054530B /* empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = empty.proto; path = ../src/google/protobuf/empty.proto; sourceTree = "<group>"; };
+ F4E675DB1B21D1DE0054530B /* field_mask.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = field_mask.proto; path = ../src/google/protobuf/field_mask.proto; sourceTree = "<group>"; };
+ F4E675DC1B21D1DE0054530B /* source_context.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = source_context.proto; path = ../src/google/protobuf/source_context.proto; sourceTree = "<group>"; };
+ F4E675DD1B21D1DE0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
+ F4E675DE1B21D1DE0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
+ F4E675DF1B21D1DE0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
+ F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 7461B52C0F94FAF800A0C422 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8B9A5EA21831993600A9D33B /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9742431A8AAA7800DCE92C /* CoreGraphics.framework in Frameworks */,
+ 8B9A5EA81831993600A9D33B /* UIKit.framework in Frameworks */,
+ 8B9A5EA61831993600A9D33B /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */,
+ 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */,
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C691A9F8F8100531423 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C6A1A9F8F8100531423 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 080E96DDFE201D6D7F000001 /* Core Source */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */,
+ F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */,
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */,
+ 7461B3C50F94F84100A0C422 /* Extensions */,
+ 7461B4850F94F96600A0C422 /* Fields */,
+ 7461B4860F94F96B00A0C422 /* IO */,
+ 7461B5150F94FA7300A0C422 /* Messages */,
+ 8BCF334414ED727300BC5317 /* Support */,
+ 29B97315FDCFA39411CA2CEA /* Generated */,
+ );
+ name = "Core Source";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */,
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */,
+ 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */,
+ F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
+ isa = PBXGroup;
+ children = (
+ 080E96DDFE201D6D7F000001 /* Core Source */,
+ 7461B6940F94FDDD00A0C422 /* Tests */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = CustomTemplate;
+ sourceTree = "<group>";
+ };
+ 29B97315FDCFA39411CA2CEA /* Generated */ = {
+ isa = PBXGroup;
+ children = (
+ F4E675B61B21D1440054530B /* Any.pbobjc.h */,
+ F4E675B71B21D1440054530B /* Any.pbobjc.m */,
+ F4E675D81B21D1DE0054530B /* any.proto */,
+ F4E675B81B21D1440054530B /* Api.pbobjc.h */,
+ F4E675B91B21D1440054530B /* Api.pbobjc.m */,
+ F4E675D91B21D1DE0054530B /* api.proto */,
+ 8B4248DD1A929C7D00BC1EC6 /* Duration.pbobjc.h */,
+ 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */,
+ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */,
+ F4E675BB1B21D1440054530B /* Empty.pbobjc.h */,
+ F4E675BC1B21D1440054530B /* Empty.pbobjc.m */,
+ F4E675DA1B21D1DE0054530B /* empty.proto */,
+ F4E675DB1B21D1DE0054530B /* field_mask.proto */,
+ F4E675BD1B21D1440054530B /* FieldMask.pbobjc.h */,
+ F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */,
+ F4E675DC1B21D1DE0054530B /* source_context.proto */,
+ F4E675BF1B21D1440054530B /* SourceContext.pbobjc.h */,
+ F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */,
+ F4E675C11B21D1440054530B /* Struct.pbobjc.h */,
+ F4E675C21B21D1440054530B /* Struct.pbobjc.m */,
+ F4E675DD1B21D1DE0054530B /* struct.proto */,
+ F4E675C31B21D1440054530B /* Timestamp.pbobjc.h */,
+ 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */,
+ 8B4249481A92A02300BC1EC6 /* timestamp.proto */,
+ F4E675C41B21D1440054530B /* Type.pbobjc.h */,
+ F4E675C51B21D1440054530B /* Type.pbobjc.m */,
+ F4E675DE1B21D1DE0054530B /* type.proto */,
+ F4E675C61B21D1440054530B /* Wrappers.pbobjc.h */,
+ F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */,
+ F4E675DF1B21D1DE0054530B /* wrappers.proto */,
+ );
+ name = Generated;
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */,
+ 8B9A5E9F1831913D00A9D33B /* UIKit.framework */,
+ 1D30AB110D05D00D00671497 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 7461B3C50F94F84100A0C422 /* Extensions */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B31A9CD1C600892426 /* GPBExtensionInternals.h */,
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */,
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */,
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */,
+ F4B6B8B51A9CD1C600892426 /* GPBRootObject_PackagePrivate.h */,
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */,
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */,
+ );
+ name = Extensions;
+ sourceTree = "<group>";
+ };
+ 7461B4850F94F96600A0C422 /* Fields */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B01A9CC99500892426 /* GPBUnknownField_PackagePrivate.h */,
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */,
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */,
+ F4B6B8B11A9CCBBB00892426 /* GPBUnknownFieldSet_PackagePrivate.h */,
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */,
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */,
+ );
+ name = Fields;
+ sourceTree = "<group>";
+ };
+ 7461B4860F94F96B00A0C422 /* IO */ = {
+ isa = PBXGroup;
+ children = (
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */,
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */,
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */,
+ F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */,
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */,
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */,
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */,
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */,
+ );
+ name = IO;
+ sourceTree = "<group>";
+ };
+ 7461B5150F94FA7300A0C422 /* Messages */ = {
+ isa = PBXGroup;
+ children = (
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */,
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */,
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */,
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */,
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */,
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */,
+ );
+ name = Messages;
+ sourceTree = "<group>";
+ };
+ 7461B6940F94FDDD00A0C422 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EA91831993600A9D33B /* iOSTestHarness */,
+ 8B4248B71A8BDD9600BC1EC6 /* protobuf */,
+ 8B210CCD159383D60032D72D /* golden_message */,
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */,
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */,
+ F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */,
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */,
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */,
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */,
+ F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */,
+ F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */,
+ F4353D3A1AC06F31005A6198 /* GPBDictionaryTests.pddm */,
+ F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */,
+ F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */,
+ F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */,
+ F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */,
+ F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */,
+ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */,
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
+ F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */,
+ F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */,
+ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */,
+ F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */,
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */,
+ 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */,
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */,
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */,
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */,
+ F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */,
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */,
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
+ 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */,
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
+ F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */,
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
+ F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */,
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */,
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */,
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */,
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */,
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */,
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */,
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */,
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */,
+ F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */,
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */,
+ F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */,
+ F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */,
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */,
+ 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */,
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */,
+ );
+ path = Tests;
+ sourceTree = "<group>";
+ };
+ 8B9A5EA91831993600A9D33B /* iOSTestHarness */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EB31831993600A9D33B /* AppDelegate.m */,
+ 8B9A5EB51831993600A9D33B /* Images.xcassets */,
+ 8B9A5EAA1831993600A9D33B /* Supporting Files */,
+ 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */,
+ );
+ path = iOSTestHarness;
+ sourceTree = "<group>";
+ };
+ 8B9A5EAA1831993600A9D33B /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EAB1831993600A9D33B /* Info.plist */,
+ 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ 8BCF334414ED727300BC5317 /* Support */ = {
+ isa = PBXGroup;
+ children = (
+ F4411BE81AF1301700324B4A /* GPBArray_PackagePrivate.h */,
+ F4487C701A9F906200531423 /* GPBArray.h */,
+ F4487C711A9F906200531423 /* GPBArray.m */,
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */,
+ F43725921AC9835D004DCAFB /* GPBDictionary_PackagePrivate.h */,
+ F4353D241ABB156F005A6198 /* GPBDictionary.h */,
+ F4353D251ABB156F005A6198 /* GPBDictionary.m */,
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */,
+ F4487C7D1AAE06C500531423 /* GPBUtilities_PackagePrivate.h */,
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */,
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */,
+ 8B4248E11A929C8900BC1EC6 /* GPBWellKnownTypes.h */,
+ 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */,
+ );
+ name = Support;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 7461B52A0F94FAF800A0C422 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C561A9F8F8100531423 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+ F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "$(ACTION)";
+ buildConfigurationList = F45BBC111B0CDB50002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */;
+ buildPhases = (
+ );
+ buildToolPath = DevTools/compile_testing_protos.sh;
+ buildWorkingDirectory = "";
+ dependencies = (
+ );
+ name = "Compile Unittest Protos";
+ passBuildSettingsInEnvironment = 1;
+ productName = "Compile Unittest Protos";
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */;
+ buildPhases = (
+ 7461B52A0F94FAF800A0C422 /* Headers */,
+ 7461B52B0F94FAF800A0C422 /* Sources */,
+ 7461B52C0F94FAF800A0C422 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = ProtocolBuffers;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+ 8B9A5EA41831993600A9D33B /* iOSTestHarness */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8B9A5ECA1831993600A9D33B /* Build configuration list for PBXNativeTarget "iOSTestHarness" */;
+ buildPhases = (
+ 8B9A5EA11831993600A9D33B /* Sources */,
+ 8B9A5EA21831993600A9D33B /* Frameworks */,
+ 8B9A5EA31831993600A9D33B /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = iOSTestHarness;
+ productName = iOSTestHarness;
+ productReference = 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */;
+ productType = "com.apple.product-type.application";
+ };
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
+ buildPhases = (
+ F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */,
+ 8BBEA4A1147C727100C4ADB7 /* Resources */,
+ 8BBEA4A2147C727100C4ADB7 /* Sources */,
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */,
+ F45BBC131B0CDBBA002D064D /* PBXTargetDependency */,
+ 8B9A5ED11831994600A9D33B /* PBXTargetDependency */,
+ );
+ name = UnitTests;
+ productName = UnitTests;
+ productReference = 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */;
+ productType = "com.apple.product-type.bundle.unit-test";
+ };
+ F4487C551A9F8F8100531423 /* TestSingleSourceBuild */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4487C6B1A9F8F8100531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */;
+ buildPhases = (
+ F4487C561A9F8F8100531423 /* Headers */,
+ F4487C5A1A9F8F8100531423 /* Sources */,
+ F4487C691A9F8F8100531423 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = TestSingleSourceBuild;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastSwiftUpdateCheck = 0710;
+ LastTestingUpgradeCheck = 0600;
+ LastUpgradeCheck = 0800;
+ TargetAttributes = {
+ 8BBEA4A5147C727100C4ADB7 = {
+ LastSwiftMigration = 0800;
+ TestTargetID = 8B9A5EA41831993600A9D33B;
+ };
+ F45BBC0E1B0CDB50002D064D = {
+ CreatedOnToolsVersion = 6.3.2;
+ };
+ };
+ };
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_iOS" */;
+ compatibilityVersion = "Xcode 6.3";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */,
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */,
+ 8B9A5EA41831993600A9D33B /* iOSTestHarness */,
+ F4487C551A9F8F8100531423 /* TestSingleSourceBuild */,
+ F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8B9A5EA31831993600A9D33B /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9A5EAE1831993600A9D33B /* InfoPlist.strings in Resources */,
+ 8B9A5EB61831993600A9D33B /* Images.xcassets in Resources */,
+ 8B9742331A89D19F00DCE92C /* LaunchScreen.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A1147C727100C4ADB7 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B210CCE159383D60032D72D /* golden_message in Resources */,
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
+ F45E57C91AE6DC98000B7D99 /* text_format_map_unittest_data.txt in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Script: Check Runtime Stamps";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 7461B52B0F94FAF800A0C422 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
+ F4E675D21B21D1620054530B /* Empty.pbobjc.m in Sources */,
+ F4487C731A9F906200531423 /* GPBArray.m in Sources */,
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */,
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */,
+ F4E675D31B21D1620054530B /* FieldMask.pbobjc.m in Sources */,
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */,
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */,
+ F47476E91D21A537007C7B1A /* Duration.pbobjc.m in Sources */,
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */,
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */,
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */,
+ F4E675D11B21D1620054530B /* Api.pbobjc.m in Sources */,
+ F4E675D41B21D1620054530B /* SourceContext.pbobjc.m in Sources */,
+ F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */,
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */,
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */,
+ F4E675D01B21D1620054530B /* Any.pbobjc.m in Sources */,
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */,
+ 8B4248E41A929C8900BC1EC6 /* GPBWellKnownTypes.m in Sources */,
+ F4E675D61B21D1620054530B /* Type.pbobjc.m in Sources */,
+ F4E675D51B21D1620054530B /* Struct.pbobjc.m in Sources */,
+ F4E675D71B21D1620054530B /* Wrappers.pbobjc.m in Sources */,
+ F47476EA1D21A537007C7B1A /* Timestamp.pbobjc.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8B9A5EA11831993600A9D33B /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9A5EB41831993600A9D33B /* AppDelegate.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A2147C727100C4ADB7 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */,
+ F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */,
+ F4353D441AC06F31005A6198 /* GPBDictionaryTests+Int64.m in Sources */,
+ F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */,
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */,
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */,
+ F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */,
+ 8B4248E61A929C9900BC1EC6 /* GPBWellKnownTypesTest.m in Sources */,
+ F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */,
+ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */,
+ F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
+ 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */,
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
+ F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */,
+ F4353D431AC06F31005A6198 /* GPBDictionaryTests+Int32.m in Sources */,
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */,
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */,
+ F4353D421AC06F31005A6198 /* GPBDictionaryTests+Bool.m in Sources */,
+ F4487C851AAF6AC500531423 /* GPBMessageTests+Merge.m in Sources */,
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */,
+ F4353D451AC06F31005A6198 /* GPBDictionaryTests+String.m in Sources */,
+ F4353D461AC06F31005A6198 /* GPBDictionaryTests+UInt32.m in Sources */,
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */,
+ F4C4B9E71E1D97BF00D3B61D /* GPBDictionaryTests.m in Sources */,
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */,
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C5A1A9F8F8100531423 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C6F1A9F8FFF00531423 /* GPBProtocolBuffers.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 8B9A5ED11831994600A9D33B /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 8B9A5EA41831993600A9D33B /* iOSTestHarness */;
+ targetProxy = 8B9A5ED01831994600A9D33B /* PBXContainerItemProxy */;
+ };
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */;
+ targetProxy = 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */;
+ };
+ F45BBC131B0CDBBA002D064D /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */;
+ targetProxy = F45BBC121B0CDBBA002D064D /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin PBXVariantGroup section */
+ 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 8B9A5EAD1831993600A9D33B /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 7461B52F0F94FAFA00A0C422 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ 7461B5300F94FAFA00A0C422 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+ 8B9A5ECB1831993600A9D33B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Tests/iOSTestHarness/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ 8B9A5ECC1831993600A9D33B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Tests/iOSTestHarness/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+ 8BBEA4A7147C727100C4ADB7 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "\"$(SDKROOT)/Developer/Library/Frameworks\"",
+ "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
+ "$(inherited)",
+ );
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(DEVELOPER_DIR)/usr/lib\"",
+ );
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Debug;
+ };
+ 8BBEA4A8147C727100C4ADB7 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "\"$(SDKROOT)/Developer/Library/Frameworks\"",
+ "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
+ "$(inherited)",
+ );
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(DEVELOPER_DIR)/usr/lib\"",
+ );
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ ONLY_ACTIVE_ARCH = YES;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = iphoneos;
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Release;
+ };
+ F4487C6C1A9F8F8100531423 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ F4487C6D1A9F8F8100531423 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+ F45BBC0F1B0CDB50002D064D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ F45BBC101B0CDB50002D064D /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7461B52F0F94FAFA00A0C422 /* Debug */,
+ 7461B5300F94FAFA00A0C422 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8B9A5ECA1831993600A9D33B /* Build configuration list for PBXNativeTarget "iOSTestHarness" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8B9A5ECB1831993600A9D33B /* Debug */,
+ 8B9A5ECC1831993600A9D33B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8BBEA4A7147C727100C4ADB7 /* Debug */,
+ 8BBEA4A8147C727100C4ADB7 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_iOS" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4487C6B1A9F8F8100531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4487C6C1A9F8F8100531423 /* Debug */,
+ F4487C6D1A9F8F8100531423 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F45BBC111B0CDB50002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F45BBC0F1B0CDB50002D064D /* Debug */,
+ F45BBC101B0CDB50002D064D /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..037a91dfae
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:ProtocolBuffers_iOS.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
new file mode 100644
index 0000000000..08de0be8d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
+ <false/>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
new file mode 100644
index 0000000000..be31c30831
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
@@ -0,0 +1,345 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "CodedInputStreamTests">
+ </Test>
+ <Test
+ Identifier = "CodedOutputStreamTests">
+ </Test>
+ <Test
+ Identifier = "ConcurrencyTests">
+ </Test>
+ <Test
+ Identifier = "DescriptorTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBridgeTests">
+ </Test>
+ <Test
+ Identifier = "GPBDoubleArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayCustomTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBFloatArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBObjectiveCPlusPlusTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBTestCase">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "MessageMergeTests">
+ </Test>
+ <Test
+ Identifier = "MessageRuntimeTests">
+ </Test>
+ <Test
+ Identifier = "MessageSerializationTests">
+ </Test>
+ <Test
+ Identifier = "MessageTests">
+ </Test>
+ <Test
+ Identifier = "UnknownFieldSetTest">
+ </Test>
+ <Test
+ Identifier = "UtilitiesTests">
+ </Test>
+ <Test
+ Identifier = "WellKnownTypesTest">
+ </Test>
+ <Test
+ Identifier = "WireFormatTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Release">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
new file mode 100644
index 0000000000..edbe689822
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "NO">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4487C551A9F8F8100531423"
+ BuildableName = "libTestSingleSourceBuild.a"
+ BlueprintName = "TestSingleSourceBuild"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "NO"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ codeCoverageEnabled = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "PerfTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/README.md b/third_party/protobuf/objectivec/README.md
new file mode 100644
index 0000000000..7226f0b9a1
--- /dev/null
+++ b/third_party/protobuf/objectivec/README.md
@@ -0,0 +1,188 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Objective C Protocol Buffers runtime library.
+
+Requirements
+------------
+
+The Objective C implementation requires:
+
+- Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X).
+- Xcode 7.0 (or later).
+- The library code does *not* use ARC (for performance reasons), but it all can
+ be called from ARC code.
+
+Installation
+------------
+
+The full distribution pulled from github includes the sources for both the
+compiler (protoc) and the runtime (this directory). To build the compiler
+and run the runtime tests, you can use:
+
+ $ objectivec/DevTools/full_mac_build.sh
+
+This will generate the `src/protoc` binary.
+
+Building
+--------
+
+There are two ways to include the Runtime sources in your project:
+
+Add `objectivec/\*.h` & `objectivec/GPBProtocolBuffers.m` to your project.
+
+*or*
+
+Add `objectivec/\*.h` & `objectivec/\*.m` except for
+`objectivec/GPBProtocolBuffers.m` to your project.
+
+
+If the target is using ARC, remember to turn off ARC (`-fno-objc-arc`) for the
+`.m` files.
+
+The files generated by `protoc` for the `*.proto` files (`\*.pbobjc.h` and
+`\*.pbobjc.m`) are then also added to the target.
+
+Usage
+-----
+
+The objects generated for messages should work like any other Objective C
+object. They are mutable objects, but if you don't change them, they are safe
+to share between threads (similar to passing an NSMutableDictionary between
+threads/queues; as long as no one mutates it, things are fine).
+
+There are a few behaviors worth calling out:
+
+A property that is type NSString\* will never return nil. If the value is
+unset, it will return an empty string (@""). This is inpart to align things
+with the Protocol Buffers spec which says the default for strings is an empty
+string, but also so you can always safely pass them to isEqual:/compare:, etc.
+and have deterministic results.
+
+A property that is type NSData\* also won't return nil, it will return an empty
+data ([NSData data]). The reasoning is the same as for NSString not returning
+nil.
+
+A property that is another GPBMessage class also will not return nil. If the
+field wasn't already set, you will get a instance of the correct class. This
+instance will be a temporary instance unless you mutate it, at which point it
+will be attached to its parent object. We call this pattern *autocreators*.
+Similar to NSString and NSData properties it makes things a little safer when
+using them with isEqual:/etc.; but more importantly, this allows you to write
+code that uses Objective C's property dot notation to walk into nested objects
+and access and/or assign things without having to check that they are not nil
+and create them each step along the way. You can write this:
+
+```
+- (void)updateRecord:(MyMessage *)msg {
+ ...
+ // Note: You don't have to check subMessage and otherMessage for nil and
+ // alloc/init/assign them back along the way.
+ msg.subMessage.otherMessage.lastName = @"Smith";
+ ...
+}
+```
+
+If you want to check if a GPBMessage property is present, there is always as
+`has\[NAME\]` property to go with the main property to check if it is set.
+
+A property that is of an Array or Dictionary type also provides *autocreator*
+behavior and will never return nil. This provides all the same benefits you
+see for the message properties. Again, you can write:
+
+```
+- (void)updateRecord:(MyMessage *)msg {
+ ...
+ // Note: Just like above, you don't have to check subMessage and otherMessage
+ // for nil and alloc/init/assign them back along the way. You also don't have
+ // to create the siblingsArray, you can safely just append to it.
+ [msg.subMessage.otherMessage.siblingsArray addObject:@"Pat"];
+ ...
+}
+```
+
+If you are inspecting a message you got from some other place (server, disk,
+etc), you may want to check if the Array or Dictionary has entries without
+causing it to be created for you. For this, there is always a `\[NAME\]_Count`
+property also provided that can return zero or the real count, but won't trigger
+the creation.
+
+For primitive type fields (ints, floats, bools, enum) in messages defined in a
+`.proto` file that use *proto2* syntax there are conceptual differences between
+having an *explicit* and *default* value. You can always get the value of the
+property. In the case that it hasn't been set you will get the default. In
+cases where you need to know whether it was set explicitly or you are just
+getting the default, you can use the `has\[NAME\]` property. If the value has
+been set, and you want to clear it, you can set the `has\[NAME\]` to `NO`.
+*proto3* syntax messages do away with this concept, thus the default values are
+never included when the message is encoded.
+
+The Objective C classes/enums can be used from Swift code.
+
+Objective C Generator Proto File Options
+----------------------------------------
+
+**objc_class_prefix=\<prefix\>** (no default)
+
+Since Objective C uses a global namespace for all of its classes, there can
+be collisions. This option provides a prefix that will be added to the Enums
+and Objects (for messages) generated from the proto. Convention is to base
+the prefix on the package the proto is in.
+
+Objective C Generator `protoc` Options
+--------------------------------------
+
+When generating Objective C code, `protoc` supports a `--objc_opt` argument; the
+argument is comma-delimited name/value pairs (_key=value,key2=value2_). The
+_keys_ are used to change the behavior during generation. The currently
+supported keys are:
+
+ * `generate_for_named_framework`: The `value` used for this key will be used
+ when generating the `#import` statements in the generated code. Instead
+ of being plain `#import "some/path/file.pbobjc.h"` lines, they will be
+ framework based, i.e. - `#import <VALUE/file.pbobjc.h>`.
+
+ _NOTE:_ If this is used with `named_framework_to_proto_path_mappings_path`,
+ then this is effectively the _default_ to use for everything that wasn't
+ mapped by the other.
+
+ * `named_framework_to_proto_path_mappings_path`: The `value` used for this key
+ is a path to a file containing the listing of framework names and proto
+ files. The generator uses this to decide if another proto file referenced
+ should use a framework style import vs. a user level import
+ (`#import <FRAMEWORK/file.pbobjc.h>` vs `#import "dir/file.pbobjc.h"`).
+
+ The format of the file is:
+ * An entry is a line of `frameworkName: file.proto, dir/file2.proto`.
+ * Comments start with `#`.
+ * A comment can go on a line after an entry.
+ (i.e. - `frameworkName: file.proto # comment`)
+
+ Any number of files can be listed for a framework, just separate them with
+ commas.
+
+ There can be multiple lines listing the same frameworkName incase it has a
+ lot of proto files included in it; and having multiple lines makes things
+ easier to read.
+
+Contributing
+------------
+
+Please make updates to the tests along with changes. If just changing the
+runtime, the Xcode projects can be used to build and run tests. If your change
+also requires changes to the generated code,
+`objectivec/DevTools/full_mac_build.sh` can be used to easily rebuild and test
+changes. Passing `-h` to the script will show the addition options that could
+be useful.
+
+Documentation
+-------------
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..b9df381a1c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj
@@ -0,0 +1,290 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ F4D5A0AE1CEE2D8F00562D79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */; };
+ F4D5A0B11CEE2D8F00562D79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0B01CEE2D8F00562D79 /* main.m */; };
+ F4D5A0B31CEE2D8F00562D79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */; };
+ F4D5A0B61CEE2D8F00562D79 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OSXCocoaPodsTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4D5A0AC1CEE2D8F00562D79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ F4D5A0B01CEE2D8F00562D79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
+ F4D5A0B51CEE2D8F00562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ F4D5A0B71CEE2D8F00562D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ F4D5A0A61CEE2D8F00562D79 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ F4D5A0A01CEE2D8F00562D79 = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0AB1CEE2D8F00562D79 /* OSXCocoaPodsTester */,
+ F4D5A0AA1CEE2D8F00562D79 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ F4D5A0AA1CEE2D8F00562D79 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ F4D5A0AB1CEE2D8F00562D79 /* OSXCocoaPodsTester */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0AC1CEE2D8F00562D79 /* AppDelegate.h */,
+ F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */,
+ F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */,
+ F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */,
+ F4D5A0B71CEE2D8F00562D79 /* Info.plist */,
+ F4D5A0AF1CEE2D8F00562D79 /* Supporting Files */,
+ );
+ path = OSXCocoaPodsTester;
+ sourceTree = "<group>";
+ };
+ F4D5A0AF1CEE2D8F00562D79 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0B01CEE2D8F00562D79 /* main.m */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ F4D5A0A81CEE2D8F00562D79 /* OSXCocoaPodsTester */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4D5A0BA1CEE2D8F00562D79 /* Build configuration list for PBXNativeTarget "OSXCocoaPodsTester" */;
+ buildPhases = (
+ F4D5A0A51CEE2D8F00562D79 /* Sources */,
+ F4D5A0A61CEE2D8F00562D79 /* Frameworks */,
+ F4D5A0A71CEE2D8F00562D79 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = OSXCocoaPodsTester;
+ productName = OSXCocoaPodsTester;
+ productReference = F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ F4D5A0A11CEE2D8F00562D79 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0730;
+ ORGANIZATIONNAME = Google;
+ TargetAttributes = {
+ F4D5A0A81CEE2D8F00562D79 = {
+ CreatedOnToolsVersion = 7.3.1;
+ };
+ };
+ };
+ buildConfigurationList = F4D5A0A41CEE2D8F00562D79 /* Build configuration list for PBXProject "OSXCocoaPodsTester" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = F4D5A0A01CEE2D8F00562D79;
+ productRefGroup = F4D5A0AA1CEE2D8F00562D79 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ F4D5A0A81CEE2D8F00562D79 /* OSXCocoaPodsTester */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ F4D5A0A71CEE2D8F00562D79 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0B31CEE2D8F00562D79 /* Assets.xcassets in Resources */,
+ F4D5A0B61CEE2D8F00562D79 /* MainMenu.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ F4D5A0A51CEE2D8F00562D79 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0B11CEE2D8F00562D79 /* main.m in Sources */,
+ F4D5A0AE1CEE2D8F00562D79 /* AppDelegate.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0B51CEE2D8F00562D79 /* Base */,
+ );
+ name = MainMenu.xib;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ F4D5A0B81CEE2D8F00562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CODE_SIGN_IDENTITY = "-";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.11;
+ MTL_ENABLE_DEBUG_INFO = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ F4D5A0B91CEE2D8F00562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CODE_SIGN_IDENTITY = "-";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.11;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ F4D5A0BB1CEE2D8F00562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ COMBINE_HIDPI_IMAGES = YES;
+ INFOPLIST_FILE = OSXCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.OSXCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ F4D5A0BC1CEE2D8F00562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ COMBINE_HIDPI_IMAGES = YES;
+ INFOPLIST_FILE = OSXCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.OSXCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ F4D5A0A41CEE2D8F00562D79 /* Build configuration list for PBXProject "OSXCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A0B81CEE2D8F00562D79 /* Debug */,
+ F4D5A0B91CEE2D8F00562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4D5A0BA1CEE2D8F00562D79 /* Build configuration list for PBXNativeTarget "OSXCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A0BB1CEE2D8F00562D79 /* Debug */,
+ F4D5A0BC1CEE2D8F00562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = F4D5A0A11CEE2D8F00562D79 /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..6d874e28a5
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:OSXCocoaPodsTester.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme
new file mode 100644
index 0000000000..56f8782eb8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0730"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h
new file mode 100644
index 0000000000..c7ab521d0f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m
new file mode 100644
index 0000000000..08735a0068
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@property (weak) IBOutlet NSWindow *window;
+@end
+
+@implementation AppDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ // Insert code here to initialize your application
+}
+
+- (void)applicationWillTerminate:(NSNotification *)aNotification {
+ // Insert code here to tear down your application
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..2db2b1c7c6
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib
new file mode 100644
index 0000000000..aa3547ca18
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib
@@ -0,0 +1,680 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6233" systemVersion="14A329f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6233"/>
+ </dependencies>
+ <objects>
+ <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
+ <connections>
+ <outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
+ </connections>
+ </customObject>
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+ <customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="">
+ <connections>
+ <outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
+ </connections>
+ </customObject>
+ <customObject id="YLy-65-1bz" customClass="NSFontManager"/>
+ <menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
+ <items>
+ <menuItem title="OSXCocoaPodsTester" id="1Xt-HY-uBw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="OSXCocoaPodsTester" systemMenu="apple" id="uQy-DD-JDr">
+ <items>
+ <menuItem title="About OSXCocoaPodsTester" id="5kV-Vb-QxS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
+ <menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
+ <menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
+ <menuItem title="Services" id="NMo-om-nkz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
+ <menuItem title="Hide OSXCocoaPodsTester" keyEquivalent="h" id="Olw-nP-bQN">
+ <connections>
+ <action selector="hide:" target="-1" id="PnN-Uc-m68"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Show All" id="Kd2-mp-pUS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
+ <menuItem title="Quit OSXCocoaPodsTester" keyEquivalent="q" id="4sb-4s-VLi">
+ <connections>
+ <action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="File" id="dMs-cI-mzQ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="File" id="bib-Uj-vzu">
+ <items>
+ <menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
+ <connections>
+ <action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
+ <connections>
+ <action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Open Recent" id="tXI-mr-wws">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
+ <items>
+ <menuItem title="Clear Menu" id="vNY-rz-j42">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
+ <menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
+ <connections>
+ <action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
+ <connections>
+ <action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
+ <connections>
+ <action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Revert to Saved" id="KaW-ft-85H">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
+ <menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
+ <modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
+ <connections>
+ <action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
+ <connections>
+ <action selector="print:" target="-1" id="qaZ-4w-aoO"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Edit" id="5QF-Oa-p0T">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Edit" id="W48-6f-4Dl">
+ <items>
+ <menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
+ <connections>
+ <action selector="undo:" target="-1" id="M6e-cu-g7V"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
+ <connections>
+ <action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
+ <menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
+ <connections>
+ <action selector="cut:" target="-1" id="YJe-68-I9s"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
+ <connections>
+ <action selector="copy:" target="-1" id="G1f-GL-Joy"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
+ <connections>
+ <action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Delete" id="pa3-QI-u2k">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
+ <connections>
+ <action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
+ <menuItem title="Find" id="4EN-yA-p0u">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Find" id="1b7-l0-nxx">
+ <items>
+ <menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
+ <connections>
+ <action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
+ <items>
+ <menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
+ <connections>
+ <action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
+ <connections>
+ <action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
+ <menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Substitutions" id="9ic-FL-obx">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
+ <items>
+ <menuItem title="Show Substitutions" id="z6F-FW-3nz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
+ <menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Quotes" id="hQb-2v-fYv">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Dashes" id="rgM-f4-ycn">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Links" id="cwL-P1-jid">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Data Detectors" id="tRr-pd-1PS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Text Replacement" id="HFQ-gK-NFA">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Transformations" id="2oI-Rn-ZJC">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Transformations" id="c8a-y6-VQd">
+ <items>
+ <menuItem title="Make Upper Case" id="vmV-6d-7jI">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Make Lower Case" id="d9M-CD-aMd">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Capitalize" id="UEZ-Bs-lqG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Speech" id="xrE-MZ-jX0">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Speech" id="3rS-ZA-NoH">
+ <items>
+ <menuItem title="Start Speaking" id="Ynk-f8-cLZ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Stop Speaking" id="Oyz-dy-DGm">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Format" id="jxT-CU-nIS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Format" id="GEO-Iw-cKr">
+ <items>
+ <menuItem title="Font" id="Gi5-1S-RQB">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
+ <items>
+ <menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
+ <connections>
+ <action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
+ <connections>
+ <action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
+ <connections>
+ <action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
+ <connections>
+ <action selector="underline:" target="-1" id="FYS-2b-JAY"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
+ <menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
+ <connections>
+ <action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
+ <connections>
+ <action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
+ <menuItem title="Kern" id="jBQ-r6-VK2">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Kern" id="tlD-Oa-oAM">
+ <items>
+ <menuItem title="Use Default" id="GUa-eO-cwY">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use None" id="cDB-IK-hbR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Tighten" id="46P-cB-AYj">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Loosen" id="ogc-rX-tC1">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Ligatures" id="o6e-r0-MWq">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
+ <items>
+ <menuItem title="Use Default" id="agt-UL-0e3">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use None" id="J7y-lM-qPV">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use All" id="xQD-1f-W4t">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Baseline" id="OaQ-X3-Vso">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Baseline" id="ijk-EB-dga">
+ <items>
+ <menuItem title="Use Default" id="3Om-Ey-2VK">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Superscript" id="Rqc-34-cIF">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Subscript" id="I0S-gh-46l">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Raise" id="2h7-ER-AoG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Lower" id="1tx-W0-xDw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
+ <menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
+ <connections>
+ <action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
+ <menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Text" id="Fal-I4-PZk">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Text" id="d9c-me-L2H">
+ <items>
+ <menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
+ <connections>
+ <action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
+ <connections>
+ <action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Justify" id="J5U-5w-g23">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
+ <connections>
+ <action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
+ <menuItem title="Writing Direction" id="H1b-Si-o9J">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
+ <items>
+ <menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem id="YGs-j5-SAR">
+ <string key="title"> Default</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
+ </connections>
+ </menuItem>
+ <menuItem id="Lbh-J2-qVU">
+ <string key="title"> Left to Right</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
+ </connections>
+ </menuItem>
+ <menuItem id="jFq-tB-4Kx">
+ <string key="title"> Right to Left</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
+ <menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem id="Nop-cj-93Q">
+ <string key="title"> Default</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
+ </connections>
+ </menuItem>
+ <menuItem id="BgM-ve-c93">
+ <string key="title"> Left to Right</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
+ </connections>
+ </menuItem>
+ <menuItem id="RB4-Sm-HuC">
+ <string key="title"> Right to Left</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
+ <menuItem title="Show Ruler" id="vLm-3I-IUL">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
+ <modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
+ <connections>
+ <action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
+ <modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
+ <connections>
+ <action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="View" id="H8h-7b-M4v">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="View" id="HyV-fh-RgO">
+ <items>
+ <menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="toggleToolbarShown:" target="-1" id="BXY-wc-z0C"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="runToolbarCustomizationPalette:" target="-1" id="pQI-g3-MTW"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Window" id="aUF-d1-5bR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
+ <items>
+ <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
+ <connections>
+ <action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Zoom" id="R4o-n2-Eq4">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
+ <menuItem title="Bring All to Front" id="LE2-aR-0XJ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Help" id="wpr-3q-Mcd">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
+ <items>
+ <menuItem title="OSXCocoaPodsTester Help" keyEquivalent="?" id="FKE-Sm-Kum">
+ <connections>
+ <action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ <window title="OSXCocoaPodsTester" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
+ <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
+ <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
+ <rect key="contentRect" x="335" y="390" width="480" height="360"/>
+ <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
+ <view key="contentView" id="EiT-Mj-1SZ">
+ <rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </view>
+ </window>
+ </objects>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist
new file mode 100644
index 0000000000..ed806e40d6
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2016 Google. All rights reserved.</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m
new file mode 100644
index 0000000000..b230090e5e
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m
@@ -0,0 +1,35 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, const char * argv[]) {
+ return NSApplicationMain(argc, argv);
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework
new file mode 100644
index 0000000000..27eeafc9c8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework
@@ -0,0 +1,10 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :osx, '10.9'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+use_frameworks!
+
+target 'OSXCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static
new file mode 100644
index 0000000000..5dfc8de578
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static
@@ -0,0 +1,8 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :osx, '10.9'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+target 'OSXCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/README.md b/third_party/protobuf/objectivec/Tests/CocoaPods/README.md
new file mode 100644
index 0000000000..0878591886
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/README.md
@@ -0,0 +1,9 @@
+CocoaPods Protocol Buffers Integration Tests
+============================================
+
+The sub directories are the basic projects as created by Xcode 6.3. They are
+used to then drive `pod` and `xcodebuild` to ensure things integrate/build
+as expected.
+
+`run_tests.sh` defaults to running all the tests, invoke it with `--help` to
+see the arguments to control what tests are run.
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework
new file mode 100644
index 0000000000..913a289b8e
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework
@@ -0,0 +1,10 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+use_frameworks!
+
+target 'iOSCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static
new file mode 100644
index 0000000000..e9b3c235dd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static
@@ -0,0 +1,8 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+target 'iOSCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..27fb553fd4
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj
@@ -0,0 +1,309 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ F4D5A08B1CEE01E200562D79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A08A1CEE01E200562D79 /* main.m */; };
+ F4D5A08E1CEE01E200562D79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A08D1CEE01E200562D79 /* AppDelegate.m */; };
+ F4D5A0911CEE01E200562D79 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0901CEE01E200562D79 /* ViewController.m */; };
+ F4D5A0941CEE01E200562D79 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0921CEE01E200562D79 /* Main.storyboard */; };
+ F4D5A0961CEE01E200562D79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0951CEE01E200562D79 /* Assets.xcassets */; };
+ F4D5A0991CEE01E200562D79 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSCocoaPodsTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4D5A08A1CEE01E200562D79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ F4D5A08C1CEE01E200562D79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ F4D5A08D1CEE01E200562D79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ F4D5A08F1CEE01E200562D79 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
+ F4D5A0901CEE01E200562D79 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
+ F4D5A0931CEE01E200562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
+ F4D5A0951CEE01E200562D79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
+ F4D5A0981CEE01E200562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
+ F4D5A09A1CEE01E200562D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ F4D5A0831CEE01E200562D79 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ F4D5A07D1CEE01E200562D79 = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0881CEE01E200562D79 /* iOSCocoaPodsTester */,
+ F4D5A0871CEE01E200562D79 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ F4D5A0871CEE01E200562D79 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ F4D5A0881CEE01E200562D79 /* iOSCocoaPodsTester */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A08C1CEE01E200562D79 /* AppDelegate.h */,
+ F4D5A08D1CEE01E200562D79 /* AppDelegate.m */,
+ F4D5A08F1CEE01E200562D79 /* ViewController.h */,
+ F4D5A0901CEE01E200562D79 /* ViewController.m */,
+ F4D5A0921CEE01E200562D79 /* Main.storyboard */,
+ F4D5A0951CEE01E200562D79 /* Assets.xcassets */,
+ F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */,
+ F4D5A09A1CEE01E200562D79 /* Info.plist */,
+ F4D5A0891CEE01E200562D79 /* Supporting Files */,
+ );
+ path = iOSCocoaPodsTester;
+ sourceTree = "<group>";
+ };
+ F4D5A0891CEE01E200562D79 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A08A1CEE01E200562D79 /* main.m */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ F4D5A0851CEE01E200562D79 /* iOSCocoaPodsTester */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4D5A09D1CEE01E200562D79 /* Build configuration list for PBXNativeTarget "iOSCocoaPodsTester" */;
+ buildPhases = (
+ F4D5A0821CEE01E200562D79 /* Sources */,
+ F4D5A0831CEE01E200562D79 /* Frameworks */,
+ F4D5A0841CEE01E200562D79 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = iOSCocoaPodsTester;
+ productName = iOSCocoaPodsTester;
+ productReference = F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ F4D5A07E1CEE01E200562D79 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0730;
+ ORGANIZATIONNAME = Google;
+ TargetAttributes = {
+ F4D5A0851CEE01E200562D79 = {
+ CreatedOnToolsVersion = 7.3.1;
+ };
+ };
+ };
+ buildConfigurationList = F4D5A0811CEE01E200562D79 /* Build configuration list for PBXProject "iOSCocoaPodsTester" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = F4D5A07D1CEE01E200562D79;
+ productRefGroup = F4D5A0871CEE01E200562D79 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ F4D5A0851CEE01E200562D79 /* iOSCocoaPodsTester */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ F4D5A0841CEE01E200562D79 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0991CEE01E200562D79 /* LaunchScreen.storyboard in Resources */,
+ F4D5A0961CEE01E200562D79 /* Assets.xcassets in Resources */,
+ F4D5A0941CEE01E200562D79 /* Main.storyboard in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ F4D5A0821CEE01E200562D79 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0911CEE01E200562D79 /* ViewController.m in Sources */,
+ F4D5A08E1CEE01E200562D79 /* AppDelegate.m in Sources */,
+ F4D5A08B1CEE01E200562D79 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ F4D5A0921CEE01E200562D79 /* Main.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0931CEE01E200562D79 /* Base */,
+ );
+ name = Main.storyboard;
+ sourceTree = "<group>";
+ };
+ F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0981CEE01E200562D79 /* Base */,
+ );
+ name = LaunchScreen.storyboard;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ F4D5A09B1CEE01E200562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
+ MTL_ENABLE_DEBUG_INFO = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ F4D5A09C1CEE01E200562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ F4D5A09E1CEE01E200562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ INFOPLIST_FILE = iOSCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.iOSCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ F4D5A09F1CEE01E200562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ INFOPLIST_FILE = iOSCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.iOSCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ F4D5A0811CEE01E200562D79 /* Build configuration list for PBXProject "iOSCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A09B1CEE01E200562D79 /* Debug */,
+ F4D5A09C1CEE01E200562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4D5A09D1CEE01E200562D79 /* Build configuration list for PBXNativeTarget "iOSCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A09E1CEE01E200562D79 /* Debug */,
+ F4D5A09F1CEE01E200562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = F4D5A07E1CEE01E200562D79 /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..008f7b4a6f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:iOSCocoaPodsTester.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme
new file mode 100644
index 0000000000..9558dd7a17
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0730"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h
new file mode 100644
index 0000000000..5eca690ca7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h
@@ -0,0 +1,39 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m
new file mode 100644
index 0000000000..dd7b969af8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m
@@ -0,0 +1,67 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@end
+
+@implementation AppDelegate
+
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ // Override point for customization after application launch.
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..36d2c80d88
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,68 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard
new file mode 100644
index 0000000000..2e721e1833
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
+ </dependencies>
+ <scenes>
+ <!--View Controller-->
+ <scene sceneID="EHf-IW-A2E">
+ <objects>
+ <viewController id="01J-lp-oVM" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
+ <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <animations/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="53" y="375"/>
+ </scene>
+ </scenes>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard
new file mode 100644
index 0000000000..82cd159ae3
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
+ </dependencies>
+ <scenes>
+ <!--View Controller-->
+ <scene sceneID="tne-QT-ifu">
+ <objects>
+ <viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
+ <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
+ </objects>
+ </scene>
+ </scenes>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist
new file mode 100644
index 0000000000..40c6215d90
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UIMainStoryboardFile</key>
+ <string>Main</string>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h
new file mode 100644
index 0000000000..777257b85a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+
+@interface ViewController : UIViewController
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m
new file mode 100644
index 0000000000..c3b7e6c0cc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "ViewController.h"
+
+@interface ViewController ()
+
+@end
+
+@implementation ViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ // Do any additional setup after loading the view, typically from a nib.
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m
new file mode 100644
index 0000000000..4df0b769cf
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m
@@ -0,0 +1,39 @@
+//
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+#import "AppDelegate.h"
+
+int main(int argc, char * argv[]) {
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh b/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh
new file mode 100755
index 0000000000..6d3e12be30
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+#
+# Helper to run the pods tests.
+
+set -eu
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+
+printUsage() {
+ NAME=$(basename "${0}")
+ cat << EOF
+usage: ${NAME} [OPTIONS]
+
+This script runs some test to check the CocoaPods integration.
+
+OPTIONS:
+
+ General:
+
+ -h, --help
+ Show this message
+ --skip-static
+ Skip the static based pods tests.
+ --skip-framework
+ Skip the framework based pods tests.
+ --skip-ios
+ Skip the iOS pods tests.
+ --skip-osx
+ Skip the OS X pods tests.
+
+EOF
+}
+
+TEST_MODES=( "static" "framework" )
+TEST_NAMES=( "iOSCocoaPodsTester" "OSXCocoaPodsTester" )
+while [[ $# != 0 ]]; do
+ case "${1}" in
+ -h | --help )
+ printUsage
+ exit 0
+ ;;
+ --skip-static )
+ TEST_MODES=(${TEST_MODES[@]/static})
+ ;;
+ --skip-framework )
+ TEST_MODES=(${TEST_MODES[@]/framework})
+ ;;
+ --skip-ios )
+ TEST_NAMES=(${TEST_NAMES[@]/iOSCocoaPodsTester})
+ ;;
+ --skip-osx )
+ TEST_NAMES=(${TEST_NAMES[@]/OSXCocoaPodsTester})
+ ;;
+ -*)
+ echo "ERROR: Unknown option: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ *)
+ echo "ERROR: Unknown argument: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Sanity check.
+if [[ "${#TEST_NAMES[@]}" == 0 ]] ; then
+ echo "ERROR: Need to run at least iOS or OS X tests." 1>&2
+ exit 2
+fi
+if [[ "${#TEST_MODES[@]}" == 0 ]] ; then
+ echo "ERROR: Need to run at least static or frameworks tests." 1>&2
+ exit 2
+fi
+
+header() {
+ echo ""
+ echo "========================================================================"
+ echo " ${@}"
+ echo "========================================================================"
+ echo ""
+}
+
+# Cleanup hook for do_test, assumes directory is correct.
+cleanup() {
+ local TEST_NAME="$1"
+
+ echo "Cleaning up..."
+
+ # Generally don't let things fail, and eat common stdout, but let stderr show
+ # incase something does hiccup.
+ xcodebuild -workspace "${TEST_NAME}.xcworkspace" -scheme "${TEST_NAME}" clean > /dev/null || true
+ pod deintegrate > /dev/null || true
+ # Flush the cache so nothing is left behind.
+ pod cache clean --all || true
+ # Delete the files left after pod deintegrate.
+ rm -f Podfile.lock || true
+ rm -rf "${TEST_NAME}.xcworkspace" || true
+ git checkout -- "${TEST_NAME}.xcodeproj" || true
+ # Remove the Podfile that was put in place.
+ rm -f Podfile || true
+}
+
+do_test() {
+ local TEST_NAME="$1"
+ local TEST_MODE="$2"
+
+ header "${TEST_NAME}" - Mode: "${TEST_MODE}"
+ cd "${ScriptDir}/${TEST_NAME}"
+
+ # Hook in cleanup for any failures.
+ trap "cleanup ${TEST_NAME}" EXIT
+
+ # Ensure nothing is cached by pods to start with that could throw things off.
+ pod cache clean --all
+
+ # Put the right Podfile in place.
+ cp -f "Podfile-${TEST_MODE}" "Podfile"
+
+ xcodebuild_args=( "-workspace" "${TEST_NAME}.xcworkspace" "-scheme" "${TEST_NAME}" )
+
+ # For iOS, if the SDK is not provided it tries to use iphoneos, and the test
+ # fail on Travis since those machines don't have a Code Signing identity.
+ if [[ "${TEST_NAME}" == iOS* ]] ; then
+ # Apparently the destination flag is required to avoid "Unsupported architecture"
+ # errors.
+ xcodebuild_args+=(
+ -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
+ -destination "platform=iOS Simulator,name=iPad 2,OS=9.3"
+ )
+ fi
+
+ # Do the work!
+ pod install --verbose
+
+ xcodebuild "${xcodebuild_args[@]}" build
+
+ # Clear the hook and manually run cleanup.
+ trap - EXIT
+ cleanup "${TEST_NAME}"
+}
+
+# Run the tests.
+for TEST_NAME in "${TEST_NAMES[@]}" ; do
+ for TEST_MODE in "${TEST_MODES[@]}" ; do
+ do_test "${TEST_NAME}" "${TEST_MODE}"
+ done
+done
diff --git a/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m b/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m
new file mode 100644
index 0000000000..29f6ccf69a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m
@@ -0,0 +1,63 @@
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Makes sure all the generated headers compile with ARC on.
+
+// The unittest_custom_options.proto extends the messages in descriptor.proto
+// so we build it in to test extending in general. The library doesn't provide
+// a descriptor as it doesn't use the classes/enums.
+#import "google/protobuf/Descriptor.pbobjc.h"
+
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestCustomOptions.pbobjc.h"
+#import "google/protobuf/UnittestCycle.pbobjc.h"
+#import "google/protobuf/UnittestDeprecated.pbobjc.h"
+#import "google/protobuf/UnittestDeprecatedFile.pbobjc.h"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h"
+#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.h"
+#import "google/protobuf/UnittestEmpty.pbobjc.h"
+#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+#import "google/protobuf/UnittestImportLite.pbobjc.h"
+#import "google/protobuf/UnittestImportPublic.pbobjc.h"
+#import "google/protobuf/UnittestImportPublicLite.pbobjc.h"
+#import "google/protobuf/UnittestLite.pbobjc.h"
+#import "google/protobuf/UnittestMset.pbobjc.h"
+#import "google/protobuf/UnittestNoGenericServices.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.h"
+#import "google/protobuf/UnittestOptimizeFor.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
diff --git a/third_party/protobuf/objectivec/Tests/GPBArrayTests.m b/third_party/protobuf/objectivec/Tests/GPBArrayTests.m
new file mode 100644
index 0000000000..31f75501dc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBArrayTests.m
@@ -0,0 +1,3611 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBArray.h"
+#import "GPBArray_PackagePrivate.h"
+
+#import "GPBTestUtilities.h"
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBEnumArray (TestingTweak)
++ (instancetype)arrayWithValue:(int32_t)value;
+- (instancetype)initWithValues:(const int32_t [])values
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 71:
+ case 72:
+ case 73:
+ case 74:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+static BOOL TestingEnum_IsValidValue2(int32_t value) {
+ switch (value) {
+ case 71:
+ case 72:
+ case 73:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBEnumArray (TestingTweak)
++ (instancetype)arrayWithValue:(int32_t)value {
+ return [[[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ count:1] autorelease];
+}
+- (instancetype)initWithValues:(const int32_t [])values
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ count:count];
+}
+@end
+
+#pragma mark - PDDM Macros
+
+//%PDDM-DEFINE ARRAY_TESTS(NAME, TYPE, VAL1, VAL2, VAL3, VAL4)
+//%ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, )
+//%PDDM-DEFINE ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, HELPER)
+//%#pragma mark - NAME
+//%
+//%@interface GPB##NAME##ArrayTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##NAME##ArrayTests
+//%
+//%- (void)testEmpty {
+//% GPB##NAME##Array *array = [[GPB##NAME##Array alloc] init];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 0U);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% #pragma unused(value, idx, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% #pragma unused(value, idx, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [array release];
+//%}
+//%
+//%- (void)testOne {
+//% GPB##NAME##Array *array = [GPB##NAME##Array arrayWithValue:VAL1];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 1U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, 0U);
+//% XCTAssertEqual(value, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, 0U);
+//% XCTAssertEqual(value, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% static const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+//% __block NSUInteger idx2 = 0;
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, idx2);
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx2;
+//% }];
+//% idx2 = 0;
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, (3 - idx2));
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx2;
+//% }];
+//% // Stopping the enumeration.
+//% idx2 = 0;
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, idx2);
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% if (idx2 == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% XCTAssertNotEqual(idx, 3U);
+//% ++idx2;
+//% }];
+//% idx2 = 0;
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, (3 - idx2));
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% if (idx2 == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 1U);
+//% XCTAssertNotEqual(idx, 0U);
+//% ++idx2;
+//% }];
+//% [array release];
+//%}
+//%
+//%- (void)testEquality {
+//% const TYPE kValues1[] = { VAL1, VAL2, VAL3 };
+//% const TYPE kValues2[] = { VAL1, VAL4, VAL3 };
+//% const TYPE kValues3[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array1 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues1
+//% NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(array1);
+//% GPB##NAME##Array *array1prime =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues1
+//% NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(array1prime);
+//% GPB##NAME##Array *array2 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues2
+//% NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(array2);
+//% GPB##NAME##Array *array3 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues3
+//% NAME$S count:GPBARRAYSIZE(kValues3)];
+//% XCTAssertNotNil(array3);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(array1, array1prime);
+//% XCTAssertEqualObjects(array1, array1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([array1 hash], [array1prime hash]);
+//%
+//% // 1/2/3 shouldn't be equal.
+//% XCTAssertNotEqualObjects(array1, array2);
+//% XCTAssertNotEqualObjects(array1, array3);
+//% XCTAssertNotEqualObjects(array2, array3);
+//%
+//% [array1 release];
+//% [array1prime release];
+//% [array2 release];
+//% [array3 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% GPB##NAME##Array *array2 = [array copy];
+//% XCTAssertNotNil(array2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(array, array2);
+//% XCTAssertEqualObjects(array, array2);
+//% [array2 release];
+//% [array release];
+//%}
+//%
+//%- (void)testArrayFromArray {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% GPB##NAME##Array *array2 = [GPB##NAME##Array arrayWithValueArray:array];
+//% XCTAssertNotNil(array2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(array, array2);
+//% XCTAssertEqualObjects(array, array2);
+//% [array release];
+//%}
+//%
+//%- (void)testAdds {
+//% GPB##NAME##Array *array = [GPB##NAME##Array array];
+//% XCTAssertNotNil(array);
+//%
+//% XCTAssertEqual(array.count, 0U);
+//% [array addValue:VAL1];
+//% XCTAssertEqual(array.count, 1U);
+//%
+//% const TYPE kValues1[] = { VAL2, VAL3 };
+//% [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% const TYPE kValues2[] = { VAL4, VAL1 };
+//% GPB##NAME##Array *array2 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues2
+//% NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(array2);
+//% [array add##HELPER##ValuesFromArray:array2];
+//% XCTAssertEqual(array.count, 5U);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//% XCTAssertEqual([array valueAtIndex:4], VAL1);
+//% [array2 release];
+//%}
+//%
+//%- (void)testInsert {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% // First
+//% [array insertValue:VAL4 atIndex:0];
+//% XCTAssertEqual(array.count, 4U);
+//%
+//% // Middle
+//% [array insertValue:VAL4 atIndex:2];
+//% XCTAssertEqual(array.count, 5U);
+//%
+//% // End
+//% [array insertValue:VAL4 atIndex:5];
+//% XCTAssertEqual(array.count, 6U);
+//%
+//% // Too far.
+//% XCTAssertThrowsSpecificNamed([array insertValue:VAL4 atIndex:7],
+//% NSException, NSRangeException);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL4);
+//% XCTAssertEqual([array valueAtIndex:1], VAL1);
+//% XCTAssertEqual([array valueAtIndex:2], VAL4);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//% XCTAssertEqual([array valueAtIndex:4], VAL3);
+//% XCTAssertEqual([array valueAtIndex:5], VAL4);
+//% [array release];
+//%}
+//%
+//%- (void)testRemove {
+//% const TYPE kValues[] = { VAL4, VAL1, VAL2, VAL4, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 6U);
+//%
+//% // First
+//% [array removeValueAtIndex:0];
+//% XCTAssertEqual(array.count, 5U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//%
+//% // Middle
+//% [array removeValueAtIndex:2];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//%
+//% // End
+//% [array removeValueAtIndex:3];
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//%
+//% // Too far.
+//% XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+//% NSException, NSRangeException);
+//%
+//% [array removeAll];
+//% XCTAssertEqual(array.count, 0U);
+//% XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+//% NSException, NSRangeException);
+//% [array release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const TYPE kValues[] = { VAL1, VAL1, VAL3, VAL3 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% [array replaceValueAtIndex:1 withValue:VAL2];
+//% [array replaceValueAtIndex:3 withValue:VAL4];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//%
+//% XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:VAL4],
+//% NSException, NSRangeException);
+//%
+//% [array exchangeValueAtIndex:1 withValueAtIndex:3];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL4);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//%
+//% [array exchangeValueAtIndex:2 withValueAtIndex:0];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL3);
+//% XCTAssertEqual([array valueAtIndex:1], VAL4);
+//% XCTAssertEqual([array valueAtIndex:2], VAL1);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//%
+//% XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+//% NSException, NSRangeException);
+//% XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+//% NSException, NSRangeException);
+//% [array release];
+//%}
+//%
+//%- (void)testInternalResizing {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% // Add/remove to trigger the intneral buffer to grow/shrink.
+//% for (int i = 0; i < 100; ++i) {
+//% [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+//% }
+//% XCTAssertEqual(array.count, 404U);
+//% for (int i = 0; i < 100; ++i) {
+//% [array removeValueAtIndex:(i * 2)];
+//% }
+//% XCTAssertEqual(array.count, 304U);
+//% for (int i = 0; i < 100; ++i) {
+//% [array insertValue:VAL4 atIndex:(i * 3)];
+//% }
+//% XCTAssertEqual(array.count, 404U);
+//% [array removeAll];
+//% XCTAssertEqual(array.count, 0U);
+//% [array release];
+//%}
+//%
+//%@end
+//%
+//%PDDM-EXPAND ARRAY_TESTS(Int32, int32_t, 1, 2, 3, 4)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@interface GPBInt32ArrayTests : XCTestCase
+@end
+
+@implementation GPBInt32ArrayTests
+
+- (void)testEmpty {
+ GPBInt32Array *array = [[GPBInt32Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBInt32Array *array = [GPBInt32Array arrayWithValue:1];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 1);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 1);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 1, 2, 3 };
+ const int32_t kValues2[] = { 1, 4, 3 };
+ const int32_t kValues3[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array1 =
+ [[GPBInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBInt32Array *array1prime =
+ [[GPBInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBInt32Array *array2 =
+ [[GPBInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBInt32Array *array3 =
+ [[GPBInt32Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt32Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt32Array *array2 = [GPBInt32Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBInt32Array *array = [GPBInt32Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:1];
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 2, 3 };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 4, 1 };
+ GPBInt32Array *array2 =
+ [[GPBInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+ XCTAssertEqual([array valueAtIndex:4], 1);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int32_t kValues[] = { 1, 2, 3 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:4 atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:4 atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:4 atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:4 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 4);
+ XCTAssertEqual([array valueAtIndex:1], 1);
+ XCTAssertEqual([array valueAtIndex:2], 4);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+ XCTAssertEqual([array valueAtIndex:4], 3);
+ XCTAssertEqual([array valueAtIndex:5], 4);
+ [array release];
+}
+
+- (void)testRemove {
+ const int32_t kValues[] = { 4, 1, 2, 4, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kValues[] = { 1, 1, 3, 3 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:2];
+ [array replaceValueAtIndex:3 withValue:4];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:4],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 4);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 3);
+ XCTAssertEqual([array valueAtIndex:1], 4);
+ XCTAssertEqual([array valueAtIndex:2], 1);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:4 atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(UInt32, uint32_t, 11U, 12U, 13U, 14U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32
+
+@interface GPBUInt32ArrayTests : XCTestCase
+@end
+
+@implementation GPBUInt32ArrayTests
+
+- (void)testEmpty {
+ GPBUInt32Array *array = [[GPBUInt32Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBUInt32Array *array = [GPBUInt32Array arrayWithValue:11U];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 11U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 11U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const uint32_t kValues1[] = { 11U, 12U, 13U };
+ const uint32_t kValues2[] = { 11U, 14U, 13U };
+ const uint32_t kValues3[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array1 =
+ [[GPBUInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBUInt32Array *array1prime =
+ [[GPBUInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBUInt32Array *array2 =
+ [[GPBUInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBUInt32Array *array3 =
+ [[GPBUInt32Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt32Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt32Array *array2 = [GPBUInt32Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBUInt32Array *array = [GPBUInt32Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:11U];
+ XCTAssertEqual(array.count, 1U);
+
+ const uint32_t kValues1[] = { 12U, 13U };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const uint32_t kValues2[] = { 14U, 11U };
+ GPBUInt32Array *array2 =
+ [[GPBUInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+ XCTAssertEqual([array valueAtIndex:4], 11U);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const uint32_t kValues[] = { 11U, 12U, 13U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:14U atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:14U atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:14U atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:14U atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 14U);
+ XCTAssertEqual([array valueAtIndex:1], 11U);
+ XCTAssertEqual([array valueAtIndex:2], 14U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+ XCTAssertEqual([array valueAtIndex:4], 13U);
+ XCTAssertEqual([array valueAtIndex:5], 14U);
+ [array release];
+}
+
+- (void)testRemove {
+ const uint32_t kValues[] = { 14U, 11U, 12U, 14U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kValues[] = { 11U, 11U, 13U, 13U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:12U];
+ [array replaceValueAtIndex:3 withValue:14U];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:14U],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 14U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 13U);
+ XCTAssertEqual([array valueAtIndex:1], 14U);
+ XCTAssertEqual([array valueAtIndex:2], 11U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:14U atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Int64, int64_t, 31LL, 32LL, 33LL, 34LL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64
+
+@interface GPBInt64ArrayTests : XCTestCase
+@end
+
+@implementation GPBInt64ArrayTests
+
+- (void)testEmpty {
+ GPBInt64Array *array = [[GPBInt64Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBInt64Array *array = [GPBInt64Array arrayWithValue:31LL];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 31LL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 31LL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int64_t kValues1[] = { 31LL, 32LL, 33LL };
+ const int64_t kValues2[] = { 31LL, 34LL, 33LL };
+ const int64_t kValues3[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array1 =
+ [[GPBInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBInt64Array *array1prime =
+ [[GPBInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBInt64Array *array2 =
+ [[GPBInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBInt64Array *array3 =
+ [[GPBInt64Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt64Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt64Array *array2 = [GPBInt64Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBInt64Array *array = [GPBInt64Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:31LL];
+ XCTAssertEqual(array.count, 1U);
+
+ const int64_t kValues1[] = { 32LL, 33LL };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int64_t kValues2[] = { 34LL, 31LL };
+ GPBInt64Array *array2 =
+ [[GPBInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+ XCTAssertEqual([array valueAtIndex:4], 31LL);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:34LL atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:34LL atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:34LL atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:34LL atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 34LL);
+ XCTAssertEqual([array valueAtIndex:1], 31LL);
+ XCTAssertEqual([array valueAtIndex:2], 34LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+ XCTAssertEqual([array valueAtIndex:4], 33LL);
+ XCTAssertEqual([array valueAtIndex:5], 34LL);
+ [array release];
+}
+
+- (void)testRemove {
+ const int64_t kValues[] = { 34LL, 31LL, 32LL, 34LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kValues[] = { 31LL, 31LL, 33LL, 33LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:32LL];
+ [array replaceValueAtIndex:3 withValue:34LL];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:34LL],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 34LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 33LL);
+ XCTAssertEqual([array valueAtIndex:1], 34LL);
+ XCTAssertEqual([array valueAtIndex:2], 31LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:34LL atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(UInt64, uint64_t, 41ULL, 42ULL, 43ULL, 44ULL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64
+
+@interface GPBUInt64ArrayTests : XCTestCase
+@end
+
+@implementation GPBUInt64ArrayTests
+
+- (void)testEmpty {
+ GPBUInt64Array *array = [[GPBUInt64Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBUInt64Array *array = [GPBUInt64Array arrayWithValue:41ULL];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 41ULL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 41ULL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const uint64_t kValues1[] = { 41ULL, 42ULL, 43ULL };
+ const uint64_t kValues2[] = { 41ULL, 44ULL, 43ULL };
+ const uint64_t kValues3[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array1 =
+ [[GPBUInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBUInt64Array *array1prime =
+ [[GPBUInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBUInt64Array *array2 =
+ [[GPBUInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBUInt64Array *array3 =
+ [[GPBUInt64Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt64Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt64Array *array2 = [GPBUInt64Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBUInt64Array *array = [GPBUInt64Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:41ULL];
+ XCTAssertEqual(array.count, 1U);
+
+ const uint64_t kValues1[] = { 42ULL, 43ULL };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const uint64_t kValues2[] = { 44ULL, 41ULL };
+ GPBUInt64Array *array2 =
+ [[GPBUInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+ XCTAssertEqual([array valueAtIndex:4], 41ULL);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:44ULL atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:44ULL atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:44ULL atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:44ULL atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 44ULL);
+ XCTAssertEqual([array valueAtIndex:1], 41ULL);
+ XCTAssertEqual([array valueAtIndex:2], 44ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+ XCTAssertEqual([array valueAtIndex:4], 43ULL);
+ XCTAssertEqual([array valueAtIndex:5], 44ULL);
+ [array release];
+}
+
+- (void)testRemove {
+ const uint64_t kValues[] = { 44ULL, 41ULL, 42ULL, 44ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kValues[] = { 41ULL, 41ULL, 43ULL, 43ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:42ULL];
+ [array replaceValueAtIndex:3 withValue:44ULL];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:44ULL],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 44ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 43ULL);
+ XCTAssertEqual([array valueAtIndex:1], 44ULL);
+ XCTAssertEqual([array valueAtIndex:2], 41ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:44ULL atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Float, float, 51.f, 52.f, 53.f, 54.f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Float
+
+@interface GPBFloatArrayTests : XCTestCase
+@end
+
+@implementation GPBFloatArrayTests
+
+- (void)testEmpty {
+ GPBFloatArray *array = [[GPBFloatArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBFloatArray *array = [GPBFloatArray arrayWithValue:51.f];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 51.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 51.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const float kValues1[] = { 51.f, 52.f, 53.f };
+ const float kValues2[] = { 51.f, 54.f, 53.f };
+ const float kValues3[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array1 =
+ [[GPBFloatArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBFloatArray *array1prime =
+ [[GPBFloatArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBFloatArray *array2 =
+ [[GPBFloatArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBFloatArray *array3 =
+ [[GPBFloatArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBFloatArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBFloatArray *array2 = [GPBFloatArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBFloatArray *array = [GPBFloatArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:51.f];
+ XCTAssertEqual(array.count, 1U);
+
+ const float kValues1[] = { 52.f, 53.f };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const float kValues2[] = { 54.f, 51.f };
+ GPBFloatArray *array2 =
+ [[GPBFloatArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+ XCTAssertEqual([array valueAtIndex:4], 51.f);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const float kValues[] = { 51.f, 52.f, 53.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:54.f atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:54.f atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:54.f atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:54.f atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 54.f);
+ XCTAssertEqual([array valueAtIndex:1], 51.f);
+ XCTAssertEqual([array valueAtIndex:2], 54.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+ XCTAssertEqual([array valueAtIndex:4], 53.f);
+ XCTAssertEqual([array valueAtIndex:5], 54.f);
+ [array release];
+}
+
+- (void)testRemove {
+ const float kValues[] = { 54.f, 51.f, 52.f, 54.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const float kValues[] = { 51.f, 51.f, 53.f, 53.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:52.f];
+ [array replaceValueAtIndex:3 withValue:54.f];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:54.f],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 54.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 53.f);
+ XCTAssertEqual([array valueAtIndex:1], 54.f);
+ XCTAssertEqual([array valueAtIndex:2], 51.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:54.f atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Double, double, 61., 62., 63., 64.)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Double
+
+@interface GPBDoubleArrayTests : XCTestCase
+@end
+
+@implementation GPBDoubleArrayTests
+
+- (void)testEmpty {
+ GPBDoubleArray *array = [[GPBDoubleArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBDoubleArray *array = [GPBDoubleArray arrayWithValue:61.];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 61.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 61.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const double kValues1[] = { 61., 62., 63. };
+ const double kValues2[] = { 61., 64., 63. };
+ const double kValues3[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array1 =
+ [[GPBDoubleArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBDoubleArray *array1prime =
+ [[GPBDoubleArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBDoubleArray *array2 =
+ [[GPBDoubleArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBDoubleArray *array3 =
+ [[GPBDoubleArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBDoubleArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBDoubleArray *array2 = [GPBDoubleArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBDoubleArray *array = [GPBDoubleArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:61.];
+ XCTAssertEqual(array.count, 1U);
+
+ const double kValues1[] = { 62., 63. };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const double kValues2[] = { 64., 61. };
+ GPBDoubleArray *array2 =
+ [[GPBDoubleArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+ XCTAssertEqual([array valueAtIndex:4], 61.);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const double kValues[] = { 61., 62., 63. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:64. atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:64. atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:64. atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:64. atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 64.);
+ XCTAssertEqual([array valueAtIndex:1], 61.);
+ XCTAssertEqual([array valueAtIndex:2], 64.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+ XCTAssertEqual([array valueAtIndex:4], 63.);
+ XCTAssertEqual([array valueAtIndex:5], 64.);
+ [array release];
+}
+
+- (void)testRemove {
+ const double kValues[] = { 64., 61., 62., 64., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const double kValues[] = { 61., 61., 63., 63. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:62.];
+ [array replaceValueAtIndex:3 withValue:64.];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:64.],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 64.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 63.);
+ XCTAssertEqual([array valueAtIndex:1], 64.);
+ XCTAssertEqual([array valueAtIndex:2], 61.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:64. atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Bool, BOOL, TRUE, TRUE, FALSE, FALSE)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool
+
+@interface GPBBoolArrayTests : XCTestCase
+@end
+
+@implementation GPBBoolArrayTests
+
+- (void)testEmpty {
+ GPBBoolArray *array = [[GPBBoolArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBBoolArray *array = [GPBBoolArray arrayWithValue:TRUE];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, TRUE);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, TRUE);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const BOOL kValues1[] = { TRUE, TRUE, FALSE };
+ const BOOL kValues2[] = { TRUE, FALSE, FALSE };
+ const BOOL kValues3[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array1 =
+ [[GPBBoolArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBBoolArray *array1prime =
+ [[GPBBoolArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBBoolArray *array2 =
+ [[GPBBoolArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBBoolArray *array3 =
+ [[GPBBoolArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBBoolArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBBoolArray *array2 = [GPBBoolArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBBoolArray *array = [GPBBoolArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:TRUE];
+ XCTAssertEqual(array.count, 1U);
+
+ const BOOL kValues1[] = { TRUE, FALSE };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const BOOL kValues2[] = { FALSE, TRUE };
+ GPBBoolArray *array2 =
+ [[GPBBoolArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+ XCTAssertEqual([array valueAtIndex:4], TRUE);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:FALSE atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:FALSE atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:FALSE atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:FALSE atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], FALSE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+ XCTAssertEqual([array valueAtIndex:4], FALSE);
+ XCTAssertEqual([array valueAtIndex:5], FALSE);
+ [array release];
+}
+
+- (void)testRemove {
+ const BOOL kValues[] = { FALSE, TRUE, TRUE, FALSE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:TRUE];
+ [array replaceValueAtIndex:3 withValue:FALSE];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:FALSE],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], FALSE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], FALSE);
+ XCTAssertEqual([array valueAtIndex:1], FALSE);
+ XCTAssertEqual([array valueAtIndex:2], TRUE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:FALSE atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS2(Enum, int32_t, 71, 72, 73, 74, Raw)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Enum
+
+@interface GPBEnumArrayTests : XCTestCase
+@end
+
+@implementation GPBEnumArrayTests
+
+- (void)testEmpty {
+ GPBEnumArray *array = [[GPBEnumArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBEnumArray *array = [GPBEnumArray arrayWithValue:71];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 71);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 71);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 71, 72, 73 };
+ const int32_t kValues2[] = { 71, 74, 73 };
+ const int32_t kValues3[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array1 =
+ [[GPBEnumArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBEnumArray *array1prime =
+ [[GPBEnumArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBEnumArray *array3 =
+ [[GPBEnumArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [GPBEnumArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBEnumArray *array = [GPBEnumArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:71];
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 72, 73 };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 74, 71 };
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addRawValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ XCTAssertEqual([array valueAtIndex:4], 71);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:74 atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:74 atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:74 atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:74 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 74);
+ XCTAssertEqual([array valueAtIndex:1], 71);
+ XCTAssertEqual([array valueAtIndex:2], 74);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+ XCTAssertEqual([array valueAtIndex:4], 73);
+ XCTAssertEqual([array valueAtIndex:5], 74);
+ [array release];
+}
+
+- (void)testRemove {
+ const int32_t kValues[] = { 74, 71, 72, 74, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kValues[] = { 71, 71, 73, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:72];
+ [array replaceValueAtIndex:3 withValue:74];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:74],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 74);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 73);
+ XCTAssertEqual([array valueAtIndex:1], 74);
+ XCTAssertEqual([array valueAtIndex:2], 71);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:74 atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+#pragma mark - Non macro-based Enum tests
+
+// These are hand written tests to cover the verification and raw methods.
+
+@interface GPBEnumArrayCustomTests : XCTestCase
+@end
+
+@implementation GPBEnumArrayCustomTests
+
+- (void)testRawBasics {
+ static const int32_t kValues[] = { 71, 272, 73, 374 };
+ static const int32_t kValuesFiltered[] = {
+ 71, kGPBUnrecognizedEnumeratorValue, 73, kGPBUnrecognizedEnumeratorValue
+ };
+ XCTAssertEqual(GPBARRAYSIZE(kValues), GPBARRAYSIZE(kValuesFiltered));
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ GPBEnumValidationFunc func = TestingEnum_IsValidValue;
+ XCTAssertEqual(array.validationFunc, func);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 272);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 73);
+ XCTAssertEqual([array rawValueAtIndex:3], 374);
+ XCTAssertEqual([array valueAtIndex:3], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertThrowsSpecificNamed([array rawValueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValuesFiltered[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateRawValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValuesFiltered[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateRawValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 71, 72, 173 }; // With unknown value
+ const int32_t kValues2[] = { 71, 74, 173 }; // With unknown value
+ const int32_t kValues3[] = { 71, 72, 173, 74 }; // With unknown value
+ GPBEnumArray *array1 =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBEnumArray *array1prime =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue2
+ rawValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBEnumArray *array3 =
+ [[GPBEnumArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+ // But different validation functions.
+ XCTAssertNotEqual(array1.validationFunc, array1prime.validationFunc);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 71, 72 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array addRawValue:1000]; // Unknown
+ XCTAssertEqual(array.count, 3U);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 72);
+ XCTAssertEqual([array rawValueAtIndex:2], 1000);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+
+ GPBEnumArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ XCTAssertEqual(array.validationFunc, array2.validationFunc);
+ XCTAssertTrue([array2 isKindOfClass:[GPBEnumArray class]]);
+ XCTAssertEqual(array2.count, 3U);
+ XCTAssertEqual([array2 rawValueAtIndex:0], 71);
+ XCTAssertEqual([array2 rawValueAtIndex:1], 72);
+ XCTAssertEqual([array2 rawValueAtIndex:2], 1000);
+ XCTAssertEqual([array2 valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknowns
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [GPBEnumArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ XCTAssertEqual(array.validationFunc, array2.validationFunc);
+ [array release];
+}
+
+- (void)testUnknownAdds {
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(array);
+
+ XCTAssertThrowsSpecificNamed([array addValue:172],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 0U);
+
+ const int32_t kValues1[] = { 172, 173 }; // Unknown
+ XCTAssertThrowsSpecificNamed([array addValues:kValues1 count:GPBARRAYSIZE(kValues1)],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+- (void)testRawAdds {
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addRawValue:71]; // Valid
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 172, 173 }; // Unknown
+ [array addRawValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 74, 71 };
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addRawValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 172);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 173);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:3], 74);
+ XCTAssertEqual([array rawValueAtIndex:4], 71);
+ [array release];
+}
+
+- (void)testUnknownInserts {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ XCTAssertThrowsSpecificNamed([array insertValue:174 atIndex:0],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+
+ // Middle
+ XCTAssertThrowsSpecificNamed([array insertValue:274 atIndex:1],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+
+ // End
+ XCTAssertThrowsSpecificNamed([array insertValue:374 atIndex:3],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+ [array release];
+}
+
+- (void)testRawInsert {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertRawValue:174 atIndex:0]; // Unknown
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertRawValue:274 atIndex:2]; // Unknown
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertRawValue:374 atIndex:5]; // Unknown
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertRawValue:74 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array rawValueAtIndex:0], 174);
+ XCTAssertEqual([array valueAtIndex:0], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:1], 71);
+ XCTAssertEqual([array rawValueAtIndex:2], 274);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:3], 72);
+ XCTAssertEqual([array rawValueAtIndex:4], 73);
+ XCTAssertEqual([array rawValueAtIndex:5], 374);
+ XCTAssertEqual([array valueAtIndex:5], kGPBUnrecognizedEnumeratorValue);
+ [array release];
+}
+
+- (void)testUnknownInplaceMutation {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:1 withValue:172],
+ NSException, NSInvalidArgumentException);
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:3 withValue:274],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ [array release];
+}
+
+
+- (void)testRawInplaceMutation {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withRawValue:172]; // Unknown
+ [array replaceValueAtIndex:3 withRawValue:274]; // Unknown
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 172);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 73);
+ XCTAssertEqual([array rawValueAtIndex:3], 274);
+ XCTAssertEqual([array valueAtIndex:3], kGPBUnrecognizedEnumeratorValue);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withRawValue:74],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testRawInternalResizing {
+ const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknown
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addRawValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertRawValue:274 atIndex:(i * 3)]; // Unknown
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+#pragma mark - GPBAutocreatedArray Tests
+
+// These are hand written tests to double check some behaviors of the
+// GPBAutocreatedArray.
+
+// NOTE: GPBAutocreatedArray is private to the library, users of the library
+// should never have to directly deal with this class.
+
+@interface GPBAutocreatedArrayTests : XCTestCase
+@end
+
+@implementation GPBAutocreatedArrayTests
+
+- (void)testEquality {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ XCTAssertTrue([array isEqual:@[]]);
+ XCTAssertTrue([array isEqualToArray:@[]]);
+
+ XCTAssertFalse([array isEqual:@[ @"foo" ]]);
+ XCTAssertFalse([array isEqualToArray:@[ @"foo" ]]);
+
+ [array addObject:@"foo"];
+
+ XCTAssertFalse([array isEqual:@[]]);
+ XCTAssertFalse([array isEqualToArray:@[]]);
+ XCTAssertTrue([array isEqual:@[ @"foo" ]]);
+ XCTAssertTrue([array isEqualToArray:@[ @"foo" ]]);
+ XCTAssertFalse([array isEqual:@[ @"bar" ]]);
+ XCTAssertFalse([array isEqualToArray:@[ @"bar" ]]);
+
+ GPBAutocreatedArray *array2 = [[GPBAutocreatedArray alloc] init];
+
+ XCTAssertFalse([array isEqual:array2]);
+ XCTAssertFalse([array isEqualToArray:array2]);
+
+ [array2 addObject:@"bar"];
+ XCTAssertFalse([array isEqual:array2]);
+ XCTAssertFalse([array isEqualToArray:array2]);
+
+ [array2 replaceObjectAtIndex:0 withObject:@"foo"];
+ XCTAssertTrue([array isEqual:array2]);
+ XCTAssertTrue([array isEqualToArray:array2]);
+
+ [array2 release];
+ [array release];
+}
+
+- (void)testCopy {
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ NSArray *cpy = [array copy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSArray *cpy2 = [array copy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ // Can't compare cpy and cpy2 because NSArray has a singleton empty
+ // array it uses, so the ptrs are the same.
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ NSMutableArray *cpy = [array mutableCopy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSMutableArray *cpy2 = [array mutableCopy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+
+ NSArray *cpy = [array copy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[0], @"foo");
+ XCTAssertEqualObjects(cpy[1], @"bar");
+
+ NSArray *cpy2 = [array copy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[0], @"foo");
+ XCTAssertEqualObjects(cpy2[1], @"bar");
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+
+ NSMutableArray *cpy = [array mutableCopy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[0], @"foo");
+ XCTAssertEqualObjects(cpy[1], @"bar");
+
+ NSMutableArray *cpy2 = [array mutableCopy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[0], @"foo");
+ XCTAssertEqualObjects(cpy2[1], @"bar");
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+}
+
+- (void)testIndexedSubscriptSupport {
+ // The base NSArray/NSMutableArray behaviors for *IndexedSubscript methods
+ // should still work via the methods that one has to override to make an
+ // NSMutableArray subclass. i.e. - this should "just work" and if these
+ // crash/fail, then something is wrong in how NSMutableArray is subclassed.
+
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+ XCTAssertEqual(array.count, (NSUInteger)2);
+ XCTAssertEqualObjects(array[0], @"foo");
+ XCTAssertEqualObjects(array[1], @"bar");
+ array[0] = @"foo2";
+ array[2] = @"baz";
+ XCTAssertEqual(array.count, (NSUInteger)3);
+ XCTAssertEqualObjects(array[0], @"foo2");
+ XCTAssertEqualObjects(array[1], @"bar");
+ XCTAssertEqualObjects(array[2], @"baz");
+
+ [array release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m b/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m
new file mode 100644
index 0000000000..cc40215698
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m
@@ -0,0 +1,335 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedInputStream.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface CodedInputStreamTests : GPBTestCase
+@end
+
+@implementation CodedInputStreamTests
+
+- (NSData*)bytes_with_sentinel:(int32_t)unused, ... {
+ va_list list;
+ va_start(list, unused);
+
+ NSMutableData* values = [NSMutableData dataWithCapacity:0];
+ int32_t i;
+
+ while ((i = va_arg(list, int32_t)) != 256) {
+ NSAssert(i >= 0 && i < 256, @"");
+ uint8_t u = (uint8_t)i;
+ [values appendBytes:&u length:1];
+ }
+
+ va_end(list);
+
+ return values;
+}
+
+#define bytes(...) [self bytes_with_sentinel:0, __VA_ARGS__, 256]
+
+- (void)testDecodeZigZag {
+ XCTAssertEqual(0, GPBDecodeZigZag32(0));
+ XCTAssertEqual(-1, GPBDecodeZigZag32(1));
+ XCTAssertEqual(1, GPBDecodeZigZag32(2));
+ XCTAssertEqual(-2, GPBDecodeZigZag32(3));
+ XCTAssertEqual((int32_t)0x3FFFFFFF, GPBDecodeZigZag32(0x7FFFFFFE));
+ XCTAssertEqual((int32_t)0xC0000000, GPBDecodeZigZag32(0x7FFFFFFF));
+ XCTAssertEqual((int32_t)0x7FFFFFFF, GPBDecodeZigZag32(0xFFFFFFFE));
+ XCTAssertEqual((int32_t)0x80000000, GPBDecodeZigZag32(0xFFFFFFFF));
+
+ XCTAssertEqual((int64_t)0, GPBDecodeZigZag64(0));
+ XCTAssertEqual((int64_t)-1, GPBDecodeZigZag64(1));
+ XCTAssertEqual((int64_t)1, GPBDecodeZigZag64(2));
+ XCTAssertEqual((int64_t)-2, GPBDecodeZigZag64(3));
+ XCTAssertEqual((int64_t)0x000000003FFFFFFFL,
+ GPBDecodeZigZag64(0x000000007FFFFFFEL));
+ XCTAssertEqual((int64_t)0xFFFFFFFFC0000000L,
+ GPBDecodeZigZag64(0x000000007FFFFFFFL));
+ XCTAssertEqual((int64_t)0x000000007FFFFFFFL,
+ GPBDecodeZigZag64(0x00000000FFFFFFFEL));
+ XCTAssertEqual((int64_t)0xFFFFFFFF80000000L,
+ GPBDecodeZigZag64(0x00000000FFFFFFFFL));
+ XCTAssertEqual((int64_t)0x7FFFFFFFFFFFFFFFL,
+ GPBDecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
+ XCTAssertEqual((int64_t)0x8000000000000000L,
+ GPBDecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
+}
+
+- (void)assertReadVarint:(NSData*)data value:(int64_t)value {
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual((int32_t)value, [input readInt32]);
+ }
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readInt64]);
+ }
+}
+
+- (void)assertReadLittleEndian32:(NSData*)data value:(int32_t)value {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readSFixed32]);
+}
+
+- (void)assertReadLittleEndian64:(NSData*)data value:(int64_t)value {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readSFixed64]);
+}
+
+- (void)assertReadVarintFailure:(NSData*)data {
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertThrows([input readInt32]);
+ }
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertThrows([input readInt64]);
+ }
+}
+
+- (void)testBytes {
+ NSData* data = bytes(0xa2, 0x74);
+ XCTAssertEqual(data.length, (NSUInteger)2);
+ XCTAssertEqual(((uint8_t*)data.bytes)[0], (uint8_t)0xa2);
+ XCTAssertEqual(((uint8_t*)data.bytes)[1], (uint8_t)0x74);
+}
+
+- (void)testReadVarint {
+ [self assertReadVarint:bytes(0x00) value:0];
+ [self assertReadVarint:bytes(0x01) value:1];
+ [self assertReadVarint:bytes(0x7f) value:127];
+ // 14882
+ [self assertReadVarint:bytes(0xa2, 0x74) value:(0x22 << 0) | (0x74 << 7)];
+ // 2961488830
+ [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x0bLL << 28)];
+
+ // 64-bit
+ // 7256456126
+ [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x1bLL << 28)];
+ // 41256202580718336
+ [self assertReadVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49)
+ value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) |
+ (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) |
+ (0x24LL << 42) | (0x49LL << 49)];
+ // 11964378330978735131
+ [self
+ assertReadVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85,
+ 0xa6, 0x01)
+ value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bLL << 28) | (0x56LL << 35) | (0x00LL << 42) |
+ (0x05LL << 49) | (0x26LL << 56) | (0x01LL << 63)];
+
+ // Failures
+ [self assertReadVarintFailure:bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+ 0x80, 0x80, 0x80, 0x00)];
+ [self assertReadVarintFailure:bytes(0x80)];
+}
+
+- (void)testReadLittleEndian {
+ [self assertReadLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12)
+ value:0x12345678];
+ [self assertReadLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a)
+ value:0x9abcdef0];
+
+ [self assertReadLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34,
+ 0x12)
+ value:0x123456789abcdef0LL];
+ [self assertReadLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc,
+ 0x9a)
+ value:0x9abcdef012345678LL];
+}
+
+- (void)testReadWholeMessage {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 =
+ [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL];
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSkipWholeMessage {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+
+ // Create two parallel inputs. Parse one as unknown fields while using
+ // skipField() to skip each field on the other. Expect the same tags.
+ GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes];
+ GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes];
+ GPBUnknownFieldSet* unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+
+ while (YES) {
+ int32_t tag = [input1 readTag];
+ XCTAssertEqual(tag, [input2 readTag]);
+ if (tag == 0) {
+ break;
+ }
+ [unknownFields mergeFieldFrom:tag input:input1];
+ [input2 skipField:tag];
+ }
+}
+
+- (void)testReadHugeBlob {
+ // Allocate and initialize a 1MB blob.
+ NSMutableData* blob = [NSMutableData dataWithLength:1 << 20];
+ for (NSUInteger i = 0; i < blob.length; i++) {
+ ((uint8_t*)blob.mutableBytes)[i] = (uint8_t)i;
+ }
+
+ // Make a message containing it.
+ TestAllTypes* message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [message setOptionalBytes:blob];
+
+ // Serialize and parse it. Make sure to parse from an InputStream, not
+ // directly from a ByteString, so that CodedInputStream uses buffered
+ // reading.
+ NSData *messageData = message.data;
+ XCTAssertNotNil(messageData);
+ GPBCodedInputStream* stream =
+ [GPBCodedInputStream streamWithData:messageData];
+ TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream
+ extensionRegistry:nil
+ error:NULL];
+
+ XCTAssertEqualObjects(message.optionalBytes, message2.optionalBytes);
+
+ // Make sure all the other fields were parsed correctly.
+ TestAllTypes* message3 = [[message2 copy] autorelease];
+ TestAllTypes* types = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* data = [types optionalBytes];
+ [message3 setOptionalBytes:data];
+
+ [self assertAllFieldsSet:message3 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testReadMaliciouslyLargeBlob {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(1, GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ [output writeRawVarint32:0x7FFFFFFF];
+ uint8_t bytes[32] = {0};
+ [output writeRawData:[NSData dataWithBytes:bytes length:32]];
+ [output flush];
+
+ NSData* data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input =
+ [GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]];
+ XCTAssertEqual(tag, [input readTag]);
+
+ XCTAssertThrows([input readBytes]);
+}
+
+// Verifies fix for b/10315336.
+// Note: Now that there isn't a custom string class under the hood, this test
+// isn't as critical, but it does cover bad input and if a custom class is added
+// again, it will help validate that class' handing of bad utf8.
+- (void)testReadMalformedString {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
+ GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ [output writeRawVarint32:5];
+ // Create an invalid utf-8 byte array.
+ uint8_t bytes[] = {0xc2, 0xf2, 0x0, 0x0, 0x0};
+ [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
+ [output flush];
+
+ NSData *data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ NSError *error = nil;
+ TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
+ extensionRegistry:nil
+ error:&error];
+ XCTAssertNotNil(error);
+ XCTAssertNil(message);
+}
+
+- (void)testBOMWithinStrings {
+ // We've seen servers that end up with BOMs within strings (not always at the
+ // start, and sometimes in multiple places), make sure they always parse
+ // correctly. (Again, this is inpart incase a custom string class is ever
+ // used again.)
+ const char* strs[] = {
+ "\xEF\xBB\xBF String with BOM",
+ "String with \xEF\xBB\xBF in middle",
+ "String with end bom \xEF\xBB\xBF",
+ "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart
+ "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM",
+ };
+ for (size_t i = 0; i < GPBARRAYSIZE(strs); ++i) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
+ GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ size_t length = strlen(strs[i]);
+ [output writeRawVarint32:(int32_t)length];
+ [output writeRawData:[NSData dataWithBytes:strs[i] length:length]];
+ [output flush];
+
+ NSData* data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ XCTAssertNotNil(message, @"Loop %zd", i);
+ // Ensure the string is there. NSString can consume the BOM in some
+ // cases, so don't actually check the string for exact equality.
+ XCTAssertTrue(message.defaultString.length > 0, @"Loop %zd", i);
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m b/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m
new file mode 100644
index 0000000000..2ad326beb9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m
@@ -0,0 +1,426 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBCodedInputStream.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface GPBCodedOutputStream (InternalMethods)
+// Declared in the .m file, expose for testing.
+- (instancetype)initWithOutputStream:(NSOutputStream *)output
+ data:(NSMutableData *)data;
+@end
+
+@interface GPBCodedOutputStream (Helper)
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output
+ bufferSize:(size_t)bufferSize;
+@end
+
+@implementation GPBCodedOutputStream (Helper)
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output
+ bufferSize:(size_t)bufferSize {
+ NSMutableData *data = [NSMutableData dataWithLength:bufferSize];
+ return [[[self alloc] initWithOutputStream:output data:data] autorelease];
+}
+@end
+
+@interface CodedOutputStreamTests : GPBTestCase
+@end
+
+@implementation CodedOutputStreamTests
+
+- (NSData*)bytes_with_sentinel:(int32_t)unused, ... {
+ va_list list;
+ va_start(list, unused);
+
+ NSMutableData* values = [NSMutableData dataWithCapacity:0];
+ int32_t i;
+
+ while ((i = va_arg(list, int32_t)) != 256) {
+ NSAssert(i >= 0 && i < 256, @"");
+ uint8_t u = (uint8_t)i;
+ [values appendBytes:&u length:1];
+ }
+
+ va_end(list);
+
+ return values;
+}
+
+#define bytes(...) [self bytes_with_sentinel:0, __VA_ARGS__, 256]
+
+- (void)assertWriteLittleEndian32:(NSData*)data value:(int32_t)value {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawLittleEndian32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeRawLittleEndian32:(int32_t)value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+}
+
+- (void)assertWriteLittleEndian64:(NSData*)data value:(int64_t)value {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawLittleEndian64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeRawLittleEndian64:value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+}
+
+- (void)assertWriteVarint:(NSData*)data value:(int64_t)value {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if (GPBLogicalRightShift64(value, 32) == 0) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawVarint32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Also try computing size.
+ XCTAssertEqual(GPBComputeRawVarint32Size((int32_t)value),
+ (size_t)data.length);
+ }
+
+ {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawVarint64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Also try computing size.
+ XCTAssertEqual(GPBComputeRawVarint64Size(value), (size_t)data.length);
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if (GPBLogicalRightShift64(value, 32) == 0) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+
+ [output writeRawVarint32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+
+ {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+
+ [output writeRawVarint64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+ }
+}
+
+- (void)assertWriteStringNoTag:(NSData*)data
+ value:(NSString *)value
+ context:(NSString *)contextMessage {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeStringNoTag:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual, @"%@", contextMessage);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeStringNoTag:value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual, @"%@", contextMessage);
+ }
+}
+
+- (void)testWriteVarint1 {
+ [self assertWriteVarint:bytes(0x00) value:0];
+}
+
+- (void)testWriteVarint2 {
+ [self assertWriteVarint:bytes(0x01) value:1];
+}
+
+- (void)testWriteVarint3 {
+ [self assertWriteVarint:bytes(0x7f) value:127];
+}
+
+- (void)testWriteVarint4 {
+ // 14882
+ [self assertWriteVarint:bytes(0xa2, 0x74) value:(0x22 << 0) | (0x74 << 7)];
+}
+
+- (void)testWriteVarint5 {
+ // 2961488830
+ [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x0bLL << 28)];
+}
+
+- (void)testWriteVarint6 {
+ // 64-bit
+ // 7256456126
+ [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x1bLL << 28)];
+}
+
+- (void)testWriteVarint7 {
+ // 41256202580718336
+ [self assertWriteVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49)
+ value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) |
+ (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) |
+ (0x24LL << 42) | (0x49LL << 49)];
+}
+
+- (void)testWriteVarint8 {
+ // 11964378330978735131
+ [self assertWriteVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85,
+ 0xa6, 0x01)
+ value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) |
+ (0x42 << 21) | (0x3bLL << 28) | (0x56LL << 35) |
+ (0x00LL << 42) | (0x05LL << 49) | (0x26LL << 56) |
+ (0x01LL << 63)];
+}
+
+- (void)testWriteLittleEndian {
+ [self assertWriteLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12)
+ value:0x12345678];
+ [self assertWriteLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a)
+ value:0x9abcdef0];
+
+ [self assertWriteLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56,
+ 0x34, 0x12)
+ value:0x123456789abcdef0LL];
+ [self assertWriteLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde,
+ 0xbc, 0x9a)
+ value:0x9abcdef012345678LL];
+}
+
+- (void)testEncodeZigZag {
+ XCTAssertEqual(0U, GPBEncodeZigZag32(0));
+ XCTAssertEqual(1U, GPBEncodeZigZag32(-1));
+ XCTAssertEqual(2U, GPBEncodeZigZag32(1));
+ XCTAssertEqual(3U, GPBEncodeZigZag32(-2));
+ XCTAssertEqual(0x7FFFFFFEU, GPBEncodeZigZag32(0x3FFFFFFF));
+ XCTAssertEqual(0x7FFFFFFFU, GPBEncodeZigZag32(0xC0000000));
+ XCTAssertEqual(0xFFFFFFFEU, GPBEncodeZigZag32(0x7FFFFFFF));
+ XCTAssertEqual(0xFFFFFFFFU, GPBEncodeZigZag32(0x80000000));
+
+ XCTAssertEqual(0ULL, GPBEncodeZigZag64(0));
+ XCTAssertEqual(1ULL, GPBEncodeZigZag64(-1));
+ XCTAssertEqual(2ULL, GPBEncodeZigZag64(1));
+ XCTAssertEqual(3ULL, GPBEncodeZigZag64(-2));
+ XCTAssertEqual(0x000000007FFFFFFEULL,
+ GPBEncodeZigZag64(0x000000003FFFFFFFLL));
+ XCTAssertEqual(0x000000007FFFFFFFULL,
+ GPBEncodeZigZag64(0xFFFFFFFFC0000000LL));
+ XCTAssertEqual(0x00000000FFFFFFFEULL,
+ GPBEncodeZigZag64(0x000000007FFFFFFFLL));
+ XCTAssertEqual(0x00000000FFFFFFFFULL,
+ GPBEncodeZigZag64(0xFFFFFFFF80000000LL));
+ XCTAssertEqual(0xFFFFFFFFFFFFFFFEULL,
+ GPBEncodeZigZag64(0x7FFFFFFFFFFFFFFFLL));
+ XCTAssertEqual(0xFFFFFFFFFFFFFFFFULL,
+ GPBEncodeZigZag64(0x8000000000000000LL));
+
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ XCTAssertEqual(0U, GPBEncodeZigZag32(GPBDecodeZigZag32(0)));
+ XCTAssertEqual(1U, GPBEncodeZigZag32(GPBDecodeZigZag32(1)));
+ XCTAssertEqual(-1U, GPBEncodeZigZag32(GPBDecodeZigZag32(-1)));
+ XCTAssertEqual(14927U, GPBEncodeZigZag32(GPBDecodeZigZag32(14927)));
+ XCTAssertEqual(-3612U, GPBEncodeZigZag32(GPBDecodeZigZag32(-3612)));
+
+ XCTAssertEqual(0ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(0)));
+ XCTAssertEqual(1ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(1)));
+ XCTAssertEqual(-1ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-1)));
+ XCTAssertEqual(14927ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(14927)));
+ XCTAssertEqual(-3612ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-3612)));
+
+ XCTAssertEqual(856912304801416ULL,
+ GPBEncodeZigZag64(GPBDecodeZigZag64(856912304801416LL)));
+ XCTAssertEqual(-75123905439571256ULL,
+ GPBEncodeZigZag64(GPBDecodeZigZag64(-75123905439571256LL)));
+}
+
+- (void)testWriteWholeMessage {
+ // Not kGPBDefaultRepeatCount because we are comparing to a golden master file
+ // that was generated with 2.
+ TestAllTypes* message = [self allSetRepeatedCount:2];
+
+ NSData* rawBytes = message.data;
+ NSData* goldenData =
+ [self getDataFileNamed:@"golden_message" dataToWrite:rawBytes];
+ XCTAssertEqualObjects(rawBytes, goldenData);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [message writeToCodedOutputStream:output];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(rawBytes, actual);
+ }
+
+ // Not kGPBDefaultRepeatCount because we are comparing to a golden master file
+ // that was generated with 2.
+ TestAllExtensions* extensions = [self allExtensionsSetRepeatedCount:2];
+ rawBytes = extensions.data;
+ goldenData = [self getDataFileNamed:@"golden_packed_fields_message"
+ dataToWrite:rawBytes];
+ XCTAssertEqualObjects(rawBytes, goldenData);
+}
+
+- (void)testCFStringGetCStringPtrAndStringsWithNullChars {
+ // This test exists to verify that CFStrings with embedded NULLs still expose
+ // their raw buffer if they are backed by UTF8 storage. If this fails, the
+ // quick/direct access paths in GPBCodedOutputStream that depend on
+ // CFStringGetCStringPtr need to be re-evalutated (maybe just removed).
+ // And yes, we do get NULLs in strings from some servers.
+
+ char zeroTest[] = "\0Test\0String";
+ // Note: there is a \0 at the end of this since it is a c-string.
+ NSString *asNSString = [[NSString alloc] initWithBytes:zeroTest
+ length:sizeof(zeroTest)
+ encoding:NSUTF8StringEncoding];
+ const char *cString =
+ CFStringGetCStringPtr((CFStringRef)asNSString, kCFStringEncodingUTF8);
+ XCTAssertTrue(cString != NULL);
+ // Again, if the above assert fails, then it means NSString no longer exposes
+ // the raw utf8 storage of a string created from utf8 input, so the code using
+ // CFStringGetCStringPtr in GPBCodedOutputStream will still work (it will take
+ // a different code path); but the optimizations for when
+ // CFStringGetCStringPtr does work could possibly go away.
+
+ XCTAssertEqual(sizeof(zeroTest),
+ [asNSString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertTrue(0 == memcmp(cString, zeroTest, sizeof(zeroTest)));
+ [asNSString release];
+}
+
+- (void)testWriteStringsWithZeroChar {
+ // Unicode allows `\0` as a character, and NSString is a class cluster, so
+ // there are a few different classes that could end up beind a given string.
+ // Historically, we've seen differences based on constant strings in code and
+ // strings built via the NSString apis. So this round trips them to ensure
+ // they are acting as expected.
+
+ NSArray<NSString *> *strs = @[
+ @"\0at start",
+ @"in\0middle",
+ @"at end\0",
+ ];
+ int i = 0;
+ for (NSString *str in strs) {
+ NSData *asUTF8 = [str dataUsingEncoding:NSUTF8StringEncoding];
+ NSMutableData *expected = [NSMutableData data];
+ uint8_t lengthByte = (uint8_t)asUTF8.length;
+ [expected appendBytes:&lengthByte length:1];
+ [expected appendData:asUTF8];
+
+ NSString *context = [NSString stringWithFormat:@"Loop %d - Literal", i];
+ [self assertWriteStringNoTag:expected value:str context:context];
+
+ // Force a new string to be built which gets a different class from the
+ // NSString class cluster than the literal did.
+ NSString *str2 = [NSString stringWithFormat:@"%@", str];
+ context = [NSString stringWithFormat:@"Loop %d - Built", i];
+ [self assertWriteStringNoTag:expected value:str2 context:context];
+
+ ++i;
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m b/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m
new file mode 100644
index 0000000000..daf75e7e72
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m
@@ -0,0 +1,206 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+static const int kNumThreads = 100;
+static const int kNumMessages = 100;
+
+// NOTE: Most of these tests don't "fail" in the sense that the XCTAsserts
+// trip. Rather, the asserts simply exercise the apis, and if there is
+// a concurancy issue, the NSAsserts in the runtime code fire and/or the
+// code just crashes outright.
+
+@interface ConcurrencyTests : GPBTestCase
+@end
+
+@implementation ConcurrencyTests
+
+- (NSArray *)createThreadsWithSelector:(SEL)selector object:(id)object {
+ NSMutableArray *array = [NSMutableArray array];
+ for (NSUInteger i = 0; i < kNumThreads; i++) {
+ NSThread *thread =
+ [[NSThread alloc] initWithTarget:self selector:selector object:object];
+ [array addObject:thread];
+ [thread release];
+ }
+ return array;
+}
+
+- (NSArray *)createMessagesWithType:(Class)msgType {
+ NSMutableArray *array = [NSMutableArray array];
+ for (NSUInteger i = 0; i < kNumMessages; i++) {
+ [array addObject:[msgType message]];
+ }
+ return array;
+}
+
+- (void)startThreads:(NSArray *)threads {
+ for (NSThread *thread in threads) {
+ [thread start];
+ }
+}
+
+- (void)joinThreads:(NSArray *)threads {
+ for (NSThread *thread in threads) {
+ while (![thread isFinished])
+ ;
+ }
+}
+
+- (void)readForeignMessage:(NSArray *)messages {
+ for (NSUInteger i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual(message.optionalForeignMessage.c, 0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetMessageField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readForeignMessage:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ }
+}
+
+- (void)readRepeatedInt32:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedInt32Array count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetRepeatedIntField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readRepeatedInt32:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedInt32Array count], (NSUInteger)0);
+ }
+}
+
+- (void)readRepeatedString:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedStringArray count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetRepeatedStringField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readRepeatedString:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedStringArray count], (NSUInteger)0);
+ }
+}
+
+- (void)readInt32Int32Map:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetInt32Int32MapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readInt32Int32Map:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+}
+
+- (void)readStringStringMap:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetStringStringMapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readStringStringMap:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+}
+
+- (void)readOptionalForeignMessageExtension:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllExtensions *message in messages) {
+ ForeignMessage *foreign =
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]];
+ XCTAssertEqual(foreign.c, 0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetExtensionField {
+ NSArray *messages = [self createMessagesWithType:[TestAllExtensions class]];
+ SEL sel = @selector(readOptionalForeignMessageExtension:);
+ NSArray *threads = [self createThreadsWithSelector:sel object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ GPBExtensionDescriptor *extension =
+ [UnittestRoot optionalForeignMessageExtension];
+ for (TestAllExtensions *message in messages) {
+ XCTAssertFalse([message hasExtension:extension]);
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m b/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m
new file mode 100644
index 0000000000..1e1c3de8d0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m
@@ -0,0 +1,256 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBDescriptor.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+#import "google/protobuf/Descriptor.pbobjc.h"
+
+@interface DescriptorTests : GPBTestCase
+@end
+
+@implementation DescriptorTests
+
+- (void)testDescriptor_containingType {
+ GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
+ GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
+ XCTAssertNil(testAllTypesDesc.containingType);
+ XCTAssertNotNil(nestedMessageDesc.containingType);
+ XCTAssertEqual(nestedMessageDesc.containingType, testAllTypesDesc); // Ptr comparison
+}
+
+- (void)testDescriptor_fullName {
+ GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
+ XCTAssertEqualObjects(testAllTypesDesc.fullName, @"protobuf_unittest.TestAllTypes");
+ GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
+ XCTAssertEqualObjects(nestedMessageDesc.fullName, @"protobuf_unittest.TestAllTypes.NestedMessage");
+
+ // Prefixes removed.
+ GPBDescriptor *descDesc = [GPBDescriptorProto descriptor];
+ XCTAssertEqualObjects(descDesc.fullName, @"google.protobuf.DescriptorProto");
+ GPBDescriptor *descExtRngDesc = [GPBDescriptorProto_ExtensionRange descriptor];
+ XCTAssertEqualObjects(descExtRngDesc.fullName, @"google.protobuf.DescriptorProto.ExtensionRange");
+
+ // Things that get "_Class" added.
+ GPBDescriptor *pointDesc = [Point_Class descriptor];
+ XCTAssertEqualObjects(pointDesc.fullName, @"protobuf_unittest.Point");
+ GPBDescriptor *pointRectDesc = [Point_Rect descriptor];
+ XCTAssertEqualObjects(pointRectDesc.fullName, @"protobuf_unittest.Point.Rect");
+}
+
+- (void)testFieldDescriptor {
+ GPBDescriptor *descriptor = [TestAllTypes descriptor];
+
+ // Nested Enum
+ GPBFieldDescriptor *fieldDescriptorWithName =
+ [descriptor fieldWithName:@"optionalNestedEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ GPBFieldDescriptor *fieldDescriptorWithNumber =
+ [descriptor fieldWithNumber:21];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"TestAllTypes_NestedEnum");
+
+ // Foreign Enum
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:22];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"ForeignEnum");
+
+ // Import Enum
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:23];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"ImportEnum");
+
+ // Nested Message
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:18];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+
+ // Foreign Message
+ fieldDescriptorWithName =
+ [descriptor fieldWithName:@"optionalForeignMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:19];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+
+ // Import Message
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:20];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+}
+
+- (void)testEnumDescriptor {
+ GPBEnumDescriptor *descriptor = TestAllTypes_NestedEnum_EnumDescriptor();
+
+ NSString *enumName = [descriptor enumNameForValue:1];
+ XCTAssertNotNil(enumName);
+ int32_t value;
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Foo"]);
+ XCTAssertTrue(
+ [descriptor getValue:NULL forEnumName:@"TestAllTypes_NestedEnum_Foo"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
+
+ enumName = [descriptor enumNameForValue:2];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar);
+
+ enumName = [descriptor enumNameForValue:3];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz);
+
+ // TextFormat
+ enumName = [descriptor textFormatNameForValue:1];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
+
+ // Bad values
+ enumName = [descriptor enumNameForValue:0];
+ XCTAssertNil(enumName);
+ XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:&value
+ forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL
+ forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL forEnumTextFormatName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:&value forEnumTextFormatName:@"Unknown"]);
+}
+
+- (void)testEnumValueValidator {
+ GPBDescriptor *descriptor = [TestAllTypes descriptor];
+ GPBFieldDescriptor *fieldDescriptor =
+ [descriptor fieldWithName:@"optionalNestedEnum"];
+
+ // Valid values
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:1]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:2]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:3]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:-1]);
+
+ // Invalid values
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:4]);
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:0]);
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:-2]);
+}
+
+- (void)testOneofDescriptor {
+ GPBDescriptor *descriptor = [TestOneof2 descriptor];
+
+ // All fields should be listed.
+ XCTAssertEqual(descriptor.fields.count, 17U);
+
+ // There are two oneofs in there.
+ XCTAssertEqual(descriptor.oneofs.count, 2U);
+
+ GPBFieldDescriptor *fooStringField =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_FooString];
+ XCTAssertNotNil(fooStringField);
+ GPBFieldDescriptor *barStringField =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_BarString];
+ XCTAssertNotNil(barStringField);
+
+ // Check the oneofs to have what is expected.
+
+ GPBOneofDescriptor *oneofFoo = [descriptor oneofWithName:@"foo"];
+ XCTAssertNotNil(oneofFoo);
+ XCTAssertEqual(oneofFoo.fields.count, 9U);
+
+ // Pointer comparisons.
+ XCTAssertEqual([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_FooString],
+ fooStringField);
+ XCTAssertEqual([oneofFoo fieldWithName:@"fooString"], fooStringField);
+
+ GPBOneofDescriptor *oneofBar = [descriptor oneofWithName:@"bar"];
+ XCTAssertNotNil(oneofBar);
+ XCTAssertEqual(oneofBar.fields.count, 6U);
+
+ // Pointer comparisons.
+ XCTAssertEqual([oneofBar fieldWithNumber:TestOneof2_FieldNumber_BarString],
+ barStringField);
+ XCTAssertEqual([oneofBar fieldWithName:@"barString"], barStringField);
+
+ // Unknown oneof not found.
+
+ XCTAssertNil([descriptor oneofWithName:@"mumble"]);
+ XCTAssertNil([descriptor oneofWithName:@"Foo"]);
+
+ // Unknown oneof item.
+
+ XCTAssertNil([oneofFoo fieldWithName:@"mumble"]);
+ XCTAssertNil([oneofFoo fieldWithNumber:666]);
+
+ // Field exists, but not in this oneof.
+
+ XCTAssertNil([oneofFoo fieldWithName:@"barString"]);
+ XCTAssertNil([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_BarString]);
+ XCTAssertNil([oneofBar fieldWithName:@"fooString"]);
+ XCTAssertNil([oneofBar fieldWithNumber:TestOneof2_FieldNumber_FooString]);
+
+ // Check pointers back to the enclosing oneofs.
+ // (pointer comparisions)
+ XCTAssertEqual(fooStringField.containingOneof, oneofFoo);
+ XCTAssertEqual(barStringField.containingOneof, oneofBar);
+ GPBFieldDescriptor *bazString =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString];
+ XCTAssertNotNil(bazString);
+ XCTAssertNil(bazString.containingOneof);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m
new file mode 100644
index 0000000000..0dbe07b6e9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m
@@ -0,0 +1,2418 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt32
+
+@interface GPBBoolUInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolUInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionaryWithUInt32:100U forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ uint32_t *seenValues = malloc(2 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const uint32_t kValues1[] = { 100U, 101U };
+ const uint32_t kValues2[] = { 101U, 100U };
+ const uint32_t kValues3[] = { 101U };
+ GPBBoolUInt32Dictionary *dict1 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolUInt32Dictionary *dict1prime =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolUInt32Dictionary *dict3 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolUInt32Dictionary *dict4 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt32Dictionary *dict2 =
+ [GPBBoolUInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const uint32_t kValues[] = { 101U };
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeUInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict setUInt32:101U forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict setUInt32:100U forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 100U);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const uint32_t kValues2[] = { 101U, 100U };
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int32
+
+@interface GPBBoolInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:YES]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionaryWithInt32:200 forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ int32_t *seenValues = malloc(2 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const int32_t kValues1[] = { 200, 201 };
+ const int32_t kValues2[] = { 201, 200 };
+ const int32_t kValues3[] = { 201 };
+ GPBBoolInt32Dictionary *dict1 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolInt32Dictionary *dict1prime =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolInt32Dictionary *dict3 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolInt32Dictionary *dict4 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt32Dictionary *dict2 =
+ [GPBBoolInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const int32_t kValues[] = { 201 };
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:YES]);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict setInt32:201 forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict setInt32:200 forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 200);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const int32_t kValues2[] = { 201, 200 };
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt64
+
+@interface GPBBoolUInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolUInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionaryWithUInt64:300U forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ uint64_t *seenValues = malloc(2 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const uint64_t kValues1[] = { 300U, 301U };
+ const uint64_t kValues2[] = { 301U, 300U };
+ const uint64_t kValues3[] = { 301U };
+ GPBBoolUInt64Dictionary *dict1 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolUInt64Dictionary *dict1prime =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolUInt64Dictionary *dict3 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolUInt64Dictionary *dict4 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt64Dictionary *dict2 =
+ [GPBBoolUInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const uint64_t kValues[] = { 301U };
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeUInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict setUInt64:301U forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict setUInt64:300U forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 300U);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const uint64_t kValues2[] = { 301U, 300U };
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int64
+
+@interface GPBBoolInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:YES]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionaryWithInt64:400 forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ int64_t *seenValues = malloc(2 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const int64_t kValues1[] = { 400, 401 };
+ const int64_t kValues2[] = { 401, 400 };
+ const int64_t kValues3[] = { 401 };
+ GPBBoolInt64Dictionary *dict1 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolInt64Dictionary *dict1prime =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolInt64Dictionary *dict3 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolInt64Dictionary *dict4 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt64Dictionary *dict2 =
+ [GPBBoolInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const int64_t kValues[] = { 401 };
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:YES]);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict setInt64:401 forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict setInt64:400 forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 400);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const int64_t kValues2[] = { 401, 400 };
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Bool
+
+@interface GPBBoolBoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolBoolDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:YES]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionaryWithBool:NO forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, NO);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ BOOL *seenValues = malloc(2 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const BOOL kValues1[] = { NO, YES };
+ const BOOL kValues2[] = { YES, NO };
+ const BOOL kValues3[] = { YES };
+ GPBBoolBoolDictionary *dict1 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolBoolDictionary *dict1prime =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolBoolDictionary *dict3 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolBoolDictionary *dict4 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolBoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolBoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolBoolDictionary *dict2 =
+ [GPBBoolBoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:NO forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const BOOL kValues[] = { YES };
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeBoolForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:YES]);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict setBool:YES forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict setBool:NO forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, NO);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const BOOL kValues2[] = { YES, NO };
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Float
+
+@interface GPBBoolFloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolFloatDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:YES]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionaryWithFloat:500.f forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ float *seenValues = malloc(2 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const float kValues1[] = { 500.f, 501.f };
+ const float kValues2[] = { 501.f, 500.f };
+ const float kValues3[] = { 501.f };
+ GPBBoolFloatDictionary *dict1 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolFloatDictionary *dict1prime =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolFloatDictionary *dict3 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolFloatDictionary *dict4 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolFloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolFloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolFloatDictionary *dict2 =
+ [GPBBoolFloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const float kValues[] = { 501.f };
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeFloatForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:YES]);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict setFloat:501.f forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict setFloat:500.f forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 500.f);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const float kValues2[] = { 501.f, 500.f };
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Double
+
+@interface GPBBoolDoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolDoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:YES]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionaryWithDouble:600. forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ double *seenValues = malloc(2 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const double kValues1[] = { 600., 601. };
+ const double kValues2[] = { 601., 600. };
+ const double kValues3[] = { 601. };
+ GPBBoolDoubleDictionary *dict1 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolDoubleDictionary *dict1prime =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolDoubleDictionary *dict3 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolDoubleDictionary *dict4 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolDoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolDoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolDoubleDictionary *dict2 =
+ [GPBBoolDoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const double kValues[] = { 601. };
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeDoubleForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:YES]);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict setDouble:601. forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict setDouble:600. forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 600.);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const double kValues2[] = { 601., 600. };
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def")
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Object
+
+@interface GPBBoolObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:YES]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionaryWithObject:@"abc" forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ NSString* *seenObjects = malloc(2 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const NSString* kObjects1[] = { @"abc", @"def" };
+ const NSString* kObjects2[] = { @"def", @"abc" };
+ const NSString* kObjects3[] = { @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict1 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolObjectDictionary<NSString*> *dict1prime =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolObjectDictionary<NSString*> *dict3 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolObjectDictionary<NSString*> *dict4 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [GPBBoolObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const NSString* kObjects[] = { @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeObjectForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:YES]);
+ XCTAssertNil([dict objectForKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict setObject:@"def" forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"def");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict setObject:@"abc" forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"def");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"abc");
+
+ const BOOL kKeys2[] = { NO, YES };
+ const NSString* kObjects2[] = { @"def", @"abc" };
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m
new file mode 100644
index 0000000000..c539bdc2ed
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int32_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int32_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - Int32 -> UInt32
+
+@interface GPBInt32UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32UInt32Dictionary *dict = [[GPBInt32UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:11]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32UInt32Dictionary *dict = [GPBInt32UInt32Dictionary dictionaryWithUInt32:100U forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict1 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32UInt32Dictionary *dict1prime =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32UInt32Dictionary *dict3 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32UInt32Dictionary *dict4 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt32Dictionary *dict2 =
+ [GPBInt32UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32UInt32Dictionary *dict = [GPBInt32UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:11]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:13]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 101U);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+@interface GPBInt32Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32Int32Dictionary *dict = [[GPBInt32Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:11]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32Int32Dictionary *dict = [GPBInt32Int32Dictionary dictionaryWithInt32:200 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict1 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32Int32Dictionary *dict1prime =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32Int32Dictionary *dict3 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32Int32Dictionary *dict4 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int32Dictionary *dict2 =
+ [GPBInt32Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32Int32Dictionary *dict = [GPBInt32Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:11]);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertFalse([dict getInt32:NULL forKey:13]);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 201);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+@interface GPBInt32UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32UInt64Dictionary *dict = [[GPBInt32UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:11]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32UInt64Dictionary *dict = [GPBInt32UInt64Dictionary dictionaryWithUInt64:300U forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict1 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32UInt64Dictionary *dict1prime =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32UInt64Dictionary *dict3 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32UInt64Dictionary *dict4 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt64Dictionary *dict2 =
+ [GPBInt32UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32UInt64Dictionary *dict = [GPBInt32UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:11]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:13]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 301U);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+@interface GPBInt32Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32Int64Dictionary *dict = [[GPBInt32Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:11]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32Int64Dictionary *dict = [GPBInt32Int64Dictionary dictionaryWithInt64:400 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict1 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32Int64Dictionary *dict1prime =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32Int64Dictionary *dict3 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32Int64Dictionary *dict4 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int64Dictionary *dict2 =
+ [GPBInt32Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32Int64Dictionary *dict = [GPBInt32Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:11]);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertFalse([dict getInt64:NULL forKey:13]);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 401);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+@interface GPBInt32BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32BoolDictionary *dict = [[GPBInt32BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:11]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32BoolDictionary *dict = [GPBInt32BoolDictionary dictionaryWithBool:YES forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict1 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32BoolDictionary *dict1prime =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32BoolDictionary *dict3 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32BoolDictionary *dict4 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32BoolDictionary *dict2 =
+ [GPBInt32BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32BoolDictionary *dict = [GPBInt32BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:11]);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertFalse([dict getBool:NULL forKey:13]);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, YES);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const BOOL kValues2[] = { NO, YES };
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Float
+
+@interface GPBInt32FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32FloatDictionary *dict = [[GPBInt32FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:11]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32FloatDictionary *dict = [GPBInt32FloatDictionary dictionaryWithFloat:500.f forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict1 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32FloatDictionary *dict1prime =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32FloatDictionary *dict3 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32FloatDictionary *dict4 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32FloatDictionary *dict2 =
+ [GPBInt32FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32FloatDictionary *dict = [GPBInt32FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:11]);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertFalse([dict getFloat:NULL forKey:13]);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 501.f);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Double
+
+@interface GPBInt32DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32DoubleDictionary *dict = [[GPBInt32DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:11]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32DoubleDictionary *dict = [GPBInt32DoubleDictionary dictionaryWithDouble:600. forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const double kValues[] = { 600., 601., 602. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict1 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32DoubleDictionary *dict1prime =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32DoubleDictionary *dict3 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32DoubleDictionary *dict4 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32DoubleDictionary *dict2 =
+ [GPBInt32DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32DoubleDictionary *dict = [GPBInt32DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const double kValues[] = { 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:11]);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertFalse([dict getDouble:NULL forKey:13]);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 601.);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const double kValues2[] = { 602., 600. };
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+@interface GPBInt32EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32EnumDictionary *dict = [[GPBInt32EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32EnumDictionary *dict = [GPBInt32EnumDictionary dictionaryWithEnum:700 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict1 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32EnumDictionary *dict1prime =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32EnumDictionary *dict3 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32EnumDictionary *dict4 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 =
+ [GPBInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32EnumDictionary *dict = [GPBInt32EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertFalse([dict getEnum:NULL forKey:13]);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 701);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum (Unknown Enums)
+
+@interface GPBInt32EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBInt32EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:13]);
+ XCTAssertTrue([dict getRawValue:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict1 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32EnumDictionary *dict1prime =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32EnumDictionary *dict3 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32EnumDictionary *dict4 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 =
+ [GPBInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBInt32EnumDictionary *dict =
+ [GPBInt32EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:12], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:12]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 11, 13, 14 };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertFalse([dict getEnum:NULL forKey:13]);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:11], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:11]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 700);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:13]);
+ XCTAssertTrue([dict getRawValue:&value forKey:13]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Object
+
+@interface GPBInt32ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:11]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertNil([dict objectForKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict1 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32ObjectDictionary<NSString*> *dict1prime =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32ObjectDictionary<NSString*> *dict3 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32ObjectDictionary<NSString*> *dict4 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [GPBInt32ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict removeObjectForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertNil([dict objectForKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:11]);
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertNil([dict objectForKey:13]);
+ XCTAssertNil([dict objectForKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict setObject:@"jkl" forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict setObject:@"def" forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"def");
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:13], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:14], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m
new file mode 100644
index 0000000000..b90cdf8c02
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - Int64 -> UInt32
+
+@interface GPBInt64UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64UInt32Dictionary *dict = [[GPBInt64UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:21LL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionaryWithUInt32:100U forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict1 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64UInt32Dictionary *dict1prime =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64UInt32Dictionary *dict3 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64UInt32Dictionary *dict4 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt32Dictionary *dict2 =
+ [GPBInt64UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 101U);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+@interface GPBInt64Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64Int32Dictionary *dict = [[GPBInt64Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:21LL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionaryWithInt32:200 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict1 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64Int32Dictionary *dict1prime =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64Int32Dictionary *dict3 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64Int32Dictionary *dict4 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int32Dictionary *dict2 =
+ [GPBInt64Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:21LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:23LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 201);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+@interface GPBInt64UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64UInt64Dictionary *dict = [[GPBInt64UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:21LL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionaryWithUInt64:300U forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict1 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64UInt64Dictionary *dict1prime =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64UInt64Dictionary *dict3 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64UInt64Dictionary *dict4 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt64Dictionary *dict2 =
+ [GPBInt64UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 301U);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+@interface GPBInt64Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64Int64Dictionary *dict = [[GPBInt64Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:21LL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionaryWithInt64:400 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict1 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64Int64Dictionary *dict1prime =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64Int64Dictionary *dict3 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64Int64Dictionary *dict4 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int64Dictionary *dict2 =
+ [GPBInt64Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:21LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:23LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 401);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+@interface GPBInt64BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64BoolDictionary *dict = [[GPBInt64BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:21LL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionaryWithBool:YES forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict1 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64BoolDictionary *dict1prime =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64BoolDictionary *dict3 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64BoolDictionary *dict4 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64BoolDictionary *dict2 =
+ [GPBInt64BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:21LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:23LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, YES);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const BOOL kValues2[] = { NO, YES };
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Float
+
+@interface GPBInt64FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64FloatDictionary *dict = [[GPBInt64FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:21LL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionaryWithFloat:500.f forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict1 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64FloatDictionary *dict1prime =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64FloatDictionary *dict3 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64FloatDictionary *dict4 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64FloatDictionary *dict2 =
+ [GPBInt64FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:21LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:23LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 501.f);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Double
+
+@interface GPBInt64DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64DoubleDictionary *dict = [[GPBInt64DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:21LL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionaryWithDouble:600. forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const double kValues[] = { 600., 601., 602. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict1 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64DoubleDictionary *dict1prime =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64DoubleDictionary *dict3 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64DoubleDictionary *dict4 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64DoubleDictionary *dict2 =
+ [GPBInt64DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const double kValues[] = { 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:21LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:23LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 601.);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const double kValues2[] = { 602., 600. };
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+@interface GPBInt64EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64EnumDictionary *dict = [[GPBInt64EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionaryWithEnum:700 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict1 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64EnumDictionary *dict1prime =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64EnumDictionary *dict3 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64EnumDictionary *dict4 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 =
+ [GPBInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:23LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 701);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum (Unknown Enums)
+
+@interface GPBInt64EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBInt64EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:23LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict1 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64EnumDictionary *dict1prime =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64EnumDictionary *dict3 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64EnumDictionary *dict4 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 =
+ [GPBInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBInt64EnumDictionary *dict =
+ [GPBInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:22LL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:22LL]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 21LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:23LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:21LL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:21LL]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 700);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:23LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:23LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Object
+
+@interface GPBInt64ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:21LL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertNil([dict objectForKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict1 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64ObjectDictionary<NSString*> *dict1prime =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64ObjectDictionary<NSString*> *dict3 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64ObjectDictionary<NSString*> *dict4 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [GPBInt64ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict removeObjectForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertNil([dict objectForKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:21LL]);
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertNil([dict objectForKey:23LL]);
+ XCTAssertNil([dict objectForKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict setObject:@"jkl" forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict setObject:@"def" forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"def");
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m
new file mode 100644
index 0000000000..5df1d51d59
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m
@@ -0,0 +1,3359 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble")
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBStringEnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBStringEnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - String -> UInt32
+
+@interface GPBStringUInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringUInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBStringUInt32Dictionary *dict = [[GPBStringUInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionaryWithUInt32:100U forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict1 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringUInt32Dictionary *dict1prime =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringUInt32Dictionary *dict3 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringUInt32Dictionary *dict4 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringUInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt32Dictionary *dict2 =
+ [GPBStringUInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 101U);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Int32
+
+@interface GPBStringInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBStringInt32Dictionary *dict = [[GPBStringInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionaryWithInt32:200 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict1 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringInt32Dictionary *dict1prime =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringInt32Dictionary *dict3 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringInt32Dictionary *dict4 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt32Dictionary *dict2 =
+ [GPBStringInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 201);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> UInt64
+
+@interface GPBStringUInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringUInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBStringUInt64Dictionary *dict = [[GPBStringUInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionaryWithUInt64:300U forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict1 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringUInt64Dictionary *dict1prime =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringUInt64Dictionary *dict3 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringUInt64Dictionary *dict4 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringUInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt64Dictionary *dict2 =
+ [GPBStringUInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 301U);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Int64
+
+@interface GPBStringInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBStringInt64Dictionary *dict = [[GPBStringInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionaryWithInt64:400 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict1 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringInt64Dictionary *dict1prime =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringInt64Dictionary *dict3 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringInt64Dictionary *dict4 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt64Dictionary *dict2 =
+ [GPBStringInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 401);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Bool
+
+@interface GPBStringBoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringBoolDictionaryTests
+
+- (void)testEmpty {
+ GPBStringBoolDictionary *dict = [[GPBStringBoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionaryWithBool:YES forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict1 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringBoolDictionary *dict1prime =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringBoolDictionary *dict3 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringBoolDictionary *dict4 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringBoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringBoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringBoolDictionary *dict2 =
+ [GPBStringBoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, YES);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const BOOL kValues2[] = { NO, YES };
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Float
+
+@interface GPBStringFloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringFloatDictionaryTests
+
+- (void)testEmpty {
+ GPBStringFloatDictionary *dict = [[GPBStringFloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionaryWithFloat:500.f forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict1 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringFloatDictionary *dict1prime =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringFloatDictionary *dict3 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringFloatDictionary *dict4 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringFloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringFloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringFloatDictionary *dict2 =
+ [GPBStringFloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 501.f);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Double
+
+@interface GPBStringDoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringDoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBStringDoubleDictionary *dict = [[GPBStringDoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionaryWithDouble:600. forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const double kValues[] = { 600., 601., 602. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict1 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringDoubleDictionary *dict1prime =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringDoubleDictionary *dict3 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringDoubleDictionary *dict4 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringDoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringDoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringDoubleDictionary *dict2 =
+ [GPBStringDoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 601., 602., 603. };
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 601.);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const double kValues2[] = { 602., 600. };
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Enum
+
+@interface GPBStringEnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringEnumDictionaryTests
+
+- (void)testEmpty {
+ GPBStringEnumDictionary *dict = [[GPBStringEnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionaryWithEnum:700 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict1 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringEnumDictionary *dict1prime =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringEnumDictionary *dict3 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringEnumDictionary *dict4 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringEnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 =
+ [GPBStringEnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 701);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Enum (Unknown Enums)
+
+@interface GPBStringEnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBStringEnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict1 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringEnumDictionary *dict1prime =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringEnumDictionary *dict3 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringEnumDictionary *dict4 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 =
+ [GPBStringEnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBStringEnumDictionary *dict =
+ [GPBStringEnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:@"bar"], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:@"bar"]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"foo", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:@"foo"], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:@"foo"]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 700);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringEnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble")
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m
new file mode 100644
index 0000000000..1d3f6f78b0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBUInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint32_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBUInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint32_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - UInt32 -> UInt32
+
+@interface GPBUInt32UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32UInt32Dictionary *dict = [[GPBUInt32UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:1U]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32UInt32Dictionary *dict = [GPBUInt32UInt32Dictionary dictionaryWithUInt32:100U forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict1 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32UInt32Dictionary *dict1prime =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32UInt32Dictionary *dict3 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32UInt32Dictionary *dict4 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt32Dictionary *dict2 =
+ [GPBUInt32UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32UInt32Dictionary *dict = [GPBUInt32UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:1U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:3U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 101U);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+@interface GPBUInt32Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32Int32Dictionary *dict = [[GPBUInt32Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:1U]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32Int32Dictionary *dict = [GPBUInt32Int32Dictionary dictionaryWithInt32:200 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict1 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32Int32Dictionary *dict1prime =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32Int32Dictionary *dict3 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32Int32Dictionary *dict4 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int32Dictionary *dict2 =
+ [GPBUInt32Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32Int32Dictionary *dict = [GPBUInt32Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:1U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:3U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 201);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+@interface GPBUInt32UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32UInt64Dictionary *dict = [[GPBUInt32UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:1U]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32UInt64Dictionary *dict = [GPBUInt32UInt64Dictionary dictionaryWithUInt64:300U forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict1 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32UInt64Dictionary *dict1prime =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32UInt64Dictionary *dict3 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32UInt64Dictionary *dict4 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt64Dictionary *dict2 =
+ [GPBUInt32UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32UInt64Dictionary *dict = [GPBUInt32UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:1U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:3U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 301U);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+@interface GPBUInt32Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32Int64Dictionary *dict = [[GPBUInt32Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:1U]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32Int64Dictionary *dict = [GPBUInt32Int64Dictionary dictionaryWithInt64:400 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict1 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32Int64Dictionary *dict1prime =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32Int64Dictionary *dict3 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32Int64Dictionary *dict4 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int64Dictionary *dict2 =
+ [GPBUInt32Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32Int64Dictionary *dict = [GPBUInt32Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:1U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:3U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 401);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+@interface GPBUInt32BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32BoolDictionary *dict = [[GPBUInt32BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:1U]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32BoolDictionary *dict = [GPBUInt32BoolDictionary dictionaryWithBool:YES forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict1 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32BoolDictionary *dict1prime =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32BoolDictionary *dict3 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32BoolDictionary *dict4 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32BoolDictionary *dict2 =
+ [GPBUInt32BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32BoolDictionary *dict = [GPBUInt32BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:1U]);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertFalse([dict getBool:NULL forKey:3U]);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, YES);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const BOOL kValues2[] = { NO, YES };
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+@interface GPBUInt32FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32FloatDictionary *dict = [[GPBUInt32FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:1U]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32FloatDictionary *dict = [GPBUInt32FloatDictionary dictionaryWithFloat:500.f forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict1 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32FloatDictionary *dict1prime =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32FloatDictionary *dict3 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32FloatDictionary *dict4 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32FloatDictionary *dict2 =
+ [GPBUInt32FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32FloatDictionary *dict = [GPBUInt32FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:1U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:3U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 501.f);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+@interface GPBUInt32DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32DoubleDictionary *dict = [[GPBUInt32DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:1U]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32DoubleDictionary *dict = [GPBUInt32DoubleDictionary dictionaryWithDouble:600. forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const double kValues[] = { 600., 601., 602. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict1 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32DoubleDictionary *dict1prime =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32DoubleDictionary *dict3 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32DoubleDictionary *dict4 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32DoubleDictionary *dict2 =
+ [GPBUInt32DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32DoubleDictionary *dict = [GPBUInt32DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const double kValues[] = { 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:1U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:3U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 601.);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const double kValues2[] = { 602., 600. };
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+@interface GPBUInt32EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32EnumDictionary *dict = [[GPBUInt32EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32EnumDictionary *dict = [GPBUInt32EnumDictionary dictionaryWithEnum:700 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict1 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32EnumDictionary *dict1prime =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32EnumDictionary *dict3 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32EnumDictionary *dict4 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 =
+ [GPBUInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32EnumDictionary *dict = [GPBUInt32EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:3U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 701);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum (Unknown Enums)
+
+@interface GPBUInt32EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBUInt32EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:3U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict1 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32EnumDictionary *dict1prime =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32EnumDictionary *dict3 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32EnumDictionary *dict4 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 =
+ [GPBUInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBUInt32EnumDictionary *dict =
+ [GPBUInt32EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:2U], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:2U]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 1U, 3U, 4U };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:3U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:1U], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:1U]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 700);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:3U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:3U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+@interface GPBUInt32ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:1U]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertNil([dict objectForKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict1 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32ObjectDictionary<NSString*> *dict1prime =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32ObjectDictionary<NSString*> *dict3 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32ObjectDictionary<NSString*> *dict4 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [GPBUInt32ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict removeObjectForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertNil([dict objectForKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:1U]);
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertNil([dict objectForKey:3U]);
+ XCTAssertNil([dict objectForKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict setObject:@"jkl" forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict setObject:@"def" forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"def");
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m
new file mode 100644
index 0000000000..94c116f67f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m
@@ -0,0 +1,3646 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBUInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint64_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBUInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint64_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - UInt64 -> UInt32
+
+@interface GPBUInt64UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64UInt32Dictionary *dict = [[GPBUInt64UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:31ULL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64UInt32Dictionary *dict = [GPBUInt64UInt32Dictionary dictionaryWithUInt32:100U forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict1 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64UInt32Dictionary *dict1prime =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64UInt32Dictionary *dict3 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64UInt32Dictionary *dict4 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt32Dictionary *dict2 =
+ [GPBUInt64UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64UInt32Dictionary *dict = [GPBUInt64UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 101U);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+@interface GPBUInt64Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64Int32Dictionary *dict = [[GPBUInt64Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:31ULL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64Int32Dictionary *dict = [GPBUInt64Int32Dictionary dictionaryWithInt32:200 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict1 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64Int32Dictionary *dict1prime =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64Int32Dictionary *dict3 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64Int32Dictionary *dict4 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int32Dictionary *dict2 =
+ [GPBUInt64Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64Int32Dictionary *dict = [GPBUInt64Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 201);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+@interface GPBUInt64UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64UInt64Dictionary *dict = [[GPBUInt64UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:31ULL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64UInt64Dictionary *dict = [GPBUInt64UInt64Dictionary dictionaryWithUInt64:300U forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict1 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64UInt64Dictionary *dict1prime =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64UInt64Dictionary *dict3 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64UInt64Dictionary *dict4 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt64Dictionary *dict2 =
+ [GPBUInt64UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64UInt64Dictionary *dict = [GPBUInt64UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 301U);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+@interface GPBUInt64Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64Int64Dictionary *dict = [[GPBUInt64Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:31ULL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64Int64Dictionary *dict = [GPBUInt64Int64Dictionary dictionaryWithInt64:400 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict1 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64Int64Dictionary *dict1prime =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64Int64Dictionary *dict3 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64Int64Dictionary *dict4 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int64Dictionary *dict2 =
+ [GPBUInt64Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64Int64Dictionary *dict = [GPBUInt64Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 401);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+@interface GPBUInt64BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64BoolDictionary *dict = [[GPBUInt64BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:31ULL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64BoolDictionary *dict = [GPBUInt64BoolDictionary dictionaryWithBool:YES forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict1 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64BoolDictionary *dict1prime =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64BoolDictionary *dict3 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64BoolDictionary *dict4 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64BoolDictionary *dict2 =
+ [GPBUInt64BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64BoolDictionary *dict = [GPBUInt64BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, YES);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const BOOL kValues2[] = { NO, YES };
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+@interface GPBUInt64FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64FloatDictionary *dict = [[GPBUInt64FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:31ULL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64FloatDictionary *dict = [GPBUInt64FloatDictionary dictionaryWithFloat:500.f forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict1 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64FloatDictionary *dict1prime =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64FloatDictionary *dict3 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64FloatDictionary *dict4 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64FloatDictionary *dict2 =
+ [GPBUInt64FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64FloatDictionary *dict = [GPBUInt64FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 501.f);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+@interface GPBUInt64DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64DoubleDictionary *dict = [[GPBUInt64DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:31ULL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64DoubleDictionary *dict = [GPBUInt64DoubleDictionary dictionaryWithDouble:600. forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const double kValues[] = { 600., 601., 602. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict1 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64DoubleDictionary *dict1prime =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64DoubleDictionary *dict3 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64DoubleDictionary *dict4 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64DoubleDictionary *dict2 =
+ [GPBUInt64DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64DoubleDictionary *dict = [GPBUInt64DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 601.);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const double kValues2[] = { 602., 600. };
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+@interface GPBUInt64EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64EnumDictionary *dict = [[GPBUInt64EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64EnumDictionary *dict = [GPBUInt64EnumDictionary dictionaryWithEnum:700 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict1 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64EnumDictionary *dict1prime =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64EnumDictionary *dict3 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64EnumDictionary *dict4 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 =
+ [GPBUInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64EnumDictionary *dict = [GPBUInt64EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 701);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum (Unknown Enums)
+
+@interface GPBUInt64EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBUInt64EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict1 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64EnumDictionary *dict1prime =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64EnumDictionary *dict3 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64EnumDictionary *dict4 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 =
+ [GPBUInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBUInt64EnumDictionary *dict =
+ [GPBUInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:32ULL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:32ULL]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 31ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:31ULL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:31ULL]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 700);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:33ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+@interface GPBUInt64ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:31ULL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertNil([dict objectForKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict1 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64ObjectDictionary<NSString*> *dict1prime =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64ObjectDictionary<NSString*> *dict3 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64ObjectDictionary<NSString*> *dict4 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [GPBUInt64ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict removeObjectForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertNil([dict objectForKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:31ULL]);
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertNil([dict objectForKey:33ULL]);
+ XCTAssertNil([dict objectForKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict setObject:@"jkl" forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict setObject:@"def" forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"def");
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL)
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m
new file mode 100644
index 0000000000..52b4b32806
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m
@@ -0,0 +1,186 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+#import "GPBDictionary_PackagePrivate.h"
+
+#import "GPBTestUtilities.h"
+
+#pragma mark - GPBAutocreatedDictionary Tests
+
+// These are hand written tests to double check some behaviors of the
+// GPBAutocreatedDictionary. The GPBDictionary+[type]Tests files are generate
+// tests.
+
+// NOTE: GPBAutocreatedDictionary is private to the library, users of the
+// library should never have to directly deal with this class.
+
+@interface GPBAutocreatedDictionaryTests : XCTestCase
+@end
+
+@implementation GPBAutocreatedDictionaryTests
+
+- (void)testEquality {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ XCTAssertTrue([dict isEqual:@{}]);
+ XCTAssertTrue([dict isEqualToDictionary:@{}]);
+
+ XCTAssertFalse([dict isEqual:@{ @"foo" : @"bar" }]);
+ XCTAssertFalse([dict isEqualToDictionary:@{ @"foo" : @"bar" }]);
+
+ [dict setObject:@"bar" forKey:@"foo"];
+
+ XCTAssertFalse([dict isEqual:@{}]);
+ XCTAssertFalse([dict isEqualToDictionary:@{}]);
+ XCTAssertTrue([dict isEqual:@{ @"foo" : @"bar" }]);
+ XCTAssertTrue([dict isEqualToDictionary:@{ @"foo" : @"bar" }]);
+ XCTAssertFalse([dict isEqual:@{ @"bar" : @"baz" }]);
+ XCTAssertFalse([dict isEqualToDictionary:@{ @"bar" : @"baz" }]);
+
+ GPBAutocreatedDictionary *dict2 = [[GPBAutocreatedDictionary alloc] init];
+
+ XCTAssertFalse([dict isEqual:dict2]);
+ XCTAssertFalse([dict isEqualToDictionary:dict2]);
+
+ [dict2 setObject:@"mumble" forKey:@"foo"];
+ XCTAssertFalse([dict isEqual:dict2]);
+ XCTAssertFalse([dict isEqualToDictionary:dict2]);
+
+ [dict2 setObject:@"bar" forKey:@"foo"];
+ XCTAssertTrue([dict isEqual:dict2]);
+ XCTAssertTrue([dict isEqualToDictionary:dict2]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopy {
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ NSDictionary *cpy = [dict copy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSDictionary *cpy2 = [dict copy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ NSMutableDictionary *cpy = [dict mutableCopy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSMutableDictionary *cpy2 = [dict mutableCopy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+ dict[@"foo"] = @"bar";
+ dict[@"baz"] = @"mumble";
+
+ NSDictionary *cpy = [dict copy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy[@"baz"], @"mumble");
+
+ NSDictionary *cpy2 = [dict copy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy2[@"baz"], @"mumble");
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+ dict[@"foo"] = @"bar";
+ dict[@"baz"] = @"mumble";
+
+ NSMutableDictionary *cpy = [dict mutableCopy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy[@"baz"], @"mumble");
+
+ NSMutableDictionary *cpy2 = [dict mutableCopy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy2[@"baz"], @"mumble");
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm
new file mode 100644
index 0000000000..d6aa721190
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm
@@ -0,0 +1,1047 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//%PDDM-DEFINE TEST_FOR_POD_KEY(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, Object, NSString*, @"abc", @"def", @"ghi", @"jkl")
+
+//%PDDM-DEFINE TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+//%TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, UInt32, uint32_t, , 100U, 101U, 102U, 103U)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Int32, int32_t, , 200, 201, 202, 203)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, UInt64, uint64_t, , 300U, 301U, 302U, 303U)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Int64, int64_t, , 400, 401, 402, 403)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Bool, BOOL, , YES, YES, NO, NO)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Float, float, , 500.f, 501.f, 502.f, 503.f)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Double, double, , 600., 601., 602., 603.)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Enum, int32_t, Raw, 700, 701, 702, 703)
+//%TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+
+//%PDDM-DEFINE TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+//%TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, , value, POD, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+
+//%PDDM-DEFINE TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VAL1, VAL2, VAL3, VAL4)
+//%TESTS_COMMON(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, Objects, object, OBJECT, , VAL1, VAL2, VAL3, VAL4)
+
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary<VALUE_TYPE>
+
+//%PDDM-DEFINE TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VSUFFIX, VNAME, VHELPER, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests
+//%
+//%- (void)testEmpty {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testOne {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VALUE_NAME$u##:VAL1 forKey:KEY1];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertEqual##KSUFFIX(aKey, KEY1);
+//% XCTAssertEqual##VSUFFIX(a##VNAME$u, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME$u##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(3 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seen##VNAME$u##s = malloc(3 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seen##VNAME$u##s[idx] = a##VNAME$u##;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(k##VNAME$u##s[i], seen##VNAME$u##s[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seen##VNAME$u##s);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u)
+//% if (idx == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEquality {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2, VAL3 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL1, VAL4, VAL3 };
+//% const VALUE_TYPE k##VNAME$u##s3[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s3
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 extra pair; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% [dict release];
+//%}
+//%
+//%- (void)testAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict set##VALUE_NAME##:VAL1 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict2);
+//% [dict add##VACCESSOR##EntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% // Remove again does nothing.
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY4];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict set##VALUE_NAME##:VAL4 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict set##VALUE_NAME##:VAL2 forKey:KEY4];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL2)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL3, VAL1 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% [dict add##VACCESSOR##EntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL2)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS2(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Enum, int32_t, , POD, 700, 801, 702, 803)
+//%PDDM-DEFINE TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS2(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VSUFFIX, VHELPER, VAL1, VAL2, VAL3, VAL4)
+//%#pragma mark - KEY_NAME -> VALUE_NAME (Unknown Enums)
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryUnknownEnumTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryUnknownEnumTests
+//%
+//%- (void)testRawBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 3U);
+//% XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY3, VAL3)
+//%RAW_VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(3 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seenValues = malloc(3 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAndEnumsUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seenValues[idx] = aValue;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% if (i == 1) {
+//% XCTAssertEqual##VSUFFIX(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+//% } else {
+//% XCTAssertEqual##VSUFFIX(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% idx = 0;
+//% [dict enumerateKeysAndRawValuesUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seenValues[idx] = aValue;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seenValues);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAndRawValuesUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% #pragma unused(aKey, aValue)
+//% if (idx == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEqualityWithUnknowns {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1, KEY4 };
+//% const VALUE_TYPE kValues1[] = { VAL1, VAL2, VAL3 }; // Unknown
+//% const VALUE_TYPE kValues2[] = { VAL1, VAL4, VAL3 }; // Unknown
+//% const VALUE_TYPE kValues3[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues2
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues3
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different values; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same values; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 extra pair; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopyWithUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% XCTAssertEqualObjects(dict, dict2);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% [dict release];
+//%}
+//%
+//%- (void)testUnknownAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% XCTAssertThrowsSpecificNamed([dict setEnum:VAL2 forKey:KEY2], // Unknown
+//% NSException, NSInvalidArgumentException);
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict setRawValue:VAL2 forKey:KEY2]; // Unknown
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL3, VAL4 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithEnums:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict2);
+//% [dict addRawEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testUnknownRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//% [dict removeEnumForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% // Remove again does nothing.
+//% [dict removeEnumForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict removeEnumForKey:KEY4];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutationUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% XCTAssertThrowsSpecificNamed([dict setEnum:VAL4 forKey:KEY1], // Unknown
+//% NSException, NSInvalidArgumentException);
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict setRawValue:VAL4 forKey:KEY1]; // Unknown
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict setRawValue:VAL1 forKey:KEY4];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, VAL1)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 };
+//% const VALUE_TYPE kValues2[] = { VAL3, VAL2 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues2
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(dict2);
+//% [dict addRawEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY3, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, VAL1)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testCopyUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
+//
+// Helpers for PODs
+//
+
+//%PDDM-DEFINE DECLARE_VALUE_STORAGEPOD(VALUE_TYPE, NAME)
+//% VALUE_TYPE NAME;
+//%
+//%PDDM-DEFINE VALUE_NOT_FOUNDPOD(VALUE_NAME, DICT, KEY)
+//% XCTAssertFalse([DICT get##VALUE_NAME##:NULL forKey:KEY]);
+//%PDDM-DEFINE TEST_VALUEPOD(VALUE_NAME, DICT, STORAGE, KEY, VALUE)
+//% XCTAssertTrue([DICT get##VALUE_NAME##:NULL forKey:KEY]);
+//% XCTAssertTrue([DICT get##VALUE_NAME##:&STORAGE forKey:KEY]);
+//% XCTAssertEqual(STORAGE, VALUE);
+//%PDDM-DEFINE COMPARE_KEYS(KEY1, KEY2)
+//%KEY1 == KEY2
+//%PDDM-DEFINE RAW_VALUE_NOT_FOUNDPOD(VALUE_NAME, DICT, KEY)
+//% XCTAssertFalse([DICT getRawValue:NULL forKey:KEY]);
+//%PDDM-DEFINE TEST_RAW_VALUEPOD(DICT, STORAGE, KEY, VALUE)
+//% XCTAssertTrue([DICT getRawValue:NULL forKey:KEY]);
+//% XCTAssertTrue([DICT getRawValue:&STORAGE forKey:KEY]);
+//% XCTAssertEqual(STORAGE, VALUE);
+
+//
+// Helpers for Objects
+//
+
+//%PDDM-DEFINE DECLARE_VALUE_STORAGEOBJECT(VALUE_TYPE, NAME)
+// Empty
+//%PDDM-DEFINE VALUE_NOT_FOUNDOBJECT(VALUE_NAME, DICT, KEY)
+//% XCTAssertNil([DICT objectForKey:KEY]);
+//%PDDM-DEFINE TEST_VALUEOBJECT(VALUE_NAME, DICT, STORAGE, KEY, VALUE)
+//% XCTAssertEqualObjects([DICT objectForKey:KEY], VALUE);
+//%PDDM-DEFINE COMPARE_KEYSObjects(KEY1, KEY2)
+//%[KEY1 isEqual:KEY2]
+
+//
+// Helpers for tests.
+//
+
+//%PDDM-DEFINE TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP)
+//%// To let the testing macros work, add some extra methods to simplify things.
+//%@interface GPB##KEY_NAME##EnumDictionary (TestingTweak)
+//%+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%- (instancetype)initWithEnums:(const int32_t [])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count;
+//%@end
+//%
+//%static BOOL TestingEnum_IsValidValue(int32_t value) {
+//% switch (value) {
+//% case 700:
+//% case 701:
+//% case 702:
+//% case 703:
+//% return YES;
+//% default:
+//% return NO;
+//% }
+//%}
+//%
+//%@implementation GPB##KEY_NAME##EnumDictionary (TestingTweak)
+//%+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+//% // type correct.
+//% return [[(GPB##KEY_NAME##EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S rawValues:&value
+//% KEY_NAME$S forKeys:&key
+//% KEY_NAME$S count:1] autorelease];
+//%}
+//%- (instancetype)initWithEnums:(const int32_t [])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% return [self initWithValidationFunction:TestingEnum_IsValidValue
+//% rawValues:values
+//% forKeys:keys
+//% count:count];
+//%}
+//%@end
+//%
+//%
+
+
+//
+// BOOL test macros
+//
+//TODO(thomasvl): enum tests
+
+//%PDDM-DEFINE BOOL_TESTS_FOR_POD_VALUE(VALUE_NAME, VALUE_TYPE, VAL1, VAL2)
+//%BOOL_TESTS_COMMON(Bool, BOOL, , , YES, NO, VALUE_NAME, VALUE_TYPE, , value, POD, VAL1, VAL2)
+
+//%PDDM-DEFINE TESTS_FOR_BOOL_KEY_OBJECT_VALUE(VALUE_NAME, VALUE_TYPE, VAL1, VAL2)
+//%BOOL_TESTS_COMMON(Bool, BOOL, , , YES, NO, VALUE_NAME, VALUE_TYPE, Objects, object, OBJECT, VAL1, VAL2)
+
+//%PDDM-DEFINE BOOL_TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, VALUE_NAME, VALUE_TYPE, VSUFFIX, VNAME, VHELPER, VAL1, VAL2)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests
+//%
+//%- (void)testEmpty {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//% [dict enumerateKeysAnd##VALUE_NAME##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u##, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testOne {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VALUE_NAME$u##:VAL1 forKey:KEY1];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertEqual##KSUFFIX(aKey, KEY1);
+//% XCTAssertEqual##VSUFFIX(a##VNAME$u, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(2 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seen##VNAME$u##s = malloc(2 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% XCTAssertLessThan(idx, 2U);
+//% seenKeys[idx] = aKey;
+//% seen##VNAME$u##s[idx] = a##VNAME$u;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 2; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 2) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(k##VNAME$u##s[i], seen##VNAME$u##s[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seen##VNAME$u##s);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u)
+//% if (idx == 0) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEquality {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1 };
+//% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 };
+//% const VALUE_TYPE k##VNAME$u##s3[] = { VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s3
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 Fewer pairs; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% [dict release];
+//%}
+//%
+//%- (void)testAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict set##VALUE_NAME:VAL1 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict2);
+//% [dict addEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 2U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2};
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%
+//% // Remove again does nothing.
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 1U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict set##VALUE_NAME##:VAL2 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict set##VALUE_NAME##:VAL1 forKey:KEY2];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL1)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% [dict addEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m
new file mode 100644
index 0000000000..c0bd5897a4
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m
@@ -0,0 +1,700 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+@interface MessageMergeTests : GPBTestCase
+@end
+
+@implementation MessageMergeTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are merge specific.
+
+- (void)testProto3MergingAndZeroValues {
+ // Proto2 covered in other tests.
+
+ Message3 *src = [[Message3 alloc] init];
+ Message3 *dst = [[Message3 alloc] init];
+ NSData *testData1 = [@"abc" dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *testData2 = [@"def" dataUsingEncoding:NSUTF8StringEncoding];
+
+ dst.optionalInt32 = 1;
+ dst.optionalInt64 = 1;
+ dst.optionalUint32 = 1;
+ dst.optionalUint64 = 1;
+ dst.optionalSint32 = 1;
+ dst.optionalSint64 = 1;
+ dst.optionalFixed32 = 1;
+ dst.optionalFixed64 = 1;
+ dst.optionalSfixed32 = 1;
+ dst.optionalSfixed64 = 1;
+ dst.optionalFloat = 1.0f;
+ dst.optionalDouble = 1.0;
+ dst.optionalBool = YES;
+ dst.optionalString = @"bar";
+ dst.optionalBytes = testData1;
+ dst.optionalEnum = Message3_Enum_Bar;
+
+ // All zeros, nothing should overright.
+
+ src.optionalInt32 = 0;
+ src.optionalInt64 = 0;
+ src.optionalUint32 = 0;
+ src.optionalUint64 = 0;
+ src.optionalSint32 = 0;
+ src.optionalSint64 = 0;
+ src.optionalFixed32 = 0;
+ src.optionalFixed64 = 0;
+ src.optionalSfixed32 = 0;
+ src.optionalSfixed64 = 0;
+ src.optionalFloat = 0.0f;
+ src.optionalDouble = 0.0;
+ src.optionalBool = NO;
+ src.optionalString = @"";
+ src.optionalBytes = [NSData data];
+ src.optionalEnum = Message3_Enum_Foo; // first value
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 1);
+ XCTAssertEqual(dst.optionalInt64, 1);
+ XCTAssertEqual(dst.optionalUint32, 1U);
+ XCTAssertEqual(dst.optionalUint64, 1U);
+ XCTAssertEqual(dst.optionalSint32, 1);
+ XCTAssertEqual(dst.optionalSint64, 1);
+ XCTAssertEqual(dst.optionalFixed32, 1U);
+ XCTAssertEqual(dst.optionalFixed64, 1U);
+ XCTAssertEqual(dst.optionalSfixed32, 1);
+ XCTAssertEqual(dst.optionalSfixed64, 1);
+ XCTAssertEqual(dst.optionalFloat, 1.0f);
+ XCTAssertEqual(dst.optionalDouble, 1.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"bar");
+ XCTAssertEqualObjects(dst.optionalBytes, testData1);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Bar);
+
+ // Half the values that will replace.
+
+ src.optionalInt32 = 0;
+ src.optionalInt64 = 2;
+ src.optionalUint32 = 0;
+ src.optionalUint64 = 2;
+ src.optionalSint32 = 0;
+ src.optionalSint64 = 2;
+ src.optionalFixed32 = 0;
+ src.optionalFixed64 = 2;
+ src.optionalSfixed32 = 0;
+ src.optionalSfixed64 = 2;
+ src.optionalFloat = 0.0f;
+ src.optionalDouble = 2.0;
+ src.optionalBool = YES; // No other value to use. :(
+ src.optionalString = @"baz";
+ src.optionalBytes = nil;
+ src.optionalEnum = Message3_Enum_Baz;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 1);
+ XCTAssertEqual(dst.optionalInt64, 2);
+ XCTAssertEqual(dst.optionalUint32, 1U);
+ XCTAssertEqual(dst.optionalUint64, 2U);
+ XCTAssertEqual(dst.optionalSint32, 1);
+ XCTAssertEqual(dst.optionalSint64, 2);
+ XCTAssertEqual(dst.optionalFixed32, 1U);
+ XCTAssertEqual(dst.optionalFixed64, 2U);
+ XCTAssertEqual(dst.optionalSfixed32, 1);
+ XCTAssertEqual(dst.optionalSfixed64, 2);
+ XCTAssertEqual(dst.optionalFloat, 1.0f);
+ XCTAssertEqual(dst.optionalDouble, 2.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"baz");
+ XCTAssertEqualObjects(dst.optionalBytes, testData1);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz);
+
+ // Other half the values that will replace.
+
+ src.optionalInt32 = 3;
+ src.optionalInt64 = 0;
+ src.optionalUint32 = 3;
+ src.optionalUint64 = 0;
+ src.optionalSint32 = 3;
+ src.optionalSint64 = 0;
+ src.optionalFixed32 = 3;
+ src.optionalFixed64 = 0;
+ src.optionalSfixed32 = 3;
+ src.optionalSfixed64 = 0;
+ src.optionalFloat = 3.0f;
+ src.optionalDouble = 0.0;
+ src.optionalBool = YES; // No other value to use. :(
+ src.optionalString = nil;
+ src.optionalBytes = testData2;
+ src.optionalEnum = Message3_Enum_Foo;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 3);
+ XCTAssertEqual(dst.optionalInt64, 2);
+ XCTAssertEqual(dst.optionalUint32, 3U);
+ XCTAssertEqual(dst.optionalUint64, 2U);
+ XCTAssertEqual(dst.optionalSint32, 3);
+ XCTAssertEqual(dst.optionalSint64, 2);
+ XCTAssertEqual(dst.optionalFixed32, 3U);
+ XCTAssertEqual(dst.optionalFixed64, 2U);
+ XCTAssertEqual(dst.optionalSfixed32, 3);
+ XCTAssertEqual(dst.optionalSfixed64, 2);
+ XCTAssertEqual(dst.optionalFloat, 3.0f);
+ XCTAssertEqual(dst.optionalDouble, 2.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"baz");
+ XCTAssertEqualObjects(dst.optionalBytes, testData2);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz);
+
+ [src release];
+ [dst release];
+}
+
+- (void)testProto3MergingEnums {
+ UnknownEnumsMyMessage *src = [UnknownEnumsMyMessage message];
+ UnknownEnumsMyMessage *dst = [UnknownEnumsMyMessage message];
+
+ // Known value.
+
+ src.e = UnknownEnumsMyEnum_Bar;
+ src.repeatedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:UnknownEnumsMyEnum_Bar];
+ src.repeatedPackedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:UnknownEnumsMyEnum_Bar];
+ src.oneofE1 = UnknownEnumsMyEnum_Bar;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.e, UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.repeatedEArray.count, 1U);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.oneofE1, UnknownEnumsMyEnum_Bar);
+
+ // Unknown value.
+
+ const int32_t kUnknownValue = 666;
+
+ SetUnknownEnumsMyMessage_E_RawValue(src, kUnknownValue);
+ src.repeatedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:kUnknownValue];
+ src.repeatedPackedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:kUnknownValue];
+ SetUnknownEnumsMyMessage_OneofE1_RawValue(src, kUnknownValue);
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(dst), kUnknownValue);
+ XCTAssertEqual(dst.repeatedEArray.count, 2U);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:1],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([dst.repeatedEArray rawValueAtIndex:1], kUnknownValue);
+ XCTAssertEqual(dst.repeatedPackedEArray.count, 2U);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:1],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([dst.repeatedPackedEArray rawValueAtIndex:1], kUnknownValue);
+ XCTAssertEqual(dst.oneofE1,
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(dst), kUnknownValue);
+}
+
+- (void)testProto2MergeOneof {
+ Message2 *src = [Message2 message];
+ Message2 *dst = [Message2 message];
+
+ //
+ // Make sure whatever is in dst gets cleared out be merging in something else.
+ //
+
+ dst.oneofEnum = Message2_Enum_Bar;
+
+//%PDDM-DEFINE MERGE2_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT)
+//% src.oneof##SET_NAME = SET_VALUE;
+//% [dst mergeFrom:src];
+//% XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_Oneof##SET_NAME);
+//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE);
+//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT);
+//%
+//%PDDM-EXPAND MERGE2_TEST(Int32, 10, Enum, Message2_Enum_Baz)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(dst.oneofInt32, 10);
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz);
+
+//%PDDM-EXPAND MERGE2_TEST(Int64, 11, Int32, 100)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt64 = 11;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(dst.oneofInt64, 11);
+ XCTAssertEqual(dst.oneofInt32, 100);
+
+//%PDDM-EXPAND MERGE2_TEST(Uint32, 12U, Int64, 101)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint32 = 12U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(dst.oneofUint32, 12U);
+ XCTAssertEqual(dst.oneofInt64, 101);
+
+//%PDDM-EXPAND MERGE2_TEST(Uint64, 13U, Uint32, 102U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint64 = 13U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(dst.oneofUint64, 13U);
+ XCTAssertEqual(dst.oneofUint32, 102U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sint32, 14, Uint64, 103U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint32 = 14;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(dst.oneofSint32, 14);
+ XCTAssertEqual(dst.oneofUint64, 103U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sint64, 15, Sint32, 104)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint64 = 15;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(dst.oneofSint64, 15);
+ XCTAssertEqual(dst.oneofSint32, 104);
+
+//%PDDM-EXPAND MERGE2_TEST(Fixed32, 16U, Sint64, 105)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed32 = 16U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(dst.oneofFixed32, 16U);
+ XCTAssertEqual(dst.oneofSint64, 105);
+
+//%PDDM-EXPAND MERGE2_TEST(Fixed64, 17U, Fixed32, 106U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed64 = 17U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(dst.oneofFixed64, 17U);
+ XCTAssertEqual(dst.oneofFixed32, 106U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sfixed32, 18, Fixed64, 107U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed32 = 18;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(dst.oneofSfixed32, 18);
+ XCTAssertEqual(dst.oneofFixed64, 107U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sfixed64, 19, Sfixed32, 108)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed64 = 19;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(dst.oneofSfixed64, 19);
+ XCTAssertEqual(dst.oneofSfixed32, 108);
+
+//%PDDM-EXPAND MERGE2_TEST(Float, 20.0f, Sfixed64, 109)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFloat = 20.0f;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(dst.oneofFloat, 20.0f);
+ XCTAssertEqual(dst.oneofSfixed64, 109);
+
+//%PDDM-EXPAND MERGE2_TEST(Double, 21.0, Float, 110.0f)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofDouble = 21.0;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(dst.oneofDouble, 21.0);
+ XCTAssertEqual(dst.oneofFloat, 110.0f);
+
+//%PDDM-EXPAND MERGE2_TEST(Bool, NO, Double, 111.0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofBool = NO;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(dst.oneofBool, NO);
+ XCTAssertEqual(dst.oneofDouble, 111.0);
+
+//%PDDM-EXPAND MERGE2_TEST(Enum, Message2_Enum_Bar, Bool, YES)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofEnum = Message2_Enum_Bar;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Bar);
+ XCTAssertEqual(dst.oneofBool, YES);
+
+//%PDDM-EXPAND-END (14 expansions)
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ src.oneofString = @"foo";
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(dst.oneofString, @"foo");
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz);
+
+ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(dst.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertEqualObjects(dst.oneofString, oneofStringDefault);
+
+ Message2_OneofGroup *group = [Message2_OneofGroup message];
+ group.a = 666;
+ src.oneofGroup = group;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ Message2_OneofGroup *mergedGroup = [[dst.oneofGroup retain] autorelease];
+ XCTAssertNotNil(mergedGroup);
+ XCTAssertNotEqual(mergedGroup, group); // Pointer comparision.
+ XCTAssertEqualObjects(mergedGroup, group);
+ XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault);
+
+ Message2 *subMessage = [Message2 message];
+ subMessage.optionalInt32 = 777;
+ src.oneofMessage = subMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ Message2 *mergedSubMessage = [[dst.oneofMessage retain] autorelease];
+ XCTAssertNotNil(mergedSubMessage);
+ XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparision.
+ XCTAssertEqualObjects(mergedSubMessage, subMessage);
+ XCTAssertNotNil(dst.oneofGroup);
+ XCTAssertNotEqual(dst.oneofGroup, mergedGroup); // Pointer comparision.
+
+ // Back to something else to make sure message clears out ok.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertNotNil(dst.oneofMessage);
+ XCTAssertNotEqual(dst.oneofMessage,
+ mergedSubMessage); // Pointer comparision.
+
+ //
+ // Test merging in to message/group when they already had something.
+ //
+
+ src.oneofGroup = group;
+ mergedGroup = [Message2_OneofGroup message];
+ mergedGroup.b = 888;
+ dst.oneofGroup = mergedGroup;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofGroup, mergedGroup); // Pointer comparision.
+ XCTAssertEqual(dst.oneofGroup.a, 666); // Pointer comparision.
+ XCTAssertEqual(dst.oneofGroup.b, 888); // Pointer comparision.
+
+ src.oneofMessage = subMessage;
+ mergedSubMessage = [Message2 message];
+ mergedSubMessage.optionalInt64 = 999;
+ dst.oneofMessage = mergedSubMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparision.
+}
+
+- (void)testProto3MergeOneof {
+ Message3 *src = [Message3 message];
+ Message3 *dst = [Message3 message];
+
+ //
+ // Make sure whatever is in dst gets cleared out be merging in something else.
+ //
+
+ dst.oneofEnum = Message3_Enum_Bar;
+
+//%PDDM-DEFINE MERGE3_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT)
+//% src.oneof##SET_NAME = SET_VALUE;
+//% [dst mergeFrom:src];
+//% XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_Oneof##SET_NAME);
+//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE);
+//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT);
+//%
+//%PDDM-EXPAND MERGE3_TEST(Int32, 10, Enum, Message3_Enum_Foo)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(dst.oneofInt32, 10);
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo);
+
+//%PDDM-EXPAND MERGE3_TEST(Int64, 11, Int32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt64 = 11;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(dst.oneofInt64, 11);
+ XCTAssertEqual(dst.oneofInt32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Uint32, 12U, Int64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint32 = 12U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(dst.oneofUint32, 12U);
+ XCTAssertEqual(dst.oneofInt64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Uint64, 13U, Uint32, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint64 = 13U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(dst.oneofUint64, 13U);
+ XCTAssertEqual(dst.oneofUint32, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sint32, 14, Uint64, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint32 = 14;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(dst.oneofSint32, 14);
+ XCTAssertEqual(dst.oneofUint64, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sint64, 15, Sint32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint64 = 15;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(dst.oneofSint64, 15);
+ XCTAssertEqual(dst.oneofSint32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Fixed32, 16U, Sint64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed32 = 16U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(dst.oneofFixed32, 16U);
+ XCTAssertEqual(dst.oneofSint64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Fixed64, 17U, Fixed32, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed64 = 17U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(dst.oneofFixed64, 17U);
+ XCTAssertEqual(dst.oneofFixed32, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sfixed32, 18, Fixed64, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed32 = 18;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(dst.oneofSfixed32, 18);
+ XCTAssertEqual(dst.oneofFixed64, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sfixed64, 19, Sfixed32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed64 = 19;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(dst.oneofSfixed64, 19);
+ XCTAssertEqual(dst.oneofSfixed32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Float, 20.0f, Sfixed64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFloat = 20.0f;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(dst.oneofFloat, 20.0f);
+ XCTAssertEqual(dst.oneofSfixed64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Double, 21.0, Float, 0.0f)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofDouble = 21.0;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(dst.oneofDouble, 21.0);
+ XCTAssertEqual(dst.oneofFloat, 0.0f);
+
+//%PDDM-EXPAND MERGE3_TEST(Bool, YES, Double, 0.0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofBool = YES;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(dst.oneofBool, YES);
+ XCTAssertEqual(dst.oneofDouble, 0.0);
+
+//%PDDM-EXPAND MERGE3_TEST(Enum, Message3_Enum_Bar, Bool, NO)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofEnum = Message3_Enum_Bar;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Bar);
+ XCTAssertEqual(dst.oneofBool, NO);
+
+//%PDDM-EXPAND-END (14 expansions)
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ src.oneofString = @"foo";
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(dst.oneofString, @"foo");
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo);
+
+ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(dst.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertEqualObjects(dst.oneofString, oneofStringDefault);
+
+
+ Message3 *subMessage = [Message3 message];
+ subMessage.optionalInt32 = 777;
+ src.oneofMessage = subMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ Message3 *mergedSubMessage = [[dst.oneofMessage retain] autorelease];
+ XCTAssertNotNil(mergedSubMessage);
+ XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparision.
+ XCTAssertEqualObjects(mergedSubMessage, subMessage);
+ XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault);
+
+ // Back to something else to make sure message clears out ok.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertNotNil(dst.oneofMessage);
+ XCTAssertNotEqual(dst.oneofMessage,
+ mergedSubMessage); // Pointer comparision.
+
+ //
+ // Test merging in to message when they already had something.
+ //
+
+ src.oneofMessage = subMessage;
+ mergedSubMessage = [Message3 message];
+ mergedSubMessage.optionalInt64 = 999;
+ dst.oneofMessage = mergedSubMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparision.
+}
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, CopyFromMessageMap)
+- (void)testMap_CopyFromMessageMap {
+ TestMessageMap *msg1 = [[TestMessageMap alloc] init];
+ TestMessageMap *msg2 = [[TestMessageMap alloc] init];
+
+ TestAllTypes *subMsg = [TestAllTypes message];
+ subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:100];
+ [msg1.mapInt32Message setObject:subMsg forKey:0];
+ subMsg = nil;
+
+ subMsg = [TestAllTypes message];
+ subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:101];
+
+ [msg2.mapInt32Message setObject:subMsg forKey:0];
+ subMsg = nil;
+
+ [msg1 mergeFrom:msg2];
+
+ // Checks repeated field is overwritten.
+ XCTAssertEqual(msg1.mapInt32Message.count, 1U);
+ subMsg = [msg1.mapInt32Message objectForKey:0];
+ XCTAssertNotNil(subMsg);
+ XCTAssertEqual(subMsg.repeatedInt32Array.count, 1U);
+ XCTAssertEqual([subMsg.repeatedInt32Array valueAtIndex:0], 101);
+
+ [msg2 release];
+ [msg1 release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m
new file mode 100644
index 0000000000..0058311b3b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m
@@ -0,0 +1,2515 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestCycle.pbobjc.h"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+@interface MessageRuntimeTests : GPBTestCase
+@end
+
+@implementation MessageRuntimeTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are runtime
+// specific.
+
+- (void)testStartupOrdering {
+ // Message class/Root class initialization is a little tricky, so these just
+ // create some possible patterns that can be a problem. The messages don't
+ // have to be exercised, just creating them is enough to test. If there
+ // is a problem, the runtime should assert or hang.
+ //
+ // Note: the messages from these proto files should not be used in any other
+ // tests, that way when they are referenced here it will be the first use and
+ // initialization will take place now.
+
+ TestObjCStartupMessage *message = [TestObjCStartupMessage message];
+ XCTAssertNotNil(message);
+
+ CycleBaz *baz = [CycleBaz message];
+ CycleBar *bar = [CycleBar message];
+ CycleFoo *foo = [CycleFoo message];
+ XCTAssertNotNil(baz);
+ XCTAssertNotNil(bar);
+ XCTAssertNotNil(foo);
+}
+
+- (void)testProto2HasMethodSupport {
+ NSArray *names = @[
+ @"Int32",
+ @"Int64",
+ @"Uint32",
+ @"Uint64",
+ @"Sint32",
+ @"Sint64",
+ @"Fixed32",
+ @"Fixed64",
+ @"Sfixed32",
+ @"Sfixed64",
+ @"Float",
+ @"Double",
+ @"Bool",
+ @"String",
+ @"Bytes",
+ @"Group",
+ @"Message",
+ @"Enum",
+ ];
+
+ // Proto2 gets:
+
+ // Single fields - has*/setHas* is valid.
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasOptional%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOptional%@:", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertTrue([Message2 instancesRespondToSelector:setHasSel], @"field: %@",
+ name);
+ }
+
+ // Repeated fields
+ // - no has*/setHas*
+ // - *Count
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasRepeated%@Array", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasRepeated%@Array:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - repeatedInt32Array_Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"repeated%@Array_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+ // OneOf fields - no has*/setHas*
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOneofInt32/setHasOneofInt32:
+ SEL hasSel =
+ NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOneof%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+
+ // map<> fields
+ // - no has*/setHas*
+ // - *Count
+
+ NSArray *mapNames = @[
+ @"Int32Int32",
+ @"Int64Int64",
+ @"Uint32Uint32",
+ @"Uint64Uint64",
+ @"Sint32Sint32",
+ @"Sint64Sint64",
+ @"Fixed32Fixed32",
+ @"Fixed64Fixed64",
+ @"Sfixed32Sfixed32",
+ @"Sfixed64Sfixed64",
+ @"Int32Float",
+ @"Int32Double",
+ @"BoolBool",
+ @"StringString",
+ @"StringBytes",
+ @"StringMessage",
+ @"Int32Bytes",
+ @"Int32Enum",
+ @"Int32Message",
+ ];
+
+ for (NSString *name in mapNames) {
+ // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasMap%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasMap%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - mapInt32Int32Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"map%@_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+}
+
+- (void)testProto3HasMethodSupport {
+ NSArray *names = @[
+ @"Int32",
+ @"Int64",
+ @"Uint32",
+ @"Uint64",
+ @"Sint32",
+ @"Sint64",
+ @"Fixed32",
+ @"Fixed64",
+ @"Sfixed32",
+ @"Sfixed64",
+ @"Float",
+ @"Double",
+ @"Bool",
+ @"String",
+ @"Bytes",
+ @"Message",
+ @"Enum",
+ ];
+
+ // Proto3 gets:
+
+ // Single fields
+ // - has*/setHas* invalid for primative types.
+ // - has*/setHas* valid for Message.
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasOptional%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOptional%@:", name]);
+ if ([name isEqual:@"Message"]) {
+ // Sub messages/groups are the exception.
+ XCTAssertTrue([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertTrue([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ } else {
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+ }
+
+ // Repeated fields
+ // - no has*/setHas*
+ // - *Count
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasRepeated%@Array", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasRepeated%@Array:", name]);
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - repeatedInt32Array_Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"repeated%@Array_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+ // OneOf fields - no has*/setHas*
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOneofInt32/setHasOneofInt32:
+ SEL hasSel =
+ NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOneof%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+
+ // map<> fields
+ // - no has*/setHas*
+ // - *Count
+
+ NSArray *mapNames = @[
+ @"Int32Int32",
+ @"Int64Int64",
+ @"Uint32Uint32",
+ @"Uint64Uint64",
+ @"Sint32Sint32",
+ @"Sint64Sint64",
+ @"Fixed32Fixed32",
+ @"Fixed64Fixed64",
+ @"Sfixed32Sfixed32",
+ @"Sfixed64Sfixed64",
+ @"Int32Float",
+ @"Int32Double",
+ @"BoolBool",
+ @"StringString",
+ @"StringBytes",
+ @"StringMessage",
+ @"Int32Bytes",
+ @"Int32Enum",
+ @"Int32Message",
+ ];
+
+ for (NSString *name in mapNames) {
+ // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasMap%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasMap%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - mapInt32Int32Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"map%@_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+}
+
+- (void)testProto2SingleFieldHasBehavior {
+ //
+ // Setting to any value including the default value (0) should result has*
+ // being true.
+ //
+
+//%PDDM-DEFINE PROTO2_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
+//% { // optional##FIELD :: NON_ZERO_VALUE
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(msg.hasOptional##FIELD);
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = NON_ZERO_VALUE;
+//% XCTAssertTrue(msg.hasOptional##FIELD);
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//% { // optional##FIELD :: ZERO_VALUE
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(msg.hasOptional##FIELD);
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = ZERO_VALUE;
+//% XCTAssertTrue(msg.hasOptional##FIELD);
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO2_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
+//% { // optional##FIELD
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = nil;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO2_TEST_HAS_FIELDS()
+//%PROTO2_TEST_HAS_FIELD(Int32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Int64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Uint32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Uint64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sint32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sint64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Fixed32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Fixed64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sfixed32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sfixed64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Float, 1.0f, 0.0f)
+//%PROTO2_TEST_HAS_FIELD(Double, 1.0, 0.0)
+//%PROTO2_TEST_HAS_FIELD(Bool, YES, NO)
+//%PROTO2_TEST_HAS_FIELD(String, @"foo", @"")
+//%PROTO2_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
+//% //
+//% // Test doesn't apply to optionalGroup/optionalMessage.
+//% //
+//%
+//%PROTO2_TEST_HAS_FIELD(Enum, Message2_Enum_Bar, Message2_Enum_Foo)
+//% //
+//% // Nil can also be used to clear strings, bytes, groups, and messages.
+//% //
+//%
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Group, [Message2_OptionalGroup message])
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message2 message])
+//%PDDM-EXPAND PROTO2_TEST_HAS_FIELDS()
+// This block of code is generated, do not edit it directly.
+
+ { // optionalInt32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 1;
+ XCTAssertTrue(msg.hasOptionalInt32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+ { // optionalInt32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 0;
+ XCTAssertTrue(msg.hasOptionalInt32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+
+ { // optionalInt64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 1;
+ XCTAssertTrue(msg.hasOptionalInt64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+ { // optionalInt64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 0;
+ XCTAssertTrue(msg.hasOptionalInt64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+
+ { // optionalUint32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 1;
+ XCTAssertTrue(msg.hasOptionalUint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+ { // optionalUint32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 0;
+ XCTAssertTrue(msg.hasOptionalUint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+
+ { // optionalUint64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 1;
+ XCTAssertTrue(msg.hasOptionalUint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+ { // optionalUint64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 0;
+ XCTAssertTrue(msg.hasOptionalUint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+
+ { // optionalSint32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 1;
+ XCTAssertTrue(msg.hasOptionalSint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+ { // optionalSint32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 0;
+ XCTAssertTrue(msg.hasOptionalSint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+
+ { // optionalSint64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 1;
+ XCTAssertTrue(msg.hasOptionalSint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+ { // optionalSint64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 0;
+ XCTAssertTrue(msg.hasOptionalSint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+
+ { // optionalFixed32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 1;
+ XCTAssertTrue(msg.hasOptionalFixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+ { // optionalFixed32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 0;
+ XCTAssertTrue(msg.hasOptionalFixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+
+ { // optionalFixed64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 1;
+ XCTAssertTrue(msg.hasOptionalFixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+ { // optionalFixed64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 0;
+ XCTAssertTrue(msg.hasOptionalFixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+
+ { // optionalSfixed32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 1;
+ XCTAssertTrue(msg.hasOptionalSfixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+ { // optionalSfixed32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 0;
+ XCTAssertTrue(msg.hasOptionalSfixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+
+ { // optionalSfixed64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 1;
+ XCTAssertTrue(msg.hasOptionalSfixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+ { // optionalSfixed64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 0;
+ XCTAssertTrue(msg.hasOptionalSfixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+
+ { // optionalFloat :: 1.0f
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFloat);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 1.0f;
+ XCTAssertTrue(msg.hasOptionalFloat);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+ { // optionalFloat :: 0.0f
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFloat);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 0.0f;
+ XCTAssertTrue(msg.hasOptionalFloat);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+
+ { // optionalDouble :: 1.0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalDouble);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 1.0;
+ XCTAssertTrue(msg.hasOptionalDouble);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+ { // optionalDouble :: 0.0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalDouble);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 0.0;
+ XCTAssertTrue(msg.hasOptionalDouble);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+
+ { // optionalBool :: YES
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBool);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ msg.optionalBool = YES;
+ XCTAssertTrue(msg.hasOptionalBool);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ [msg release];
+ }
+ { // optionalBool :: NO
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBool);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ msg.optionalBool = NO;
+ XCTAssertTrue(msg.hasOptionalBool);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ [msg release];
+ }
+
+ { // optionalString :: @"foo"
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalString);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(msg.hasOptionalString);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+ { // optionalString :: @""
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalString);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"";
+ XCTAssertTrue(msg.hasOptionalString);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes :: [@"foo" dataUsingEncoding:NSUTF8StringEncoding]
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBytes);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(msg.hasOptionalBytes);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+ { // optionalBytes :: [NSData data]
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBytes);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [NSData data];
+ XCTAssertTrue(msg.hasOptionalBytes);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ //
+ // Test doesn't apply to optionalGroup/optionalMessage.
+ //
+
+ { // optionalEnum :: Message2_Enum_Bar
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message2_Enum_Bar;
+ XCTAssertTrue(msg.hasOptionalEnum);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+ { // optionalEnum :: Message2_Enum_Foo
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message2_Enum_Foo;
+ XCTAssertTrue(msg.hasOptionalEnum);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+
+ //
+ // Nil can also be used to clear strings, bytes, groups, and messages.
+ //
+
+ { // optionalString
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ { // optionalGroup
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ msg.optionalGroup = [Message2_OptionalGroup message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ msg.optionalGroup = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ [msg release];
+ }
+
+ { // optionalMessage
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ msg.optionalMessage = [Message2 message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ msg.optionalMessage = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ [msg release];
+ }
+
+//%PDDM-EXPAND-END PROTO2_TEST_HAS_FIELDS()
+}
+
+- (void)testProto3SingleFieldHasBehavior {
+ //
+ // Setting to any value but the default value (0) should result has*
+ // being true. When set to the default, shouldn't be true.
+ //
+
+//%PDDM-DEFINE PROTO3_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
+//% { // optional##FIELD
+//% Message3 *msg = [[Message3 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = NON_ZERO_VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = ZERO_VALUE;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO3_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
+//% { // optional##FIELD
+//% Message3 *msg = [[Message3 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = nil;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO3_TEST_HAS_FIELDS()
+//%PROTO3_TEST_HAS_FIELD(Int32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Int64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Uint32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Uint64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sint32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sint64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Fixed32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Fixed64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sfixed32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sfixed64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Float, 1.0f, 0.0f)
+//%PROTO3_TEST_HAS_FIELD(Double, 1.0, 0.0)
+//%PROTO3_TEST_HAS_FIELD(Bool, YES, NO)
+//%PROTO3_TEST_HAS_FIELD(String, @"foo", @"")
+//%PROTO3_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
+//% //
+//% // Test doesn't apply to optionalMessage (no groups in proto3).
+//% //
+//%
+//%PROTO3_TEST_HAS_FIELD(Enum, Message3_Enum_Bar, Message3_Enum_Foo)
+//% //
+//% // Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
+//% //
+//%
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message3 message])
+//%PDDM-EXPAND PROTO3_TEST_HAS_FIELDS()
+// This block of code is generated, do not edit it directly.
+
+ { // optionalInt32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+
+ { // optionalInt64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+
+ { // optionalUint32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+
+ { // optionalUint64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+
+ { // optionalSint32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+
+ { // optionalSint64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+
+ { // optionalFixed32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+
+ { // optionalFixed64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+
+ { // optionalSfixed32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+
+ { // optionalSfixed64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+
+ { // optionalFloat
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 1.0f;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 0.0f;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+
+ { // optionalDouble
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 1.0;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 0.0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+
+ { // optionalBool
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ msg.optionalBool = YES;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ msg.optionalBool = NO;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ [msg release];
+ }
+
+ { // optionalString
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"";
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [NSData data];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ //
+ // Test doesn't apply to optionalMessage (no groups in proto3).
+ //
+
+ { // optionalEnum
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message3_Enum_Bar;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message3_Enum_Foo;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+
+ //
+ // Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
+ //
+
+ { // optionalString
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ { // optionalMessage
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ msg.optionalMessage = [Message3 message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ msg.optionalMessage = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ [msg release];
+ }
+
+//%PDDM-EXPAND-END PROTO3_TEST_HAS_FIELDS()
+}
+
+- (void)testAccessingProto2UnknownEnumValues {
+ Message2 *msg = [[Message2 alloc] init];
+
+ // Set it to something non zero, try and confirm it doesn't change.
+
+ msg.optionalEnum = Message2_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum_Bar);
+
+ msg.oneofEnum = Message2_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+
+ [msg release];
+}
+
+- (void)testAccessingProto3UnknownEnumValues {
+ Message3 *msg = [[Message3 alloc] init];
+
+ // Set it to something non zero, try and confirm it doesn't change.
+
+ msg.optionalEnum = Message3_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum_Bar);
+
+ msg.oneofEnum = Message3_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Bar);
+
+ // Set via raw api to confirm it works.
+
+ SetMessage3_OptionalEnum_RawValue(msg, 666);
+ XCTAssertEqual(msg.optionalEnum,
+ Message3_Enum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg), 666);
+
+ SetMessage3_OneofEnum_RawValue(msg, 666);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(Message3_OneofEnum_RawValue(msg), 666);
+
+ [msg release];
+}
+
+- (void)testProto2OneofBasicBehaviors {
+ Message2 *msg = [[Message2 alloc] init];
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ // Nothing set.
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+
+ // Set, check the case, check everyone has default but the one, confirm case
+ // didn't change.
+
+ msg.oneofInt32 = 1;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+
+ msg.oneofInt64 = 2;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+
+ msg.oneofUint32 = 3;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+
+ msg.oneofUint64 = 4;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+
+ msg.oneofSint32 = 5;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+
+ msg.oneofSint64 = 6;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+
+ msg.oneofFixed32 = 7;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+
+ msg.oneofFixed64 = 8;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+
+ msg.oneofSfixed32 = 9;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+
+ msg.oneofSfixed64 = 10;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+
+ msg.oneofFloat = 11.0f;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+
+ msg.oneofDouble = 12.0;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+
+ msg.oneofBool = NO;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+
+ msg.oneofString = @"foo";
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+
+ Message2_OneofGroup *group = [Message2_OneofGroup message];
+ msg.oneofGroup = group;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+
+ Message2 *subMessage = [Message2 message];
+ msg.oneofMessage = subMessage;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+
+ msg.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+
+ // Test setting/calling clear clearing.
+
+ [msg release];
+ msg = [[Message2 alloc] init];
+
+ uint32_t values[] = {
+ Message2_O_OneOfCase_OneofInt32,
+ Message2_O_OneOfCase_OneofInt64,
+ Message2_O_OneOfCase_OneofUint32,
+ Message2_O_OneOfCase_OneofUint64,
+ Message2_O_OneOfCase_OneofSint32,
+ Message2_O_OneOfCase_OneofSint64,
+ Message2_O_OneOfCase_OneofFixed32,
+ Message2_O_OneOfCase_OneofFixed64,
+ Message2_O_OneOfCase_OneofSfixed32,
+ Message2_O_OneOfCase_OneofSfixed64,
+ Message2_O_OneOfCase_OneofFloat,
+ Message2_O_OneOfCase_OneofDouble,
+ Message2_O_OneOfCase_OneofBool,
+ Message2_O_OneOfCase_OneofString,
+ Message2_O_OneOfCase_OneofBytes,
+ Message2_O_OneOfCase_OneofGroup,
+ Message2_O_OneOfCase_OneofMessage,
+ Message2_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message2_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 1;
+ break;
+ case Message2_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 2;
+ break;
+ case Message2_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 3;
+ break;
+ case Message2_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 4;
+ break;
+ case Message2_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 5;
+ break;
+ case Message2_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 6;
+ break;
+ case Message2_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 7;
+ break;
+ case Message2_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 8;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 9;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 10;
+ break;
+ case Message2_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 11.0f;
+ break;
+ case Message2_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 12.0;
+ break;
+ case Message2_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message2_O_OneOfCase_OneofString:
+ msg.oneofString = @"foo";
+ break;
+ case Message2_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ break;
+ case Message2_O_OneOfCase_OneofGroup:
+ msg.oneofGroup = group;
+ break;
+ case Message2_O_OneOfCase_OneofMessage:
+ msg.oneofMessage = subMessage;
+ break;
+ case Message2_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message2_Enum_Bar;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+ // No need to check the value was set, the above tests did that.
+ Message2_ClearOOneOfCase(msg);
+ // Nothing in the case.
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase,
+ "Loop: %zd", i);
+ // Confirm everything is back to defaults after a clear.
+ XCTAssertEqual(msg.oneofInt32, 100, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 101, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 102U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 103U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 104, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 105, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 106U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 107U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 108, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 109, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 110.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 111.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, YES, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofGroup, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofGroup, group, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz, "Loop: %zd", i);
+ }
+
+ [msg release];
+}
+
+- (void)testProto3OneofBasicBehaviors {
+ Message3 *msg = [[Message3 alloc] init];
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ // Nothing set.
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+
+ // Set, check the case, check everyone has default but the one, confirm case
+ // didn't change.
+
+ msg.oneofInt32 = 1;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+
+ msg.oneofInt64 = 2;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+
+ msg.oneofUint32 = 3;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+
+ msg.oneofUint64 = 4;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+
+ msg.oneofSint32 = 5;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+
+ msg.oneofSint64 = 6;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+
+ msg.oneofFixed32 = 7;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+
+ msg.oneofFixed64 = 8;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+
+ msg.oneofSfixed32 = 9;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+
+ msg.oneofSfixed64 = 10;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+
+ msg.oneofFloat = 11.0f;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+
+ msg.oneofDouble = 12.0;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+
+ msg.oneofBool = YES;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+
+ msg.oneofString = @"foo";
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+
+ Message3 *subMessage = [Message3 message];
+ msg.oneofMessage = subMessage;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+
+ msg.oneofEnum = Message3_Enum_Bar;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Bar);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+
+ // Test setting/calling clear clearing.
+
+ [msg release];
+ msg = [[Message3 alloc] init];
+
+ uint32_t values[] = {
+ Message3_O_OneOfCase_OneofInt32,
+ Message3_O_OneOfCase_OneofInt64,
+ Message3_O_OneOfCase_OneofUint32,
+ Message3_O_OneOfCase_OneofUint64,
+ Message3_O_OneOfCase_OneofSint32,
+ Message3_O_OneOfCase_OneofSint64,
+ Message3_O_OneOfCase_OneofFixed32,
+ Message3_O_OneOfCase_OneofFixed64,
+ Message3_O_OneOfCase_OneofSfixed32,
+ Message3_O_OneOfCase_OneofSfixed64,
+ Message3_O_OneOfCase_OneofFloat,
+ Message3_O_OneOfCase_OneofDouble,
+ Message3_O_OneOfCase_OneofBool,
+ Message3_O_OneOfCase_OneofString,
+ Message3_O_OneOfCase_OneofBytes,
+ Message3_O_OneOfCase_OneofMessage,
+ Message3_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message3_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 1;
+ break;
+ case Message3_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 2;
+ break;
+ case Message3_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 3;
+ break;
+ case Message3_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 4;
+ break;
+ case Message3_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 5;
+ break;
+ case Message3_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 6;
+ break;
+ case Message3_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 7;
+ break;
+ case Message3_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 8;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 9;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 10;
+ break;
+ case Message3_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 11.0f;
+ break;
+ case Message3_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 12.0;
+ break;
+ case Message3_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message3_O_OneOfCase_OneofString:
+ msg.oneofString = @"foo";
+ break;
+ case Message3_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ break;
+ case Message3_O_OneOfCase_OneofMessage:
+ msg.oneofMessage = subMessage;
+ break;
+ case Message3_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Baz;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+ // No need to check the value was set, the above tests did that.
+ Message3_ClearOOneOfCase(msg);
+ // Nothing in the case.
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase,
+ "Loop: %zd", i);
+ // Confirm everything is back to defaults after a clear.
+ XCTAssertEqual(msg.oneofInt32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 0.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 0.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, NO, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo, "Loop: %zd", i);
+ }
+
+ [msg release];
+}
+
+- (void)testProto2OneofSetToDefault {
+
+ // proto3 doesn't normally write out zero (default) fields, but if they are
+ // in a oneof it does. proto2 doesn't have this special behavior, but we
+ // still confirm setting to the explicit default does set the case to be
+ // sure the runtime is working correctly.
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ Message2 *msg = [[Message2 alloc] init];
+
+ uint32_t values[] = {
+ Message2_O_OneOfCase_OneofInt32,
+ Message2_O_OneOfCase_OneofInt64,
+ Message2_O_OneOfCase_OneofUint32,
+ Message2_O_OneOfCase_OneofUint64,
+ Message2_O_OneOfCase_OneofSint32,
+ Message2_O_OneOfCase_OneofSint64,
+ Message2_O_OneOfCase_OneofFixed32,
+ Message2_O_OneOfCase_OneofFixed64,
+ Message2_O_OneOfCase_OneofSfixed32,
+ Message2_O_OneOfCase_OneofSfixed64,
+ Message2_O_OneOfCase_OneofFloat,
+ Message2_O_OneOfCase_OneofDouble,
+ Message2_O_OneOfCase_OneofBool,
+ Message2_O_OneOfCase_OneofString,
+ Message2_O_OneOfCase_OneofBytes,
+ // Skip group
+ // Skip message
+ Message2_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message2_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 100;
+ break;
+ case Message2_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 101;
+ break;
+ case Message2_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 102;
+ break;
+ case Message2_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 103;
+ break;
+ case Message2_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 104;
+ break;
+ case Message2_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 105;
+ break;
+ case Message2_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 106;
+ break;
+ case Message2_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 107;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 108;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 109;
+ break;
+ case Message2_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 110.0f;
+ break;
+ case Message2_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 111.0;
+ break;
+ case Message2_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message2_O_OneOfCase_OneofString:
+ msg.oneofString = oneofStringDefault;
+ break;
+ case Message2_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = oneofBytesDefault;
+ break;
+ case Message2_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Baz;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ // Should be set to the correct case.
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+
+ // Confirm everything is the defaults.
+ XCTAssertEqual(msg.oneofInt32, 100, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 101, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 102U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 103U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 104, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 105, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 106U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 107U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 108, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 109, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 110.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 111.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, YES, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ // Skip group, no default to consider.
+ // Skip message, no default to consider.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz, "Loop: %zd", i);
+ }
+
+ // We special case nil on string, data, group, and message, ensure they work
+ // as expected. i.e. - it clears the case.
+ msg.oneofString = nil;
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ msg.oneofBytes = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ msg.oneofGroup = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofGroup);
+ msg.oneofMessage = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofMessage);
+
+ [msg release];
+}
+
+- (void)testProto3OneofSetToZero {
+
+ // Normally setting a proto3 field to the zero value should result in it being
+ // reset/cleared. But in a oneof, it still gets recored so it can go out
+ // over the wire and the other side can see what was set in the oneof.
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ Message3 *msg = [[Message3 alloc] init];
+
+ uint32_t values[] = {
+ Message3_O_OneOfCase_OneofInt32,
+ Message3_O_OneOfCase_OneofInt64,
+ Message3_O_OneOfCase_OneofUint32,
+ Message3_O_OneOfCase_OneofUint64,
+ Message3_O_OneOfCase_OneofSint32,
+ Message3_O_OneOfCase_OneofSint64,
+ Message3_O_OneOfCase_OneofFixed32,
+ Message3_O_OneOfCase_OneofFixed64,
+ Message3_O_OneOfCase_OneofSfixed32,
+ Message3_O_OneOfCase_OneofSfixed64,
+ Message3_O_OneOfCase_OneofFloat,
+ Message3_O_OneOfCase_OneofDouble,
+ Message3_O_OneOfCase_OneofBool,
+ Message3_O_OneOfCase_OneofString,
+ Message3_O_OneOfCase_OneofBytes,
+ Message3_O_OneOfCase_OneofMessage,
+ Message3_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message3_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 0.0f;
+ break;
+ case Message3_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 0.0;
+ break;
+ case Message3_O_OneOfCase_OneofBool:
+ msg.oneofBool = NO;
+ break;
+ case Message3_O_OneOfCase_OneofString:
+ msg.oneofString = oneofStringDefault;
+ break;
+ case Message3_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = oneofBytesDefault;
+ break;
+ case Message3_O_OneOfCase_OneofMessage:
+ msg.oneofMessage.optionalInt32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Foo;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ // Should be set to the correct case.
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+
+ // Confirm everything is still zeros.
+ XCTAssertEqual(msg.oneofInt32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 0.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 0.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, NO, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo, "Loop: %zd", i);
+ }
+
+ // We special case nil on string, data, message, ensure they work as expected.
+ msg.oneofString = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ msg.oneofBytes = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ msg.oneofMessage = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofMessage);
+
+ [msg release];
+}
+
+- (void)testCopyingMakesUniqueObjects {
+ const int repeatCount = 5;
+ TestAllTypes *msg1 = [TestAllTypes message];
+ [self setAllFields:msg1 repeatedCount:repeatCount];
+
+ TestAllTypes *msg2 = [[msg1 copy] autorelease];
+
+ XCTAssertNotEqual(msg1, msg2); // Ptr compare, new object.
+ XCTAssertEqualObjects(msg1, msg2); // Equal values.
+
+ // Pointer comparisions, different objects.
+
+ XCTAssertNotEqual(msg1.optionalGroup, msg2.optionalGroup);
+ XCTAssertNotEqual(msg1.optionalNestedMessage, msg2.optionalNestedMessage);
+ XCTAssertNotEqual(msg1.optionalForeignMessage, msg2.optionalForeignMessage);
+ XCTAssertNotEqual(msg1.optionalImportMessage, msg2.optionalImportMessage);
+
+ XCTAssertNotEqual(msg1.repeatedInt32Array, msg2.repeatedInt32Array);
+ XCTAssertNotEqual(msg1.repeatedInt64Array, msg2.repeatedInt64Array);
+ XCTAssertNotEqual(msg1.repeatedUint32Array, msg2.repeatedUint32Array);
+ XCTAssertNotEqual(msg1.repeatedUint64Array, msg2.repeatedUint64Array);
+ XCTAssertNotEqual(msg1.repeatedSint32Array, msg2.repeatedSint32Array);
+ XCTAssertNotEqual(msg1.repeatedSint64Array, msg2.repeatedSint64Array);
+ XCTAssertNotEqual(msg1.repeatedFixed32Array, msg2.repeatedFixed32Array);
+ XCTAssertNotEqual(msg1.repeatedFixed64Array, msg2.repeatedFixed64Array);
+ XCTAssertNotEqual(msg1.repeatedSfixed32Array, msg2.repeatedSfixed32Array);
+ XCTAssertNotEqual(msg1.repeatedSfixed64Array, msg2.repeatedSfixed64Array);
+ XCTAssertNotEqual(msg1.repeatedFloatArray, msg2.repeatedFloatArray);
+ XCTAssertNotEqual(msg1.repeatedDoubleArray, msg2.repeatedDoubleArray);
+ XCTAssertNotEqual(msg1.repeatedBoolArray, msg2.repeatedBoolArray);
+ XCTAssertNotEqual(msg1.repeatedStringArray, msg2.repeatedStringArray);
+ XCTAssertNotEqual(msg1.repeatedBytesArray, msg2.repeatedBytesArray);
+ XCTAssertNotEqual(msg1.repeatedGroupArray, msg2.repeatedGroupArray);
+ XCTAssertNotEqual(msg1.repeatedNestedMessageArray,
+ msg2.repeatedNestedMessageArray);
+ XCTAssertNotEqual(msg1.repeatedForeignMessageArray,
+ msg2.repeatedForeignMessageArray);
+ XCTAssertNotEqual(msg1.repeatedImportMessageArray,
+ msg2.repeatedImportMessageArray);
+ XCTAssertNotEqual(msg1.repeatedNestedEnumArray, msg2.repeatedNestedEnumArray);
+ XCTAssertNotEqual(msg1.repeatedForeignEnumArray,
+ msg2.repeatedForeignEnumArray);
+ XCTAssertNotEqual(msg1.repeatedImportEnumArray, msg2.repeatedImportEnumArray);
+ XCTAssertNotEqual(msg1.repeatedStringPieceArray,
+ msg2.repeatedStringPieceArray);
+ XCTAssertNotEqual(msg1.repeatedCordArray, msg2.repeatedCordArray);
+
+ for (int i = 0; i < repeatCount; i++) {
+ XCTAssertNotEqual(msg1.repeatedNestedMessageArray[i],
+ msg2.repeatedNestedMessageArray[i]);
+ XCTAssertNotEqual(msg1.repeatedForeignMessageArray[i],
+ msg2.repeatedForeignMessageArray[i]);
+ XCTAssertNotEqual(msg1.repeatedImportMessageArray[i],
+ msg2.repeatedImportMessageArray[i]);
+ }
+}
+
+- (void)testCopyingMapsMakesUniqueObjects {
+ TestMap *msg1 = [TestMap message];
+ [self setAllMapFields:msg1 numEntries:5];
+
+ TestMap *msg2 = [[msg1 copy] autorelease];
+
+ XCTAssertNotEqual(msg1, msg2); // Ptr compare, new object.
+ XCTAssertEqualObjects(msg1, msg2); // Equal values.
+
+ // Pointer comparisions, different objects.
+ XCTAssertNotEqual(msg1.mapInt32Int32, msg2.mapInt32Int32);
+ XCTAssertNotEqual(msg1.mapInt64Int64, msg2.mapInt64Int64);
+ XCTAssertNotEqual(msg1.mapUint32Uint32, msg2.mapUint32Uint32);
+ XCTAssertNotEqual(msg1.mapUint64Uint64, msg2.mapUint64Uint64);
+ XCTAssertNotEqual(msg1.mapSint32Sint32, msg2.mapSint32Sint32);
+ XCTAssertNotEqual(msg1.mapSint64Sint64, msg2.mapSint64Sint64);
+ XCTAssertNotEqual(msg1.mapFixed32Fixed32, msg2.mapFixed32Fixed32);
+ XCTAssertNotEqual(msg1.mapFixed64Fixed64, msg2.mapFixed64Fixed64);
+ XCTAssertNotEqual(msg1.mapSfixed32Sfixed32, msg2.mapSfixed32Sfixed32);
+ XCTAssertNotEqual(msg1.mapSfixed64Sfixed64, msg2.mapSfixed64Sfixed64);
+ XCTAssertNotEqual(msg1.mapInt32Float, msg2.mapInt32Float);
+ XCTAssertNotEqual(msg1.mapInt32Double, msg2.mapInt32Double);
+ XCTAssertNotEqual(msg1.mapBoolBool, msg2.mapBoolBool);
+ XCTAssertNotEqual(msg1.mapStringString, msg2.mapStringString);
+ XCTAssertNotEqual(msg1.mapInt32Bytes, msg2.mapInt32Bytes);
+ XCTAssertNotEqual(msg1.mapInt32Enum, msg2.mapInt32Enum);
+ XCTAssertNotEqual(msg1.mapInt32ForeignMessage, msg2.mapInt32ForeignMessage);
+
+ // Ensure the messages are unique per map.
+ [msg1.mapInt32ForeignMessage
+ enumerateKeysAndObjectsUsingBlock:^(int32_t key, id value, BOOL *stop) {
+#pragma unused(stop)
+ ForeignMessage *subMsg2 = [msg2.mapInt32ForeignMessage objectForKey:key];
+ XCTAssertNotEqual(value, subMsg2); // Ptr compare, new object.
+ }];
+}
+
+- (void)test_GPBGetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableArray *fieldArray = GPBGetMessageRepeatedField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldArray); // Should have autocreated.
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+}
+
+- (void)test_GPBSetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableArray *fieldArray = [NSMutableArray arrayWithObject:@"foo"];
+ GPBSetMessageRepeatedField(message, fieldDescriptor, fieldArray);
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+ XCTAssertEqualObjects(@"foo", message.repeatedStringArray.firstObject);
+}
+
+- (void)test_GPBGetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableDictionary *fieldMap = GPBGetMessageMapField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldMap); // Should have autocreated.
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+}
+
+- (void)test_GPBSetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableDictionary *fieldMap = [NSMutableDictionary dictionaryWithObject:@"bar" forKey:@"foo"];
+ GPBSetMessageMapField(message, fieldDescriptor, fieldMap);
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+ XCTAssertEqualObjects(@"bar", message.mapStringString[@"foo"]);
+}
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, IsInitialized)
+- (void)testMap_IsInitialized {
+ TestRequiredMessageMap *msg = [[TestRequiredMessageMap alloc] init];
+
+ // Add an uninitialized message.
+ TestRequired *subMsg = [[TestRequired alloc] init];
+ [msg.mapField setObject:subMsg forKey:0];
+ XCTAssertFalse(msg.initialized);
+
+ // Initialize uninitialized message
+ subMsg.a = 0;
+ subMsg.b = 0;
+ subMsg.c = 0;
+ XCTAssertTrue(msg.initialized);
+
+ [subMsg release];
+ [msg release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m
new file mode 100644
index 0000000000..3c861fefdd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m
@@ -0,0 +1,1210 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapProto2Unittest.pbobjc.h"
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+static NSData *DataFromCStr(const char *str) {
+ return [NSData dataWithBytes:str length:strlen(str)];
+}
+
+@interface MessageSerializationTests : GPBTestCase
+@end
+
+@implementation MessageSerializationTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are serialization
+// specific.
+
+- (void)testProto3SerializationHandlingDefaults {
+ // Proto2 covered in other tests.
+
+ Message3 *msg = [[Message3 alloc] init];
+
+ // Add defaults, no output.
+
+ NSData *data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // All zeros, still nothing.
+
+ msg.optionalInt32 = 0;
+ msg.optionalInt64 = 0;
+ msg.optionalUint32 = 0;
+ msg.optionalUint64 = 0;
+ msg.optionalSint32 = 0;
+ msg.optionalSint64 = 0;
+ msg.optionalFixed32 = 0;
+ msg.optionalFixed64 = 0;
+ msg.optionalSfixed32 = 0;
+ msg.optionalSfixed64 = 0;
+ msg.optionalFloat = 0.0f;
+ msg.optionalDouble = 0.0;
+ msg.optionalBool = NO;
+ msg.optionalString = @"";
+ msg.optionalBytes = [NSData data];
+ msg.optionalEnum = Message3_Enum_Foo; // first value
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // The two that also take nil as nothing.
+
+ msg.optionalString = nil;
+ msg.optionalBytes = nil;
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // Set one field...
+
+ msg.optionalInt32 = 1;
+
+ data = [msg data];
+ const uint8_t expectedBytes[] = {0x08, 0x01};
+ NSData *expected = [NSData dataWithBytes:expectedBytes length:2];
+ XCTAssertEqualObjects(data, expected);
+
+ // Back to zero...
+
+ msg.optionalInt32 = 0;
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ [msg release];
+}
+
+- (void)testProto3DroppingUnknownFields {
+ DropUnknownsFooWithExtraFields *fooWithExtras =
+ [[DropUnknownsFooWithExtraFields alloc] init];
+
+ fooWithExtras.int32Value = 1;
+ fooWithExtras.enumValue = DropUnknownsFooWithExtraFields_NestedEnum_Baz;
+ fooWithExtras.extraInt32Value = 2;
+
+ NSData *data = [fooWithExtras data];
+ XCTAssertNotNil(data);
+ DropUnknownsFoo *foo = [DropUnknownsFoo parseFromData:data error:NULL];
+
+ XCTAssertEqual(foo.int32Value, 1);
+ XCTAssertEqual(foo.enumValue, DropUnknownsFoo_NestedEnum_Baz);
+ // Nothing should end up in the unknowns.
+ XCTAssertEqual([foo.unknownFields countOfFields], 0U);
+
+ [fooWithExtras release];
+ data = [foo data];
+ fooWithExtras =
+ [DropUnknownsFooWithExtraFields parseFromData:data error:NULL];
+ XCTAssertEqual(fooWithExtras.int32Value, 1);
+ XCTAssertEqual(fooWithExtras.enumValue,
+ DropUnknownsFooWithExtraFields_NestedEnum_Baz);
+ // And the extra value is gone (back to the default).
+ XCTAssertEqual(fooWithExtras.extraInt32Value, 0);
+ XCTAssertEqual([foo.unknownFields countOfFields], 0U);
+}
+
+- (void)testProto2UnknownEnumToUnknownField {
+ Message3 *orig = [[Message3 alloc] init];
+
+ orig.optionalEnum = Message3_Enum_Extra3;
+ orig.repeatedEnumArray =
+ [GPBEnumArray arrayWithValidationFunction:Message3_Enum_IsValidValue
+ rawValue:Message3_Enum_Extra3];
+ orig.oneofEnum = Message3_Enum_Extra3;
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [[Message2 alloc] initWithData:data error:NULL];
+
+ // None of the fields should be set.
+
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertEqual(msg.repeatedEnumArray.count, 0U);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+
+ // All the values should be in unknown fields.
+
+ GPBUnknownFieldSet *unknownFields = msg.unknownFields;
+
+ XCTAssertEqual([unknownFields countOfFields], 3U);
+ XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OptionalEnum]);
+ XCTAssertTrue(
+ [unknownFields hasField:Message2_FieldNumber_RepeatedEnumArray]);
+ XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OneofEnum]);
+
+ GPBUnknownField *field =
+ [unknownFields getField:Message2_FieldNumber_OptionalEnum];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0],
+ (uint64_t)Message3_Enum_Extra3);
+
+ field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3);
+
+ field = [unknownFields getField:Message2_FieldNumber_OneofEnum];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0],
+ (uint64_t)Message3_Enum_Extra3);
+
+ [msg release];
+ [orig release];
+}
+
+- (void)testProto3UnknownEnumPreserving {
+ UnknownEnumsMyMessagePlusExtra *orig =
+ [UnknownEnumsMyMessagePlusExtra message];
+
+ orig.e = UnknownEnumsMyEnumPlusExtra_EExtra;
+ orig.repeatedEArray = [GPBEnumArray
+ arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue
+ rawValue:UnknownEnumsMyEnumPlusExtra_EExtra];
+ orig.repeatedPackedEArray = [GPBEnumArray
+ arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue
+ rawValue:UnknownEnumsMyEnumPlusExtra_EExtra];
+ orig.oneofE1 = UnknownEnumsMyEnumPlusExtra_EExtra;
+
+ // Everything should be there via raw values.
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ UnknownEnumsMyMessage *msg =
+ [UnknownEnumsMyMessage parseFromData:data error:NULL];
+
+ XCTAssertEqual(msg.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg),
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.repeatedEArray.count, 1U);
+ XCTAssertEqual([msg.repeatedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([msg.repeatedEArray rawValueAtIndex:0],
+ (UnknownEnumsMyEnum)UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([msg.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([msg.repeatedPackedEArray rawValueAtIndex:0],
+ (UnknownEnumsMyEnum)UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.oneofE1,
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(msg),
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+
+ // Everything should go out and come back.
+
+ data = [msg data];
+ orig = [UnknownEnumsMyMessagePlusExtra parseFromData:data error:NULL];
+
+ XCTAssertEqual(orig.e, UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.repeatedEArray.count, 1U);
+ XCTAssertEqual([orig.repeatedEArray valueAtIndex:0],
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([orig.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.oneofE1, UnknownEnumsMyEnumPlusExtra_EExtra);
+}
+
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF(MESSAGE, FIELD, VALUE)
+//%TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, )
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, EQ_SUFFIX)
+//% { // oneof##FIELD
+//% MESSAGE *orig = [[MESSAGE alloc] init];
+//% orig.oneof##FIELD = VALUE;
+//% XCTAssertEqual(orig.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
+//% NSData *data = [orig data];
+//% XCTAssertNotNil(data);
+//% MESSAGE *msg = [MESSAGE parseFromData:data error:NULL];
+//% XCTAssertEqual(msg.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
+//% XCTAssertEqual##EQ_SUFFIX(msg.oneof##FIELD, VALUE);
+//% [orig release];
+//% }
+//%
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOFS(SYNTAX, BOOL_NON_DEFAULT)
+//%- (void)testProto##SYNTAX##RoundTripOneof {
+//%
+//%GROUP_INIT##SYNTAX() Message##SYNTAX *subMessage = [[Message##SYNTAX alloc] init];
+//% XCTAssertNotNil(subMessage);
+//% subMessage.optionalInt32 = 666;
+//%
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Int32, 1)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Int64, 2)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Uint32, 3U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Uint64, 4U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sint32, 5)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sint64, 6)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Fixed32, 7U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Fixed64, 8U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sfixed32, 9)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sfixed64, 10)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Float, 11.0f)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Double, 12.0)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Bool, BOOL_NON_DEFAULT)
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, String, @"foo", Objects)
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, Bytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding], Objects)
+//%GROUP_TEST##SYNTAX()TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, Message, subMessage, Objects)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Enum, Message2_Enum_Bar)
+//%GROUP_CLEANUP##SYNTAX() [subMessage release];
+//%}
+//%
+//%PDDM-DEFINE GROUP_INIT2()
+//% Message2_OneofGroup *group = [[Message2_OneofGroup alloc] init];
+//% XCTAssertNotNil(group);
+//% group.a = 777;
+//%
+//%PDDM-DEFINE GROUP_CLEANUP2()
+//% [group release];
+//%
+//%PDDM-DEFINE GROUP_TEST2()
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message2, Group, group, Objects)
+//%
+//%PDDM-DEFINE GROUP_INIT3()
+// Empty
+//%PDDM-DEFINE GROUP_CLEANUP3()
+// Empty
+//%PDDM-DEFINE GROUP_TEST3()
+//% // Not "group" in proto3.
+//%
+//%
+//%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(2, NO)
+// This block of code is generated, do not edit it directly.
+
+- (void)testProto2RoundTripOneof {
+
+ Message2_OneofGroup *group = [[Message2_OneofGroup alloc] init];
+ XCTAssertNotNil(group);
+ group.a = 777;
+ Message2 *subMessage = [[Message2 alloc] init];
+ XCTAssertNotNil(subMessage);
+ subMessage.optionalInt32 = 666;
+
+ { // oneofInt32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofInt32 = 1;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ [orig release];
+ }
+
+ { // oneofInt64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofInt64 = 2;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ [orig release];
+ }
+
+ { // oneofUint32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofUint32 = 3U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ [orig release];
+ }
+
+ { // oneofUint64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofUint64 = 4U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ [orig release];
+ }
+
+ { // oneofSint32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSint32 = 5;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ [orig release];
+ }
+
+ { // oneofSint64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSint64 = 6;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ [orig release];
+ }
+
+ { // oneofFixed32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFixed32 = 7U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ [orig release];
+ }
+
+ { // oneofFixed64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFixed64 = 8U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ [orig release];
+ }
+
+ { // oneofSfixed32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSfixed32 = 9;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ [orig release];
+ }
+
+ { // oneofSfixed64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSfixed64 = 10;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ [orig release];
+ }
+
+ { // oneofFloat
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFloat = 11.0f;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ [orig release];
+ }
+
+ { // oneofDouble
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofDouble = 12.0;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ [orig release];
+ }
+
+ { // oneofBool
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofBool = NO;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofBool, NO);
+ [orig release];
+ }
+
+ { // oneofString
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofString = @"foo";
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ [orig release];
+ }
+
+ { // oneofBytes
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ [orig release];
+ }
+
+ { // oneofGroup
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofGroup = group;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ XCTAssertEqualObjects(msg.oneofGroup, group);
+ [orig release];
+ }
+
+ { // oneofMessage
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofMessage = subMessage;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ XCTAssertEqualObjects(msg.oneofMessage, subMessage);
+ [orig release];
+ }
+
+ { // oneofEnum
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ [orig release];
+ }
+
+ [group release];
+ [subMessage release];
+}
+
+//%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(3, YES)
+// This block of code is generated, do not edit it directly.
+
+- (void)testProto3RoundTripOneof {
+
+ Message3 *subMessage = [[Message3 alloc] init];
+ XCTAssertNotNil(subMessage);
+ subMessage.optionalInt32 = 666;
+
+ { // oneofInt32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofInt32 = 1;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ [orig release];
+ }
+
+ { // oneofInt64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofInt64 = 2;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ [orig release];
+ }
+
+ { // oneofUint32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofUint32 = 3U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ [orig release];
+ }
+
+ { // oneofUint64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofUint64 = 4U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ [orig release];
+ }
+
+ { // oneofSint32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSint32 = 5;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ [orig release];
+ }
+
+ { // oneofSint64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSint64 = 6;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ [orig release];
+ }
+
+ { // oneofFixed32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFixed32 = 7U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ [orig release];
+ }
+
+ { // oneofFixed64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFixed64 = 8U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ [orig release];
+ }
+
+ { // oneofSfixed32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSfixed32 = 9;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ [orig release];
+ }
+
+ { // oneofSfixed64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSfixed64 = 10;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ [orig release];
+ }
+
+ { // oneofFloat
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFloat = 11.0f;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ [orig release];
+ }
+
+ { // oneofDouble
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofDouble = 12.0;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ [orig release];
+ }
+
+ { // oneofBool
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofBool = YES;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofBool, YES);
+ [orig release];
+ }
+
+ { // oneofString
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofString = @"foo";
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ [orig release];
+ }
+
+ { // oneofBytes
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ [orig release];
+ }
+
+ // Not "group" in proto3.
+
+ { // oneofMessage
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofMessage = subMessage;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ XCTAssertEqualObjects(msg.oneofMessage, subMessage);
+ [orig release];
+ }
+
+ { // oneofEnum
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ [orig release];
+ }
+
+ [subMessage release];
+}
+
+//%PDDM-EXPAND-END (2 expansions)
+
+- (void)testPackedUnpackedMessageParsing {
+ // packed is optional, a repeated field should parse when packed or unpacked.
+
+ TestPackedTypes *packedOrig = [TestPackedTypes message];
+ TestUnpackedTypes *unpackedOrig = [TestUnpackedTypes message];
+ [self setPackedFields:packedOrig repeatedCount:4];
+ [self setUnpackedFields:unpackedOrig repeatedCount:4];
+
+ NSData *packedData = [packedOrig data];
+ NSData *unpackedData = [unpackedOrig data];
+ XCTAssertNotNil(packedData);
+ XCTAssertNotNil(unpackedData);
+ XCTAssertNotEqualObjects(packedData, unpackedData,
+ @"Data should differ (packed vs unpacked) use");
+
+ NSError *error = nil;
+ TestPackedTypes *packedParse =
+ [TestPackedTypes parseFromData:unpackedData error:&error];
+ XCTAssertNotNil(packedParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(packedParse, packedOrig);
+
+ error = nil;
+ TestUnpackedTypes *unpackedParsed =
+ [TestUnpackedTypes parseFromData:packedData error:&error];
+ XCTAssertNotNil(unpackedParsed);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(unpackedParsed, unpackedOrig);
+}
+
+- (void)testPackedUnpackedExtensionParsing {
+ // packed is optional, a repeated extension should parse when packed or
+ // unpacked.
+
+ TestPackedExtensions *packedOrig = [TestPackedExtensions message];
+ TestUnpackedExtensions *unpackedOrig = [TestUnpackedExtensions message];
+ [self setPackedExtensions:packedOrig repeatedCount:kGPBDefaultRepeatCount];
+ [self setUnpackedExtensions:unpackedOrig repeatedCount:kGPBDefaultRepeatCount];
+
+ NSData *packedData = [packedOrig data];
+ NSData *unpackedData = [unpackedOrig data];
+ XCTAssertNotNil(packedData);
+ XCTAssertNotNil(unpackedData);
+ XCTAssertNotEqualObjects(packedData, unpackedData,
+ @"Data should differ (packed vs unpacked) use");
+
+ NSError *error = nil;
+ TestPackedExtensions *packedParse =
+ [TestPackedExtensions parseFromData:unpackedData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(packedParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(packedParse, packedOrig);
+
+ error = nil;
+ TestUnpackedExtensions *unpackedParsed =
+ [TestUnpackedExtensions parseFromData:packedData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(unpackedParsed);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(unpackedParsed, unpackedOrig);
+}
+
+- (void)testPackedExtensionVsFieldParsing {
+ // Extensions and fields end up on the wire the same way, so they can parse
+ // each other.
+
+ TestPackedTypes *fieldsOrig = [TestPackedTypes message];
+ TestPackedExtensions *extsOrig = [TestPackedExtensions message];
+ [self setPackedFields:fieldsOrig repeatedCount:kGPBDefaultRepeatCount];
+ [self setPackedExtensions:extsOrig repeatedCount:kGPBDefaultRepeatCount];
+
+ NSData *fieldsData = [fieldsOrig data];
+ NSData *extsData = [extsOrig data];
+ XCTAssertNotNil(fieldsData);
+ XCTAssertNotNil(extsData);
+ XCTAssertEqualObjects(fieldsData, extsData);
+
+ NSError *error = nil;
+ TestPackedTypes *fieldsParse =
+ [TestPackedTypes parseFromData:extsData error:&error];
+ XCTAssertNotNil(fieldsParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(fieldsParse, fieldsOrig);
+
+ error = nil;
+ TestPackedExtensions *extsParse =
+ [TestPackedExtensions parseFromData:fieldsData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(extsParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(extsParse, extsOrig);
+}
+
+- (void)testUnpackedExtensionVsFieldParsing {
+ // Extensions and fields end up on the wire the same way, so they can parse
+ // each other.
+
+ TestUnpackedTypes *fieldsOrig = [TestUnpackedTypes message];
+ TestUnpackedExtensions *extsOrig = [TestUnpackedExtensions message];
+ [self setUnpackedFields:fieldsOrig repeatedCount:3];
+ [self setUnpackedExtensions:extsOrig repeatedCount:3];
+
+ NSData *fieldsData = [fieldsOrig data];
+ NSData *extsData = [extsOrig data];
+ XCTAssertNotNil(fieldsData);
+ XCTAssertNotNil(extsData);
+ XCTAssertEqualObjects(fieldsData, extsData);
+
+ TestUnpackedTypes *fieldsParse =
+ [TestUnpackedTypes parseFromData:extsData error:NULL];
+ XCTAssertNotNil(fieldsParse);
+ XCTAssertEqualObjects(fieldsParse, fieldsOrig);
+
+ TestUnpackedExtensions *extsParse =
+ [TestUnpackedExtensions parseFromData:fieldsData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:NULL];
+ XCTAssertNotNil(extsParse);
+ XCTAssertEqualObjects(extsParse, extsOrig);
+}
+
+- (void)testErrorSubsectionInvalidLimit {
+ NSData *data = DataFromCStr(
+ "\x0A\x08\x0A\x07\x12\x04\x72\x02\x4B\x50\x12\x04\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSubsectionLimit);
+}
+
+- (void)testErrorSubsectionLimitReached {
+ NSData *data = DataFromCStr("\x0A\x06\x12\x03\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorSubsectionLimitReached);
+}
+
+- (void)testErrorInvalidVarint {
+ NSData *data = DataFromCStr("\x72\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
+ NSError *error = nil;
+ TestAllTypes *msg = [TestAllTypes parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidVarInt);
+}
+
+- (void)testErrorInvalidUTF8 {
+ NSData *data = DataFromCStr("\x72\x04\xF4\xFF\xFF\xFF");
+ NSError *error = nil;
+ TestAllTypes *msg = [TestAllTypes parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidUTF8);
+}
+
+- (void)testErrorInvalidSize {
+ NSData *data = DataFromCStr("\x72\x03\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSize);
+}
+
+- (void)testErrorInvalidTag {
+ NSData *data = DataFromCStr("\x0F");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidTag);
+}
+
+- (void)testErrorRecursionDepthReached {
+ NSData *data = DataFromCStr(
+ "\x0A\xF2\x01\x0A\xEF\x01\x0A\xEC\x01\x0A\xE9\x01\x0A\xE6\x01"
+ "\x0A\xE3\x01\x0A\xE0\x01\x0A\xDD\x01\x0A\xDA\x01\x0A\xD7\x01"
+ "\x0A\xD4\x01\x0A\xD1\x01\x0A\xCE\x01\x0A\xCB\x01\x0A\xC8\x01"
+ "\x0A\xC5\x01\x0A\xC2\x01\x0A\xBF\x01\x0A\xBC\x01\x0A\xB9\x01"
+ "\x0A\xB6\x01\x0A\xB3\x01\x0A\xB0\x01\x0A\xAD\x01\x0A\xAA\x01"
+ "\x0A\xA7\x01\x0A\xA4\x01\x0A\xA1\x01\x0A\x9E\x01\x0A\x9B\x01"
+ "\x0A\x98\x01\x0A\x95\x01\x0A\x92\x01\x0A\x8F\x01\x0A\x8C\x01"
+ "\x0A\x89\x01\x0A\x86\x01\x0A\x83\x01\x0A\x80\x01\x0A\x7E"
+ "\x0A\x7C\x0A\x7A\x0A\x78\x0A\x76\x0A\x74\x0A\x72\x0A\x70"
+ "\x0A\x6E\x0A\x6C\x0A\x6A\x0A\x68\x0A\x66\x0A\x64\x0A\x62"
+ "\x0A\x60\x0A\x5E\x0A\x5C\x0A\x5A\x0A\x58\x0A\x56\x0A\x54"
+ "\x0A\x52\x0A\x50\x0A\x4E\x0A\x4C\x0A\x4A\x0A\x48\x0A\x46"
+ "\x0A\x44\x0A\x42\x0A\x40\x0A\x3E\x0A\x3C\x0A\x3A\x0A\x38"
+ "\x0A\x36\x0A\x34\x0A\x32\x0A\x30\x0A\x2E\x0A\x2C\x0A\x2A"
+ "\x0A\x28\x0A\x26\x0A\x24\x0A\x22\x0A\x20\x0A\x1E\x0A\x1C"
+ "\x0A\x1A\x0A\x18\x0A\x16\x0A\x14\x0A\x12\x0A\x10\x0A\x0E"
+ "\x0A\x0C\x0A\x0A\x0A\x08\x0A\x06\x12\x04\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorRecursionDepthExceeded);
+}
+
+#ifdef DEBUG
+- (void)testErrorMissingRequiredField {
+ NSData *data = DataFromCStr("");
+ NSError *error = nil;
+ TestRequired *msg = [TestRequired parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMissingRequiredField);
+}
+#endif
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, StandardWireFormat)
+- (void)testMap_StandardWireFormat {
+ NSData *data = DataFromCStr("\x0A\x04\x08\x01\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, UnorderedWireFormat)
+- (void)testMap_UnorderedWireFormat {
+ // put value before key in wire format
+ NSData *data = DataFromCStr("\x0A\x04\x10\x01\x08\x02");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, DuplicatedKeyWireFormat)
+- (void)testMap_DuplicatedKeyWireFormat {
+ // Two key fields in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x01\x08\x02\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, DuplicatedValueWireFormat)
+- (void)testMap_DuplicatedValueWireFormat {
+ // Two value fields in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x01\x10\x01\x10\x02");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 2);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, MissedKeyWireFormat)
+- (void)testMap_MissedKeyWireFormat {
+ // No key field in wire format
+ NSData *data = DataFromCStr("\x0A\x02\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:0]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, MissedValueWireFormat)
+- (void)testMap_MissedValueWireFormat {
+ // No value field in wire format
+ NSData *data = DataFromCStr("\x0A\x02\x08\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 0);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, UnknownFieldWireFormat)
+- (void)testMap_UnknownFieldWireFormat {
+ // Unknown field in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x02\x10\x03\x18\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 3);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, CorruptedWireFormat)
+- (void)testMap_CorruptedWireFormat {
+ // corrupted data in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x02\x11\x03");
+
+ NSError *error = nil;
+ TestMap *msg = [TestMap parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSubsectionLimit);
+}
+
+// TEST(GeneratedMapFieldTest, Proto2UnknownEnum)
+- (void)testMap_Proto2UnknownEnum {
+ TestEnumMapPlusExtra *orig = [[TestEnumMapPlusExtra alloc] init];
+
+ orig.knownMapField = [GPBInt32EnumDictionary
+ dictionaryWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue];
+ orig.unknownMapField = [GPBInt32EnumDictionary
+ dictionaryWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue];
+ [orig.knownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumFoo
+ forKey:0];
+ [orig.unknownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumExtra
+ forKey:0];
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ TestEnumMap *msg1 = [TestEnumMap parseFromData:data error:NULL];
+ XCTAssertEqual(msg1.knownMapField.count, 1U);
+ int32_t val = -1;
+ XCTAssertTrue([msg1.knownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnum_Proto2MapEnumFoo);
+ XCTAssertEqual(msg1.unknownFields.countOfFields, 1U);
+
+ data = [msg1 data];
+ TestEnumMapPlusExtra *msg2 =
+ [TestEnumMapPlusExtra parseFromData:data error:NULL];
+ val = -1;
+ XCTAssertEqual(msg2.knownMapField.count, 1U);
+ XCTAssertTrue([msg2.knownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnumPlusExtra_EProto2MapEnumFoo);
+ val = -1;
+ XCTAssertEqual(msg2.unknownMapField.count, 1U);
+ XCTAssertTrue([msg2.unknownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnumPlusExtra_EProto2MapEnumExtra);
+ XCTAssertEqual(msg2.unknownFields.countOfFields, 0U);
+
+ XCTAssertEqualObjects(orig, msg2);
+
+ [orig release];
+}
+
+#pragma mark - Map Round Tripping
+
+- (void)testProto2MapRoundTripping {
+ Message2 *msg = [[Message2 alloc] init];
+
+ // Key/Value data should result in different byte lengths on wire to ensure
+ // everything is right.
+ [msg.mapInt32Int32 setInt32:1000 forKey:200];
+ [msg.mapInt32Int32 setInt32:101 forKey:2001];
+ [msg.mapInt64Int64 setInt64:1002 forKey:202];
+ [msg.mapInt64Int64 setInt64:103 forKey:2003];
+ [msg.mapUint32Uint32 setUInt32:1004 forKey:204];
+ [msg.mapUint32Uint32 setUInt32:105 forKey:2005];
+ [msg.mapUint64Uint64 setUInt64:1006 forKey:206];
+ [msg.mapUint64Uint64 setUInt64:107 forKey:2007];
+ [msg.mapSint32Sint32 setInt32:1008 forKey:208];
+ [msg.mapSint32Sint32 setInt32:109 forKey:2009];
+ [msg.mapSint64Sint64 setInt64:1010 forKey:210];
+ [msg.mapSint64Sint64 setInt64:111 forKey:2011];
+ [msg.mapFixed32Fixed32 setUInt32:1012 forKey:212];
+ [msg.mapFixed32Fixed32 setUInt32:113 forKey:2013];
+ [msg.mapFixed64Fixed64 setUInt64:1014 forKey:214];
+ [msg.mapFixed64Fixed64 setUInt64:115 forKey:2015];
+ [msg.mapSfixed32Sfixed32 setInt32:1016 forKey:216];
+ [msg.mapSfixed32Sfixed32 setInt32:117 forKey:2017];
+ [msg.mapSfixed64Sfixed64 setInt64:1018 forKey:218];
+ [msg.mapSfixed64Sfixed64 setInt64:119 forKey:2019];
+ [msg.mapInt32Float setFloat:1020.f forKey:220];
+ [msg.mapInt32Float setFloat:121.f forKey:2021];
+ [msg.mapInt32Double setDouble:1022. forKey:222];
+ [msg.mapInt32Double setDouble:123. forKey:2023];
+ [msg.mapBoolBool setBool:false forKey:true];
+ [msg.mapBoolBool setBool:true forKey:false];
+ msg.mapStringString[@"224"] = @"1024";
+ msg.mapStringString[@"2025"] = @"125";
+ msg.mapStringBytes[@"226"] = DataFromCStr("1026");
+ msg.mapStringBytes[@"2027"] = DataFromCStr("127");
+ Message2 *val1 = [[Message2 alloc] init];
+ val1.optionalInt32 = 1028;
+ Message2 *val2 = [[Message2 alloc] init];
+ val2.optionalInt32 = 129;
+ [msg.mapStringMessage setObject:val1 forKey:@"228"];
+ [msg.mapStringMessage setObject:val2 forKey:@"2029"];
+ [msg.mapInt32Bytes setObject:DataFromCStr("1030 bytes") forKey:230];
+ [msg.mapInt32Bytes setObject:DataFromCStr("131") forKey:2031];
+ [msg.mapInt32Enum setEnum:Message2_Enum_Bar forKey:232];
+ [msg.mapInt32Enum setEnum:Message2_Enum_Baz forKey:2033];
+ Message2 *val3 = [[Message2 alloc] init];
+ val3.optionalInt32 = 1034;
+ Message2 *val4 = [[Message2 alloc] init];
+ val4.optionalInt32 = 135;
+ [msg.mapInt32Message setObject:val3 forKey:234];
+ [msg.mapInt32Message setObject:val4 forKey:2035];
+
+ NSData *data = [msg data];
+ XCTAssertNotNil(data);
+ Message2 *msg2 = [[Message2 alloc] initWithData:data error:NULL];
+
+ XCTAssertNotEqual(msg2, msg); // Pointer comparison
+ XCTAssertEqualObjects(msg2, msg);
+
+ [val4 release];
+ [val3 release];
+ [val2 release];
+ [val1 release];
+ [msg2 release];
+ [msg release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests.m
new file mode 100644
index 0000000000..c15535c508
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests.m
@@ -0,0 +1,2053 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBDescriptor.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+@interface MessageTests : GPBTestCase
+@end
+
+@implementation MessageTests
+
+// TODO(thomasvl): this should get split into a few files of logic junks, it is
+// a jumble of things at the moment (and the testutils have a bunch of the real
+// assertions).
+
+- (TestAllTypes *)mergeSource {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalString:@"foo"];
+ [message setOptionalForeignMessage:[ForeignMessage message]];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllTypes *)mergeDestination {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"baz"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:3];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ return message;
+}
+
+- (TestAllTypes *)mergeDestinationWithoutForeignMessageIvar {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"baz"];
+ [message.repeatedStringArray addObject:@"qux"];
+ return message;
+}
+
+- (TestAllTypes *)mergeResult {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:3];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllTypes *)mergeResultForDestinationWithoutForeignMessageIvar {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsDestination {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.c = 4;
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsSource {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@6];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 7;
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsResult {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@6];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.c = 4;
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 7;
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (void)testMergeFrom {
+ TestAllTypes *result = [[self.mergeDestination copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ NSData *resultData = [result data];
+ NSData *mergeResultData = [self.mergeResult data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, self.mergeResult);
+
+ // Test when destination does not have an Ivar (type is an object) but source
+ // has such Ivar.
+ // The result must has the Ivar which is same as the one in source.
+ result = [[self.mergeDestinationWithoutForeignMessageIvar copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ resultData = [result data];
+ mergeResultData =
+ [self.mergeResultForDestinationWithoutForeignMessageIvar data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(
+ result, self.mergeResultForDestinationWithoutForeignMessageIvar);
+
+ // Test when destination is empty.
+ // The result must is same as the source.
+ result = [TestAllTypes message];
+ [result mergeFrom:self.mergeSource];
+ resultData = [result data];
+ mergeResultData = [self.mergeSource data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, self.mergeSource);
+}
+
+- (void)testMergeFromWithExtensions {
+ TestAllExtensions *result = [self mergeExtensionsDestination];
+ [result mergeFrom:[self mergeExtensionsSource]];
+ NSData *resultData = [result data];
+ NSData *mergeResultData = [[self mergeExtensionsResult] data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, [self mergeExtensionsResult]);
+
+ // Test merging from data.
+ result = [self mergeExtensionsDestination];
+ NSData *data = [[self mergeExtensionsSource] data];
+ XCTAssertNotNil(data);
+ [result mergeFromData:data
+ extensionRegistry:[UnittestRoot extensionRegistry]];
+ resultData = [result data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, [self mergeExtensionsResult]);
+}
+
+- (void)testIsEquals {
+ TestAllTypes *result = [[self.mergeDestination copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ XCTAssertEqualObjects(result.data, self.mergeResult.data);
+ XCTAssertEqualObjects(result, self.mergeResult);
+ TestAllTypes *result2 = [[self.mergeDestination copy] autorelease];
+ XCTAssertNotEqualObjects(result2.data, self.mergeResult.data);
+ XCTAssertNotEqualObjects(result2, self.mergeResult);
+}
+
+// =================================================================
+// Required-field-related tests.
+
+- (TestRequired *)testRequiredInitialized {
+ TestRequired *message = [TestRequired message];
+ [message setA:1];
+ [message setB:2];
+ [message setC:3];
+ return message;
+}
+
+- (void)testRequired {
+ TestRequired *message = [TestRequired message];
+
+ XCTAssertFalse(message.initialized);
+ [message setA:1];
+ XCTAssertFalse(message.initialized);
+ [message setB:1];
+ XCTAssertFalse(message.initialized);
+ [message setC:1];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testRequiredForeign {
+ TestRequiredForeign *message = [TestRequiredForeign message];
+
+ XCTAssertTrue(message.initialized);
+
+ [message setOptionalMessage:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setOptionalMessage:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message.repeatedMessageArray removeAllObjects];
+ [message.repeatedMessageArray addObject:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testRequiredExtension {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ XCTAssertTrue(message.initialized);
+
+ [message setExtension:[TestRequired single] value:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setExtension:[TestRequired single]
+ value:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+
+ [message addExtension:[TestRequired multi] value:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setExtension:[TestRequired multi]
+ index:0
+ value:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testDataFromUninitialized {
+ TestRequired *message = [TestRequired message];
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
+#endif // DEBUG
+}
+
+- (void)testInitialized {
+ // We're mostly testing that no exception is thrown.
+ TestRequired *message = [TestRequired message];
+ XCTAssertFalse(message.initialized);
+}
+
+- (void)testDataFromNestedUninitialized {
+ TestRequiredForeign *message = [TestRequiredForeign message];
+ [message setOptionalMessage:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
+#endif // DEBUG
+}
+
+- (void)testNestedInitialized {
+ // We're mostly testing that no exception is thrown.
+
+ TestRequiredForeign *message = [TestRequiredForeign message];
+ [message setOptionalMessage:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+
+ XCTAssertFalse(message.initialized);
+}
+
+- (void)testParseUninitialized {
+ NSError *error = nil;
+ TestRequired *msg =
+ [TestRequired parseFromData:GPBEmptyNSData() error:&error];
+ // In DEBUG, the parse will fail, but in non DEBUG, it passes because
+ // the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMissingRequiredField);
+#else
+ XCTAssertNotNil(msg);
+ XCTAssertNil(error);
+ XCTAssertFalse(msg.initialized);
+#endif // DEBUG
+}
+
+- (void)testCoding {
+ NSData *data =
+ [NSKeyedArchiver archivedDataWithRootObject:[self mergeResult]];
+ id unarchivedObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
+
+ XCTAssertEqualObjects(unarchivedObject, [self mergeResult]);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(unarchivedObject, [self mergeResult]);
+}
+
+- (void)testObjectReset {
+ // Tests a failure where clearing out defaults values caused an over release.
+ TestAllTypes *message = [TestAllTypes message];
+ message.hasOptionalNestedMessage = NO;
+ [message setOptionalNestedMessage:[TestAllTypes_NestedMessage message]];
+ message.hasOptionalNestedMessage = NO;
+ [message setOptionalNestedMessage:[TestAllTypes_NestedMessage message]];
+ [message setOptionalNestedMessage:nil];
+ message.hasOptionalNestedMessage = NO;
+}
+
+- (void)testSettingHasToYes {
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertThrows([message setHasOptionalNestedMessage:YES]);
+}
+
+- (void)testRoot {
+ XCTAssertNotNil([UnittestRoot extensionRegistry]);
+}
+
+- (void)testGPBMessageSize {
+ // See the note in GPBMessage_PackagePrivate.h about why we want to keep the
+ // base instance size pointer size aligned.
+ size_t messageSize = class_getInstanceSize([GPBMessage class]);
+ XCTAssertEqual((messageSize % sizeof(void *)), (size_t)0,
+ @"Base size isn't pointer size aligned");
+
+ // Since we add storage ourselves (see +allocWithZone: in GPBMessage), confirm
+ // that the size of some generated classes is still the same as the base for
+ // that logic to work as desired.
+ size_t testMessageSize = class_getInstanceSize([TestAllTypes class]);
+ XCTAssertEqual(testMessageSize, messageSize);
+}
+
+- (void)testInit {
+ TestAllTypes *message = [TestAllTypes message];
+ [self assertClear:message];
+}
+
+- (void)testAccessors {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsSet:message repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testKVC_ValueForKey {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+}
+
+- (void)testKVC_SetValue_ForKey {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFieldsViaKVC:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+ [self assertAllFieldsSet:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+}
+
+- (void)testDescription {
+ // No real test, just exercise code
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+
+ GPBUnknownFieldSet *unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [unknownFields addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [unknownFields addField:field];
+
+ [message setUnknownFields:unknownFields];
+
+ NSString *description = [message description];
+ XCTAssertGreaterThan([description length], 0U);
+
+ GPBMessage *message2 = [TestAllExtensions message];
+ [message2 setExtension:[UnittestRoot optionalInt32Extension] value:@1];
+
+ [message2 addExtension:[UnittestRoot repeatedInt32Extension] value:@2];
+
+ description = [message2 description];
+ XCTAssertGreaterThan([description length], 0U);
+}
+
+- (void)testSetter {
+ // Test to make sure that if we set a value that has a default value
+ // with the default, that the has is set, and the value gets put into the
+ // message correctly.
+ TestAllTypes *message = [TestAllTypes message];
+ GPBDescriptor *descriptor = [[message class] descriptor];
+ XCTAssertNotNil(descriptor);
+ GPBFieldDescriptor *fieldDescriptor =
+ [descriptor fieldWithName:@"defaultInt32"];
+ XCTAssertNotNil(fieldDescriptor);
+ GPBGenericValue defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultInt32:defaultValue.valueInt32];
+ XCTAssertTrue(message.hasDefaultInt32);
+ XCTAssertEqual(message.defaultInt32, defaultValue.valueInt32);
+
+ // Do the same thing with an object type.
+ message = [TestAllTypes message];
+ fieldDescriptor = [descriptor fieldWithName:@"defaultString"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultString:defaultValue.valueString];
+ XCTAssertTrue(message.hasDefaultString);
+ XCTAssertEqualObjects(message.defaultString, defaultValue.valueString);
+
+ // Test default string type.
+ message = [TestAllTypes message];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertFalse(message.hasDefaultString);
+ fieldDescriptor = [descriptor fieldWithName:@"defaultString"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultString:defaultValue.valueString];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertTrue(message.hasDefaultString);
+ [message setDefaultString:nil];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertFalse(message.hasDefaultString);
+ message.hasDefaultString = NO;
+ XCTAssertFalse(message.hasDefaultString);
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+
+ // Test default bytes type.
+ NSData *defaultBytes = [@"world" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertFalse(message.hasDefaultString);
+ fieldDescriptor = [descriptor fieldWithName:@"defaultBytes"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultBytes:defaultValue.valueData];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertTrue(message.hasDefaultBytes);
+ [message setDefaultBytes:nil];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertFalse(message.hasDefaultBytes);
+ message.hasDefaultBytes = NO;
+ XCTAssertFalse(message.hasDefaultBytes);
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+
+ // Test optional string.
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ XCTAssertFalse(message.hasOptionalString);
+ message.optionalString = nil;
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ NSString *string = @"string";
+ message.optionalString = string;
+ XCTAssertEqualObjects(message.optionalString, string);
+ XCTAssertTrue(message.hasOptionalString);
+ message.optionalString = nil;
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+
+ // Test optional data.
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+ XCTAssertFalse(message.hasOptionalBytes);
+ message.optionalBytes = nil;
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+ NSData *data = [@"bytes" dataUsingEncoding:NSUTF8StringEncoding];
+ message.optionalBytes = data;
+ XCTAssertEqualObjects(message.optionalBytes, data);
+ XCTAssertTrue(message.hasOptionalBytes);
+ message.optionalBytes = nil;
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+
+ // Test lazy message setting
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.hasOptionalLazyMessage = NO;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.optionalLazyMessage = nil;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // Test nested messages
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.optionalLazyMessage.bb = 1;
+ XCTAssertTrue(message.hasOptionalLazyMessage);
+ XCTAssertEqual(message.optionalLazyMessage.bb, 1);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ message.optionalLazyMessage = nil;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertEqual(message.optionalLazyMessage.bb, 0);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+
+ // -testDefaultSubMessages tests the "defaulting" handling of fields
+ // containing messages.
+}
+
+- (void)testRepeatedSetters {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedFields:message];
+ [self assertRepeatedFieldsModified:message
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testClear {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self clearAllFields:message];
+ [self assertClear:message];
+ TestAllTypes *message2 = [TestAllTypes message];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testClearKVC {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self clearAllFields:message];
+ [self assertClear:message];
+ [self assertClearKVC:message];
+}
+
+- (void)testClearExtension {
+ // clearExtension() is not actually used in TestUtil, so try it manually.
+ GPBMessage *message1 = [TestAllExtensions message];
+ [message1 setExtension:[UnittestRoot optionalInt32Extension] value:@1];
+
+ XCTAssertTrue([message1 hasExtension:[UnittestRoot optionalInt32Extension]]);
+ [message1 clearExtension:[UnittestRoot optionalInt32Extension]];
+ XCTAssertFalse([message1 hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ GPBMessage *message2 = [TestAllExtensions message];
+ [message2 addExtension:[UnittestRoot repeatedInt32Extension] value:@1];
+
+ XCTAssertEqual(
+ [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count],
+ (NSUInteger)1);
+ [message2 clearExtension:[UnittestRoot repeatedInt32Extension]];
+ XCTAssertEqual(
+ [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count],
+ (NSUInteger)0);
+
+ // Clearing an unset extension field shouldn't make the target message
+ // visible.
+ GPBMessage *message3 = [TestAllExtensions message];
+ GPBMessage *extension_msg =
+ [message3 getExtension:[UnittestObjcRoot recursiveExtension]];
+ XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]);
+ [extension_msg clearExtension:[UnittestRoot optionalInt32Extension]];
+ XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]);
+}
+
+- (void)testDefaultingSubMessages {
+ TestAllTypes *message = [TestAllTypes message];
+
+ // Initially they should all not have values.
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // They should auto create something when fetched.
+
+ TestAllTypes_OptionalGroup *optionalGroup = [message.optionalGroup retain];
+ TestAllTypes_NestedMessage *optionalNestedMessage =
+ [message.optionalNestedMessage retain];
+ ForeignMessage *optionalForeignMessage =
+ [message.optionalForeignMessage retain];
+ ImportMessage *optionalImportMessage = [message.optionalImportMessage retain];
+ PublicImportMessage *optionalPublicImportMessage =
+ [message.optionalPublicImportMessage retain];
+ TestAllTypes_NestedMessage *optionalLazyMessage =
+ [message.optionalLazyMessage retain];
+
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil(optionalNestedMessage);
+ XCTAssertNotNil(optionalForeignMessage);
+ XCTAssertNotNil(optionalImportMessage);
+ XCTAssertNotNil(optionalPublicImportMessage);
+ XCTAssertNotNil(optionalLazyMessage);
+
+ // Although they were created, they should not respond to hasValue until that
+ // submessage is mutated.
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // And they set that value back in to the message since the value created was
+ // mutable (so a second fetch should give the same object).
+
+ XCTAssertEqual(message.optionalGroup, optionalGroup);
+ XCTAssertEqual(message.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertEqual(message.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertEqual(message.optionalImportMessage, optionalImportMessage);
+ XCTAssertEqual(message.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertEqual(message.optionalLazyMessage, optionalLazyMessage);
+
+ // And the default objects for a second message should be distinct (again,
+ // since they are mutable, each needs their own copy).
+
+ TestAllTypes *message2 = [TestAllTypes message];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message2.optionalGroup, optionalGroup);
+ XCTAssertNotEqual(message2.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertNotEqual(message2.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertNotEqual(message2.optionalImportMessage, optionalImportMessage);
+ XCTAssertNotEqual(message2.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(message2.optionalLazyMessage, optionalLazyMessage);
+
+ // Setting the values to nil will clear the has flag, and on next access you
+ // get back new submessages.
+
+ message.optionalGroup = nil;
+ message.optionalNestedMessage = nil;
+ message.optionalForeignMessage = nil;
+ message.optionalImportMessage = nil;
+ message.optionalPublicImportMessage = nil;
+ message.optionalLazyMessage = nil;
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.optionalGroup, optionalGroup);
+ XCTAssertNotEqual(message.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertNotEqual(message.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertNotEqual(message.optionalImportMessage, optionalImportMessage);
+ XCTAssertNotEqual(message.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(message.optionalLazyMessage, optionalLazyMessage);
+
+ [optionalGroup release];
+ [optionalNestedMessage release];
+ [optionalForeignMessage release];
+ [optionalImportMessage release];
+ [optionalPublicImportMessage release];
+ [optionalLazyMessage release];
+}
+
+- (void)testMultiplePointersToAutocreatedMessage {
+ // Multiple objects pointing to the same autocreated message.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes *message2 = [TestAllTypes message];
+ message2.optionalGroup = message.optionalGroup;
+ XCTAssertTrue([message2 hasOptionalGroup]);
+ XCTAssertFalse([message hasOptionalGroup]);
+ message2.optionalGroup.a = 42;
+ XCTAssertTrue([message hasOptionalGroup]);
+ XCTAssertTrue([message2 hasOptionalGroup]);
+}
+
+- (void)testCopyWithAutocreatedMessage {
+ // Mutable copy should not copy autocreated messages.
+ TestAllTypes *message = [TestAllTypes message];
+ message.optionalGroup.a = 42;
+ XCTAssertNotNil(message.optionalNestedMessage);
+ TestAllTypes *message2 = [[message copy] autorelease];
+ XCTAssertTrue([message2 hasOptionalGroup]);
+ XCTAssertFalse([message2 hasOptionalNestedMessage]);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.optionalNestedMessage,
+ message2.optionalNestedMessage);
+}
+
+- (void)testClearAutocreatedSubmessage {
+ // Call clear on an intermediate submessage should cause it to get recreated
+ // on the next call.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *message_inner = [message.a.a.a retain];
+ XCTAssertNotNil(message_inner);
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(message_inner, message.a.a));
+ [message.a.a clear];
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_inner, message.a.a));
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.a.a.a, message_inner);
+ [message_inner release];
+}
+
+- (void)testRetainAutocreatedSubmessage {
+ // Should be able to retain autocreated submessage while the creator is
+ // dealloced.
+ TestAllTypes *message = [TestAllTypes message];
+
+ ForeignMessage *subMessage;
+ @autoreleasepool {
+ TestAllTypes *message2 = [TestAllTypes message];
+ subMessage = message2.optionalForeignMessage; // Autocreated
+ message.optionalForeignMessage = subMessage;
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(message.optionalForeignMessage,
+ message2));
+ }
+
+ // Should be the same object, and should still be live.
+ XCTAssertEqual(message.optionalForeignMessage, subMessage);
+ XCTAssertNotNil([subMessage description]);
+}
+
+- (void)testSetNilAutocreatedSubmessage {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *message_inner = [message.a.a retain];
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ message.a.a = nil;
+
+ // |message.a| has to be made visible, but |message.a.a| was set to nil so
+ // shouldn't be.
+ XCTAssertTrue([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+
+ // Setting submessage to nil should cause it to lose its creator.
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_inner, message.a));
+
+ // After setting to nil, getting it again should create a new autocreated
+ // message.
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.a.a, message_inner);
+
+ [message_inner release];
+}
+
+- (void)testSetDoesntHaveAutocreatedSubmessage {
+ // Clearing submessage (set has == NO) should NOT cause it to lose its
+ // creator.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes_NestedMessage *nestedMessage = message.optionalNestedMessage;
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ [message setHasOptionalNestedMessage:NO];
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ XCTAssertEqual(message.optionalNestedMessage, nestedMessage);
+}
+
+- (void)testSetAutocreatedMessageBecomesVisible {
+ // Setting a value should cause the submessage to appear to its creator.
+ // Test this several levels deep.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ message.a.a.a.a.i = 42;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertTrue([message.a.a hasA]);
+ XCTAssertTrue([message.a.a.a hasA]);
+ XCTAssertFalse([message.a.a.a.a hasA]);
+ XCTAssertEqual(message.a.a.a.a.i, 42);
+}
+
+- (void)testClearUnsetFieldOfAutocreatedMessage {
+ // Clearing an unset field should not cause the submessage to appear to its
+ // creator.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ message.a.a.a.a.hasI = NO;
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertFalse([message.a.a hasA]);
+ XCTAssertFalse([message.a.a.a hasA]);
+}
+
+- (void)testAutocreatedSubmessageAssignSkip {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *messageLevel1 = [message.a retain];
+ TestRecursiveMessage *messageLevel2 = [message.a.a retain];
+ TestRecursiveMessage *messageLevel3 = [message.a.a.a retain];
+ TestRecursiveMessage *messageLevel4 = [message.a.a.a.a retain];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel1, message));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel4, messageLevel3));
+
+ // Test skipping over an autocreated submessage and ensure it gets unset.
+ message.a = message.a.a;
+ XCTAssertEqual(message.a, messageLevel2);
+ XCTAssertTrue([message hasA]);
+ XCTAssertEqual(message.a.a, messageLevel3);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertEqual(message.a.a.a, messageLevel4);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel1,
+ message)); // Because it was orphaned.
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+
+ [messageLevel1 release];
+ [messageLevel2 release];
+ [messageLevel3 release];
+ [messageLevel4 release];
+}
+
+- (void)testAutocreatedSubmessageAssignLoop {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *messageLevel1 = [message.a retain];
+ TestRecursiveMessage *messageLevel2 = [message.a.a retain];
+ TestRecursiveMessage *messageLevel3 = [message.a.a.a retain];
+ TestRecursiveMessage *messageLevel4 = [message.a.a.a.a retain];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel1, message));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel4, messageLevel3));
+
+ // Test a property with a loop. You'd never do this but at least ensure the
+ // autocreated submessages behave sanely.
+ message.a.a = message.a;
+ XCTAssertTrue([message hasA]);
+ XCTAssertEqual(message.a, messageLevel1);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual(message.a.a, messageLevel1);
+ XCTAssertTrue([message.a.a hasA]);
+ XCTAssertEqual(message.a.a.a, messageLevel1);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel1,
+ message)); // Because it was assigned.
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel2,
+ messageLevel1)); // Because it was orphaned.
+ XCTAssertFalse([messageLevel2 hasA]);
+
+ // Break the retain loop.
+ message.a.a = nil;
+ XCTAssertTrue([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+
+ [messageLevel1 release];
+ [messageLevel2 release];
+ [messageLevel3 release];
+ [messageLevel4 release];
+}
+
+- (void)testSetAutocreatedSubmessage {
+ // Setting autocreated submessage to another value should cause the old one to
+ // lose its creator.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message.optionalNestedMessage retain];
+
+ message.optionalNestedMessage = [TestAllTypes_NestedMessage message];
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+ XCTAssertTrue(message.optionalNestedMessage != nestedMessage);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(nestedMessage, message));
+
+ [nestedMessage release];
+}
+
+- (void)testAutocreatedUnknownFields {
+ // Doing anything with (except reading) unknown fields should cause the
+ // submessage to become visible.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ XCTAssertNil(message.optionalNestedMessage.unknownFields);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+
+ GPBUnknownFieldSet *unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ message.optionalNestedMessage.unknownFields = unknownFields;
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+
+ message.optionalNestedMessage = nil;
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ [message.optionalNestedMessage setUnknownFields:unknownFields];
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+}
+
+- (void)testSetAutocreatedSubmessageToSelf {
+ // Setting submessage to itself should cause it to become visible.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ message.optionalNestedMessage = message.optionalNestedMessage;
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+}
+
+- (void)testAutocreatedSubmessageMemoryLeaks {
+ // Test for memory leaks with autocreated submessages.
+ TestRecursiveMessage *message;
+ TestRecursiveMessage *messageLevel1;
+ TestRecursiveMessage *messageLevel2;
+ TestRecursiveMessage *messageLevel3;
+ TestRecursiveMessage *messageLevel4;
+ @autoreleasepool {
+ message = [[TestRecursiveMessage alloc] init];
+ messageLevel1 = [message.a retain];
+ messageLevel2 = [message.a.a retain];
+ messageLevel3 = [message.a.a.a retain];
+ messageLevel4 = [message.a.a.a.a retain];
+ message.a.i = 1;
+ }
+
+ XCTAssertEqual(message.retainCount, (NSUInteger)1);
+ [message release];
+ XCTAssertEqual(messageLevel1.retainCount, (NSUInteger)1);
+ [messageLevel1 release];
+ XCTAssertEqual(messageLevel2.retainCount, (NSUInteger)1);
+ [messageLevel2 release];
+ XCTAssertEqual(messageLevel3.retainCount, (NSUInteger)1);
+ [messageLevel3 release];
+ XCTAssertEqual(messageLevel4.retainCount, (NSUInteger)1);
+ [messageLevel4 release];
+}
+
+- (void)testDefaultingArrays {
+ // Basic tests for default creation of arrays in a message.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ // Simply accessing the array should not make any fields visible.
+ XCTAssertNotNil(message.a.a.iArray);
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertNotNil(message2.a.a.strArray);
+ XCTAssertFalse([message2 hasA]);
+ XCTAssertFalse([message2.a hasA]);
+
+ // But adding an element to the array should.
+ [message.a.a.iArray addValue:42];
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual([message.a.a.iArray count], (NSUInteger)1);
+ [message2.a.a.strArray addObject:@"foo"];
+ XCTAssertTrue([message2 hasA]);
+ XCTAssertTrue([message2.a hasA]);
+ XCTAssertEqual([message2.a.a.strArray count], (NSUInteger)1);
+}
+
+- (void)testAutocreatedArrayShared {
+ // Multiple objects pointing to the same array.
+ TestRecursiveMessageWithRepeatedField *message1a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message1b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message1a.a.iArray = message1b.a.iArray;
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertFalse([message1b hasA]);
+ [message1a.a.iArray addValue:1];
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertTrue([message1b hasA]);
+ XCTAssertEqual(message1a.a.iArray, message1b.a.iArray);
+
+ TestRecursiveMessageWithRepeatedField *message2a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message2a.a.strArray = message2b.a.strArray;
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertFalse([message2b hasA]);
+ [message2a.a.strArray addObject:@"bar"];
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertTrue([message2b hasA]);
+ XCTAssertEqual(message2a.a.strArray, message2b.a.strArray);
+}
+
+- (void)testAutocreatedArrayCopy {
+ // Copy should not copy autocreated arrays.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.repeatedStringArray);
+ XCTAssertNotNil(message.repeatedInt32Array);
+ TestAllTypes *message2 = [[message copy] autorelease];
+ // Pointer conparisions.
+ XCTAssertNotEqual(message.repeatedStringArray, message2.repeatedStringArray);
+ XCTAssertNotEqual(message.repeatedInt32Array, message2.repeatedInt32Array);
+
+ // Mutable copy should copy empty arrays that were explicitly set (end up
+ // with different objects that are equal).
+ TestAllTypes *message3 = [TestAllTypes message];
+ message3.repeatedInt32Array = [GPBInt32Array arrayWithValue:42];
+ message3.repeatedStringArray = [NSMutableArray arrayWithObject:@"wee"];
+ XCTAssertNotNil(message.repeatedInt32Array);
+ XCTAssertNotNil(message.repeatedStringArray);
+ TestAllTypes *message4 = [[message3 copy] autorelease];
+ XCTAssertNotEqual(message3.repeatedInt32Array, message4.repeatedInt32Array);
+ XCTAssertEqualObjects(message3.repeatedInt32Array,
+ message4.repeatedInt32Array);
+ XCTAssertNotEqual(message3.repeatedStringArray, message4.repeatedStringArray);
+ XCTAssertEqualObjects(message3.repeatedStringArray,
+ message4.repeatedStringArray);
+}
+
+- (void)testAutocreatedArrayRetain {
+ // Should be able to retain autocreated array while the creator is dealloced.
+ TestAllTypes *message = [TestAllTypes message];
+
+ @autoreleasepool {
+ TestAllTypes *message2 = [TestAllTypes message];
+ message.repeatedInt32Array = message2.repeatedInt32Array;
+ message.repeatedStringArray = message2.repeatedStringArray;
+ // Pointer conparision
+ XCTAssertEqual(message.repeatedInt32Array->_autocreator, message2);
+ XCTAssertTrue([message.repeatedStringArray
+ isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(
+ ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator,
+ message2);
+ }
+
+ XCTAssertNil(message.repeatedInt32Array->_autocreator);
+ XCTAssertTrue(
+ [message.repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertNil(
+ ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator);
+}
+
+- (void)testSetNilAutocreatedArray {
+ // Setting array to nil should cause it to lose its delegate.
+ TestAllTypes *message = [TestAllTypes message];
+ GPBInt32Array *repeatedInt32Array = [message.repeatedInt32Array retain];
+ GPBAutocreatedArray *repeatedStringArray =
+ (GPBAutocreatedArray *)[message.repeatedStringArray retain];
+ XCTAssertTrue([repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(repeatedInt32Array->_autocreator, message);
+ XCTAssertEqual(repeatedStringArray->_autocreator, message);
+ message.repeatedInt32Array = nil;
+ message.repeatedStringArray = nil;
+ XCTAssertNil(repeatedInt32Array->_autocreator);
+ XCTAssertNil(repeatedStringArray->_autocreator);
+ [repeatedInt32Array release];
+ [repeatedStringArray release];
+}
+
+- (void)testSetOverAutocreatedArrayAndSetAgain {
+ // Ensure when dealing with replacing an array it is handled being either
+ // an autocreated one or a straight NSArray.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestAllTypes *message = [TestAllTypes message];
+ [message.repeatedStringArray addObject:@"foo"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+ message.repeatedStringArray = [NSMutableArray arrayWithObjects:@"bar", @"bar2", nil];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)2);
+ message.repeatedStringArray = [NSMutableArray arrayWithObject:@"baz"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+}
+
+- (void)testReplaceAutocreatedArray {
+ // Replacing array should orphan the old one and cause its creator to become
+ // visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iArray);
+ XCTAssertFalse([message hasA]);
+ GPBInt32Array *iArray = [message.a.iArray retain];
+ XCTAssertEqual(iArray->_autocreator, message.a); // Pointer comparision
+ message.a.iArray = [GPBInt32Array arrayWithValue:1];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.iArray, iArray); // Pointer comparision
+ XCTAssertNil(iArray->_autocreator);
+ [iArray release];
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strArray);
+ XCTAssertFalse([message hasA]);
+ GPBAutocreatedArray *strArray =
+ (GPBAutocreatedArray *)[message.a.strArray retain];
+ XCTAssertTrue([strArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(strArray->_autocreator, message.a); // Pointer comparision
+ message.a.strArray = [NSMutableArray arrayWithObject:@"foo"];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.strArray, strArray); // Pointer comparision
+ XCTAssertNil(strArray->_autocreator);
+ [strArray release];
+ }
+}
+
+- (void)testSetAutocreatedArrayToSelf {
+ // Setting array to itself should cause it to become visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iArray);
+ XCTAssertFalse([message hasA]);
+ message.a.iArray = message.a.iArray;
+ XCTAssertTrue([message hasA]);
+ XCTAssertNil(message.a.iArray->_autocreator);
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strArray);
+ XCTAssertFalse([message hasA]);
+ message.a.strArray = message.a.strArray;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a.strArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertNil(((GPBAutocreatedArray *)message.a.strArray)->_autocreator);
+ }
+}
+
+- (void)testAutocreatedArrayRemoveAllValues {
+ // Calling removeAllValues on autocreated array should not cause it to be
+ // visible.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ [message.a.iArray removeAll];
+ XCTAssertFalse([message hasA]);
+ [message.a.strArray removeAllObjects];
+ XCTAssertFalse([message hasA]);
+}
+
+- (void)testDefaultingMaps {
+ // Basic tests for default creation of maps in a message.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ // Simply accessing the map should not make any fields visible.
+ XCTAssertNotNil(message.a.a.iToI);
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertNotNil(message2.a.a.strToStr);
+ XCTAssertFalse([message2 hasA]);
+ XCTAssertFalse([message2.a hasA]);
+
+ // But adding an element to the map should.
+ [message.a.a.iToI setInt32:100 forKey:200];
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual([message.a.a.iToI count], (NSUInteger)1);
+ [message2.a.a.strToStr setObject:@"foo" forKey:@"bar"];
+ XCTAssertTrue([message2 hasA]);
+ XCTAssertTrue([message2.a hasA]);
+ XCTAssertEqual([message2.a.a.strToStr count], (NSUInteger)1);
+}
+
+- (void)testAutocreatedMapShared {
+ // Multiple objects pointing to the same map.
+ TestRecursiveMessageWithRepeatedField *message1a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message1b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message1a.a.iToI = message1b.a.iToI;
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertFalse([message1b hasA]);
+ [message1a.a.iToI setInt32:1 forKey:2];
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertTrue([message1b hasA]);
+ XCTAssertEqual(message1a.a.iToI, message1b.a.iToI);
+
+ TestRecursiveMessageWithRepeatedField *message2a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message2a.a.strToStr = message2b.a.strToStr;
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertFalse([message2b hasA]);
+ [message2a.a.strToStr setObject:@"bar" forKey:@"foo"];
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertTrue([message2b hasA]);
+ XCTAssertEqual(message2a.a.strToStr, message2b.a.strToStr);
+}
+
+- (void)testAutocreatedMapCopy {
+ // Copy should not copy autocreated maps.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.strToStr);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [[message copy] autorelease];
+ // Pointer conparisions.
+ XCTAssertNotEqual(message.strToStr, message2.strToStr);
+ XCTAssertNotEqual(message.iToI, message2.iToI);
+
+ // Mutable copy should copy empty arrays that were explicitly set (end up
+ // with different objects that are equal).
+ TestRecursiveMessageWithRepeatedField *message3 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message3.iToI = [GPBInt32Int32Dictionary dictionaryWithInt32:10 forKey:20];
+ message3.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"123"];
+ XCTAssertNotNil(message.iToI);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message4 =
+ [[message3 copy] autorelease];
+ XCTAssertNotEqual(message3.iToI, message4.iToI);
+ XCTAssertEqualObjects(message3.iToI, message4.iToI);
+ XCTAssertNotEqual(message3.strToStr, message4.strToStr);
+ XCTAssertEqualObjects(message3.strToStr, message4.strToStr);
+}
+
+- (void)testAutocreatedMapRetain {
+ // Should be able to retain autocreated map while the creator is dealloced.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ @autoreleasepool {
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.iToI = message2.iToI;
+ message.strToStr = message2.strToStr;
+ // Pointer conparision
+ XCTAssertEqual(message.iToI->_autocreator, message2);
+ XCTAssertTrue([message.strToStr
+ isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator,
+ message2);
+ }
+
+ XCTAssertNil(message.iToI->_autocreator);
+ XCTAssertTrue(
+ [message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator);
+}
+
+- (void)testSetNilAutocreatedMap {
+ // Setting map to nil should cause it to lose its delegate.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ GPBInt32Int32Dictionary *iToI = [message.iToI retain];
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(iToI->_autocreator, message);
+ XCTAssertEqual(strToStr->_autocreator, message);
+ message.iToI = nil;
+ message.strToStr = nil;
+ XCTAssertNil(iToI->_autocreator);
+ XCTAssertNil(strToStr->_autocreator);
+ [iToI release];
+ [strToStr release];
+}
+
+- (void)testSetOverAutocreatedMapAndSetAgain {
+ // Ensure when dealing with replacing a map it is handled being either
+ // an autocreated one or a straight NSDictionary.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.strToStr[@"foo"] = @"bar";
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:@"bar", @"key1", @"baz", @"key2", nil];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)2);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"baz" forKey:@"mumble"];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+}
+
+- (void)testReplaceAutocreatedMap {
+ // Replacing map should orphan the old one and cause its creator to become
+ // visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ GPBInt32Int32Dictionary *iToI = [message.a.iToI retain];
+ XCTAssertEqual(iToI->_autocreator, message.a); // Pointer comparision
+ message.a.iToI = [GPBInt32Int32Dictionary dictionaryWithInt32:6 forKey:7];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.iToI, iToI); // Pointer comparision
+ XCTAssertNil(iToI->_autocreator);
+ [iToI release];
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.a.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(strToStr->_autocreator, message.a); // Pointer comparision
+ message.a.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"def"];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.strToStr, strToStr); // Pointer comparision
+ XCTAssertNil(strToStr->_autocreator);
+ [strToStr release];
+ }
+}
+
+- (void)testSetAutocreatedMapToSelf {
+ // Setting map to itself should cause it to become visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ message.a.iToI = message.a.iToI;
+ XCTAssertTrue([message hasA]);
+ XCTAssertNil(message.a.iToI->_autocreator);
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ message.a.strToStr = message.a.strToStr;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(((GPBAutocreatedDictionary *)message.a.strToStr)->_autocreator);
+ }
+}
+
+- (void)testAutocreatedMapRemoveAllValues {
+ // Calling removeAll on autocreated map should not cause it to be visible.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ [message.a.iToI removeAll];
+ XCTAssertFalse([message hasA]);
+ [message.a.strToStr removeAllObjects];
+ XCTAssertFalse([message hasA]);
+}
+
+- (void)testExtensionAccessors {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllExtensionsSet:message repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testExtensionRepeatedSetters {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+ [self assertRepeatedExtensionsModified:message
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testExtensionDefaults {
+ [self assertExtensionsClear:[TestAllExtensions message]];
+}
+
+- (void)testExtensionIsEquals {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [self setAllExtensions:message2 repeatedCount:kGPBDefaultRepeatCount];
+ XCTAssertFalse([message isEqual:message2]);
+ message2 = [TestAllExtensions message];
+ [self setAllExtensions:message2 repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message2];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testExtensionsMergeFrom {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+
+ message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [self modifyRepeatedExtensions:message2];
+ [message2 mergeFrom:message];
+
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testDefaultingExtensionMessages {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ // Initially they should all not have values.
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message
+ hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ // They should auto create something when fetched.
+
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ TestAllTypes_NestedMessage *optionalNestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ ForeignMessage *optionalForeignMessage =
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]];
+ ImportMessage *optionalImportMessage =
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]];
+ PublicImportMessage *optionalPublicImportMessage = [message
+ getExtension:[UnittestRoot optionalPublicImportMessageExtension]];
+ TestAllTypes_NestedMessage *optionalLazyMessage =
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]];
+
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil(optionalNestedMessage);
+ XCTAssertNotNil(optionalForeignMessage);
+ XCTAssertNotNil(optionalImportMessage);
+ XCTAssertNotNil(optionalPublicImportMessage);
+ XCTAssertNotNil(optionalLazyMessage);
+
+ // Although it auto-created empty messages, it should not show that it has
+ // them.
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ // And they set that value back in to the message since the value created was
+ // mutable (so a second fetch should give the same object).
+
+ XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+
+ // And the default objects for a second message should be distinct (again,
+ // since they are mutable, each needs their own copy).
+
+ TestAllExtensions *message2 = [TestAllExtensions message];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+
+ // Clear values, and on next access you get back new submessages.
+
+ [message setExtension:[UnittestRoot optionalGroupExtension] value:nil];
+ [message setExtension:[UnittestRoot optionalGroupExtension] value:nil];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalImportMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalPublicImportMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalLazyMessageExtension] value:nil];
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message
+ hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertEqual(
+ [message
+ getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+}
+
+- (void)testMultiplePointersToAutocreatedExtension {
+ // 2 objects point to the same auto-created extension. One should "has" it.
+ // The other should not.
+ TestAllExtensions *message = [TestAllExtensions message];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ GPBExtensionDescriptor *extension = [UnittestRoot optionalGroupExtension];
+ [message setExtension:extension value:[message2 getExtension:extension]];
+ XCTAssertEqual([message getExtension:extension],
+ [message2 getExtension:extension]);
+ XCTAssertFalse([message2 hasExtension:extension]);
+ XCTAssertTrue([message hasExtension:extension]);
+
+ TestAllTypes_OptionalGroup *extensionValue =
+ [message2 getExtension:extension];
+ extensionValue.a = 1;
+ XCTAssertTrue([message2 hasExtension:extension]);
+ XCTAssertTrue([message hasExtension:extension]);
+}
+
+- (void)testCopyWithAutocreatedExtension {
+ // Mutable copy shouldn't copy autocreated extensions.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ GPBExtensionDescriptor *optionalNestedMessageExtesion =
+ [UnittestRoot optionalNestedMessageExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [message getExtension:optionalGroupExtension];
+ optionalGroup.a = 42;
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil([message getExtension:optionalNestedMessageExtesion]);
+ XCTAssertTrue([message hasExtension:optionalGroupExtension]);
+ XCTAssertFalse([message hasExtension:optionalNestedMessageExtesion]);
+
+ TestAllExtensions *message2 = [[message copy] autorelease];
+
+ // message2 should end up with its own copy of the optional group.
+ XCTAssertTrue([message2 hasExtension:optionalGroupExtension]);
+ XCTAssertEqualObjects([message getExtension:optionalGroupExtension],
+ [message2 getExtension:optionalGroupExtension]);
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual([message getExtension:optionalGroupExtension],
+ [message2 getExtension:optionalGroupExtension]);
+
+ XCTAssertFalse([message2 hasExtension:optionalNestedMessageExtesion]);
+ // Intentionally doing a pointer comparison (auto creation should be
+ // different)
+ XCTAssertNotEqual([message getExtension:optionalNestedMessageExtesion],
+ [message2 getExtension:optionalNestedMessageExtesion]);
+}
+
+- (void)testClearMessageAutocreatedExtension {
+ // Call clear should cause it to recreate its autocreated extensions.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [[message getExtension:optionalGroupExtension] retain];
+ [message clear];
+ TestAllTypes_OptionalGroup *optionalGroupNew =
+ [message getExtension:optionalGroupExtension];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(optionalGroup, optionalGroupNew);
+ [optionalGroup release];
+}
+
+- (void)testRetainAutocreatedExtension {
+ // Should be able to retain autocreated extension while the creator is
+ // dealloced.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+
+ @autoreleasepool {
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [message setExtension:optionalGroupExtension
+ value:[message2 getExtension:optionalGroupExtension]];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(
+ [message getExtension:optionalGroupExtension], message2));
+ }
+
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(
+ [message getExtension:optionalGroupExtension], message));
+}
+
+- (void)testClearAutocreatedExtension {
+ // Clearing autocreated extension should NOT cause it to lose its creator.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [[message getExtension:optionalGroupExtension] retain];
+ [message clearExtension:optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroupNew =
+ [message getExtension:optionalGroupExtension];
+ XCTAssertEqual(optionalGroup, optionalGroupNew);
+ XCTAssertFalse([message hasExtension:optionalGroupExtension]);
+ [optionalGroup release];
+
+ // Clearing autocreated extension should not cause its creator to become
+ // visible
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+ TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl3 =
+ [message_lvl2 getExtension:recursiveExtension];
+ [message_lvl3 clearExtension:recursiveExtension];
+ XCTAssertFalse([message hasExtension:recursiveExtension]);
+}
+
+- (void)testSetAutocreatedExtensionBecomesVisible {
+ // Setting an extension should cause the extension to appear to its creator.
+ // Test this several levels deep.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+ TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl3 =
+ [message_lvl2 getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl4 =
+ [message_lvl3 getExtension:recursiveExtension];
+ XCTAssertFalse([message hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl2 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl3 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl4 hasExtension:recursiveExtension]);
+ [message_lvl4 setExtension:[UnittestRoot optionalInt32Extension] value:@(1)];
+ XCTAssertTrue([message hasExtension:recursiveExtension]);
+ XCTAssertTrue([message_lvl2 hasExtension:recursiveExtension]);
+ XCTAssertTrue([message_lvl3 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl4 hasExtension:recursiveExtension]);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl4, message_lvl3));
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl3, message_lvl2));
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl2, message));
+}
+
+- (void)testSetAutocreatedExtensionToSelf {
+ // Setting extension to itself should cause it to become visible.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ XCTAssertNotNil([message getExtension:optionalGroupExtension]);
+ XCTAssertFalse([message hasExtension:optionalGroupExtension]);
+ [message setExtension:optionalGroupExtension
+ value:[message getExtension:optionalGroupExtension]];
+ XCTAssertTrue([message hasExtension:optionalGroupExtension]);
+}
+
+- (void)testAutocreatedExtensionMemoryLeaks {
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+
+ // Test for memory leaks with autocreated extensions.
+ TestAllExtensions *message;
+ TestAllExtensions *message_lvl2;
+ TestAllExtensions *message_lvl3;
+ TestAllExtensions *message_lvl4;
+ @autoreleasepool {
+ message = [[TestAllExtensions alloc] init];
+ message_lvl2 = [[message getExtension:recursiveExtension] retain];
+ message_lvl3 = [[message_lvl2 getExtension:recursiveExtension] retain];
+ message_lvl4 = [[message_lvl3 getExtension:recursiveExtension] retain];
+ [message_lvl2 setExtension:[UnittestRoot optionalInt32Extension]
+ value:@(1)];
+ }
+
+ XCTAssertEqual(message.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message release];
+ }
+ XCTAssertEqual(message_lvl2.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message_lvl2 release];
+ }
+ XCTAssertEqual(message_lvl3.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message_lvl3 release];
+ }
+ XCTAssertEqual(message_lvl4.retainCount, (NSUInteger)1);
+ [message_lvl4 release];
+}
+
+- (void)testSetExtensionWithAutocreatedValue {
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+
+ TestAllExtensions *message;
+ @autoreleasepool {
+ message = [[TestAllExtensions alloc] init];
+ [message getExtension:recursiveExtension];
+ }
+
+ // This statements checks that the extension value isn't accidentally
+ // dealloced when removing it from the autocreated map.
+ [message setExtension:recursiveExtension
+ value:[message getExtension:recursiveExtension]];
+ XCTAssertTrue([message hasExtension:recursiveExtension]);
+ [message release];
+}
+
+- (void)testRecursion {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.a);
+ XCTAssertEqual(message.a.a.i, 0);
+}
+
+- (void)testGenerateAndParseUnknownMessage {
+ GPBUnknownFieldSet *unknowns =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns mergeVarintField:123 value:456];
+ GPBMessage *message = [GPBMessage message];
+ [message setUnknownFields:unknowns];
+ NSData *data = [message data];
+ GPBMessage *message2 =
+ [GPBMessage parseFromData:data extensionRegistry:nil error:NULL];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testDelimitedWriteAndParseMultipleMessages {
+ GPBUnknownFieldSet *unknowns1 =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns1 mergeVarintField:123 value:456];
+ GPBMessage *message1 = [GPBMessage message];
+ [message1 setUnknownFields:unknowns1];
+
+ GPBUnknownFieldSet *unknowns2 =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns2 mergeVarintField:789 value:987];
+ [unknowns2 mergeVarintField:654 value:321];
+ GPBMessage *message2 = [GPBMessage message];
+ [message2 setUnknownFields:unknowns2];
+
+ NSMutableData *delimitedData = [NSMutableData data];
+ [delimitedData appendData:[message1 delimitedData]];
+ [delimitedData appendData:[message2 delimitedData]];
+ GPBCodedInputStream *input =
+ [GPBCodedInputStream streamWithData:delimitedData];
+ GPBMessage *message3 = [GPBMessage parseDelimitedFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ GPBMessage *message4 = [GPBMessage parseDelimitedFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ XCTAssertEqualObjects(message1, message3);
+ XCTAssertEqualObjects(message2, message4);
+}
+
+- (void)testDuplicateEnums {
+ XCTAssertEqual(TestEnumWithDupValue_Foo1, TestEnumWithDupValue_Foo2);
+}
+
+- (void)testWeirdDefaults {
+ ObjcWeirdDefaults *message = [ObjcWeirdDefaults message];
+ GPBDescriptor *descriptor = [[message class] descriptor];
+ GPBFieldDescriptor *fieldDesc = [descriptor fieldWithName:@"foo"];
+ XCTAssertNotNil(fieldDesc);
+ XCTAssertTrue(fieldDesc.hasDefaultValue);
+ XCTAssertFalse(message.hasFoo);
+ XCTAssertEqualObjects(message.foo, @"");
+
+ fieldDesc = [descriptor fieldWithName:@"bar"];
+ XCTAssertNotNil(fieldDesc);
+ XCTAssertTrue(fieldDesc.hasDefaultValue);
+ XCTAssertFalse(message.hasBar);
+ XCTAssertEqualObjects(message.bar, GPBEmptyNSData());
+}
+
+- (void)testEnumDescriptorFromExtensionDescriptor {
+ GPBExtensionDescriptor *extDescriptor =
+ [UnittestRoot optionalForeignEnumExtension];
+ XCTAssertEqual(extDescriptor.dataType, GPBDataTypeEnum);
+ GPBEnumDescriptor *enumDescriptor = extDescriptor.enumDescriptor;
+ GPBEnumDescriptor *expectedDescriptor = ForeignEnum_EnumDescriptor();
+ XCTAssertEqualObjects(enumDescriptor, expectedDescriptor);
+}
+
+- (void)testPropertyNaming {
+ // objectivec_helpers.cc has some special handing to get proper all caps
+ // for a few cases to meet objc developer expectations.
+ //
+ // This "test" confirms that the expected names are generated, otherwise the
+ // test itself will fail to compile.
+ ObjCPropertyNaming *msg = [ObjCPropertyNaming message];
+ // On their own, at the end, in the middle.
+ msg.URL = @"good";
+ msg.thumbnailURL = @"good";
+ msg.URLFoo = @"good";
+ msg.someURLBlah = @"good";
+ msg.HTTP = @"good";
+ msg.HTTPS = @"good";
+ // No caps since it was "urls".
+ [msg.urlsArray addObject:@"good"];
+}
+
+- (void)testEnumNaming {
+ // objectivec_helpers.cc has some interesting cases to deal with in
+ // EnumValueName/EnumValueShortName. Confirm that things generated as
+ // expected.
+
+ // This block just has to compile to confirm we got the expected types/names.
+ // The *_IsValidValue() calls are just there to keep the projects warnings
+ // flags happy by providing use of the variables/values.
+
+ Foo aFoo = Foo_SerializedSize;
+ Foo_IsValidValue(aFoo);
+ aFoo = Foo_Size;
+ Foo_IsValidValue(aFoo);
+
+ Category_Enum aCat = Category_Enum_Red;
+ Category_Enum_IsValidValue(aCat);
+
+ Time aTime = Time_Base;
+ Time_IsValidValue(aTime);
+ aTime = Time_SomethingElse;
+ Time_IsValidValue(aTime);
+
+ // This block confirms the names in the decriptors is what we wanted.
+
+ GPBEnumDescriptor *descriptor;
+ NSString *valueName;
+
+ descriptor = Foo_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Foo", descriptor.name);
+ valueName = [descriptor enumNameForValue:Foo_SerializedSize];
+ XCTAssertEqualObjects(@"Foo_SerializedSize", valueName);
+ valueName = [descriptor enumNameForValue:Foo_Size];
+ XCTAssertEqualObjects(@"Foo_Size", valueName);
+
+ descriptor = Category_Enum_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Category_Enum", descriptor.name);
+ valueName = [descriptor enumNameForValue:Category_Enum_Red];
+ XCTAssertEqualObjects(@"Category_Enum_Red", valueName);
+
+ descriptor = Time_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Time", descriptor.name);
+ valueName = [descriptor enumNameForValue:Time_Base];
+ XCTAssertEqualObjects(@"Time_Base", valueName);
+ valueName = [descriptor enumNameForValue:Time_SomethingElse];
+ XCTAssertEqualObjects(@"Time_SomethingElse", valueName);
+}
+
+- (void)testNegativeEnums {
+ EnumTestMsg *msg = [EnumTestMsg message];
+
+ // Defaults
+ XCTAssertEqual(msg.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_One);
+ XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegOne);
+ // Bounce to wire and back.
+ NSData *data = [msg data];
+ XCTAssertNotNil(data);
+ EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_One);
+ XCTAssertEqual(msgPrime.baz, EnumTestMsg_MyEnum_NegOne);
+
+ // Other values
+ msg.bar = EnumTestMsg_MyEnum_Two;
+ msg.baz = EnumTestMsg_MyEnum_NegTwo;
+ XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegTwo);
+ // Bounce to wire and back.
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual(msgPrime.baz, EnumTestMsg_MyEnum_NegTwo);
+
+ // Repeated field (shouldn't ever be an issue since developer has to use the
+ // right GPBArray methods themselves).
+ msg.mumbleArray = [GPBEnumArray
+ arrayWithValidationFunction:EnumTestMsg_MyEnum_IsValidValue];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Zero];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_One];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Two];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_NegOne];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_NegTwo];
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:0], EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:1], EnumTestMsg_MyEnum_One);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:2], EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:3], EnumTestMsg_MyEnum_NegOne);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:4], EnumTestMsg_MyEnum_NegTwo);
+ // Bounce to wire and back.
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0],
+ EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:1], EnumTestMsg_MyEnum_One);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:2], EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:3],
+ EnumTestMsg_MyEnum_NegOne);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:4],
+ EnumTestMsg_MyEnum_NegTwo);
+}
+
+- (void)testOneBasedEnumHolder {
+ // Test case for https://github.com/google/protobuf/issues/1453
+ // Message with no explicit defaults, but a non zero default for an enum.
+ MessageWithOneBasedEnum *enumMsg = [MessageWithOneBasedEnum message];
+ XCTAssertEqual(enumMsg.enumField, MessageWithOneBasedEnum_OneBasedEnum_One);
+}
+
+- (void)testBoolOffsetUsage {
+ // Bools use storage within has_bits; this test ensures that this is honored
+ // in all places where things should crash or fail based on reading out of
+ // field storage instead.
+ BoolOnlyMessage *msg1 = [BoolOnlyMessage message];
+ BoolOnlyMessage *msg2 = [BoolOnlyMessage message];
+
+ msg1.boolField1 = YES;
+ msg2.boolField1 = YES;
+ msg1.boolField3 = YES;
+ msg2.boolField3 = YES;
+ msg1.boolField5 = YES;
+ msg2.boolField5 = YES;
+ msg1.boolField7 = YES;
+ msg2.boolField7 = YES;
+ msg1.boolField9 = YES;
+ msg2.boolField9 = YES;
+ msg1.boolField11 = YES;
+ msg2.boolField11 = YES;
+ msg1.boolField13 = YES;
+ msg2.boolField13 = YES;
+ msg1.boolField15 = YES;
+ msg2.boolField15 = YES;
+ msg1.boolField17 = YES;
+ msg2.boolField17 = YES;
+ msg1.boolField19 = YES;
+ msg2.boolField19 = YES;
+ msg1.boolField21 = YES;
+ msg2.boolField21 = YES;
+ msg1.boolField23 = YES;
+ msg2.boolField23 = YES;
+ msg1.boolField25 = YES;
+ msg2.boolField25 = YES;
+ msg1.boolField27 = YES;
+ msg2.boolField27 = YES;
+ msg1.boolField29 = YES;
+ msg2.boolField29 = YES;
+ msg1.boolField31 = YES;
+ msg2.boolField31 = YES;
+
+ msg1.boolField32 = YES;
+ msg2.boolField32 = YES;
+
+ XCTAssertTrue(msg1 != msg2); // Different pointers.
+ XCTAssertEqual([msg1 hash], [msg2 hash]);
+ XCTAssertEqualObjects(msg1, msg2);
+
+ BoolOnlyMessage *msg1Prime = [[msg1 copy] autorelease];
+ XCTAssertTrue(msg1Prime != msg1); // Different pointers.
+ XCTAssertEqual([msg1 hash], [msg1Prime hash]);
+ XCTAssertEqualObjects(msg1, msg1Prime);
+
+ // Field set in one, but not the other means they don't match (even if
+ // set to default value).
+ msg1Prime.boolField2 = NO;
+ XCTAssertNotEqualObjects(msg1Prime, msg1);
+ // And when set to different values.
+ msg1.boolField2 = YES;
+ XCTAssertNotEqualObjects(msg1Prime, msg1);
+ // And then they match again.
+ msg1.boolField2 = NO;
+ XCTAssertEqualObjects(msg1Prime, msg1);
+ XCTAssertEqual([msg1 hash], [msg1Prime hash]);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm b/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm
new file mode 100644
index 0000000000..9ba8fd0b90
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm
@@ -0,0 +1,69 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#import "GPBTestUtilities.h"
+
+
+//
+// This is just a compile test (here to make sure things never regress).
+//
+// Objective C++ can run into issues with how the NS_ENUM/CF_ENUM declartion
+// works because of the C++ spec being used for that compilation unit. So
+// the fact that these imports all work without errors/warning means things
+// are still good.
+//
+// The "well know types" should have cross file enums needing imports.
+#import "GPBProtocolBuffers.h"
+// Some of the tests explicitly use cross file enums also.
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+
+// Sanity check the conditions of the test within the Xcode project.
+#if !__cplusplus
+ #error This isn't compiled as Objective C++?
+#elif __cplusplus >= 201103L
+ // If this trips, it means the Xcode default might have change (or someone
+ // edited the testing project) and it might be time to revisit the GPB_ENUM
+ // define in GPBBootstrap.h.
+ #warning Did the Xcode default for C++ spec change?
+#endif
+
+
+// Dummy XCTest.
+@interface GPBObjectiveCPlusPlusTests : GPBTestCase
+@end
+
+@implementation GPBObjectiveCPlusPlusTests
+- (void)testCPlusPlus {
+ // Nothing, This was a compile test.
+ XCTAssertTrue(YES);
+}
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBPerfTests.m b/third_party/protobuf/objectivec/Tests/GPBPerfTests.m
new file mode 100644
index 0000000000..1259d1460f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBPerfTests.m
@@ -0,0 +1,307 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+//
+// This file really just uses the unittests framework as a testbed to
+// run some simple performance tests. The data can then be used to help
+// evaluate changes to the runtime.
+//
+
+static const uint32_t kRepeatedCount = 100;
+
+@interface PerfTests : GPBTestCase
+@end
+
+@implementation PerfTests
+
+- (void)setUp {
+ // A convenient place to put a break point if you want to connect instruments.
+ [super setUp];
+}
+
+- (void)testMessagePerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 200; ++i) {
+ TestAllTypes* message = [[TestAllTypes alloc] init];
+ [self setAllFields:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ message = [[TestAllTypes alloc] initWithData:rawBytes error:NULL];
+ [message release];
+ }
+ }];
+}
+
+- (void)testExtensionsPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 200; ++i) {
+ TestAllExtensions* message = [[TestAllExtensions alloc] init];
+ [self setAllExtensions:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ TestAllExtensions* message2 =
+ [[TestAllExtensions alloc] initWithData:rawBytes error:NULL];
+ [message2 release];
+ }
+ }];
+}
+
+- (void)testPackedTypesPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 1000; ++i) {
+ TestPackedTypes* message = [[TestPackedTypes alloc] init];
+ [self setPackedFields:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ message = [[TestPackedTypes alloc] initWithData:rawBytes error:NULL];
+ [message release];
+ }
+ }];
+}
+
+- (void)testPackedExtensionsPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 1000; ++i) {
+ TestPackedExtensions* message = [[TestPackedExtensions alloc] init];
+ [self setPackedExtensions:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ TestPackedExtensions* message2 =
+ [[TestPackedExtensions alloc] initWithData:rawBytes error:NULL];
+ [message2 release];
+ }
+ }];
+}
+
+- (void)testHas {
+ TestAllTypes* message = [self allSetRepeatedCount:1];
+ [self measureBlock:^{
+ for (int i = 0; i < 10000; ++i) {
+ [message hasOptionalInt32];
+ message.hasOptionalInt32 = NO;
+ [message hasOptionalInt32];
+
+ [message hasOptionalInt64];
+ message.hasOptionalInt64 = NO;
+ [message hasOptionalInt64];
+
+ [message hasOptionalUint32];
+ message.hasOptionalUint32 = NO;
+ [message hasOptionalUint32];
+
+ [message hasOptionalUint64];
+ message.hasOptionalUint64 = NO;
+ [message hasOptionalUint64];
+
+ [message hasOptionalSint32];
+ message.hasOptionalSint32 = NO;
+ [message hasOptionalSint32];
+
+ [message hasOptionalSint64];
+ message.hasOptionalSint64 = NO;
+ [message hasOptionalSint64];
+
+ [message hasOptionalFixed32];
+ message.hasOptionalFixed32 = NO;
+ [message hasOptionalFixed32];
+
+ [message hasOptionalFixed64];
+ message.hasOptionalFixed64 = NO;
+ [message hasOptionalFixed64];
+
+ [message hasOptionalSfixed32];
+ message.hasOptionalSfixed32 = NO;
+ [message hasOptionalSfixed32];
+
+ [message hasOptionalSfixed64];
+ message.hasOptionalSfixed64 = NO;
+ [message hasOptionalSfixed64];
+
+ [message hasOptionalFloat];
+ message.hasOptionalFloat = NO;
+ [message hasOptionalFloat];
+
+ [message hasOptionalDouble];
+ message.hasOptionalDouble = NO;
+ [message hasOptionalDouble];
+
+ [message hasOptionalBool];
+ message.hasOptionalBool = NO;
+ [message hasOptionalBool];
+
+ [message hasOptionalString];
+ message.hasOptionalString = NO;
+ [message hasOptionalString];
+
+ [message hasOptionalBytes];
+ message.hasOptionalBytes = NO;
+ [message hasOptionalBytes];
+
+ [message hasOptionalGroup];
+ message.hasOptionalGroup = NO;
+ [message hasOptionalGroup];
+
+ [message hasOptionalNestedMessage];
+ message.hasOptionalNestedMessage = NO;
+ [message hasOptionalNestedMessage];
+
+ [message hasOptionalForeignMessage];
+ message.hasOptionalForeignMessage = NO;
+ [message hasOptionalForeignMessage];
+
+ [message hasOptionalImportMessage];
+ message.hasOptionalImportMessage = NO;
+ [message hasOptionalImportMessage];
+
+ [message.optionalGroup hasA];
+ message.optionalGroup.hasA = NO;
+ [message.optionalGroup hasA];
+
+ [message.optionalNestedMessage hasBb];
+ message.optionalNestedMessage.hasBb = NO;
+ [message.optionalNestedMessage hasBb];
+
+ [message.optionalForeignMessage hasC];
+ message.optionalForeignMessage.hasC = NO;
+ [message.optionalForeignMessage hasC];
+
+ [message.optionalImportMessage hasD];
+ message.optionalImportMessage.hasD = NO;
+ [message.optionalImportMessage hasD];
+
+ [message hasOptionalNestedEnum];
+ message.hasOptionalNestedEnum = NO;
+ [message hasOptionalNestedEnum];
+
+ [message hasOptionalForeignEnum];
+ message.hasOptionalForeignEnum = NO;
+ [message hasOptionalForeignEnum];
+
+ [message hasOptionalImportEnum];
+ message.hasOptionalImportEnum = NO;
+ [message hasOptionalImportEnum];
+
+ [message hasOptionalStringPiece];
+ message.hasOptionalStringPiece = NO;
+ [message hasOptionalStringPiece];
+
+ [message hasOptionalCord];
+ message.hasOptionalCord = NO;
+ [message hasOptionalCord];
+
+ [message hasDefaultInt32];
+ message.hasDefaultInt32 = NO;
+ [message hasDefaultInt32];
+
+ [message hasDefaultInt64];
+ message.hasDefaultInt64 = NO;
+ [message hasDefaultInt64];
+
+ [message hasDefaultUint32];
+ message.hasDefaultUint32 = NO;
+ [message hasDefaultUint32];
+
+ [message hasDefaultUint64];
+ message.hasDefaultUint64 = NO;
+ [message hasDefaultUint64];
+
+ [message hasDefaultSint32];
+ message.hasDefaultSint32 = NO;
+ [message hasDefaultSint32];
+
+ [message hasDefaultSint64];
+ message.hasDefaultSint64 = NO;
+ [message hasDefaultSint64];
+
+ [message hasDefaultFixed32];
+ message.hasDefaultFixed32 = NO;
+ [message hasDefaultFixed32];
+
+ [message hasDefaultFixed64];
+ message.hasDefaultFixed64 = NO;
+ [message hasDefaultFixed64];
+
+ [message hasDefaultSfixed32];
+ message.hasDefaultSfixed32 = NO;
+ [message hasDefaultSfixed32];
+
+ [message hasDefaultSfixed64];
+ message.hasDefaultSfixed64 = NO;
+ [message hasDefaultSfixed64];
+
+ [message hasDefaultFloat];
+ message.hasDefaultFloat = NO;
+ [message hasDefaultFloat];
+
+ [message hasDefaultDouble];
+ message.hasDefaultDouble = NO;
+ [message hasDefaultDouble];
+
+ [message hasDefaultBool];
+ message.hasDefaultBool = NO;
+ [message hasDefaultBool];
+
+ [message hasDefaultString];
+ message.hasDefaultString = NO;
+ [message hasDefaultString];
+
+ [message hasDefaultBytes];
+ message.hasDefaultBytes = NO;
+ [message hasDefaultBytes];
+
+ [message hasDefaultNestedEnum];
+ message.hasDefaultNestedEnum = NO;
+ [message hasDefaultNestedEnum];
+
+ [message hasDefaultForeignEnum];
+ message.hasDefaultForeignEnum = NO;
+ [message hasDefaultForeignEnum];
+
+ [message hasDefaultImportEnum];
+ message.hasDefaultImportEnum = NO;
+ [message hasDefaultImportEnum];
+
+ [message hasDefaultStringPiece];
+ message.hasDefaultStringPiece = NO;
+ [message hasDefaultStringPiece];
+
+ [message hasDefaultCord];
+ message.hasDefaultCord = NO;
+ [message hasDefaultCord];
+ }
+ }];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift b/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift
new file mode 100644
index 0000000000..9d8a0faeb0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift
@@ -0,0 +1,460 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import Foundation
+import XCTest
+
+// Test some usage of the ObjC library from Swift.
+
+class GPBBridgeTests: XCTestCase {
+
+ func testProto2Basics() {
+ let msg = Message2()
+ let msg2 = Message2()
+ let msg3 = Message2_OptionalGroup()
+
+ msg.optionalInt32 = 100
+ msg.optionalString = "abc"
+ msg.optionalEnum = .bar
+ msg2.optionalString = "other"
+ msg.optional = msg2
+ msg3.a = 200
+ msg.optionalGroup = msg3
+ msg.repeatedInt32Array.addValue(300)
+ msg.repeatedInt32Array.addValue(301)
+ msg.repeatedStringArray.add("mno")
+ msg.repeatedStringArray.add("pqr")
+ msg.repeatedEnumArray.addValue(Message2_Enum.bar.rawValue)
+ msg.repeatedEnumArray.addValue(Message2_Enum.baz.rawValue)
+ msg.mapInt32Int32.setInt32(400, forKey:500)
+ msg.mapInt32Int32.setInt32(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+ msg.mapInt32Enum.setEnum(Message2_Enum.bar.rawValue, forKey:600)
+ msg.mapInt32Enum.setEnum(Message2_Enum.baz.rawValue, forKey:601)
+
+ // Check has*.
+ XCTAssertTrue(msg.hasOptionalInt32)
+ XCTAssertTrue(msg.hasOptionalString)
+ XCTAssertTrue(msg.hasOptionalEnum)
+ XCTAssertTrue(msg2.hasOptionalString)
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg3.hasA)
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.hasOptionalInt64)
+ XCTAssertFalse(msg.hasOptionalFloat)
+
+ // Check values.
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalString, "abc")
+ XCTAssertEqual(msg2.optionalString, "other")
+ XCTAssertTrue(msg.optional === msg2)
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum.bar)
+ XCTAssertEqual(msg3.a, Int32(200))
+ XCTAssertTrue(msg.optionalGroup === msg3)
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(2))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 0), Int32(300))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 1), Int32(301))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 0) as? String, "mno")
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 1) as? String, "pqr")
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(2))
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 0), Message2_Enum.bar.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 1), Message2_Enum.baz.rawValue)
+ XCTAssertEqual(msg.repeatedInt64Array.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey: 500))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey: 501))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.object(forKey: "bar") as? String, "foo")
+ XCTAssertEqual(msg.mapStringString.object(forKey: "xyz") as? String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:600))
+ XCTAssertEqual(intValue, Message2_Enum.bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:601))
+ XCTAssertEqual(intValue, Message2_Enum.baz.rawValue)
+
+ // Clearing a string with nil.
+ msg2.optionalString = nil
+ XCTAssertFalse(msg2.hasOptionalString)
+ XCTAssertEqual(msg2.optionalString, "")
+
+ // Clearing a message with nil.
+ msg.optionalGroup = nil
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optionalGroup !== msg3) // New instance
+
+ // Clear.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalInt32)
+ XCTAssertFalse(msg.hasOptionalString)
+ XCTAssertFalse(msg.hasOptionalEnum)
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalInt64)
+ XCTAssertFalse(msg.hasOptionalFloat)
+ XCTAssertEqual(msg.optionalInt32, Int32(0))
+ XCTAssertEqual(msg.optionalString, "")
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum.foo) // Default
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
+ }
+
+ func testProto3Basics() {
+ let msg = Message3()
+ let msg2 = Message3()
+
+ msg.optionalInt32 = 100
+ msg.optionalString = "abc"
+ msg.optionalEnum = .bar
+ msg2.optionalString = "other"
+ msg.optional = msg2
+ msg.repeatedInt32Array.addValue(300)
+ msg.repeatedInt32Array.addValue(301)
+ msg.repeatedStringArray.add("mno")
+ msg.repeatedStringArray.add("pqr")
+ // "proto3" syntax lets enum get unknown values.
+ msg.repeatedEnumArray.addValue(Message3_Enum.bar.rawValue)
+ msg.repeatedEnumArray.addRawValue(666)
+ SetMessage3_OptionalEnum_RawValue(msg2, 666)
+ msg.mapInt32Int32.setInt32(400, forKey:500)
+ msg.mapInt32Int32.setInt32(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+ msg.mapInt32Enum.setEnum(Message2_Enum.bar.rawValue, forKey:600)
+ // "proto3" syntax lets enum get unknown values.
+ msg.mapInt32Enum.setRawValue(666, forKey:601)
+
+ // Has only exists on for message fields.
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertFalse(msg2.hasOptionalMessage)
+
+ // Check values.
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalString, "abc")
+ XCTAssertEqual(msg2.optionalString, "other")
+ XCTAssertTrue(msg.optional === msg2)
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum.bar)
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(2))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 0), Int32(300))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 1), Int32(301))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 0) as? String, "mno")
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 1) as? String, "pqr")
+ XCTAssertEqual(msg.repeatedInt64Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(2))
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 0), Message3_Enum.bar.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 1), Message3_Enum.gpbUnrecognizedEnumeratorValue.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.rawValue(at: 1), 666)
+ XCTAssertEqual(msg2.optionalEnum, Message3_Enum.gpbUnrecognizedEnumeratorValue)
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Int32(666))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey:500))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey:501))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.object(forKey: "bar") as? String, "foo")
+ XCTAssertEqual(msg.mapStringString.object(forKey: "xyz") as? String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:600))
+ XCTAssertEqual(intValue, Message2_Enum.bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:601))
+ XCTAssertEqual(intValue, Message3_Enum.gpbUnrecognizedEnumeratorValue.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getRawValue(&intValue, forKey:601))
+ XCTAssertEqual(intValue, 666)
+
+ // Clearing a string with nil.
+ msg2.optionalString = nil
+ XCTAssertEqual(msg2.optionalString, "")
+
+ // Clearing a message with nil.
+ msg.optional = nil
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+
+ // Clear.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertEqual(msg.optionalInt32, Int32(0))
+ XCTAssertEqual(msg.optionalString, "")
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum.foo) // Default
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(0))
+ msg2.clear()
+ XCTAssertEqual(msg2.optionalEnum, Message3_Enum.foo) // Default
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Message3_Enum.foo.rawValue)
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
+ }
+
+ func testAutoCreation() {
+ let msg = Message2()
+
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.hasOptionalMessage)
+
+ // Access shouldn't result in has* but should return objects.
+ let msg2 = msg.optionalGroup
+ let msg3 = msg.optional.optional
+ let msg4 = msg.optional
+ XCTAssertNotNil(msg2)
+ XCTAssertNotNil(msg3)
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.optional.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalMessage)
+
+ // Setting things should trigger has* getting set.
+ msg.optionalGroup.a = 10
+ msg.optional.optional.optionalInt32 = 100
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optional.hasOptionalMessage)
+ XCTAssertTrue(msg.hasOptionalMessage)
+
+ // And they should be the same pointer as before.
+ XCTAssertTrue(msg2 === msg.optionalGroup)
+ XCTAssertTrue(msg3 === msg.optional.optional)
+ XCTAssertTrue(msg4 === msg.optional)
+
+ // Clear gets us new objects next time around.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.optional.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalMessage)
+ msg.optionalGroup.a = 20
+ msg.optional.optional.optionalInt32 = 200
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optional.hasOptionalMessage)
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg2 !== msg.optionalGroup)
+ XCTAssertTrue(msg3 !== msg.optional.optional)
+ XCTAssertTrue(msg4 !== msg.optional)
+
+ // Explicit set of a message, means autocreated object doesn't bind.
+ msg.clear()
+ let autoCreated = msg.optional
+ XCTAssertFalse(msg.hasOptionalMessage)
+ let msg5 = Message2()
+ msg5.optionalInt32 = 123
+ msg.optional = msg5
+ XCTAssertTrue(msg.hasOptionalMessage)
+ // Modifing the autocreated doesn't replaced the explicit set one.
+ autoCreated?.optionalInt32 = 456
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg.optional === msg5)
+ XCTAssertEqual(msg.optional.optionalInt32, Int32(123))
+ }
+
+ func testProto2OneOfSupport() {
+ let msg = Message2()
+
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ let autoCreated = msg.oneof // Default create one.
+ XCTAssertNotNil(autoCreated)
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofInt32)
+
+ msg.oneofFloat = 20.0
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(20.0))
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofFloat)
+
+ msg.oneofEnum = .bar
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.bar)
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofEnum)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 200
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(200))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofMessage)
+
+ // Clear the oneof.
+ Message2_ClearOOneOfCase(msg)
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ let autoCreated2 = msg.oneof // Default create one
+ XCTAssertNotNil(autoCreated2)
+ XCTAssertTrue(autoCreated2 !== autoCreated) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofInt32)
+
+ // Confirm Message.clear() handles the oneof correctly.
+ msg.clear()
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 300
+ XCTAssertTrue(msg.oneof !== autoCreated) // New instance
+ XCTAssertTrue(msg.oneof !== autoCreated2) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(300))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofMessage)
+
+ // Set message to nil clears the oneof.
+ msg.oneof = nil
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+}
+
+ func testProto3OneOfSupport() {
+ let msg = Message3()
+
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ let autoCreated = msg.oneof // Default create one.
+ XCTAssertNotNil(autoCreated)
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofInt32)
+
+ msg.oneofFloat = 20.0
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(20.0))
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofFloat)
+
+ msg.oneofEnum = .bar
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.bar)
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofEnum)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 200
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(200))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofMessage)
+
+ // Clear the oneof.
+ Message3_ClearOOneOfCase(msg)
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ let autoCreated2 = msg.oneof // Default create one
+ XCTAssertNotNil(autoCreated2)
+ XCTAssertTrue(autoCreated2 !== autoCreated) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofInt32)
+
+ // Confirm Message.clear() handles the oneof correctly.
+ msg.clear()
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 300
+ XCTAssertTrue(msg.oneof !== autoCreated) // New instance
+ XCTAssertTrue(msg.oneof !== autoCreated2) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(300))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofMessage)
+
+ // Set message to nil clears the oneof.
+ msg.oneof = nil
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+ }
+
+ func testSerialization() {
+ let msg = Message2()
+
+ msg.optionalInt32 = 100
+ msg.optionalInt64 = 101
+ msg.optionalGroup.a = 102
+ msg.repeatedStringArray.add("abc")
+ msg.repeatedStringArray.add("def")
+ msg.mapInt32Int32.setInt32(200, forKey:300)
+ msg.mapInt32Int32.setInt32(201, forKey:201)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+
+ let data = msg.data()
+
+ let msg2 = try! Message2(data: data!)
+ XCTAssertTrue(msg2 !== msg) // New instance
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalInt64, Int64(101))
+ XCTAssertEqual(msg.optionalGroup.a, Int32(102))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg2, msg)
+ }
+
+}
diff --git a/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h
new file mode 100644
index 0000000000..44c808449d
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h
@@ -0,0 +1,100 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <XCTest/XCTest.h>
+
+@class TestAllExtensions;
+@class TestAllTypes;
+@class TestMap;
+@class TestPackedTypes;
+@class TestPackedExtensions;
+@class TestUnpackedTypes;
+@class TestUnpackedExtensions;
+@class GPBExtensionRegistry;
+
+
+// Helper for uses of C arrays in tests cases.
+#ifndef GPBARRAYSIZE
+#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
+#endif // GPBARRAYSIZE
+
+
+// The number of repetitions of any repeated objects inside of test messages.
+extern const uint32_t kGPBDefaultRepeatCount;
+
+@interface GPBTestCase : XCTestCase
+
+- (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count;
+- (void)clearAllFields:(TestAllTypes *)message;
+- (void)setAllExtensions:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setPackedFields:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)setUnpackedFields:(TestUnpackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)setPackedExtensions:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count;
+
+- (TestAllTypes *)allSetRepeatedCount:(uint32_t)count;
+- (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count;
+- (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count;
+- (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count;
+
+- (void)assertAllFieldsSet:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertAllExtensionsSet:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertRepeatedFieldsModified:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertExtensionsClear:(TestAllExtensions *)message;
+- (void)assertClear:(TestAllTypes *)message;
+- (void)assertPackedFieldsSet:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+
+- (void)modifyRepeatedExtensions:(TestAllExtensions *)message;
+- (void)modifyRepeatedFields:(TestAllTypes *)message;
+
+- (GPBExtensionRegistry *)extensionRegistry;
+
+- (NSData *)getDataFileNamed:(NSString *)name dataToWrite:(NSData *)dataToWrite;
+
+- (void)assertAllFieldsKVCMatch:(TestAllTypes *)message;
+- (void)setAllFieldsViaKVC:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertClearKVC:(TestAllTypes *)message;
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m
new file mode 100644
index 0000000000..ebccaac9c7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m
@@ -0,0 +1,2546 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+
+const uint32_t kGPBDefaultRepeatCount = 2;
+
+// Small category to easily turn a CString into an NSData.
+@interface NSData (GPBTestCase)
++ (NSData *)gpbtu_dataWithCString:(char *)buffer;
++ (instancetype)gpbtu_dataWithEmbeddedNulls;
+@end
+
+@implementation NSData (GPBTestCase)
++ (NSData *)gpbtu_dataWithCString:(char *)buffer {
+ return [NSData dataWithBytes:buffer length:strlen(buffer)];
+}
+
++ (instancetype)gpbtu_dataWithUint32:(uint32_t)value {
+ return [[[self alloc] initWithUint32_gpbtu:value] autorelease];
+}
+
+- (instancetype)initWithUint32_gpbtu:(uint32_t)value {
+ value = CFSwapInt32HostToLittle(value);
+ return [self initWithBytes:&value length:sizeof(value)];
+}
+
++ (instancetype)gpbtu_dataWithEmbeddedNulls {
+ char bytes[6] = "\1\0\2\3\0\5";
+ return [self dataWithBytes:bytes length:sizeof(bytes)];
+}
+@end
+
+@implementation GPBTestCase
+
+// Return data for name. Optionally (based on #if setting) write out dataToWrite
+// to replace that data. Useful for setting golden masters.
+- (NSData *)getDataFileNamed:(NSString *)name
+ dataToWrite:(NSData *)dataToWrite {
+ NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+ NSString *path = [bundle pathForResource:[name stringByDeletingPathExtension]
+ ofType:[name pathExtension]];
+ XCTAssertNotNil(path, @"Unable to find %@", name);
+ NSData *data = [NSData dataWithContentsOfFile:path];
+ XCTAssertNotNil(data, @"Unable to load from %@", path);
+#if 0
+ // Enable to write out golden master files.
+ if (!path) {
+ path = [[bundle resourcePath] stringByAppendingPathComponent:name];
+ }
+ NSError *error = nil;
+ BOOL wrote = [dataToWrite writeToFile:path options:NSDataWritingAtomic error:&error];
+ XCTAssertTrue(wrote, @"Unable to write %@ (%@)", path, error);
+ NSLog(@"Wrote data file to %@", path);
+#else
+ // Kill off the unused variable warning.
+ dataToWrite = dataToWrite;
+#endif
+ return data;
+}
+
+// -------------------------------------------------------------------
+
+- (void)modifyRepeatedExtensions:(TestAllExtensions *)message {
+ [message setExtension:[UnittestRoot repeatedInt32Extension]
+ index:1
+ value:@501];
+ [message setExtension:[UnittestRoot repeatedInt64Extension]
+ index:1
+ value:@502];
+ [message setExtension:[UnittestRoot repeatedUint32Extension]
+ index:1
+ value:@503];
+ [message setExtension:[UnittestRoot repeatedUint64Extension]
+ index:1
+ value:@504];
+ [message setExtension:[UnittestRoot repeatedSint32Extension]
+ index:1
+ value:@505];
+ [message setExtension:[UnittestRoot repeatedSint64Extension]
+ index:1
+ value:@506];
+ [message setExtension:[UnittestRoot repeatedFixed32Extension]
+ index:1
+ value:@507];
+ [message setExtension:[UnittestRoot repeatedFixed64Extension]
+ index:1
+ value:@508];
+ [message setExtension:[UnittestRoot repeatedSfixed32Extension]
+ index:1
+ value:@509];
+ [message setExtension:[UnittestRoot repeatedSfixed64Extension]
+ index:1
+ value:@510];
+ [message setExtension:[UnittestRoot repeatedFloatExtension]
+ index:1
+ value:@511.0f];
+ [message setExtension:[UnittestRoot repeatedDoubleExtension]
+ index:1
+ value:@512.0];
+ [message setExtension:[UnittestRoot repeatedBoolExtension]
+ index:1
+ value:@YES];
+ [message setExtension:[UnittestRoot repeatedStringExtension]
+ index:1
+ value:@"515"];
+ [message setExtension:[UnittestRoot repeatedBytesExtension]
+ index:1
+ value:[NSData gpbtu_dataWithUint32:516]];
+
+ RepeatedGroup_extension *repeatedGroup = [RepeatedGroup_extension message];
+ [repeatedGroup setA:517];
+ [message setExtension:[UnittestRoot repeatedGroupExtension]
+ index:1
+ value:repeatedGroup];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:518];
+ [message setExtension:[UnittestRoot repeatedNestedMessageExtension]
+ index:1
+ value:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:519];
+ [message setExtension:[UnittestRoot repeatedForeignMessageExtension]
+ index:1
+ value:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:520];
+ [message setExtension:[UnittestRoot repeatedImportMessageExtension]
+ index:1
+ value:importMessage];
+
+ [message setExtension:[UnittestRoot repeatedNestedEnumExtension]
+ index:1
+ value:@(TestAllTypes_NestedEnum_Foo)];
+ [message setExtension:[UnittestRoot repeatedForeignEnumExtension]
+ index:1
+ value:@(ForeignEnum_ForeignFoo)];
+ [message setExtension:[UnittestRoot repeatedImportEnumExtension]
+ index:1
+ value:@(ImportEnum_ImportFoo)];
+
+ [message setExtension:[UnittestRoot repeatedStringPieceExtension]
+ index:1
+ value:@"524"];
+ [message setExtension:[UnittestRoot repeatedCordExtension]
+ index:1
+ value:@"525"];
+}
+
+- (void)assertAllExtensionsSet:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalCordExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ XCTAssertEqual(101, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]);
+ XCTAssertEqual(102LL, [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]);
+ XCTAssertEqual(103U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(104ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(105, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]);
+ XCTAssertEqual(106LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]);
+ XCTAssertEqual(107U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(108ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(109, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]);
+ XCTAssertEqual(110LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(111.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(112.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"115", [message getExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], [message getExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertEqual(117, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]);
+ XCTAssertEqual(118, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]);
+ XCTAssertEqual(119, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]);
+ XCTAssertEqual(120, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBaz, [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"124", [message getExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertEqualObjects(@"125", [message getExtension:[UnittestRoot optionalCordExtension]]);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ id extension = [message getExtension:[UnittestRoot repeatedInt32Extension]];
+ XCTAssertEqual((int)(201 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedInt64Extension]];
+ XCTAssertEqual(202 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedUint32Extension]];
+ XCTAssertEqual(203 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot repeatedUint64Extension]];
+ XCTAssertEqual(204 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSint32Extension]];
+ XCTAssertEqual((int)(205 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSint64Extension]];
+ XCTAssertEqual(206 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFixed32Extension]];
+ XCTAssertEqual(207 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFixed64Extension]];
+ XCTAssertEqual(208 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSfixed32Extension]];
+ XCTAssertEqual((int)(209 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSfixed64Extension]];
+ XCTAssertEqual(210 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFloatExtension]];
+ XCTAssertEqualWithAccuracy(211 + i * 100, [extension[i] floatValue], 0.01);
+ extension = [message getExtension:[UnittestRoot repeatedDoubleExtension]];
+ XCTAssertEqualWithAccuracy(212 + i * 100, [extension[i] doubleValue], 0.01);
+ extension = [message getExtension:[UnittestRoot repeatedBoolExtension]];
+ XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]);
+
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedStringExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedBytesExtension]];
+ XCTAssertEqualObjects(data, extension[i]);
+ [data release];
+
+ extension = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual((int)(217 + i * 100), [(TestAllTypes_OptionalGroup*)extension[i] a]);
+ extension = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual((int)(218 + i * 100), [(TestAllTypes_NestedMessage*)extension[i] bb]);
+ extension = [message getExtension:[UnittestRoot repeatedForeignMessageExtension]];
+ XCTAssertEqual((int)(219 + i * 100), [extension[i] c]);
+ extension = [message getExtension:[UnittestRoot repeatedImportMessageExtension]];
+ XCTAssertEqual((int)(220 + i * 100), [extension[i] d]);
+
+ extension = [message getExtension:[UnittestRoot repeatedNestedEnumExtension]];
+ XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedForeignEnumExtension]];
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedImportEnumExtension]];
+ XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [extension[i] intValue]);
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedStringPieceExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedCordExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ XCTAssertEqual(401, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]);
+ XCTAssertEqual(402LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]);
+ XCTAssertEqual(403U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(404ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(405, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]);
+ XCTAssertEqual(406LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]);
+ XCTAssertEqual(407U, [[message getExtension:[UnittestRoot defaultFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(408ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(409, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]);
+ XCTAssertEqual(410LL,[[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(411.0f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(412.0, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"415", [message getExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], [message getExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo, [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"424", [message getExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertEqualObjects(@"425", [message getExtension:[UnittestRoot defaultCordExtension]]);
+}
+
+- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ XCTAssertEqual(201,[[message getExtension:[UnittestRoot repeatedInt32Extension]][0] intValue]);
+ XCTAssertEqual(202LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][0] longLongValue]);
+ XCTAssertEqual(203U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][0] unsignedIntValue]);
+ XCTAssertEqual(204ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][0] unsignedLongLongValue]);
+ XCTAssertEqual(205, [[message getExtension:[UnittestRoot repeatedSint32Extension]][0] intValue]);
+ XCTAssertEqual(206LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][0] longLongValue]);
+ XCTAssertEqual(207U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][0] unsignedIntValue]);
+ XCTAssertEqual(208ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][0] unsignedLongLongValue]);
+ XCTAssertEqual(209, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][0] intValue]);
+ XCTAssertEqual(210LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][0] longLongValue]);
+ XCTAssertEqualWithAccuracy(211.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][0] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(212.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][0] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot repeatedBoolExtension]][0] boolValue]);
+ XCTAssertEqualObjects(@"215", [message getExtension:[UnittestRoot repeatedStringExtension]][0]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], [message getExtension:[UnittestRoot repeatedBytesExtension]][0]);
+
+ XCTAssertEqual(217, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][0] a]);
+ XCTAssertEqual(218, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][0] bb]);
+ XCTAssertEqual(219, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][0] c]);
+ XCTAssertEqual(220, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][0] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz,
+ [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][0] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz,
+ [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][0] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBaz,
+ [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][0] intValue]);
+
+ XCTAssertEqualObjects(@"224", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][0]);
+ XCTAssertEqualObjects(@"225", [message getExtension:[UnittestRoot repeatedCordExtension]][0]);
+
+ // Actually verify the second (modified) elements now.
+ XCTAssertEqual(501, [[message getExtension:[UnittestRoot repeatedInt32Extension]][1] intValue]);
+ XCTAssertEqual(502LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][1] longLongValue]);
+ XCTAssertEqual(503U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][1] unsignedIntValue]);
+ XCTAssertEqual(504ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][1] unsignedLongLongValue]);
+ XCTAssertEqual(505, [[message getExtension:[UnittestRoot repeatedSint32Extension]][1] intValue]);
+ XCTAssertEqual(506LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][1] longLongValue]);
+ XCTAssertEqual(507U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][1] unsignedIntValue]);
+ XCTAssertEqual(508ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][1] unsignedLongLongValue]);
+ XCTAssertEqual(509, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][1] intValue]);
+ XCTAssertEqual(510LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][1] longLongValue]);
+ XCTAssertEqualWithAccuracy(511.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][1] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(512.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][1] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot repeatedBoolExtension]][1] boolValue]);
+ XCTAssertEqualObjects(@"515", [message getExtension:[UnittestRoot repeatedStringExtension]][1]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], [message getExtension:[UnittestRoot repeatedBytesExtension]][1]);
+
+ XCTAssertEqual(517, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][1] a]);
+ XCTAssertEqual(518, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][1] bb]);
+ XCTAssertEqual(519, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][1] c]);
+ XCTAssertEqual(520, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][1] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo,
+ [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][1] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo,
+ [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][1] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo,
+ [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][1] intValue]);
+
+ XCTAssertEqualObjects(@"524", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][1]);
+ XCTAssertEqualObjects(@"525", [message getExtension:[UnittestRoot repeatedCordExtension]][1]);
+}
+
+// -------------------------------------------------------------------
+
+- (void)assertAllFieldsSet:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertTrue(message.hasOptionalInt32);
+ XCTAssertTrue(message.hasOptionalInt64);
+ XCTAssertTrue(message.hasOptionalUint32);
+ XCTAssertTrue(message.hasOptionalUint64);
+ XCTAssertTrue(message.hasOptionalSint32);
+ XCTAssertTrue(message.hasOptionalSint64);
+ XCTAssertTrue(message.hasOptionalFixed32);
+ XCTAssertTrue(message.hasOptionalFixed64);
+ XCTAssertTrue(message.hasOptionalSfixed32);
+ XCTAssertTrue(message.hasOptionalSfixed64);
+ XCTAssertTrue(message.hasOptionalFloat);
+ XCTAssertTrue(message.hasOptionalDouble);
+ XCTAssertTrue(message.hasOptionalBool);
+ XCTAssertTrue(message.hasOptionalString);
+ XCTAssertTrue(message.hasOptionalBytes);
+
+ XCTAssertTrue(message.hasOptionalGroup);
+ XCTAssertTrue(message.hasOptionalNestedMessage);
+ XCTAssertTrue(message.hasOptionalForeignMessage);
+ XCTAssertTrue(message.hasOptionalImportMessage);
+
+ XCTAssertTrue(message.optionalGroup.hasA);
+ XCTAssertTrue(message.optionalNestedMessage.hasBb);
+ XCTAssertTrue(message.optionalForeignMessage.hasC);
+ XCTAssertTrue(message.optionalImportMessage.hasD);
+
+ XCTAssertTrue(message.hasOptionalNestedEnum);
+ XCTAssertTrue(message.hasOptionalForeignEnum);
+ XCTAssertTrue(message.hasOptionalImportEnum);
+
+ XCTAssertTrue(message.hasOptionalStringPiece);
+ XCTAssertTrue(message.hasOptionalCord);
+
+ XCTAssertEqual(101, message.optionalInt32);
+ XCTAssertEqual(102LL, message.optionalInt64);
+ XCTAssertEqual(103U, message.optionalUint32);
+ XCTAssertEqual(104ULL, message.optionalUint64);
+ XCTAssertEqual(105, message.optionalSint32);
+ XCTAssertEqual(106LL, message.optionalSint64);
+ XCTAssertEqual(107U, message.optionalFixed32);
+ XCTAssertEqual(108ULL, message.optionalFixed64);
+ XCTAssertEqual(109, message.optionalSfixed32);
+ XCTAssertEqual(110LL, message.optionalSfixed64);
+ XCTAssertEqualWithAccuracy(111.0f, message.optionalFloat, 0.1);
+ XCTAssertEqualWithAccuracy(112.0, message.optionalDouble, 0.1);
+ XCTAssertTrue(message.optionalBool);
+ XCTAssertEqualObjects(@"115", message.optionalString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls],
+ message.optionalBytes);
+
+ XCTAssertEqual(117, message.optionalGroup.a);
+ XCTAssertEqual(118, message.optionalNestedMessage.bb);
+ XCTAssertEqual(119, message.optionalForeignMessage.c);
+ XCTAssertEqual(120, message.optionalImportMessage.d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, message.optionalNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, message.optionalForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportBaz, message.optionalImportEnum);
+
+ XCTAssertEqualObjects(@"124", message.optionalStringPiece);
+ XCTAssertEqualObjects(@"125", message.optionalCord);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqual(count, message.repeatedInt32Array.count);
+ XCTAssertEqual(count, message.repeatedInt64Array.count);
+ XCTAssertEqual(count, message.repeatedUint32Array.count);
+ XCTAssertEqual(count, message.repeatedUint64Array.count);
+ XCTAssertEqual(count, message.repeatedSint32Array.count);
+ XCTAssertEqual(count, message.repeatedSint64Array.count);
+ XCTAssertEqual(count, message.repeatedFixed32Array.count);
+ XCTAssertEqual(count, message.repeatedFixed64Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(count, message.repeatedFloatArray.count);
+ XCTAssertEqual(count, message.repeatedDoubleArray.count);
+ XCTAssertEqual(count, message.repeatedBoolArray.count);
+ XCTAssertEqual(count, message.repeatedStringArray.count);
+ XCTAssertEqual(count, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray.count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(count, message.repeatedCordArray.count);
+
+ XCTAssertEqual(count, message.repeatedInt32Array_Count);
+ XCTAssertEqual(count, message.repeatedInt64Array_Count);
+ XCTAssertEqual(count, message.repeatedUint32Array_Count);
+ XCTAssertEqual(count, message.repeatedUint64Array_Count);
+ XCTAssertEqual(count, message.repeatedSint32Array_Count);
+ XCTAssertEqual(count, message.repeatedSint64Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedFloatArray_Count);
+ XCTAssertEqual(count, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(count, message.repeatedBoolArray_Count);
+ XCTAssertEqual(count, message.repeatedStringArray_Count);
+ XCTAssertEqual(count, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(count, message.repeatedCordArray_Count);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ XCTAssertEqual((int)(201 + i * 100),
+ [message.repeatedInt32Array valueAtIndex:i]);
+ XCTAssertEqual(202 + i * 100, [message.repeatedInt64Array valueAtIndex:i]);
+ XCTAssertEqual(203 + i * 100, [message.repeatedUint32Array valueAtIndex:i]);
+ XCTAssertEqual(204 + i * 100, [message.repeatedUint64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(205 + i * 100),
+ [message.repeatedSint32Array valueAtIndex:i]);
+ XCTAssertEqual(206 + i * 100, [message.repeatedSint64Array valueAtIndex:i]);
+ XCTAssertEqual(207 + i * 100,
+ [message.repeatedFixed32Array valueAtIndex:i]);
+ XCTAssertEqual(208 + i * 100,
+ [message.repeatedFixed64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(209 + i * 100),
+ [message.repeatedSfixed32Array valueAtIndex:i]);
+ XCTAssertEqual(210 + i * 100,
+ [message.repeatedSfixed64Array valueAtIndex:i]);
+ XCTAssertEqualWithAccuracy(
+ 211 + i * 100, [message.repeatedFloatArray valueAtIndex:i], 0.1);
+ XCTAssertEqualWithAccuracy(
+ 212 + i * 100, [message.repeatedDoubleArray valueAtIndex:i], 0.1);
+ XCTAssertEqual((i % 2) ? YES : NO,
+ [message.repeatedBoolArray valueAtIndex:i]);
+
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedStringArray[i]);
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ XCTAssertEqualObjects(data, message.repeatedBytesArray[i]);
+ [data release];
+
+ XCTAssertEqual((int)(217 + i * 100), ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[i]).a);
+ XCTAssertEqual((int)(218 + i * 100), ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[i]).bb);
+ XCTAssertEqual((int)(219 + i * 100), ((ForeignMessage*)message.repeatedForeignMessageArray[i]).c);
+ XCTAssertEqual((int)(220 + i * 100), ((ImportMessage*)message.repeatedImportMessageArray[i]).d);
+
+ XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:i]);
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedStringPieceArray[i]);
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedCordArray[i]);
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ XCTAssertTrue(message.hasDefaultInt32);
+ XCTAssertTrue(message.hasDefaultInt64);
+ XCTAssertTrue(message.hasDefaultUint32);
+ XCTAssertTrue(message.hasDefaultUint64);
+ XCTAssertTrue(message.hasDefaultSint32);
+ XCTAssertTrue(message.hasDefaultSint64);
+ XCTAssertTrue(message.hasDefaultFixed32);
+ XCTAssertTrue(message.hasDefaultFixed64);
+ XCTAssertTrue(message.hasDefaultSfixed32);
+ XCTAssertTrue(message.hasDefaultSfixed64);
+ XCTAssertTrue(message.hasDefaultFloat);
+ XCTAssertTrue(message.hasDefaultDouble);
+ XCTAssertTrue(message.hasDefaultBool);
+ XCTAssertTrue(message.hasDefaultString);
+ XCTAssertTrue(message.hasDefaultBytes);
+
+ XCTAssertTrue(message.hasDefaultNestedEnum);
+ XCTAssertTrue(message.hasDefaultForeignEnum);
+ XCTAssertTrue(message.hasDefaultImportEnum);
+
+ XCTAssertTrue(message.hasDefaultStringPiece);
+ XCTAssertTrue(message.hasDefaultCord);
+
+ XCTAssertEqual(401, message.defaultInt32);
+ XCTAssertEqual(402LL, message.defaultInt64);
+ XCTAssertEqual(403U, message.defaultUint32);
+ XCTAssertEqual(404ULL, message.defaultUint64);
+ XCTAssertEqual(405, message.defaultSint32);
+ XCTAssertEqual(406LL, message.defaultSint64);
+ XCTAssertEqual(407U, message.defaultFixed32);
+ XCTAssertEqual(408ULL, message.defaultFixed64);
+ XCTAssertEqual(409, message.defaultSfixed32);
+ XCTAssertEqual(410LL, message.defaultSfixed64);
+ XCTAssertEqualWithAccuracy(411.0f, message.defaultFloat, 0.1);
+ XCTAssertEqualWithAccuracy(412.0, message.defaultDouble, 0.1);
+ XCTAssertFalse(message.defaultBool);
+ XCTAssertEqualObjects(@"415", message.defaultString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416],
+ message.defaultBytes);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.defaultNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, message.defaultForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportFoo, message.defaultImportEnum);
+
+ XCTAssertEqualObjects(@"424", message.defaultStringPiece);
+ XCTAssertEqualObjects(@"425", message.defaultCord);
+}
+
+- (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count {
+ [message setOptionalInt32:101];
+ [message setOptionalInt64:102];
+ [message setOptionalUint32:103];
+ [message setOptionalUint64:104];
+ [message setOptionalSint32:105];
+ [message setOptionalSint64:106];
+ [message setOptionalFixed32:107];
+ [message setOptionalFixed64:108];
+ [message setOptionalSfixed32:109];
+ [message setOptionalSfixed64:110];
+ [message setOptionalFloat:111];
+ [message setOptionalDouble:112];
+ [message setOptionalBool:YES];
+ [message setOptionalString:@"115"];
+ [message setOptionalBytes:[NSData gpbtu_dataWithEmbeddedNulls]];
+
+ TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message];
+ [allTypes setA:117];
+ [message setOptionalGroup:allTypes];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:118];
+ [message setOptionalNestedMessage:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:119];
+ [message setOptionalForeignMessage:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:120];
+ [message setOptionalImportMessage:importMessage];
+
+ [message setOptionalNestedEnum:TestAllTypes_NestedEnum_Baz];
+ [message setOptionalForeignEnum:ForeignEnum_ForeignBaz];
+ [message setOptionalImportEnum:ImportEnum_ImportBaz];
+
+ [message setOptionalStringPiece:@"124"];
+ [message setOptionalCord:@"125"];
+
+ // -----------------------------------------------------------------
+
+ for (uint32_t i = 0; i < count; i++) {
+ [message.repeatedInt32Array addValue:201 + i * 100];
+ [message.repeatedInt64Array addValue:202 + i * 100];
+ [message.repeatedUint32Array addValue:203 + i * 100];
+ [message.repeatedUint64Array addValue:204 + i * 100];
+ [message.repeatedSint32Array addValue:205 + i * 100];
+ [message.repeatedSint64Array addValue:206 + i * 100];
+ [message.repeatedFixed32Array addValue:207 + i * 100];
+ [message.repeatedFixed64Array addValue:208 + i * 100];
+ [message.repeatedSfixed32Array addValue:209 + i * 100];
+ [message.repeatedSfixed64Array addValue:210 + i * 100];
+ [message.repeatedFloatArray addValue:211 + i * 100];
+ [message.repeatedDoubleArray addValue:212 + i * 100];
+ [message.repeatedBoolArray addValue:(i % 2)];
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [message.repeatedStringArray addObject:string];
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [message.repeatedBytesArray addObject:data];
+ [data release];
+
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:217 + i * 100];
+ [message.repeatedGroupArray addObject:testAll];
+ [testAll release];
+
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [message.repeatedNestedMessageArray addObject:nestedMessage];
+ [nestedMessage release];
+
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [message.repeatedForeignMessageArray addObject:foreignMessage];
+ [foreignMessage release];
+
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [message.repeatedImportMessageArray addObject:importMessage];
+ [importMessage release];
+
+ [message.repeatedNestedEnumArray addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz];
+
+ [message.repeatedForeignEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ [message.repeatedImportEnumArray addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [message.repeatedStringPieceArray addObject:string];
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [message.repeatedCordArray addObject:string];
+ [string release];
+ }
+ // -----------------------------------------------------------------
+
+ message.defaultInt32 = 401;
+ message.defaultInt64 = 402;
+ message.defaultUint32 = 403;
+ message.defaultUint64 = 404;
+ message.defaultSint32 = 405;
+ message.defaultSint64 = 406;
+ message.defaultFixed32 = 407;
+ message.defaultFixed64 = 408;
+ message.defaultSfixed32 = 409;
+ message.defaultSfixed64 = 410;
+ message.defaultFloat = 411;
+ message.defaultDouble = 412;
+ message.defaultBool = NO;
+ message.defaultString = @"415";
+ message.defaultBytes = [NSData gpbtu_dataWithUint32:416];
+
+ message.defaultNestedEnum = TestAllTypes_NestedEnum_Foo;
+ message.defaultForeignEnum = ForeignEnum_ForeignFoo;
+ message.defaultImportEnum = ImportEnum_ImportFoo;
+
+ message.defaultStringPiece = @"424";
+ message.defaultCord = @"425";
+}
+
+- (void)clearAllFields:(TestAllTypes *)message {
+ message.hasOptionalInt32 = NO;
+ message.hasOptionalInt64 = NO;
+ message.hasOptionalUint32 = NO;
+ message.hasOptionalUint64 = NO;
+ message.hasOptionalSint32 = NO;
+ message.hasOptionalSint64 = NO;
+ message.hasOptionalFixed32 = NO;
+ message.hasOptionalFixed64 = NO;
+ message.hasOptionalSfixed32 = NO;
+ message.hasOptionalSfixed64 = NO;
+ message.hasOptionalFloat = NO;
+ message.hasOptionalDouble = NO;
+ message.hasOptionalBool = NO;
+ message.hasOptionalString = NO;
+ message.hasOptionalBytes = NO;
+
+ message.hasOptionalGroup = NO;
+ message.hasOptionalNestedMessage = NO;
+ message.hasOptionalForeignMessage = NO;
+ message.hasOptionalImportMessage = NO;
+
+ message.hasOptionalNestedEnum = NO;
+ message.hasOptionalForeignEnum = NO;
+ message.hasOptionalImportEnum = NO;
+
+ message.hasOptionalStringPiece = NO;
+ message.hasOptionalCord = NO;
+
+ // -----------------------------------------------------------------
+
+ [message.repeatedInt32Array removeAll];
+ [message.repeatedInt64Array removeAll];
+ [message.repeatedUint32Array removeAll];
+ [message.repeatedUint64Array removeAll];
+ [message.repeatedSint32Array removeAll];
+ [message.repeatedSint64Array removeAll];
+ [message.repeatedFixed32Array removeAll];
+ [message.repeatedFixed64Array removeAll];
+ [message.repeatedSfixed32Array removeAll];
+ [message.repeatedSfixed64Array removeAll];
+ [message.repeatedFloatArray removeAll];
+ [message.repeatedDoubleArray removeAll];
+ [message.repeatedBoolArray removeAll];
+ [message.repeatedStringArray removeAllObjects];
+ [message.repeatedBytesArray removeAllObjects];
+
+ [message.repeatedGroupArray removeAllObjects];
+ [message.repeatedNestedMessageArray removeAllObjects];
+ [message.repeatedForeignMessageArray removeAllObjects];
+ [message.repeatedImportMessageArray removeAllObjects];
+
+ [message.repeatedNestedEnumArray removeAll];
+ [message.repeatedForeignEnumArray removeAll];
+ [message.repeatedImportEnumArray removeAll];
+
+ [message.repeatedStringPieceArray removeAllObjects];
+ [message.repeatedCordArray removeAllObjects];
+
+ // -----------------------------------------------------------------
+
+ message.hasDefaultInt32 = NO;
+ message.hasDefaultInt64 = NO;
+ message.hasDefaultUint32 = NO;
+ message.hasDefaultUint64 = NO;
+ message.hasDefaultSint32 = NO;
+ message.hasDefaultSint64 = NO;
+ message.hasDefaultFixed32 = NO;
+ message.hasDefaultFixed64 = NO;
+ message.hasDefaultSfixed32 = NO;
+ message.hasDefaultSfixed64 = NO;
+ message.hasDefaultFloat = NO;
+ message.hasDefaultDouble = NO;
+ message.hasDefaultBool = NO;
+ message.hasDefaultString = NO;
+ message.hasDefaultBytes = NO;
+
+ message.hasDefaultNestedEnum = NO;
+ message.hasDefaultForeignEnum = NO;
+ message.hasDefaultImportEnum = NO;
+
+ message.hasDefaultStringPiece = NO;
+ message.hasDefaultCord = NO;
+}
+
+- (void)setAllExtensions:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@101];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@102L];
+ [message setExtension:[UnittestRoot optionalUint32Extension] value:@103];
+ [message setExtension:[UnittestRoot optionalUint64Extension] value:@104L];
+ [message setExtension:[UnittestRoot optionalSint32Extension] value:@105];
+ [message setExtension:[UnittestRoot optionalSint64Extension] value:@106L];
+ [message setExtension:[UnittestRoot optionalFixed32Extension] value:@107];
+ [message setExtension:[UnittestRoot optionalFixed64Extension] value:@108L];
+ [message setExtension:[UnittestRoot optionalSfixed32Extension] value:@109];
+ [message setExtension:[UnittestRoot optionalSfixed64Extension] value:@110L];
+ [message setExtension:[UnittestRoot optionalFloatExtension] value:@111.0f];
+ [message setExtension:[UnittestRoot optionalDoubleExtension] value:@112.0];
+ [message setExtension:[UnittestRoot optionalBoolExtension] value:@YES];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"115"];
+ [message setExtension:[UnittestRoot optionalBytesExtension]
+ value:[NSData gpbtu_dataWithEmbeddedNulls]];
+
+ OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message];
+ [optionalGroup setA:117];
+ [message setExtension:[UnittestRoot optionalGroupExtension]
+ value:optionalGroup];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:118];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:119];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:120];
+ [message setExtension:[UnittestRoot optionalImportMessageExtension]
+ value:importMessage];
+
+ [message setExtension:[UnittestRoot optionalNestedEnumExtension]
+ value:@(TestAllTypes_NestedEnum_Baz)];
+ [message setExtension:[UnittestRoot optionalForeignEnumExtension]
+ value:@(ForeignEnum_ForeignBaz)];
+ [message setExtension:[UnittestRoot optionalImportEnumExtension]
+ value:@(ImportEnum_ImportBaz)];
+
+ [message setExtension:[UnittestRoot optionalStringPieceExtension]
+ value:@"124"];
+ [message setExtension:[UnittestRoot optionalCordExtension] value:@"125"];
+
+ for (uint32_t i = 0; i < count; ++i) {
+ [message addExtension:[UnittestRoot repeatedInt32Extension]
+ value:@(201 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedInt64Extension]
+ value:@(202 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedUint32Extension]
+ value:@(203 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedUint64Extension]
+ value:@(204 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSint32Extension]
+ value:@(205 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSint64Extension]
+ value:@(206 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFixed32Extension]
+ value:@(207 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFixed64Extension]
+ value:@(208 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSfixed32Extension]
+ value:@(209 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSfixed64Extension]
+ value:@(210 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFloatExtension]
+ value:@(211 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedDoubleExtension]
+ value:@(212 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [message addExtension:[UnittestRoot repeatedStringExtension] value:string];
+ [string release];
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [message addExtension:[UnittestRoot repeatedBytesExtension] value:data];
+ [data release];
+
+ RepeatedGroup_extension *repeatedGroup =
+ [[RepeatedGroup_extension alloc] init];
+ [repeatedGroup setA:217 + i * 100];
+ [message addExtension:[UnittestRoot repeatedGroupExtension]
+ value:repeatedGroup];
+ [repeatedGroup release];
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [message addExtension:[UnittestRoot repeatedNestedMessageExtension]
+ value:nestedMessage];
+ [nestedMessage release];
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [message addExtension:[UnittestRoot repeatedForeignMessageExtension]
+ value:foreignMessage];
+ [foreignMessage release];
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [message addExtension:[UnittestRoot repeatedImportMessageExtension]
+ value:importMessage];
+ [importMessage release];
+ [message addExtension:[UnittestRoot repeatedNestedEnumExtension]
+ value:@((i % 2) ? TestAllTypes_NestedEnum_Bar
+ : TestAllTypes_NestedEnum_Baz)];
+ [message addExtension:[UnittestRoot repeatedForeignEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ [message
+ addExtension:[UnittestRoot repeatedImportEnumExtension]
+ value:@((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz)];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [message addExtension:[UnittestRoot repeatedStringPieceExtension]
+ value:string];
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [message addExtension:[UnittestRoot repeatedCordExtension] value:string];
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ [message setExtension:[UnittestRoot defaultInt32Extension] value:@401];
+ [message setExtension:[UnittestRoot defaultInt64Extension] value:@402L];
+ [message setExtension:[UnittestRoot defaultUint32Extension] value:@403];
+ [message setExtension:[UnittestRoot defaultUint64Extension] value:@404L];
+ [message setExtension:[UnittestRoot defaultSint32Extension] value:@405];
+ [message setExtension:[UnittestRoot defaultSint64Extension] value:@406L];
+ [message setExtension:[UnittestRoot defaultFixed32Extension] value:@407];
+ [message setExtension:[UnittestRoot defaultFixed64Extension] value:@408L];
+ [message setExtension:[UnittestRoot defaultSfixed32Extension] value:@409];
+ [message setExtension:[UnittestRoot defaultSfixed64Extension] value:@410L];
+ [message setExtension:[UnittestRoot defaultFloatExtension] value:@411.0f];
+ [message setExtension:[UnittestRoot defaultDoubleExtension] value:@412.0];
+ [message setExtension:[UnittestRoot defaultBoolExtension] value:@NO];
+ [message setExtension:[UnittestRoot defaultStringExtension] value:@"415"];
+ [message setExtension:[UnittestRoot defaultBytesExtension]
+ value:[NSData gpbtu_dataWithUint32:416]];
+
+ [message setExtension:[UnittestRoot defaultNestedEnumExtension]
+ value:@(TestAllTypes_NestedEnum_Foo)];
+ [message setExtension:[UnittestRoot defaultForeignEnumExtension]
+ value:@(ForeignEnum_ForeignFoo)];
+ [message setExtension:[UnittestRoot defaultImportEnumExtension]
+ value:@(ImportEnum_ImportFoo)];
+
+ [message setExtension:[UnittestRoot defaultStringPieceExtension]
+ value:@"424"];
+ [message setExtension:[UnittestRoot defaultCordExtension] value:@"425"];
+}
+
+- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count {
+ for (uint32_t i = 0; i < count; i++) {
+ [message.mapInt32Int32 setInt32:(i + 1) forKey:100 + i * 100];
+ [message.mapInt64Int64 setInt64:(i + 1) forKey:101 + i * 100];
+ [message.mapUint32Uint32 setUInt32:(i + 1) forKey:102 + i * 100];
+ [message.mapUint64Uint64 setUInt64:(i + 1) forKey:103 + i * 100];
+ [message.mapSint32Sint32 setInt32:(i + 1) forKey:104 + i * 100];
+ [message.mapSint64Sint64 setInt64:(i + 1) forKey:105 + i * 100];
+ [message.mapFixed32Fixed32 setUInt32:(i + 1) forKey:106 + i * 100];
+ [message.mapFixed64Fixed64 setUInt64:(i + 1) forKey:107 + i * 100];
+ [message.mapSfixed32Sfixed32 setInt32:(i + 1) forKey:108 + i * 100];
+ [message.mapSfixed64Sfixed64 setInt64:(i + 1) forKey:109 + i * 100];
+ [message.mapInt32Float setFloat:(i + 1) forKey:110 + i * 100];
+ [message.mapInt32Double setDouble:(i + 1) forKey:111 + i * 100];
+ [message.mapBoolBool setBool:((i % 2) == 1) forKey:((i % 2) == 0)];
+
+ NSString *keyStr = [[NSString alloc] initWithFormat:@"%d", 112 + i * 100];
+ NSString *dataStr = [[NSString alloc] initWithFormat:@"%d", i + 1];
+ [message.mapStringString setObject:dataStr forKey:keyStr];
+ [keyStr release];
+ [dataStr release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:i + 1];
+ [message.mapInt32Bytes setObject:data forKey:113 + i * 100];
+ [data release];
+
+ [message.mapInt32Enum
+ setEnum:(i % 2) ? MapEnum_MapEnumBar : MapEnum_MapEnumBaz
+ forKey:114 + i * 100];
+
+ ForeignMessage *subMsg = [[ForeignMessage alloc] init];
+ subMsg.c = i + 1;
+ [message.mapInt32ForeignMessage setObject:subMsg forKey:115 + i * 100];
+ [subMsg release];
+ }
+}
+
+- (void)setAllTestPackedFields:(TestPackedTypes *)message {
+ // Must match -setAllTestUnpackedFields:
+ [message.packedInt32Array addValue:101];
+ [message.packedInt64Array addValue:102];
+ [message.packedUint32Array addValue:103];
+ [message.packedUint64Array addValue:104];
+ [message.packedSint32Array addValue:105];
+ [message.packedSint64Array addValue:106];
+ [message.packedFixed32Array addValue:107];
+ [message.packedFixed64Array addValue:108];
+ [message.packedSfixed32Array addValue:109];
+ [message.packedSfixed64Array addValue:110];
+ [message.packedFloatArray addValue:111.f];
+ [message.packedDoubleArray addValue:112.];
+ [message.packedBoolArray addValue:YES];
+ [message.packedEnumArray addValue:ForeignEnum_ForeignBar];
+
+ [message.packedInt32Array addValue:201];
+ [message.packedInt64Array addValue:302];
+ [message.packedUint32Array addValue:203];
+ [message.packedUint64Array addValue:204];
+ [message.packedSint32Array addValue:205];
+ [message.packedSint64Array addValue:206];
+ [message.packedFixed32Array addValue:207];
+ [message.packedFixed64Array addValue:208];
+ [message.packedSfixed32Array addValue:209];
+ [message.packedSfixed64Array addValue:210];
+ [message.packedFloatArray addValue:211.f];
+ [message.packedDoubleArray addValue:212.];
+ [message.packedBoolArray addValue:NO];
+ [message.packedEnumArray addValue:ForeignEnum_ForeignBaz];
+}
+
+- (void)setAllTestUnpackedFields:(TestUnpackedTypes *)message {
+ // Must match -setAllTestPackedFields:
+ [message.unpackedInt32Array addValue:101];
+ [message.unpackedInt64Array addValue:102];
+ [message.unpackedUint32Array addValue:103];
+ [message.unpackedUint64Array addValue:104];
+ [message.unpackedSint32Array addValue:105];
+ [message.unpackedSint64Array addValue:106];
+ [message.unpackedFixed32Array addValue:107];
+ [message.unpackedFixed64Array addValue:108];
+ [message.unpackedSfixed32Array addValue:109];
+ [message.unpackedSfixed64Array addValue:110];
+ [message.unpackedFloatArray addValue:111.f];
+ [message.unpackedDoubleArray addValue:112.];
+ [message.unpackedBoolArray addValue:YES];
+ [message.unpackedEnumArray addValue:ForeignEnum_ForeignBar];
+
+ [message.unpackedInt32Array addValue:201];
+ [message.unpackedInt64Array addValue:302];
+ [message.unpackedUint32Array addValue:203];
+ [message.unpackedUint64Array addValue:204];
+ [message.unpackedSint32Array addValue:205];
+ [message.unpackedSint64Array addValue:206];
+ [message.unpackedFixed32Array addValue:207];
+ [message.unpackedFixed64Array addValue:208];
+ [message.unpackedSfixed32Array addValue:209];
+ [message.unpackedSfixed64Array addValue:210];
+ [message.unpackedFloatArray addValue:211.f];
+ [message.unpackedDoubleArray addValue:212.];
+ [message.unpackedBoolArray addValue:NO];
+ [message.unpackedEnumArray addValue:ForeignEnum_ForeignBaz];
+}
+
+- (GPBExtensionRegistry *)extensionRegistry {
+ return [UnittestRoot extensionRegistry];
+}
+
+- (TestAllTypes *)allSetRepeatedCount:(uint32_t)count {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:count];
+ return message;
+}
+
+- (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:count];
+ return message;
+}
+
+- (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count {
+ TestPackedTypes *message = [TestPackedTypes message];
+ [self setPackedFields:message repeatedCount:count];
+ return message;
+}
+
+- (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count {
+ TestPackedExtensions *message = [TestPackedExtensions message];
+ [self setPackedExtensions:message repeatedCount:count];
+ return message;
+}
+
+// -------------------------------------------------------------------
+
+- (void)assertClear:(TestAllTypes *)message {
+ // hasBlah() should initially be NO for all optional fields.
+ XCTAssertFalse(message.hasOptionalInt32);
+ XCTAssertFalse(message.hasOptionalInt64);
+ XCTAssertFalse(message.hasOptionalUint32);
+ XCTAssertFalse(message.hasOptionalUint64);
+ XCTAssertFalse(message.hasOptionalSint32);
+ XCTAssertFalse(message.hasOptionalSint64);
+ XCTAssertFalse(message.hasOptionalFixed32);
+ XCTAssertFalse(message.hasOptionalFixed64);
+ XCTAssertFalse(message.hasOptionalSfixed32);
+ XCTAssertFalse(message.hasOptionalSfixed64);
+ XCTAssertFalse(message.hasOptionalFloat);
+ XCTAssertFalse(message.hasOptionalDouble);
+ XCTAssertFalse(message.hasOptionalBool);
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertFalse(message.hasOptionalBytes);
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+
+ XCTAssertFalse(message.hasOptionalNestedEnum);
+ XCTAssertFalse(message.hasOptionalForeignEnum);
+ XCTAssertFalse(message.hasOptionalImportEnum);
+
+ XCTAssertFalse(message.hasOptionalStringPiece);
+ XCTAssertFalse(message.hasOptionalCord);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqual(0, message.optionalInt32);
+ XCTAssertEqual(0LL, message.optionalInt64);
+ XCTAssertEqual(0U, message.optionalUint32);
+ XCTAssertEqual(0ULL, message.optionalUint64);
+ XCTAssertEqual(0, message.optionalSint32);
+ XCTAssertEqual(0LL, message.optionalSint64);
+ XCTAssertEqual(0U, message.optionalFixed32);
+ XCTAssertEqual(0ULL, message.optionalFixed64);
+ XCTAssertEqual(0, message.optionalSfixed32);
+ XCTAssertEqual(0LL, message.optionalSfixed64);
+ XCTAssertEqual(0.0f, message.optionalFloat);
+ XCTAssertEqual(0.0, message.optionalDouble);
+ XCTAssertFalse(message.optionalBool);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+
+ // Embedded messages should also be clear.
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.optionalNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, message.optionalForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportFoo, message.optionalImportEnum);
+
+ XCTAssertEqualObjects(message.optionalStringPiece, @"");
+ XCTAssertEqualObjects(message.optionalCord, @"");
+
+ // Repeated fields are empty.
+
+ XCTAssertEqual(0U, message.repeatedInt32Array.count);
+ XCTAssertEqual(0U, message.repeatedInt64Array.count);
+ XCTAssertEqual(0U, message.repeatedUint32Array.count);
+ XCTAssertEqual(0U, message.repeatedUint64Array.count);
+ XCTAssertEqual(0U, message.repeatedSint32Array.count);
+ XCTAssertEqual(0U, message.repeatedSint64Array.count);
+ XCTAssertEqual(0U, message.repeatedFixed32Array.count);
+ XCTAssertEqual(0U, message.repeatedFixed64Array.count);
+ XCTAssertEqual(0U, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(0U, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(0U, message.repeatedFloatArray.count);
+ XCTAssertEqual(0U, message.repeatedDoubleArray.count);
+ XCTAssertEqual(0U, message.repeatedBoolArray.count);
+ XCTAssertEqual(0U, message.repeatedStringArray.count);
+ XCTAssertEqual(0U, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(0U, message.repeatedGroupArray.count);
+ XCTAssertEqual(0U, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(0U, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(0U, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(0U, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(0U, message.repeatedCordArray.count);
+
+ XCTAssertEqual(0U, message.repeatedInt32Array_Count);
+ XCTAssertEqual(0U, message.repeatedInt64Array_Count);
+ XCTAssertEqual(0U, message.repeatedUint32Array_Count);
+ XCTAssertEqual(0U, message.repeatedUint64Array_Count);
+ XCTAssertEqual(0U, message.repeatedSint32Array_Count);
+ XCTAssertEqual(0U, message.repeatedSint64Array_Count);
+ XCTAssertEqual(0U, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(0U, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(0U, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(0U, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(0U, message.repeatedFloatArray_Count);
+ XCTAssertEqual(0U, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(0U, message.repeatedBoolArray_Count);
+ XCTAssertEqual(0U, message.repeatedStringArray_Count);
+ XCTAssertEqual(0U, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(0U, message.repeatedGroupArray_Count);
+ XCTAssertEqual(0U, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(0U, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(0U, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(0U, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(0U, message.repeatedCordArray_Count);
+
+ // hasBlah() should also be NO for all default fields.
+ XCTAssertFalse(message.hasDefaultInt32);
+ XCTAssertFalse(message.hasDefaultInt64);
+ XCTAssertFalse(message.hasDefaultUint32);
+ XCTAssertFalse(message.hasDefaultUint64);
+ XCTAssertFalse(message.hasDefaultSint32);
+ XCTAssertFalse(message.hasDefaultSint64);
+ XCTAssertFalse(message.hasDefaultFixed32);
+ XCTAssertFalse(message.hasDefaultFixed64);
+ XCTAssertFalse(message.hasDefaultSfixed32);
+ XCTAssertFalse(message.hasDefaultSfixed64);
+ XCTAssertFalse(message.hasDefaultFloat);
+ XCTAssertFalse(message.hasDefaultDouble);
+ XCTAssertFalse(message.hasDefaultBool);
+ XCTAssertFalse(message.hasDefaultString);
+ XCTAssertFalse(message.hasDefaultBytes);
+
+ XCTAssertFalse(message.hasDefaultNestedEnum);
+ XCTAssertFalse(message.hasDefaultForeignEnum);
+ XCTAssertFalse(message.hasDefaultImportEnum);
+
+ XCTAssertFalse(message.hasDefaultStringPiece);
+ XCTAssertFalse(message.hasDefaultCord);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqual(41, message.defaultInt32);
+ XCTAssertEqual(42LL, message.defaultInt64);
+ XCTAssertEqual(43U, message.defaultUint32);
+ XCTAssertEqual(44ULL, message.defaultUint64);
+ XCTAssertEqual(-45, message.defaultSint32);
+ XCTAssertEqual(46LL, message.defaultSint64);
+ XCTAssertEqual(47U, message.defaultFixed32);
+ XCTAssertEqual(48ULL, message.defaultFixed64);
+ XCTAssertEqual(49, message.defaultSfixed32);
+ XCTAssertEqual(-50LL, message.defaultSfixed64);
+ XCTAssertEqualWithAccuracy(51.5f, message.defaultFloat, 0.1);
+ XCTAssertEqualWithAccuracy(52e3, message.defaultDouble, 0.1);
+ XCTAssertTrue(message.defaultBool);
+ XCTAssertEqualObjects(@"hello", message.defaultString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"],
+ message.defaultBytes);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Bar, message.defaultNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignBar, message.defaultForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportBar, message.defaultImportEnum);
+
+ XCTAssertEqualObjects(@"abc", message.defaultStringPiece);
+ XCTAssertEqualObjects(@"123", message.defaultCord);
+}
+
+- (void)assertExtensionsClear:(TestAllExtensions *)message {
+ // hasBlah() should initially be NO for all optional fields.
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFloatExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalDoubleExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalBoolExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportEnumExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalCordExtension]]);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]);
+ XCTAssertEqual(0LL,[[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]);
+ XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]);
+ XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(0.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(0.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertEqualObjects(GPBEmptyNSData(), [message getExtension:[UnittestRoot optionalBytesExtension]]);
+
+ // Embedded messages should also be clear.
+
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]);
+
+ XCTAssertEqual(0, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]);
+ XCTAssertEqual(0, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo,
+ [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo,
+ [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo,
+ [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalCordExtension]]);
+
+ // Repeated fields are empty.
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ // hasBlah() should also be NO for all default fields.
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqual( 41, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]);
+ XCTAssertEqual( 42LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]);
+ XCTAssertEqual( 43U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual( 44ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(-45, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]);
+ XCTAssertEqual( 46LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]);
+ XCTAssertEqual( 47, [[message getExtension:[UnittestRoot defaultFixed32Extension]] intValue]);
+ XCTAssertEqual( 48ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual( 49, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]);
+ XCTAssertEqual(-50LL, [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy( 51.5f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy( 52e3, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"hello", [message getExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], [message getExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Bar,
+ [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBar,
+ [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBar,
+ [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"abc", [message getExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertEqualObjects(@"123", [message getExtension:[UnittestRoot defaultCordExtension]]);
+}
+
+- (void)modifyRepeatedFields:(TestAllTypes *)message {
+ [message.repeatedInt32Array replaceValueAtIndex:1 withValue:501];
+ [message.repeatedInt64Array replaceValueAtIndex:1 withValue:502];
+ [message.repeatedUint32Array replaceValueAtIndex:1 withValue:503];
+ [message.repeatedUint64Array replaceValueAtIndex:1 withValue:504];
+ [message.repeatedSint32Array replaceValueAtIndex:1 withValue:505];
+ [message.repeatedSint64Array replaceValueAtIndex:1 withValue:506];
+ [message.repeatedFixed32Array replaceValueAtIndex:1 withValue:507];
+ [message.repeatedFixed64Array replaceValueAtIndex:1 withValue:508];
+ [message.repeatedSfixed32Array replaceValueAtIndex:1 withValue:509];
+ [message.repeatedSfixed64Array replaceValueAtIndex:1 withValue:510];
+ [message.repeatedFloatArray replaceValueAtIndex:1 withValue:511];
+ [message.repeatedDoubleArray replaceValueAtIndex:1 withValue:512];
+ [message.repeatedBoolArray replaceValueAtIndex:1 withValue:YES];
+ [message.repeatedStringArray replaceObjectAtIndex:1 withObject:@"515"];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:516];
+ [message.repeatedBytesArray replaceObjectAtIndex:1 withObject:data];
+ [data release];
+
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:517];
+ [message.repeatedGroupArray replaceObjectAtIndex:1 withObject:testAll];
+ [testAll release];
+
+ TestAllTypes_NestedMessage *nestedMessage =
+ [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:518];
+ [message.repeatedNestedMessageArray replaceObjectAtIndex:1
+ withObject:nestedMessage];
+ [nestedMessage release];
+
+ ForeignMessage *foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:519];
+ [message.repeatedForeignMessageArray replaceObjectAtIndex:1
+ withObject:foreignMessage];
+ [foreignMessage release];
+
+ ImportMessage *importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:520];
+ [message.repeatedImportMessageArray replaceObjectAtIndex:1
+ withObject:importMessage];
+ [importMessage release];
+
+ [message.repeatedNestedEnumArray replaceValueAtIndex:1 withValue:TestAllTypes_NestedEnum_Foo];
+ [message.repeatedForeignEnumArray replaceValueAtIndex:1 withValue:ForeignEnum_ForeignFoo];
+ [message.repeatedImportEnumArray replaceValueAtIndex:1 withValue:ImportEnum_ImportFoo];
+
+ [message.repeatedStringPieceArray replaceObjectAtIndex:1 withObject:@"524"];
+ [message.repeatedCordArray replaceObjectAtIndex:1 withObject:@"525"];
+}
+
+- (void)assertRepeatedFieldsModified:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+
+ XCTAssertEqual(count, message.repeatedInt32Array.count);
+ XCTAssertEqual(count, message.repeatedInt64Array.count);
+ XCTAssertEqual(count, message.repeatedUint32Array.count);
+ XCTAssertEqual(count, message.repeatedUint64Array.count);
+ XCTAssertEqual(count, message.repeatedSint32Array.count);
+ XCTAssertEqual(count, message.repeatedSint64Array.count);
+ XCTAssertEqual(count, message.repeatedFixed32Array.count);
+ XCTAssertEqual(count, message.repeatedFixed64Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(count, message.repeatedFloatArray.count);
+ XCTAssertEqual(count, message.repeatedDoubleArray.count);
+ XCTAssertEqual(count, message.repeatedBoolArray.count);
+ XCTAssertEqual(count, message.repeatedStringArray.count);
+ XCTAssertEqual(count, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray.count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(count, message.repeatedCordArray.count);
+
+ XCTAssertEqual(count, message.repeatedInt32Array_Count);
+ XCTAssertEqual(count, message.repeatedInt64Array_Count);
+ XCTAssertEqual(count, message.repeatedUint32Array_Count);
+ XCTAssertEqual(count, message.repeatedUint64Array_Count);
+ XCTAssertEqual(count, message.repeatedSint32Array_Count);
+ XCTAssertEqual(count, message.repeatedSint64Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedFloatArray_Count);
+ XCTAssertEqual(count, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(count, message.repeatedBoolArray_Count);
+ XCTAssertEqual(count, message.repeatedStringArray_Count);
+ XCTAssertEqual(count, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(count, message.repeatedCordArray_Count);
+
+ XCTAssertEqual(201, [message.repeatedInt32Array valueAtIndex:0]);
+ XCTAssertEqual(202LL, [message.repeatedInt64Array valueAtIndex:0]);
+ XCTAssertEqual(203U, [message.repeatedUint32Array valueAtIndex:0]);
+ XCTAssertEqual(204ULL, [message.repeatedUint64Array valueAtIndex:0]);
+ XCTAssertEqual(205, [message.repeatedSint32Array valueAtIndex:0]);
+ XCTAssertEqual(206LL, [message.repeatedSint64Array valueAtIndex:0]);
+ XCTAssertEqual(207U, [message.repeatedFixed32Array valueAtIndex:0]);
+ XCTAssertEqual(208ULL, [message.repeatedFixed64Array valueAtIndex:0]);
+ XCTAssertEqual(209, [message.repeatedSfixed32Array valueAtIndex:0]);
+ XCTAssertEqual(210LL, [message.repeatedSfixed64Array valueAtIndex:0]);
+ XCTAssertEqualWithAccuracy(211.0f, [message.repeatedFloatArray valueAtIndex:0], 0.01);
+ XCTAssertEqualWithAccuracy(212.0, [message.repeatedDoubleArray valueAtIndex:0], 0.01);
+ XCTAssertFalse([message.repeatedBoolArray valueAtIndex:0]);
+ XCTAssertEqualObjects(@"215", message.repeatedStringArray[0]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216],
+ message.repeatedBytesArray[0]);
+
+ XCTAssertEqual(217, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[0]).a);
+ XCTAssertEqual(218, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[0]).bb);
+ XCTAssertEqual(219, ((ForeignMessage*)message.repeatedForeignMessageArray[0]).c);
+ XCTAssertEqual(220, ((ImportMessage*)message.repeatedImportMessageArray[0]).d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:0]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:0]);
+ XCTAssertEqual(ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:0]);
+
+ XCTAssertEqualObjects(@"224", message.repeatedStringPieceArray[0]);
+ XCTAssertEqualObjects(@"225", message.repeatedCordArray[0]);
+
+ // Actually verify the second (modified) elements now.
+ XCTAssertEqual(501, [message.repeatedInt32Array valueAtIndex:1]);
+ XCTAssertEqual(502LL, [message.repeatedInt64Array valueAtIndex:1]);
+ XCTAssertEqual(503U, [message.repeatedUint32Array valueAtIndex:1]);
+ XCTAssertEqual(504ULL, [message.repeatedUint64Array valueAtIndex:1]);
+ XCTAssertEqual(505, [message.repeatedSint32Array valueAtIndex:1]);
+ XCTAssertEqual(506LL, [message.repeatedSint64Array valueAtIndex:1]);
+ XCTAssertEqual(507U, [message.repeatedFixed32Array valueAtIndex:1]);
+ XCTAssertEqual(508ULL, [message.repeatedFixed64Array valueAtIndex:1]);
+ XCTAssertEqual(509, [message.repeatedSfixed32Array valueAtIndex:1]);
+ XCTAssertEqual(510LL, [message.repeatedSfixed64Array valueAtIndex:1]);
+ XCTAssertEqualWithAccuracy(511.0f, [message.repeatedFloatArray valueAtIndex:1], 0.01);
+ XCTAssertEqualWithAccuracy(512.0, [message.repeatedDoubleArray valueAtIndex:1], 0.01);
+ XCTAssertTrue([message.repeatedBoolArray valueAtIndex:1]);
+ XCTAssertEqualObjects(@"515", message.repeatedStringArray[1]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516],
+ message.repeatedBytesArray[1]);
+
+ XCTAssertEqual(517, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[1]).a);
+ XCTAssertEqual(518, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[1]).bb);
+ XCTAssertEqual(519, ((ForeignMessage*)message.repeatedForeignMessageArray[1]).c);
+ XCTAssertEqual(520, ((ImportMessage*)message.repeatedImportMessageArray[1]).d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [message.repeatedNestedEnumArray valueAtIndex:1]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, [message.repeatedForeignEnumArray valueAtIndex:1]);
+ XCTAssertEqual(ImportEnum_ImportFoo, [message.repeatedImportEnumArray valueAtIndex:1]);
+
+ XCTAssertEqualObjects(@"524", message.repeatedStringPieceArray[1]);
+ XCTAssertEqualObjects(@"525", message.repeatedCordArray[1]);
+}
+
+- (void)setPackedFields:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedInt32Array addValue:601 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedInt64Array addValue:602 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedUint32Array addValue:603 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedUint64Array addValue:604 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSint32Array addValue:605 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSint64Array addValue:606 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFixed32Array addValue:607 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFixed64Array addValue:608 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSfixed32Array addValue:609 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSfixed64Array addValue:610 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFloatArray addValue:611 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedDoubleArray addValue:612 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedBoolArray addValue:(i % 2) ? YES : NO];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedEnumArray
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+}
+
+- (void)setUnpackedFields:(TestUnpackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedInt32Array addValue:601 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedInt64Array addValue:602 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedUint32Array addValue:603 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedUint64Array addValue:604 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSint32Array addValue:605 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSint64Array addValue:606 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFixed32Array addValue:607 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFixed64Array addValue:608 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSfixed32Array addValue:609 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSfixed64Array addValue:610 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFloatArray addValue:611 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedDoubleArray addValue:612 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedBoolArray addValue:(i % 2) ? YES : NO];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedEnumArray
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+}
+
+- (void)assertPackedFieldsSet:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertEqual(count, message.packedInt32Array.count);
+ XCTAssertEqual(count, message.packedInt64Array.count);
+ XCTAssertEqual(count, message.packedUint32Array.count);
+ XCTAssertEqual(count, message.packedUint64Array.count);
+ XCTAssertEqual(count, message.packedSint32Array.count);
+ XCTAssertEqual(count, message.packedSint64Array.count);
+ XCTAssertEqual(count, message.packedFixed32Array.count);
+ XCTAssertEqual(count, message.packedFixed64Array.count);
+ XCTAssertEqual(count, message.packedSfixed32Array.count);
+ XCTAssertEqual(count, message.packedSfixed64Array.count);
+ XCTAssertEqual(count, message.packedFloatArray.count);
+ XCTAssertEqual(count, message.packedDoubleArray.count);
+ XCTAssertEqual(count, message.packedBoolArray.count);
+ XCTAssertEqual(count, message.packedEnumArray.count);
+ for (uint32_t i = 0; i < count; ++i) {
+ XCTAssertEqual((int)(601 + i * 100),
+ [message.packedInt32Array valueAtIndex:i]);
+ XCTAssertEqual(602 + i * 100, [message.packedInt64Array valueAtIndex:i]);
+ XCTAssertEqual(603 + i * 100, [message.packedUint32Array valueAtIndex:i]);
+ XCTAssertEqual(604 + i * 100, [message.packedUint64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(605 + i * 100),
+ [message.packedSint32Array valueAtIndex:i]);
+ XCTAssertEqual(606 + i * 100, [message.packedSint64Array valueAtIndex:i]);
+ XCTAssertEqual(607 + i * 100, [message.packedFixed32Array valueAtIndex:i]);
+ XCTAssertEqual(608 + i * 100, [message.packedFixed64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(609 + i * 100),
+ [message.packedSfixed32Array valueAtIndex:i]);
+ XCTAssertEqual(610 + i * 100, [message.packedSfixed64Array valueAtIndex:i]);
+ XCTAssertEqualWithAccuracy(611 + i * 100,
+ [message.packedFloatArray valueAtIndex:i], 0.01);
+ XCTAssertEqualWithAccuracy(
+ 612 + i * 100, [message.packedDoubleArray valueAtIndex:i], 0.01);
+ XCTAssertEqual((i % 2) ? YES : NO,
+ [message.packedBoolArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz,
+ [message.packedEnumArray valueAtIndex:i]);
+ }
+}
+
+- (void)setPackedExtensions:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; i++) {
+ [message addExtension:[UnittestRoot packedInt32Extension]
+ value:@(601 + i * 100)];
+ [message addExtension:[UnittestRoot packedInt64Extension]
+ value:@(602 + i * 100)];
+ [message addExtension:[UnittestRoot packedUint32Extension]
+ value:@(603 + i * 100)];
+ [message addExtension:[UnittestRoot packedUint64Extension]
+ value:@(604 + i * 100)];
+ [message addExtension:[UnittestRoot packedSint32Extension]
+ value:@(605 + i * 100)];
+ [message addExtension:[UnittestRoot packedSint64Extension]
+ value:@(606 + i * 100)];
+ [message addExtension:[UnittestRoot packedFixed32Extension]
+ value:@(607 + i * 100)];
+ [message addExtension:[UnittestRoot packedFixed64Extension]
+ value:@(608 + i * 100)];
+ [message addExtension:[UnittestRoot packedSfixed32Extension]
+ value:@(609 + i * 100)];
+ [message addExtension:[UnittestRoot packedSfixed64Extension]
+ value:@(610 + i * 100)];
+ [message addExtension:[UnittestRoot packedFloatExtension]
+ value:@(611 + i * 100)];
+ [message addExtension:[UnittestRoot packedDoubleExtension]
+ value:@(612 + i * 100)];
+ [message addExtension:[UnittestRoot packedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ [message addExtension:[UnittestRoot packedEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ }
+}
+
+- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; i++) {
+ [message addExtension:[UnittestRoot unpackedInt32Extension]
+ value:@(601 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedInt64Extension]
+ value:@(602 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedUint32Extension]
+ value:@(603 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedUint64Extension]
+ value:@(604 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSint32Extension]
+ value:@(605 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSint64Extension]
+ value:@(606 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFixed32Extension]
+ value:@(607 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFixed64Extension]
+ value:@(608 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSfixed32Extension]
+ value:@(609 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSfixed64Extension]
+ value:@(610 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFloatExtension]
+ value:@(611 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedDoubleExtension]
+ value:@(612 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ [message addExtension:[UnittestRoot unpackedEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ }
+}
+
+- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count{
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedEnumExtension]] count]);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ id extension = [message getExtension:[UnittestRoot packedInt32Extension]];
+ XCTAssertEqual((int)(601 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedInt64Extension]];
+ XCTAssertEqual(602 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedUint32Extension]];
+ XCTAssertEqual(603 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot packedUint64Extension]];
+ XCTAssertEqual(604 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot packedSint32Extension]];
+ XCTAssertEqual((int)(605 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedSint64Extension]];
+ XCTAssertEqual(606 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedFixed32Extension]];
+ XCTAssertEqual(607 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot packedFixed64Extension]];
+ XCTAssertEqual(608 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot packedSfixed32Extension]];
+ XCTAssertEqual((int)(609 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedSfixed64Extension]];
+ XCTAssertEqual(610 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedFloatExtension]];
+ XCTAssertEqualWithAccuracy(611 + i * 100, [extension[i] floatValue], 0.01);
+ extension = [message getExtension:[UnittestRoot packedDoubleExtension]];
+ XCTAssertEqualWithAccuracy(612 + i * 100, [extension[i] doubleValue], 0.01);
+ extension = [message getExtension:[UnittestRoot packedBoolExtension]];
+ XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]);
+ extension = [message getExtension:[UnittestRoot packedEnumExtension]];
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz,
+ [extension[i] intValue]);
+ }
+}
+
+- (void)assertAllFieldsKVCMatch:(TestAllTypes *)message {
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalInt32), [message valueForKey:@"optionalInt32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalInt64), [message valueForKey:@"optionalInt64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalUint32), [message valueForKey:@"optionalUint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalUint64), [message valueForKey:@"optionalUint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSint32), [message valueForKey:@"optionalSint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSint64), [message valueForKey:@"optionalSint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFixed32), [message valueForKey:@"optionalFixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFixed64), [message valueForKey:@"optionalFixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSfixed32), [message valueForKey:@"optionalSfixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSfixed64), [message valueForKey:@"optionalSfixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFloat), [message valueForKey:@"optionalFloat"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @YES);
+ XCTAssertEqualObjects(@(message.optionalDouble), [message valueForKey:@"optionalDouble"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @YES);
+ XCTAssertEqualObjects(@(message.optionalBool), [message valueForKey:@"optionalBool"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @YES);
+ XCTAssertEqualObjects(message.optionalString, [message valueForKey:@"optionalString"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @YES);
+ XCTAssertEqualObjects(message.optionalBytes, [message valueForKey:@"optionalBytes"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @YES);
+ XCTAssertNotNil(message.optionalGroup);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @YES);
+ XCTAssertEqualObjects(@(message.optionalGroup.a), [message valueForKeyPath:@"optionalGroup.a"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @YES);
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.hasBb"], @YES);
+ XCTAssertEqualObjects(@(message.optionalNestedMessage.bb), [message valueForKeyPath:@"optionalNestedMessage.bb"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], @YES);
+ XCTAssertNotNil(message.optionalForeignMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.hasC"], @YES);
+ XCTAssertEqualObjects(@(message.optionalForeignMessage.c), [message valueForKeyPath:@"optionalForeignMessage.c"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @YES);
+ XCTAssertNotNil(message.optionalForeignMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], @YES);
+ XCTAssertEqualObjects(@(message.optionalImportMessage.d), [message valueForKeyPath:@"optionalImportMessage.d"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalNestedEnum), [message valueForKey:@"optionalNestedEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalForeignEnum), [message valueForKey:@"optionalForeignEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalImportEnum), [message valueForKey:@"optionalImportEnum"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @YES);
+ XCTAssertEqualObjects(message.optionalStringPiece, [message valueForKey:@"optionalStringPiece"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @YES);
+ XCTAssertEqualObjects(message.optionalCord, [message valueForKey:@"optionalCord"]);
+
+ // -----------------------------------------------------------------
+
+ // GPBArray interface for repeated
+
+ XCTAssertEqualObjects(message.repeatedInt32Array, [message valueForKey:@"repeatedInt32Array"]);
+ XCTAssertEqualObjects(message.repeatedInt64Array, [message valueForKey:@"repeatedInt64Array"]);
+ XCTAssertEqualObjects(message.repeatedUint32Array, [message valueForKey:@"repeatedUint32Array"]);
+ XCTAssertEqualObjects(message.repeatedUint64Array, [message valueForKey:@"repeatedUint64Array"]);
+ XCTAssertEqualObjects(message.repeatedSint32Array, [message valueForKey:@"repeatedSint32Array"]);
+ XCTAssertEqualObjects(message.repeatedSint64Array, [message valueForKey:@"repeatedSint64Array"]);
+ XCTAssertEqualObjects(message.repeatedFixed32Array, [message valueForKey:@"repeatedFixed32Array"]);
+ XCTAssertEqualObjects(message.repeatedFixed64Array, [message valueForKey:@"repeatedFixed64Array"]);
+ XCTAssertEqualObjects(message.repeatedSfixed32Array, [message valueForKey:@"repeatedSfixed32Array"]);
+ XCTAssertEqualObjects(message.repeatedSfixed64Array, [message valueForKey:@"repeatedSfixed64Array"]);
+ XCTAssertEqualObjects(message.repeatedFloatArray, [message valueForKey:@"repeatedFloatArray"]);
+ XCTAssertEqualObjects(message.repeatedDoubleArray, [message valueForKey:@"repeatedDoubleArray"]);
+ XCTAssertEqualObjects(message.repeatedBoolArray, [message valueForKey:@"repeatedBoolArray"]);
+ XCTAssertEqualObjects(message.repeatedStringArray, [message valueForKey:@"repeatedStringArray"]);
+ XCTAssertEqualObjects(message.repeatedBytesArray, [message valueForKey:@"repeatedBytesArray"]);
+
+ XCTAssertEqualObjects(message.repeatedGroupArray, [message valueForKey:@"repeatedGroupArray"]);
+ XCTAssertEqualObjects(message.repeatedNestedMessageArray, [message valueForKey:@"repeatedNestedMessageArray"]);
+ XCTAssertEqualObjects(message.repeatedForeignMessageArray, [message valueForKey:@"repeatedForeignMessageArray"]);
+ XCTAssertEqualObjects(message.repeatedImportMessageArray, [message valueForKey:@"repeatedImportMessageArray"]);
+
+ XCTAssertEqualObjects(message.repeatedNestedEnumArray, [message valueForKey:@"repeatedNestedEnumArray"]);
+ XCTAssertEqualObjects(message.repeatedForeignEnumArray, [message valueForKey:@"repeatedForeignEnumArray"]);
+ XCTAssertEqualObjects(message.repeatedImportEnumArray, [message valueForKey:@"repeatedImportEnumArray"]);
+
+ XCTAssertEqualObjects(message.repeatedStringPieceArray, [message valueForKey:@"repeatedStringPieceArray"]);
+ XCTAssertEqualObjects(message.repeatedCordArray, [message valueForKey:@"repeatedCordArray"]);
+
+ XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), [message valueForKey:@"repeatedInt32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), [message valueForKey:@"repeatedInt64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), [message valueForKey:@"repeatedUint32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), [message valueForKey:@"repeatedUint64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), [message valueForKey:@"repeatedSint32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), [message valueForKey:@"repeatedSint64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), [message valueForKey:@"repeatedFixed32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), [message valueForKey:@"repeatedFixed64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), [message valueForKey:@"repeatedSfixed32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), [message valueForKey:@"repeatedSfixed64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), [message valueForKey:@"repeatedFloatArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), [message valueForKey:@"repeatedDoubleArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), [message valueForKey:@"repeatedBoolArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedStringArray_Count), [message valueForKey:@"repeatedStringArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), [message valueForKey:@"repeatedBytesArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), [message valueForKey:@"repeatedGroupArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), [message valueForKey:@"repeatedNestedMessageArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), [message valueForKey:@"repeatedForeignMessageArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), [message valueForKey:@"repeatedImportMessageArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), [message valueForKey:@"repeatedNestedEnumArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), [message valueForKey:@"repeatedForeignEnumArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), [message valueForKey:@"repeatedImportEnumArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), [message valueForKey:@"repeatedStringPieceArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedCordArray_Count), [message valueForKey:@"repeatedCordArray_Count"]);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultInt32), [message valueForKey:@"defaultInt32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultInt64), [message valueForKey:@"defaultInt64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultUint32), [message valueForKey:@"defaultUint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultUint64), [message valueForKey:@"defaultUint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSint32), [message valueForKey:@"defaultSint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSint64), [message valueForKey:@"defaultSint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFixed32), [message valueForKey:@"defaultFixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFixed64), [message valueForKey:@"defaultFixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSfixed32), [message valueForKey:@"defaultSfixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSfixed64), [message valueForKey:@"defaultSfixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFloat), [message valueForKey:@"defaultFloat"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @YES);
+ XCTAssertEqualObjects(@(message.defaultDouble), [message valueForKey:@"defaultDouble"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @YES);
+ XCTAssertEqualObjects(@(message.defaultBool), [message valueForKey:@"defaultBool"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @YES);
+ XCTAssertEqualObjects(message.defaultString, [message valueForKey:@"defaultString"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @YES);
+ XCTAssertEqualObjects(message.defaultBytes, [message valueForKey:@"defaultBytes"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultNestedEnum), [message valueForKey:@"defaultNestedEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultForeignEnum), [message valueForKey:@"defaultForeignEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultImportEnum), [message valueForKey:@"defaultImportEnum"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @YES);
+ XCTAssertEqualObjects(message.defaultStringPiece, [message valueForKey:@"defaultStringPiece"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @YES);
+ XCTAssertEqualObjects(message.defaultCord, [message valueForKey:@"defaultCord"]);
+}
+
+- (void)setAllFieldsViaKVC:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ [message setValue:@101 forKey:@"optionalInt32"];
+ [message setValue:@102 forKey:@"optionalInt64"];
+ [message setValue:@103 forKey:@"optionalUint32"];
+ [message setValue:@104 forKey:@"optionalUint64"];
+ [message setValue:@105 forKey:@"optionalSint32"];
+ [message setValue:@106 forKey:@"optionalSint64"];
+ [message setValue:@107 forKey:@"optionalFixed32"];
+ [message setValue:@108 forKey:@"optionalFixed64"];
+ [message setValue:@109 forKey:@"optionalSfixed32"];
+ [message setValue:@110 forKey:@"optionalSfixed64"];
+ [message setValue:@111 forKey:@"optionalFloat"];
+ [message setValue:@112 forKey:@"optionalDouble"];
+ [message setValue:@YES forKey:@"optionalBool"];
+ [message setValue:@"115" forKey:@"optionalString"];
+ [message setValue:[NSData gpbtu_dataWithEmbeddedNulls]
+ forKey:@"optionalBytes"];
+
+ TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message];
+ [allTypes setValue:@117 forKey:@"a"];
+ [message setValue:allTypes forKey:@"optionalGroup"];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setValue:@118 forKey:@"bb"];
+ [message setValue:nestedMessage forKey:@"optionalNestedMessage"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setValue:@119 forKey:@"c"];
+ [message setValue:foreignMessage forKey:@"optionalForeignMessage"];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setValue:@120 forKey:@"d"];
+ [message setValue:importMessage forKey:@"optionalImportMessage"];
+
+ [message setValue:@(TestAllTypes_NestedEnum_Baz)
+ forKey:@"optionalNestedEnum"];
+ [message setValue:@(ForeignEnum_ForeignBaz) forKey:@"optionalForeignEnum"];
+ [message setValue:@(ImportEnum_ImportBaz) forKey:@"optionalImportEnum"];
+
+ [message setValue:@"124" forKey:@"optionalStringPiece"];
+ [message setValue:@"125" forKey:@"optionalCord"];
+
+ // -----------------------------------------------------------------
+
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:201 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedInt32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:202 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedInt64Array"];
+ }
+ {
+ GPBUInt32Array *scratch = [GPBUInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:203 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedUint32Array"];
+ }
+ {
+ GPBUInt64Array *scratch = [GPBUInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:204 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedUint64Array"];
+ }
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:205 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSint32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:206 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSint64Array"];
+ }
+ {
+ GPBUInt32Array *scratch = [GPBUInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:207 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFixed32Array"];
+ }
+ {
+ GPBUInt64Array *scratch = [GPBUInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:208 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFixed64Array"];
+ }
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:209 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSfixed32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:210 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSfixed64Array"];
+ }
+ {
+ GPBFloatArray *scratch = [GPBFloatArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:211 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFloatArray"];
+ }
+ {
+ GPBDoubleArray *scratch = [GPBDoubleArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:212 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedDoubleArray"];
+ }
+ {
+ GPBBoolArray *scratch = [GPBBoolArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? YES : NO];
+ }
+ [message setValue:scratch forKey:@"repeatedBoolArray"];
+ }
+
+ NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedStringArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [array addObject:data];
+ [data release];
+ }
+ [message setValue:array forKey:@"repeatedBytesArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:217 + i * 100];
+ [array addObject:testAll];
+ [testAll release];
+ }
+ [message setValue:array forKey:@"repeatedGroupArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [array addObject:nestedMessage];
+ [nestedMessage release];
+ }
+ [message setValue:array forKey:@"repeatedNestedMessageArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [array addObject:foreignMessage];
+ [foreignMessage release];
+ }
+ [message setValue:array forKey:@"repeatedForeignMessageArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [array addObject:importMessage];
+ [importMessage release];
+ }
+ [message setValue:array forKey:@"repeatedImportMessageArray"];
+ [array release];
+
+ {
+ GPBEnumArray *scratch = [GPBEnumArray
+ arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar
+ : TestAllTypes_NestedEnum_Baz];
+ }
+ [message setValue:scratch forKey:@"repeatedNestedEnumArray"];
+ }
+ {
+ GPBEnumArray *scratch =
+ [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+ [message setValue:scratch forKey:@"repeatedForeignEnumArray"];
+ }
+ {
+ GPBEnumArray *scratch =
+ [GPBEnumArray arrayWithValidationFunction:ImportEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz];
+ }
+ [message setValue:scratch forKey:@"repeatedImportEnumArray"];
+ }
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedStringPieceArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedCordArray"];
+ [array release];
+
+ // -----------------------------------------------------------------
+
+ [message setValue:@401 forKey:@"defaultInt32"];
+ [message setValue:@402 forKey:@"defaultInt64"];
+ [message setValue:@403 forKey:@"defaultUint32"];
+ [message setValue:@404 forKey:@"defaultUint64"];
+ [message setValue:@405 forKey:@"defaultSint32"];
+ [message setValue:@406 forKey:@"defaultSint64"];
+ [message setValue:@407 forKey:@"defaultFixed32"];
+ [message setValue:@408 forKey:@"defaultFixed64"];
+ [message setValue:@409 forKey:@"defaultSfixed32"];
+ [message setValue:@410 forKey:@"defaultSfixed64"];
+ [message setValue:@411 forKey:@"defaultFloat"];
+ [message setValue:@412 forKey:@"defaultDouble"];
+ [message setValue:@NO forKey:@"defaultBool"];
+ [message setValue:@"415" forKey:@"defaultString"];
+ [message setValue:[NSData gpbtu_dataWithUint32:416] forKey:@"defaultBytes"];
+
+ [message setValue:@(TestAllTypes_NestedEnum_Foo) forKey:@"defaultNestedEnum"];
+ [message setValue:@(ForeignEnum_ForeignFoo) forKey:@"defaultForeignEnum"];
+ [message setValue:@(ImportEnum_ImportFoo) forKey:@"defaultImportEnum"];
+
+ [message setValue:@"424" forKey:@"defaultStringPiece"];
+ [message setValue:@"425" forKey:@"defaultCord"];
+}
+
+- (void)assertClearKVC:(TestAllTypes *)message {
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"],
+ @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @NO);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqualObjects([message valueForKey:@"optionalInt32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalInt64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalUint32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalUint64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSint32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSint64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFixed32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFixed64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSfixed32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSfixed64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFloat"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalDouble"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"optionalString"], @"");
+ XCTAssertEqualObjects([message valueForKey:@"optionalBytes"],
+ GPBEmptyNSData());
+
+ // Embedded messages should also be exist, but be clear.
+ XCTAssertNotNil([message valueForKeyPath:@"optionalGroup"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalNestedMessage"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalForeignMessage"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalImportMessage"]);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @NO);
+ XCTAssertEqualObjects(
+ [message valueForKeyPath:@"optionalNestedMessage.hasBb"], @NO);
+ XCTAssertEqualObjects(
+ [message valueForKeyPath:@"optionalForeignMessage.hasC"], @NO);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"],
+ @NO);
+
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.a"], @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.bb"],
+ @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.c"],
+ @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.d"],
+ @0);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqualObjects([message valueForKey:@"optionalNestedEnum"],
+ @(TestAllTypes_NestedEnum_Foo));
+ XCTAssertEqualObjects([message valueForKey:@"optionalForeignEnum"],
+ @(ForeignEnum_ForeignFoo));
+ XCTAssertEqualObjects([message valueForKey:@"optionalImportEnum"],
+ @(ImportEnum_ImportFoo));
+
+ XCTAssertEqualObjects([message valueForKey:@"optionalStringPiece"], @"");
+ XCTAssertEqualObjects([message valueForKey:@"optionalCord"], @"");
+
+ // NSArray interface for repeated doesn't have has*, nil means no value.
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @NO);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqualObjects([message valueForKey:@"defaultInt32"], @41);
+ XCTAssertEqualObjects([message valueForKey:@"defaultInt64"], @42);
+ XCTAssertEqualObjects([message valueForKey:@"defaultUint32"], @43);
+ XCTAssertEqualObjects([message valueForKey:@"defaultUint64"], @44);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSint32"], @-45);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSint64"], @46);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFixed32"], @47);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFixed64"], @48);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSfixed32"], @49);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSfixed64"], @-50);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFloat"], @51.5);
+ XCTAssertEqualObjects([message valueForKey:@"defaultDouble"], @52e3);
+ XCTAssertEqualObjects([message valueForKey:@"defaultBool"], @YES);
+ XCTAssertEqualObjects([message valueForKey:@"defaultString"], @"hello");
+ XCTAssertEqualObjects([message valueForKey:@"defaultBytes"],
+ [NSData gpbtu_dataWithCString:"world"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"defaultNestedEnum"],
+ @(TestAllTypes_NestedEnum_Bar));
+ XCTAssertEqualObjects([message valueForKey:@"defaultForeignEnum"],
+ @(ForeignEnum_ForeignBar));
+ XCTAssertEqualObjects([message valueForKey:@"defaultImportEnum"],
+ @(ImportEnum_ImportBar));
+
+ XCTAssertEqualObjects([message valueForKey:@"defaultStringPiece"], @"abc");
+ XCTAssertEqualObjects([message valueForKey:@"defaultCord"], @"123");
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m
new file mode 100644
index 0000000000..756bd99ef7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m
@@ -0,0 +1,75 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Collects all the compiled protos into one file and compiles them to make sure
+// the compiler is generating valid code.
+
+// The unittest_custom_options.proto extends the messages in descriptor.proto
+// so we build it in to test extending in general. The library doesn't provide
+// a descriptor as it doesn't use the classes/enums.
+#import "google/protobuf/Descriptor.pbobjc.m"
+
+#import "google/protobuf/AnyTest.pbobjc.m"
+#import "google/protobuf/MapProto2Unittest.pbobjc.m"
+#import "google/protobuf/MapUnittest.pbobjc.m"
+#import "google/protobuf/Unittest.pbobjc.m"
+#import "google/protobuf/UnittestArena.pbobjc.m"
+#import "google/protobuf/UnittestCustomOptions.pbobjc.m"
+#import "google/protobuf/UnittestCycle.pbobjc.m"
+#import "google/protobuf/UnittestDeprecated.pbobjc.m"
+#import "google/protobuf/UnittestDeprecatedFile.pbobjc.m"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.m"
+#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.m"
+#import "google/protobuf/UnittestEmpty.pbobjc.m"
+#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.m"
+#import "google/protobuf/UnittestImport.pbobjc.m"
+#import "google/protobuf/UnittestImportLite.pbobjc.m"
+#import "google/protobuf/UnittestImportPublic.pbobjc.m"
+#import "google/protobuf/UnittestImportPublicLite.pbobjc.m"
+#import "google/protobuf/UnittestLite.pbobjc.m"
+#import "google/protobuf/UnittestMset.pbobjc.m"
+#import "google/protobuf/UnittestMsetWireFormat.pbobjc.m"
+#import "google/protobuf/UnittestNoArena.pbobjc.m"
+#import "google/protobuf/UnittestNoArenaImport.pbobjc.m"
+#import "google/protobuf/UnittestNoGenericServices.pbobjc.m"
+#import "google/protobuf/UnittestObjc.pbobjc.m"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.m"
+#import "google/protobuf/UnittestOptimizeFor.pbobjc.m"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.m"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.m"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.m"
+
+#import "google/protobuf/UnittestExtensionChainA.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainB.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainC.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainD.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainE.pbobjc.m"
+// See GPBUnittestProtos2.m for for "UnittestExtensionChainF.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainG.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m
new file mode 100644
index 0000000000..ef9f070222
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m
@@ -0,0 +1,34 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This one file in the chain tests is compiled by itself to ensure if was
+// generated with the extra #imports needed to pull in the indirect Root class
+// used in its Root registry.
+#import "google/protobuf/UnittestExtensionChainF.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m b/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m
new file mode 100644
index 0000000000..b2b5b21e61
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m
@@ -0,0 +1,255 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface GPBUnknownFieldSet (GPBUnknownFieldSetTest)
+- (void)getTags:(int32_t*)tags;
+@end
+
+@interface UnknownFieldSetTest : GPBTestCase {
+ @private
+ TestAllTypes* allFields_;
+ NSData* allFieldsData_;
+
+ // An empty message that has been parsed from allFieldsData. So, it has
+ // unknown fields of every type.
+ TestEmptyMessage* emptyMessage_;
+ GPBUnknownFieldSet* unknownFields_;
+}
+
+@end
+
+@implementation UnknownFieldSetTest
+
+- (void)setUp {
+ allFields_ = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ allFieldsData_ = [allFields_ data];
+ emptyMessage_ = [TestEmptyMessage parseFromData:allFieldsData_ error:NULL];
+ unknownFields_ = emptyMessage_.unknownFields;
+}
+
+// Constructs a protocol buffer which contains fields with all the same
+// numbers as allFieldsData except that each field is some other wire
+// type.
+- (NSData*)getBizarroData {
+ GPBUnknownFieldSet* bizarroFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ NSUInteger count = [unknownFields_ countOfFields];
+ int32_t tags[count];
+ [unknownFields_ getTags:tags];
+ for (NSUInteger i = 0; i < count; ++i) {
+ int32_t tag = tags[i];
+ GPBUnknownField* field = [unknownFields_ getField:tag];
+ if (field.varintList.count == 0) {
+ // Original field is not a varint, so use a varint.
+ GPBUnknownField* varintField =
+ [[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
+ [varintField addVarint:1];
+ [bizarroFields addField:varintField];
+ } else {
+ // Original field *is* a varint, so use something else.
+ GPBUnknownField* fixed32Field =
+ [[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
+ [fixed32Field addFixed32:1];
+ [bizarroFields addField:fixed32Field];
+ }
+ }
+
+ return [bizarroFields data];
+}
+
+- (void)testSerialize {
+ // Check that serializing the UnknownFieldSet produces the original data
+ // again.
+ NSData* data = [emptyMessage_ data];
+ XCTAssertEqualObjects(allFieldsData_, data);
+}
+
+- (void)testCopyFrom {
+ TestEmptyMessage* message = [TestEmptyMessage message];
+ [message mergeFrom:emptyMessage_];
+
+ XCTAssertEqualObjects(emptyMessage_.data, message.data);
+}
+
+- (void)testMergeFrom {
+ GPBUnknownFieldSet* set1 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [set1 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [set1 addField:field];
+
+ GPBUnknownFieldSet* set2 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:1];
+ [set2 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:3];
+ [set2 addField:field];
+
+ GPBUnknownFieldSet* set3 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:1];
+ [set3 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [set3 addField:field];
+
+ GPBUnknownFieldSet* set4 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [set4 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:3];
+ [set4 addField:field];
+
+ TestEmptyMessage* source1 = [TestEmptyMessage message];
+ [source1 setUnknownFields:set1];
+ TestEmptyMessage* source2 = [TestEmptyMessage message];
+ [source2 setUnknownFields:set2];
+ TestEmptyMessage* source3 = [TestEmptyMessage message];
+ [source3 setUnknownFields:set3];
+ TestEmptyMessage* source4 = [TestEmptyMessage message];
+ [source4 setUnknownFields:set4];
+
+ TestEmptyMessage* destination1 = [TestEmptyMessage message];
+ [destination1 mergeFrom:source1];
+ [destination1 mergeFrom:source2];
+
+ TestEmptyMessage* destination2 = [TestEmptyMessage message];
+ [destination2 mergeFrom:source3];
+ [destination2 mergeFrom:source4];
+
+ XCTAssertEqualObjects(destination1.data, destination2.data);
+}
+
+- (void)testClearMessage {
+ TestEmptyMessage *message = [TestEmptyMessage message];
+ [message mergeFrom:emptyMessage_];
+ [message clear];
+ XCTAssertEqual(message.serializedSize, (size_t)0);
+}
+
+- (void)testParseKnownAndUnknown {
+ // Test mixing known and unknown fields when parsing.
+ GPBUnknownFieldSet *fields = [[unknownFields_ copy] autorelease];
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:123456] autorelease];
+ [field addVarint:654321];
+ [fields addField:field];
+
+ NSData* data = fields.data;
+ TestAllTypes* destination = [TestAllTypes parseFromData:data error:NULL];
+
+ [self assertAllFieldsSet:destination repeatedCount:kGPBDefaultRepeatCount];
+ XCTAssertEqual(destination.unknownFields.countOfFields, (NSUInteger)1);
+
+ GPBUnknownField* field2 = [destination.unknownFields getField:123456];
+ XCTAssertEqual(field2.varintList.count, (NSUInteger)1);
+ XCTAssertEqual(654321ULL, [field2.varintList valueAtIndex:0]);
+}
+
+- (void)testWrongTypeTreatedAsUnknown {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing.
+
+ NSData* bizarroData = [self getBizarroData];
+ TestAllTypes* allTypesMessage =
+ [TestAllTypes parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ XCTAssertEqualObjects(emptyMessage.data, allTypesMessage.data);
+}
+
+- (void)testUnknownExtensions {
+ // Make sure fields are properly parsed to the UnknownFieldSet even when
+ // they are declared as extension numbers.
+
+ TestEmptyMessageWithExtensions* message =
+ [TestEmptyMessageWithExtensions parseFromData:allFieldsData_ error:NULL];
+
+ XCTAssertEqual(unknownFields_.countOfFields,
+ message.unknownFields.countOfFields);
+ XCTAssertEqualObjects(allFieldsData_, message.data);
+}
+
+- (void)testWrongExtensionTypeTreatedAsUnknown {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing extensions.
+
+ NSData* bizarroData = [self getBizarroData];
+ TestAllExtensions* allExtensionsMessage =
+ [TestAllExtensions parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ XCTAssertEqualObjects(emptyMessage.data, allExtensionsMessage.data);
+}
+
+- (void)testLargeVarint {
+ GPBUnknownFieldSet* fields = [[unknownFields_ copy] autorelease];
+ GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:0x7FFFFFFFFFFFFFFFL];
+ [fields addField:field];
+
+ NSData* data = [fields data];
+
+ GPBUnknownFieldSet* parsed = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [parsed mergeFromData:data];
+ GPBUnknownField* field2 = [parsed getField:1];
+ XCTAssertEqual(field2.varintList.count, (NSUInteger)1);
+ XCTAssertEqual(0x7FFFFFFFFFFFFFFFULL, [field2.varintList valueAtIndex:0]);
+}
+
+- (void)testMergingFields {
+ GPBUnknownField* field1 = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field1 addVarint:1];
+ [field1 addFixed32:2];
+ [field1 addFixed64:3];
+ [field1 addLengthDelimited:[NSData dataWithBytes:"hello" length:5]];
+ [field1 addGroup:[[unknownFields_ copy] autorelease]];
+ GPBUnknownField* field2 = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field2 mergeFromField:field1];
+ XCTAssertEqualObjects(field1, field2);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m b/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m
new file mode 100644
index 0000000000..2e206a54ea
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m
@@ -0,0 +1,400 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <XCTest/XCTest.h>
+
+#import "GPBUtilities_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBTestUtilities.h"
+
+#import "GPBDescriptor.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage.h"
+#import "GPBUnknownField_PackagePrivate.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+@interface UtilitiesTests : GPBTestCase
+@end
+
+@implementation UtilitiesTests
+
+- (void)testRightShiftFunctions {
+ XCTAssertEqual((1UL << 31) >> 31, 1UL);
+ XCTAssertEqual((1 << 31) >> 31, -1);
+ XCTAssertEqual((1ULL << 63) >> 63, 1ULL);
+ XCTAssertEqual((1LL << 63) >> 63, -1LL);
+
+ XCTAssertEqual(GPBLogicalRightShift32((1 << 31), 31), 1);
+ XCTAssertEqual(GPBLogicalRightShift64((1LL << 63), 63), 1LL);
+}
+
+- (void)testGPBDecodeTextFormatName {
+ uint8_t decodeData[] = {
+ 0x6,
+ // An inlined string (first to make sure the leading null is handled
+ // correctly, and with a key of zero to check that).
+ 0x0, 0x0, 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 0x0,
+ // All as is (00 op)
+ 0x1, 0x0A, 0x0,
+ // Underscore, upper + 9 (10 op)
+ 0x3, 0xCA, 0x0,
+ // Upper + 3 (10 op), underscore, upper + 5 (10 op)
+ 0x2, 0x44, 0xC6, 0x0,
+ // All Upper for 4 (11 op), underscore, underscore, upper + 5 (10 op),
+ // underscore, lower + 0 (01 op)
+ 0x4, 0x64, 0x80, 0xC5, 0xA1, 0x0,
+ // 2 byte key: as is + 3 (00 op), underscore, lower + 4 (01 op),
+ // underscore, lower + 3 (01 op), underscore, lower + 1 (01 op),
+ // underscore, lower + 30 (01 op), as is + 30 (00 op), as is + 13 (00 op),
+ // underscore, as is + 3 (00 op)
+ 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0,
+ };
+ NSString *inputStr = @"abcdefghIJ";
+
+ // Empty inputs
+
+ XCTAssertNil(GPBDecodeTextFormatName(nil, 1, NULL));
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, 1, NULL));
+ XCTAssertNil(GPBDecodeTextFormatName(nil, 1, inputStr));
+
+ // Keys not found.
+
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, 5, inputStr));
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, -1, inputStr));
+
+ // Some name decodes.
+
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 1, inputStr), @"abcdefghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 2, inputStr), @"Abcd_EfghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 3, inputStr), @"_AbcdefghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 4, inputStr), @"ABCD__EfghI_j");
+
+ // An inlined string (and key of zero).
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 0, inputStr), @"zbcdefghIJ");
+
+ // Long name so multiple decode ops are needed.
+ inputStr = @"longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000";
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 1000, inputStr),
+ @"long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000");
+}
+
+- (void)testTextFormat {
+ TestAllTypes *message = [TestAllTypes message];
+
+ // Not kGPBDefaultRepeatCount because we are comparing to golden master file
+ // which was generated with 2.
+ [self setAllFields:message repeatedCount:2];
+
+ NSString *result = GPBTextFormatForMessage(message, nil);
+
+ NSString *fileName = @"text_format_unittest_data.txt";
+ NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *expectedData =
+ [self getDataFileNamed:fileName dataToWrite:resultData];
+ NSString *expected = [[NSString alloc] initWithData:expectedData
+ encoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(expected, result);
+ [expected release];
+}
+
+- (void)testTextFormatExtra {
+ // -testTextFormat uses all protos with fields that don't require special
+ // handing for figuring out the names. The ObjC proto has a bunch of oddball
+ // field and enum names that require the decode info to get right, so this
+ // confirms they generated and decoded correctly.
+
+ self_Class *message = [self_Class message];
+ message.cmd = YES;
+ message.isProxy_p = YES;
+ message.subEnum = self_autorelease_RetainCount;
+ message.new_p.copy_p = @"foo";
+
+ NSString *expected = @"_cmd: true\n"
+ @"isProxy: true\n"
+ @"SubEnum: retainCount\n"
+ @"New {\n"
+ @" copy: \"foo\"\n"
+ @"}\n";
+ NSString *result = GPBTextFormatForMessage(message, nil);
+ XCTAssertEqualObjects(expected, result);
+}
+
+- (void)testTextFormatMaps {
+ TestMap *message = [TestMap message];
+
+ // Map iteration order doesn't have to be stable, so use only one entry.
+ [self setAllMapFields:message numEntries:1];
+
+ NSString *result = GPBTextFormatForMessage(message, nil);
+
+ NSString *fileName = @"text_format_map_unittest_data.txt";
+ NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *expectedData =
+ [self getDataFileNamed:fileName dataToWrite:resultData];
+ NSString *expected = [[NSString alloc] initWithData:expectedData
+ encoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(expected, result);
+ [expected release];
+}
+
+// TODO(thomasvl): add test with extensions once those format with correct names.
+
+- (void)testSetRepeatedFields {
+ TestAllTypes *message = [TestAllTypes message];
+
+ NSDictionary *repeatedFieldValues = @{
+ @"repeatedStringArray" : [@[@"foo", @"bar"] mutableCopy],
+ @"repeatedBoolArray" : [GPBBoolArray arrayWithValue:YES],
+ @"repeatedInt32Array" : [GPBInt32Array arrayWithValue:14],
+ @"repeatedInt64Array" : [GPBInt64Array arrayWithValue:15],
+ @"repeatedUint32Array" : [GPBUInt32Array arrayWithValue:16],
+ @"repeatedUint64Array" : [GPBUInt64Array arrayWithValue:16],
+ @"repeatedFloatArray" : [GPBFloatArray arrayWithValue:16],
+ @"repeatedDoubleArray" : [GPBDoubleArray arrayWithValue:16],
+ @"repeatedNestedEnumArray" :
+ [GPBEnumArray arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue
+ rawValue:TestAllTypes_NestedEnum_Foo],
+ };
+ for (NSString *fieldName in repeatedFieldValues) {
+ GPBFieldDescriptor *field =
+ [message.descriptor fieldWithName:fieldName];
+ XCTAssertNotNil(field, @"No field with name: %@", fieldName);
+ id expectedValues = repeatedFieldValues[fieldName];
+ GPBSetMessageRepeatedField(message, field, expectedValues);
+ XCTAssertEqualObjects(expectedValues,
+ [message valueForKeyPath:fieldName]);
+ }
+}
+
+// Helper to make an unknown field set with something in it.
+static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) {
+ GPBUnknownFieldSet *result =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:num] autorelease];
+ [field addVarint:num];
+ [result addField:field];
+
+ return result;
+}
+
+- (void)testDropMessageUnknownFieldsRecursively {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ // Give it unknownFields.
+ message.unknownFields = UnknownFieldsSetHelper(777);
+
+ // Given it extensions that include a message with unknown fields of its own.
+ {
+ // Int
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+
+ // Group
+ OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message];
+ optionalGroup.a = 123;
+ optionalGroup.unknownFields = UnknownFieldsSetHelper(779);
+ [message setExtension:[UnittestRoot optionalGroupExtension]
+ value:optionalGroup];
+
+ // Message
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 456;
+ nestedMessage.unknownFields = UnknownFieldsSetHelper(778);
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+
+ // Repeated Group
+ RepeatedGroup_extension *repeatedGroup =
+ [[RepeatedGroup_extension alloc] init];
+ repeatedGroup.a = 567;
+ repeatedGroup.unknownFields = UnknownFieldsSetHelper(780);
+ [message addExtension:[UnittestRoot repeatedGroupExtension]
+ value:repeatedGroup];
+ [repeatedGroup release];
+
+ // Repeated Message
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ nestedMessage.bb = 678;
+ nestedMessage.unknownFields = UnknownFieldsSetHelper(781);
+ [message addExtension:[UnittestRoot repeatedNestedMessageExtension]
+ value:nestedMessage];
+ [nestedMessage release];
+ }
+
+ // Confirm everything is there.
+
+ XCTAssertNotNil(message);
+ XCTAssertNotNil(message.unknownFields);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ OptionalGroup_extension *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertEqual(optionalGroup.a, 123);
+ XCTAssertNotNil(optionalGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ XCTAssertNotNil(nestedMessage);
+ XCTAssertEqual(nestedMessage.bb, 456);
+ XCTAssertNotNil(nestedMessage.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedGroupExtension]]);
+ NSArray *repeatedGroups = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual(repeatedGroups.count, (NSUInteger)1);
+ RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject;
+ XCTAssertNotNil(repeatedGroup);
+ XCTAssertEqual(repeatedGroup.a, 567);
+ XCTAssertNotNil(repeatedGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]);
+ NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1);
+ TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject;
+ XCTAssertNotNil(repeatedNestedMessage);
+ XCTAssertEqual(repeatedNestedMessage.bb, 678);
+ XCTAssertNotNil(repeatedNestedMessage.unknownFields);
+ }
+
+ // Drop them.
+ GPBMessageDropUnknownFieldsRecursively(message);
+
+ // Confirm unknowns are gone from within the messages.
+
+ XCTAssertNotNil(message);
+ XCTAssertNil(message.unknownFields);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ OptionalGroup_extension *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertEqual(optionalGroup.a, 123);
+ XCTAssertNil(optionalGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ XCTAssertNotNil(nestedMessage);
+ XCTAssertEqual(nestedMessage.bb, 456);
+ XCTAssertNil(nestedMessage.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedGroupExtension]]);
+ NSArray *repeatedGroups = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual(repeatedGroups.count, (NSUInteger)1);
+ RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject;
+ XCTAssertNotNil(repeatedGroup);
+ XCTAssertEqual(repeatedGroup.a, 567);
+ XCTAssertNil(repeatedGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]);
+ NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1);
+ TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject;
+ XCTAssertNotNil(repeatedNestedMessage);
+ XCTAssertEqual(repeatedNestedMessage.bb, 678);
+ XCTAssertNil(repeatedNestedMessage.unknownFields);
+ }
+
+}
+
+- (void)testDropMessageUnknownFieldsRecursively_Maps {
+ TestMap *message = [TestMap message];
+
+ {
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.unknownFields = UnknownFieldsSetHelper(100);
+ [message.mapInt32ForeignMessage setObject:foreignMessage forKey:100];
+
+ foreignMessage = [ForeignMessage message];
+ foreignMessage.unknownFields = UnknownFieldsSetHelper(101);
+ [message.mapStringForeignMessage setObject:foreignMessage forKey:@"101"];
+ }
+
+ // Confirm everything is there.
+
+ XCTAssertNotNil(message);
+
+ {
+ ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNotNil(foreignMessage.unknownFields);
+ }
+
+ {
+ ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNotNil(foreignMessage.unknownFields);
+ }
+
+ GPBMessageDropUnknownFieldsRecursively(message);
+
+ // Confirm unknowns are gone from within the messages.
+
+ XCTAssertNotNil(message);
+
+ {
+ ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNil(foreignMessage.unknownFields);
+ }
+
+ {
+ ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNil(foreignMessage.unknownFields);
+ }
+
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m b/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m
new file mode 100644
index 0000000000..592d5afd4b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m
@@ -0,0 +1,214 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBWellKnownTypes.h"
+
+#import <XCTest/XCTest.h>
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/AnyTest.pbobjc.h"
+
+// Nanosecond time accuracy
+static const NSTimeInterval kTimeAccuracy = 1e-9;
+
+@interface WellKnownTypesTest : XCTestCase
+@end
+
+@implementation WellKnownTypesTest
+
+- (void)testTimeStamp {
+ // Test negative and positive values.
+ NSTimeInterval values[] = {
+ -428027599.483999967, -1234567.0, -0.5, 0, 0.75, 54321.0, 2468086,483999967
+ };
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ NSTimeInterval value = values[i];
+
+ // Test Creation - date.
+ NSDate *date = [NSDate dateWithTimeIntervalSince1970:value];
+ GPBTimestamp *timeStamp = [[GPBTimestamp alloc] initWithDate:date];
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ // Comparing timeIntervals instead of directly comparing dates because date
+ // equality requires the time intervals to be exactly the same, and the
+ // timeintervals go through a bit of floating point error as they are
+ // converted back and forth from the internal representation.
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Creation - timeIntervalSince1970.
+ timeStamp = [[GPBTimestamp alloc] initWithTimeIntervalSince1970:value];
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Mutation - date.
+ timeStamp = [[GPBTimestamp alloc] init];
+ timeStamp.date = date;
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Mutation - timeIntervalSince1970.
+ timeStamp = [[GPBTimestamp alloc] init];
+ timeStamp.timeIntervalSince1970 = value;
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ [timeStamp release];
+ }
+}
+
+- (void)testDuration {
+ // Test negative and positive values.
+ NSTimeInterval values[] = { -1000.0001, -500.0, -0.5, 0, 0.75, 1000.0, 2000.0002 };
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ NSTimeInterval value = values[i];
+
+ // Test Creation.
+ GPBDuration *duration =
+ [[GPBDuration alloc] initWithTimeInterval:value];
+ XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy,
+ @"For interval %f", (double)value);
+ if (value > 0) {
+ XCTAssertGreaterThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertGreaterThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ } else {
+ XCTAssertLessThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertLessThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ }
+ [duration release];
+
+ // Test Mutation.
+ duration = [[GPBDuration alloc] init];
+ duration.timeInterval = value;
+ XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy,
+ @"For interval %f", (double)value);
+ if (value > 0) {
+ XCTAssertGreaterThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertGreaterThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ } else {
+ XCTAssertLessThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertLessThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ }
+ [duration release];
+ }
+}
+
+- (void)testAnyHelpers {
+
+ // Set and extract covers most of the code.
+
+ TestAny *subMessage = [TestAny message];
+ subMessage.int32Value = 12345;
+ TestAny *message = [TestAny message];
+ NSError *err = nil;
+ message.anyValue = [GPBAny anyWithMessage:subMessage error:&err];
+ XCTAssertNil(err);
+
+ NSData *data = message.data;
+ XCTAssertNotNil(data);
+
+ TestAny *message2 = [TestAny parseFromData:data error:&err];
+ XCTAssertNil(err);
+ XCTAssertNotNil(message2);
+ XCTAssertTrue(message2.hasAnyValue);
+
+ TestAny *subMessage2 =
+ (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
+ error:&err];
+ XCTAssertNil(err);
+ XCTAssertNotNil(subMessage2);
+ XCTAssertEqual(subMessage2.int32Value, 12345);
+
+ // NULL errorPtr in the two calls.
+
+ message.anyValue = [GPBAny anyWithMessage:subMessage error:NULL];
+ NSData *data2 = message.data;
+ XCTAssertEqualObjects(data2, data);
+
+ TestAny *subMessage3 =
+ (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
+ error:NULL];
+ XCTAssertNotNil(subMessage3);
+ XCTAssertEqualObjects(subMessage2, subMessage3);
+
+ // Try to extract wrong type.
+
+ GPBTimestamp *wrongMessage =
+ (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
+ error:&err];
+ XCTAssertNotNil(err);
+ XCTAssertNil(wrongMessage);
+ XCTAssertEqualObjects(err.domain, GPBWellKnownTypesErrorDomain);
+ XCTAssertEqual(err.code, GPBWellKnownTypesErrorCodeTypeURLMismatch);
+
+ wrongMessage =
+ (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
+ error:NULL];
+ XCTAssertNil(wrongMessage);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m b/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m
new file mode 100644
index 0000000000..dbeab21564
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m
@@ -0,0 +1,258 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedInputStream.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestMset.pbobjc.h"
+#import "google/protobuf/UnittestMsetWireFormat.pbobjc.h"
+
+@interface WireFormatTests : GPBTestCase
+@end
+
+@implementation WireFormatTests
+
+- (void)testSerialization {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
+
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializationPacked {
+ TestPackedTypes* message =
+ [self packedSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestPackedTypes* message2 =
+ [TestPackedTypes parseFromData:rawBytes error:NULL];
+
+ [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializeExtensions {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serealize a TestAllExtensions then parse it as TestAllTypes
+ // it should work.
+
+ TestAllExtensions* message =
+ [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
+
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializePackedExtensions {
+ // TestPackedTypes and TestPackedExtensions should have compatible wire
+ // formats; check that they serialize to the same string.
+ TestPackedExtensions* message =
+ [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ TestPackedTypes* message2 =
+ [self packedSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes2 = message2.data;
+
+ XCTAssertEqualObjects(rawBytes, rawBytes2);
+}
+
+- (void)testParseExtensions {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllTypes then parse it as TestAllExtensions
+ // it should work.
+
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ GPBExtensionRegistry* registry = [self extensionRegistry];
+
+ TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
+
+ [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+
+- (void)testExtensionsSerializedSize {
+ size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize;
+ size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize;
+ XCTAssertEqual(allSet, extensionSet);
+}
+
+- (void)testParsePackedExtensions {
+ // Ensure that packed extensions can be properly parsed.
+ TestPackedExtensions* message =
+ [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ GPBExtensionRegistry* registry = [self extensionRegistry];
+
+ TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
+
+ [self assertPackedExtensionsSet:message2
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+const int kUnknownTypeId = 1550055;
+
+- (void)testSerializeMessageSet {
+ // Set up a TestMessageSet with two known messages and an unknown one.
+ TestMessageSet* message_set = [TestMessageSet message];
+ [[message_set getExtension:[TestMessageSetExtension1 messageSetExtension]]
+ setI:123];
+ [[message_set getExtension:[TestMessageSetExtension2 messageSetExtension]]
+ setStr:@"foo"];
+ GPBUnknownField* unknownField =
+ [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease];
+ [unknownField addLengthDelimited:[NSData dataWithBytes:"bar" length:3]];
+ GPBUnknownFieldSet* unknownFieldSet =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknownFieldSet addField:unknownField];
+ [message_set setUnknownFields:unknownFieldSet];
+
+ NSData* data = [message_set data];
+
+ // Parse back using RawMessageSet and check the contents.
+ RawMessageSet* raw = [RawMessageSet parseFromData:data error:NULL];
+
+ XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0);
+
+ XCTAssertEqual(raw.itemArray.count, (NSUInteger)3);
+ XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId],
+ [TestMessageSetExtension1 messageSetExtension].fieldNumber);
+ XCTAssertEqual((uint32_t)[raw.itemArray[1] typeId],
+ [TestMessageSetExtension2 messageSetExtension].fieldNumber);
+ XCTAssertEqual([raw.itemArray[2] typeId], kUnknownTypeId);
+
+ TestMessageSetExtension1* message1 =
+ [TestMessageSetExtension1 parseFromData:[((RawMessageSet_Item*)raw.itemArray[0]) message]
+ error:NULL];
+ XCTAssertEqual(message1.i, 123);
+
+ TestMessageSetExtension2* message2 =
+ [TestMessageSetExtension2 parseFromData:[((RawMessageSet_Item*)raw.itemArray[1]) message]
+ error:NULL];
+ XCTAssertEqualObjects(message2.str, @"foo");
+
+ XCTAssertEqualObjects([raw.itemArray[2] message],
+ [NSData dataWithBytes:"bar" length:3]);
+}
+
+- (void)testParseMessageSet {
+ // Set up a RawMessageSet with two known messages and an unknown one.
+ RawMessageSet* raw = [RawMessageSet message];
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = [TestMessageSetExtension1 messageSetExtension].fieldNumber;
+ TestMessageSetExtension1* message = [TestMessageSetExtension1 message];
+ message.i = 123;
+ item.message = [message data];
+ [raw.itemArray addObject:item];
+ }
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = [TestMessageSetExtension2 messageSetExtension].fieldNumber;
+ TestMessageSetExtension2* message = [TestMessageSetExtension2 message];
+ message.str = @"foo";
+ item.message = [message data];
+ [raw.itemArray addObject:item];
+ }
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = kUnknownTypeId;
+ item.message = [NSData dataWithBytes:"bar" length:3];
+ [raw.itemArray addObject:item];
+ }
+
+ NSData* data = [raw data];
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet* messageSet =
+ [TestMessageSet parseFromData:data
+ extensionRegistry:[UnittestMsetRoot extensionRegistry]
+ error:NULL];
+
+ XCTAssertEqual(
+ [[messageSet
+ getExtension:[TestMessageSetExtension1 messageSetExtension]] i],
+ 123);
+ XCTAssertEqualObjects(
+ [[messageSet
+ getExtension:[TestMessageSetExtension2 messageSetExtension]] str],
+ @"foo");
+
+ XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1);
+ GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId];
+ XCTAssertNotNil(unknownField);
+ XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1);
+ XCTAssertEqualObjects(unknownField.lengthDelimitedList[0],
+ [NSData dataWithBytes:"bar" length:3]);
+}
+
+- (void)assertFieldsInOrder:(NSData*)data {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ int32_t previousTag = 0;
+
+ while (YES) {
+ int32_t tag = [input readTag];
+ if (tag == 0) {
+ break;
+ }
+
+ XCTAssertGreaterThan(tag, previousTag);
+ [input skipField:tag];
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h b/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h
new file mode 100644
index 0000000000..46292fce73
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h
@@ -0,0 +1,6 @@
+//
+// Use this file to import your target's public headers that you would like to expose to Swift.
+//
+
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
diff --git a/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist b/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist
new file mode 100644
index 0000000000..460a7d931c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/golden_message b/third_party/protobuf/objectivec/Tests/golden_message
new file mode 100644
index 0000000000..7bceab4138
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/golden_message
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/golden_packed_fields_message b/third_party/protobuf/objectivec/Tests/golden_packed_fields_message
new file mode 100644
index 0000000000..7bceab4138
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/golden_packed_fields_message
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m b/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m
new file mode 100644
index 0000000000..8c4a586bbd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m
@@ -0,0 +1,35 @@
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+@property (strong, nonatomic) UIWindow *window;
+@end
+
+@implementation AppDelegate
+
+@synthesize window;
+
+- (BOOL)application:(UIApplication *)application
+ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ #pragma unused (application, launchOptions)
+
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.window.backgroundColor = [UIColor whiteColor];
+ [self.window makeKeyAndVisible];
+ self.window.rootViewController = [[UIViewController alloc] init];
+
+ UILabel *label =
+ [[UILabel alloc] initWithFrame:CGRectMake(0, 200, CGRectGetWidth(self.window.frame), 40)];
+ label.text = @"Protocol Buffer Test Harness";
+ label.textAlignment = NSTextAlignmentCenter;
+ [self.window addSubview:label];
+
+ return YES;
+}
+
+@end
+
+int main(int argc, char * argv[]) {
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..0cbf9acc1c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,116 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "size" : "57x57",
+ "idiom" : "iphone",
+ "filename" : "iPhone6.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "57x57",
+ "idiom" : "iphone",
+ "filename" : "iPhone6_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "iPhone7_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "iPhone7_3x.png",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "50x50",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "50x50",
+ "scale" : "2x"
+ },
+ {
+ "size" : "72x72",
+ "idiom" : "ipad",
+ "filename" : "iPad6.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "72x72",
+ "idiom" : "ipad",
+ "filename" : "iPad6_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "iPad7.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "iPad7_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "car",
+ "size" : "120x120",
+ "scale" : "1x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png
new file mode 100644
index 0000000000..43da2ee434
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png
new file mode 100644
index 0000000000..2ec93704ca
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png
new file mode 100644
index 0000000000..aec8bc1b1b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png
new file mode 100644
index 0000000000..e39cc3e754
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png
new file mode 100644
index 0000000000..5572d79f6f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png
new file mode 100644
index 0000000000..2424997f93
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png
new file mode 100644
index 0000000000..10bfc3cfae
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png
new file mode 100644
index 0000000000..8d16f14dcc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json
new file mode 100644
index 0000000000..5a2966687a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json
@@ -0,0 +1,49 @@
+{
+ "images" : [
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "1x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "iphone",
+ "minimum-system-version" : "7.0",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "iphone",
+ "minimum-system-version" : "7.0",
+ "subtype" : "retina4",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "1x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist
new file mode 100644
index 0000000000..24bd333d0b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ </array>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib b/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib
new file mode 100644
index 0000000000..22204bfe44
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
+ <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
+ </dependencies>
+ <objects>
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+ <view contentMode="scaleToFill" id="iN0-l3-epB">
+ <rect key="frame" x="0.0" y="0.0" width="630" height="503"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Protocol Buffer Test Harness" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
+ <rect key="frame" x="20" y="147" width="591" height="43"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ </subviews>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ <constraints>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="Kid-kn-2rF"/>
+ <constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
+ </constraints>
+ <nil key="simulatedStatusBarMetrics"/>
+ <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
+ <point key="canvasLocation" x="479" y="456.5"/>
+ </view>
+ </objects>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings b/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings
new file mode 100644
index 0000000000..477b28ff8f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git a/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt b/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt
new file mode 100644
index 0000000000..ad1195e2f9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt
@@ -0,0 +1,70 @@
+map_int32_int32 {
+ key: 100
+ value: 1
+}
+map_int64_int64 {
+ key: 101
+ value: 1
+}
+map_uint32_uint32 {
+ key: 102
+ value: 1
+}
+map_uint64_uint64 {
+ key: 103
+ value: 1
+}
+map_sint32_sint32 {
+ key: 104
+ value: 1
+}
+map_sint64_sint64 {
+ key: 105
+ value: 1
+}
+map_fixed32_fixed32 {
+ key: 106
+ value: 1
+}
+map_fixed64_fixed64 {
+ key: 107
+ value: 1
+}
+map_sfixed32_sfixed32 {
+ key: 108
+ value: 1
+}
+map_sfixed64_sfixed64 {
+ key: 109
+ value: 1
+}
+map_int32_float {
+ key: 110
+ value: 1
+}
+map_int32_double {
+ key: 111
+ value: 1
+}
+map_bool_bool {
+ key: true
+ value: false
+}
+map_string_string {
+ key: "112"
+ value: "1"
+}
+map_int32_bytes {
+ key: 113
+ value: "\001\000\000\000"
+}
+map_int32_enum {
+ key: 114
+ value: MAP_ENUM_BAZ
+}
+map_int32_foreign_message {
+ key: 115
+ value {
+ c: 1
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt b/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt
new file mode 100644
index 0000000000..d10f10006a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt
@@ -0,0 +1,116 @@
+optional_int32: 101
+optional_int64: 102
+optional_uint32: 103
+optional_uint64: 104
+optional_sint32: 105
+optional_sint64: 106
+optional_fixed32: 107
+optional_fixed64: 108
+optional_sfixed32: 109
+optional_sfixed64: 110
+optional_float: 111
+optional_double: 112
+optional_bool: true
+optional_string: "115"
+optional_bytes: "\001\000\002\003\000\005"
+OptionalGroup {
+ a: 117
+}
+optional_nested_message {
+ bb: 118
+}
+optional_foreign_message {
+ c: 119
+}
+optional_import_message {
+ d: 120
+}
+optional_nested_enum: BAZ
+optional_foreign_enum: FOREIGN_BAZ
+optional_import_enum: IMPORT_BAZ
+optional_string_piece: "124"
+optional_cord: "125"
+repeated_int32: 201
+repeated_int32: 301
+repeated_int64: 202
+repeated_int64: 302
+repeated_uint32: 203
+repeated_uint32: 303
+repeated_uint64: 204
+repeated_uint64: 304
+repeated_sint32: 205
+repeated_sint32: 305
+repeated_sint64: 206
+repeated_sint64: 306
+repeated_fixed32: 207
+repeated_fixed32: 307
+repeated_fixed64: 208
+repeated_fixed64: 308
+repeated_sfixed32: 209
+repeated_sfixed32: 309
+repeated_sfixed64: 210
+repeated_sfixed64: 310
+repeated_float: 211
+repeated_float: 311
+repeated_double: 212
+repeated_double: 312
+repeated_bool: false
+repeated_bool: true
+repeated_string: "215"
+repeated_string: "315"
+repeated_bytes: "\330\000\000\000"
+repeated_bytes: "<\001\000\000"
+RepeatedGroup {
+ a: 217
+}
+RepeatedGroup {
+ a: 317
+}
+repeated_nested_message {
+ bb: 218
+}
+repeated_nested_message {
+ bb: 318
+}
+repeated_foreign_message {
+ c: 219
+}
+repeated_foreign_message {
+ c: 319
+}
+repeated_import_message {
+ d: 220
+}
+repeated_import_message {
+ d: 320
+}
+repeated_nested_enum: BAZ
+repeated_nested_enum: BAR
+repeated_foreign_enum: FOREIGN_BAZ
+repeated_foreign_enum: FOREIGN_BAR
+repeated_import_enum: IMPORT_BAZ
+repeated_import_enum: IMPORT_BAR
+repeated_string_piece: "224"
+repeated_string_piece: "324"
+repeated_cord: "225"
+repeated_cord: "325"
+default_int32: 401
+default_int64: 402
+default_uint32: 403
+default_uint64: 404
+default_sint32: 405
+default_sint64: 406
+default_fixed32: 407
+default_fixed64: 408
+default_sfixed32: 409
+default_sfixed64: 410
+default_float: 411
+default_double: 412
+default_bool: false
+default_string: "415"
+default_bytes: "\240\001\000\000"
+default_nested_enum: FOO
+default_foreign_enum: FOREIGN_FOO
+default_import_enum: IMPORT_FOO
+default_string_piece: "424"
+default_cord: "425"
diff --git a/third_party/protobuf/objectivec/Tests/unittest_cycle.proto b/third_party/protobuf/objectivec/Tests/unittest_cycle.proto
new file mode 100644
index 0000000000..afc1b0fe27
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_cycle.proto
@@ -0,0 +1,56 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+// Cycles in the Message graph can cause problems for message class
+// initialization order.
+
+// You can't make a object graph that spans files, so this can only be done
+// within a single proto file.
+
+message CycleFoo {
+ optional CycleFoo a_foo = 1;
+ optional CycleBar a_bar = 2;
+ optional CycleBaz a_baz = 3;
+}
+
+message CycleBar {
+ optional CycleBar a_bar = 1;
+ optional CycleBaz a_baz = 2;
+ optional CycleFoo a_foo = 3;
+}
+
+message CycleBaz {
+ optional CycleBaz a_baz = 1;
+ optional CycleFoo a_foo = 2;
+ optional CycleBar a_bar = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto b/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto
new file mode 100644
index 0000000000..96a52bbbe2
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto
@@ -0,0 +1,95 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_deprecated;
+option objc_class_prefix = "Dep";
+
+//
+// This file is like unittest_deprecated_file.proto, but uses message, enum,
+// enum value, and field level deprecation.
+//
+// The source generated from this file needs to be inspect to confirm it has
+// all of the expected annotations. It also will be compiled into the unittest
+// and that compile should be clean without errors.
+//
+
+// Mix of field types marked as deprecated.
+message Msg1 {
+ extensions 100 to max;
+
+ optional string string_field = 1 [deprecated=true];
+ required int32 int_field = 2 [deprecated=true];
+ repeated fixed32 fixed_field = 3 [deprecated=true];
+ optional Msg1 msg_field = 4 [deprecated=true];
+}
+
+// Mix of extension field types marked as deprecated.
+extend Msg1 {
+ optional string string_ext_field = 101 [deprecated=true];
+ optional int32 int_ext_field = 102 [deprecated=true];
+ repeated fixed32 fixed_ext_field = 103 [deprecated=true];
+ optional Msg1 msg_ext_field = 104 [deprecated=true];
+}
+
+// Mix of extension field types (scoped to a message) marked as deprecated.
+message Msg1A {
+ extend Msg1 {
+ optional string string_ext2_field = 201 [deprecated=true];
+ optional int32 int_ext2_field = 202 [deprecated=true];
+ repeated fixed32 fixed_ext2_field = 203 [deprecated=true];
+ optional Msg1 msg_ext2_field = 204 [deprecated=true];
+ }
+}
+
+// Enum value marked as deprecated.
+enum Enum1 {
+ ENUM1_ONE = 1;
+ ENUM1_TWO = 2;
+ ENUM1_THREE = 3 [deprecated=true];
+}
+
+// Message marked as deprecated.
+message Msg2 {
+ option deprecated = true;
+
+ optional string string_field = 1;
+ required int32 int_field = 2;
+ repeated fixed32 fixed_field = 3;
+}
+
+// Enum marked as deprecated.
+enum Enum2 {
+ option deprecated = true;
+
+ ENUM2_ONE = 1;
+ ENUM2_TWO = 2;
+ ENUM2_THREE = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto b/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto
new file mode 100644
index 0000000000..ef92e7de1a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto
@@ -0,0 +1,76 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_deprecated_file;
+option objc_class_prefix = "FileDep";
+
+//
+// This file is like unittest_deprecated.proto, but does NOT use message, enum,
+// enum value, or field level deprecation; instead it uses the file level option
+// to mark everything.
+//
+// The source generated from this file needs to be inspect to confirm it has
+// all of the expected annotations. It also will be compiled into the unittest
+// and that compile should be clean without errors.
+//
+option deprecated = true;
+
+// Message to catch the deprecation.
+message Msg1 {
+ extensions 100 to max;
+
+ optional string string_field = 1;
+}
+
+// Mix of extension field types to catch the deprecation.
+extend Msg1 {
+ optional string string_ext_field = 101;
+ optional int32 int_ext_field = 102;
+ repeated fixed32 fixed_ext_field = 103;
+ optional Msg1 msg_ext_field = 104;
+}
+
+// Mix of extension field types (scoped to a message) to catch the deprecation.
+message Msg1A {
+ extend Msg1 {
+ optional string string_ext2_field = 201;
+ optional int32 int_ext2_field = 202;
+ repeated fixed32 fixed_ext2_field = 203;
+ optional Msg1 msg_ext2_field = 204;
+ }
+}
+
+// Enum to catch the deprecation.
+enum Enum1 {
+ ENUM1_ONE = 1;
+ ENUM1_TWO = 2;
+ ENUM1_THREE = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto
new file mode 100644
index 0000000000..6a227eb977
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_b.proto";
+import "unittest_extension_chain_c.proto";
+import "unittest_extension_chain_d.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from D's Root (unittest and C will come via D's).
+
+message ChainAMessage {
+ optional ChainBMessage b = 1;
+ optional ChainCMessage c = 2;
+ optional ChainDMessage d = 3;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_a_extension = 10001;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto
new file mode 100644
index 0000000000..0da7ed3e4c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto
@@ -0,0 +1,47 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_c.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from C's Root (unittest will come via C's).
+
+message ChainBMessage {
+ optional ChainCMessage c = 1;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_b_extension = 10002;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto
new file mode 100644
index 0000000000..c702900a4a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto
@@ -0,0 +1,45 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from unittest.proto's Root.
+
+message ChainCMessage {
+ optional int32 my_field = 1;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_c_extension = 10003;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto
new file mode 100644
index 0000000000..f9abe3ba59
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_b.proto";
+import "unittest_extension_chain_c.proto";
+
+// The root should end up needing to merge B (C will be merged into B, so it
+// doesn't need to be directly merged).
+
+message ChainDMessage {
+ optional ChainBMessage b = 1;
+ optional ChainCMessage c = 2;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_d_extension = 10004;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto
new file mode 100644
index 0000000000..fe11663180
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+// The Root for this file should end up just merging in unittest's Root.
+
+message ChainEMessage {
+ optional TestAllTypes my_field = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto
new file mode 100644
index 0000000000..b9bed7239b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto
@@ -0,0 +1,44 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "unittest_extension_chain_g.proto";
+
+// The Root for this file should just be merging in the extensions from C's
+// Root (because G doens't define anything itself).
+
+// The generated source will also have to directly import C's .h file so it can
+// compile the reference to C's Root class.
+
+message ChainFMessage {
+ optional ChainGMessage g = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto
new file mode 100644
index 0000000000..aee827b176
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto
@@ -0,0 +1,41 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "unittest_extension_chain_c.proto";
+
+// The Root for this file should just be merging in the extensions from C's
+// Root.
+
+message ChainGMessage {
+ optional ChainCMessage c = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_objc.proto b/third_party/protobuf/objectivec/Tests/unittest_objc.proto
new file mode 100644
index 0000000000..e5577faf0d
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_objc.proto
@@ -0,0 +1,467 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2011 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+import "google/protobuf/any.proto";
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+// Used to check that Headerdocs and appledoc work correctly. If these comments
+// are not handled correctly, Xcode will fail to build the tests.
+message TestGeneratedComments {
+ // This is a string that could contain stuff like
+ // mime types as image/* or */plain. Maybe twitter usernames
+ // like @protobuf, @google or @something.
+ optional string string_field = 1;
+}
+
+// Using the messages in unittest.proto, setup for recursive cases for testing
+// extensions at various depths.
+extend TestAllExtensions {
+ optional TestAllExtensions recursive_extension = 86;
+}
+
+// Recursive message to for testing autocreators at different depths.
+message TestRecursiveMessageWithRepeatedField {
+ optional TestRecursiveMessageWithRepeatedField a = 1;
+ repeated int32 i = 2;
+ repeated string str = 3;
+ map<int32, int32> i_to_i = 4;
+ map<string, string> str_to_str = 5;
+}
+
+// Recursive message and extension to for testing autocreators at different
+// depths.
+message TestRecursiveExtension {
+ optional TestRecursiveExtension recursive_sub_message = 1;
+ repeated int32 repeated_value = 2;
+ extensions 1000 to max;
+}
+
+extend TestRecursiveExtension {
+ optional TestRecursiveExtension recursive_message_extension = 1000;
+}
+
+message self {
+ message super {
+ optional int32 description = 1;
+ }
+
+ enum autorelease {
+ retain = 1;
+ release = 2;
+ retainCount = 3;
+ }
+
+ // Singular
+ optional bool id = 1;
+ optional bool _cmd = 2;
+ optional bool in = 3;
+ optional bool out = 4;
+ optional bool inout = 5;
+ optional bool bycopy = 6;
+ optional bool byref = 7;
+ optional bool oneway = 8;
+ optional bool dealloc = 9;
+ optional bool zone = 10;
+ optional bool isProxy = 11;
+ optional bool copy = 12;
+ optional bool readonly = 13;
+ optional bool default = 14;
+ optional bool assign = 15;
+ optional bool getter = 16;
+ optional bool setter = 17;
+ optional bool weak = 18;
+ optional bool public = 19;
+ optional bool case = 20;
+
+ optional autorelease SubEnum = 25;
+
+ optional group New = 50 {
+ optional string copy = 51;
+ }
+ optional group MutableCopy = 60 {
+ optional int32 extensionRegistry = 61;
+ }
+
+ extensions 90 to 94;
+
+}
+
+enum retain {
+ count = 4;
+ initialized = 5;
+ serializedSize = 6;
+}
+
+message ObjCPropertyNaming {
+ // Test that the properties properly get things all caps.
+ optional string url = 1;
+ optional string thumbnail_url = 2;
+ optional string url_foo = 3;
+ optional string some_url_blah = 4;
+ optional string http = 5;
+ optional string https = 6;
+ // This one doesn't.
+ repeated string urls = 7;
+}
+
+// EnumValueShortName: The short names shouldn't get suffixes/prefixes.
+enum Foo {
+ SERIALIZED_SIZE = 1;
+ SIZE = 2;
+ OTHER = 3;
+}
+
+// EnumValueShortName: The enum name gets a prefix.
+enum Category {
+ RED = 1;
+ BLUE = 2;
+}
+
+// EnumValueShortName: Twist case, full name gets PB, but the short names
+// should still end up correct.
+enum Time {
+ BASE = 1;
+ RECORD = 2;
+ SOMETHING_ELSE = 3;
+}
+
+extend self {
+ repeated int32 debugDescription = 90 [packed = true];
+ repeated int64 finalize = 91 [packed = true];
+ repeated uint32 hash = 92 [packed = true];
+ repeated uint64 classForCoder = 93 [packed = true];
+ repeated sint32 byref = 94 [packed = true];
+}
+
+// Test handing of fields that start with init* since Xcode 5's ARC support
+// doesn't like messages that look like initializers but aren't.
+message ObjCInitFoo {
+ optional string init_val = 11;
+ optional int32 init_size = 12;
+ optional self init_self = 13;
+
+ repeated string init_vals = 21;
+ repeated int32 init_sizes = 22;
+ repeated self init_selfs = 23;
+}
+
+// Test handling of fields that start with retained names.
+message ObjCRetainedFoo {
+ optional string new_val_lower_complex = 11;
+ optional string new_Val_upper_complex = 12;
+ optional string newvalue_lower_no_underscore_complex = 13;
+ optional string newValue_upper_no_underscore_complex = 14;
+
+ optional int32 new_val_lower_primitive = 15;
+ optional int32 new_Val_upper_primitive = 16;
+ optional int32 newvalue_lower_no_underscore_primitive = 17;
+ optional int32 newValue_upper_no_underscore_primitive = 18;
+
+ optional self new_val_lower_message = 19;
+ optional self new_Val_upper_message = 20;
+ optional self newvalue_lower_no_underscore_message = 21;
+ optional self newValue_upper_no_underscore_message = 22;
+
+ optional Foo new_val_lower_enum = 23;
+ optional Foo new_Val_upper_enum = 24;
+ optional Foo newvalue_lower_no_underscore_enum = 25;
+ optional Foo newValue_upper_no_underscore_enum = 26;
+
+ repeated string new_val_lower_complex_repeated = 111;
+ repeated string new_Val_upper_complex_repeated = 112;
+ repeated string newvalue_lower_no_underscore_complex_repeated = 113;
+ repeated string newValue_upper_no_underscore_complex_repeated = 114;
+
+ repeated int32 new_val_lower_primitive_repeated = 115;
+ repeated int32 new_Val_upper_primitive_repeated = 116;
+ repeated int32 newvalue_lower_no_underscore_primitive_repeated = 117;
+ repeated int32 newValue_upper_no_underscore_primitive_repeated = 118;
+
+ repeated self new_val_lower_message_repeated = 119;
+ repeated self new_Val_upper_message_repeated = 120;
+ repeated self newvalue_lower_no_underscore_message_repeated = 121;
+ repeated self newValue_upper_no_underscore_message_repeated = 122;
+
+ repeated Foo new_val_lower_enum_repeated = 123;
+ repeated Foo new_Val_upper_enum_repeated = 124;
+ repeated Foo newvalue_lower_no_underscore_enum_repeated = 125;
+ repeated Foo newValue_upper_no_underscore_enum_repeated = 126;
+
+ optional string alloc_val_lower_complex = 211;
+ optional string alloc_Val_upper_complex = 212;
+ optional string allocvalue_lower_no_underscore_complex = 213;
+ optional string allocValue_upper_no_underscore_complex = 214;
+
+ optional int32 alloc_val_lower_primitive = 215;
+ optional int32 alloc_Val_upper_primitive = 216;
+ optional int32 allocvalue_lower_no_underscore_primitive = 217;
+ optional int32 allocValue_upper_no_underscore_primitive = 218;
+
+ optional self alloc_val_lower_message = 219;
+ optional self alloc_Val_upper_message = 220;
+ optional self allocvalue_lower_no_underscore_message = 221;
+ optional self allocValue_upper_no_underscore_message = 222;
+
+ optional Foo alloc_val_lower_enum = 223;
+ optional Foo alloc_Val_upper_enum = 224;
+ optional Foo allocvalue_lower_no_underscore_enum = 225;
+ optional Foo allocValue_upper_no_underscore_enum = 226;
+
+ repeated string alloc_val_lower_complex_repeated = 311;
+ repeated string alloc_Val_upper_complex_repeated = 312;
+ repeated string allocvalue_lower_no_underscore_complex_repeated = 313;
+ repeated string allocValue_upper_no_underscore_complex_repeated = 314;
+
+ repeated int32 alloc_val_lower_primitive_repeated = 315;
+ repeated int32 alloc_Val_upper_primitive_repeated = 316;
+ repeated int32 allocvalue_lower_no_underscore_primitive_repeated = 317;
+ repeated int32 allocValue_upper_no_underscore_primitive_repeated = 318;
+
+ repeated self alloc_val_lower_message_repeated = 319;
+ repeated self alloc_Val_upper_message_repeated = 320;
+ repeated self allocvalue_lower_no_underscore_message_repeated = 321;
+ repeated self allocValue_upper_no_underscore_message_repeated = 322;
+
+ repeated Foo alloc_val_lower_enum_repeated = 323;
+ repeated Foo alloc_Val_upper_enum_repeated = 324;
+ repeated Foo allocvalue_lower_no_underscore_enum_repeated = 325;
+ repeated Foo allocValue_upper_no_underscore_enum_repeated = 326;
+
+ optional string copy_val_lower_complex = 411;
+ optional string copy_Val_upper_complex = 412;
+ optional string copyvalue_lower_no_underscore_complex = 413;
+ optional string copyValue_upper_no_underscore_complex = 414;
+
+ optional int32 copy_val_lower_primitive = 415;
+ optional int32 copy_Val_upper_primitive = 416;
+ optional int32 copyvalue_lower_no_underscore_primitive = 417;
+ optional int32 copyValue_upper_no_underscore_primitive = 418;
+
+ optional self copy_val_lower_message = 419;
+ optional self copy_Val_upper_message = 420;
+ optional self copyvalue_lower_no_underscore_message = 421;
+ optional self copyValue_upper_no_underscore_message = 422;
+
+ optional Foo copy_val_lower_enum = 423;
+ optional Foo copy_Val_upper_enum = 424;
+ optional Foo copyvalue_lower_no_underscore_enum = 425;
+ optional Foo copyValue_upper_no_underscore_enum = 426;
+
+ repeated string copy_val_lower_complex_repeated = 511;
+ repeated string copy_Val_upper_complex_repeated = 512;
+ repeated string copyvalue_lower_no_underscore_complex_repeated = 513;
+ repeated string copyValue_upper_no_underscore_complex_repeated = 514;
+
+ repeated int32 copy_val_lower_primitive_repeated = 515;
+ repeated int32 copy_Val_upper_primitive_repeated = 516;
+ repeated int32 copyvalue_lower_no_underscore_primitive_repeated = 517;
+ repeated int32 copyValue_upper_no_underscore_primitive_repeated = 518;
+
+ repeated self copy_val_lower_message_repeated = 519;
+ repeated self copy_Val_upper_message_repeated = 520;
+ repeated self copyvalue_lower_no_underscore_message_repeated = 521;
+ repeated self copyValue_upper_no_underscore_message_repeated = 522;
+
+ repeated Foo copy_val_lower_enum_repeated = 523;
+ repeated Foo copy_Val_upper_enum_repeated = 524;
+ repeated Foo copyvalue_lower_no_underscore_enum_repeated = 525;
+ repeated Foo copyValue_upper_no_underscore_enum_repeated = 526;
+
+ optional string mutableCopy_val_lower_complex = 611;
+ optional string mutableCopy_Val_upper_complex = 612;
+ optional string mutableCopyvalue_lower_no_underscore_complex = 613;
+ optional string mutableCopyValue_upper_no_underscore_complex = 614;
+
+ optional int32 mutableCopy_val_lower_primitive = 615;
+ optional int32 mutableCopy_Val_upper_primitive = 616;
+ optional int32 mutableCopyvalue_lower_no_underscore_primitive = 617;
+ optional int32 mutableCopyValue_upper_no_underscore_primitive = 618;
+
+ optional self mutableCopy_val_lower_message = 619;
+ optional self mutableCopy_Val_upper_message = 620;
+ optional self mutableCopyvalue_lower_no_underscore_message = 621;
+ optional self mutableCopyValue_upper_no_underscore_message = 622;
+
+ optional Foo mutableCopy_val_lower_enum = 623;
+ optional Foo mutableCopy_Val_upper_enum = 624;
+ optional Foo mutableCopyvalue_lower_no_underscore_enum = 625;
+ optional Foo mutableCopyValue_upper_no_underscore_enum = 626;
+
+ repeated string mutableCopy_val_lower_complex_repeated = 711;
+ repeated string mutableCopy_Val_upper_complex_repeated = 712;
+ repeated string mutableCopyvalue_lower_no_underscore_complex_repeated = 713;
+ repeated string mutableCopyValue_upper_no_underscore_complex_repeated = 714;
+
+ repeated int32 mutableCopy_val_lower_primitive_repeated = 715;
+ repeated int32 mutableCopy_Val_upper_primitive_repeated = 716;
+ repeated int32 mutableCopyvalue_lower_no_underscore_primitive_repeated = 717;
+ repeated int32 mutableCopyValue_upper_no_underscore_primitive_repeated = 718;
+
+ repeated self mutableCopy_val_lower_message_repeated = 719;
+ repeated self mutableCopy_Val_upper_message_repeated = 720;
+ repeated self mutableCopyvalue_lower_no_underscore_message_repeated = 721;
+ repeated self mutableCopyValue_upper_no_underscore_message_repeated = 722;
+
+ repeated Foo mutableCopy_val_lower_enum_repeated = 723;
+ repeated Foo mutableCopy_Val_upper_enum_repeated = 724;
+ repeated Foo mutableCopyvalue_lower_no_underscore_enum_repeated = 725;
+ repeated Foo mutableCopyValue_upper_no_underscore_enum_repeated = 726;
+}
+
+// Test handling of fields that are the retained names.
+message ObjCRetainedComplex {
+ optional string new = 1;
+ optional string alloc = 2;
+ optional string copy = 3;
+ optional string mutableCopy = 4;
+}
+
+message ObjCRetainedComplexRepeated {
+ repeated string new = 1;
+ repeated string alloc = 2;
+ repeated string copy = 3;
+ repeated string mutableCopy = 4;
+}
+
+message ObjCRetainedPrimitive {
+ optional int32 new = 1;
+ optional int32 alloc = 2;
+ optional int32 copy = 3;
+ optional int32 mutableCopy = 4;
+}
+
+message ObjCRetainedPrimitiveRepeated {
+ repeated int32 new = 1;
+ repeated int32 alloc = 2;
+ repeated int32 copy = 3;
+ repeated int32 mutableCopy = 4;
+}
+
+message ObjCRetainedMessage {
+ optional self new = 1;
+ optional self alloc = 2;
+ optional self copy = 3;
+ optional self mutableCopy = 4;
+}
+
+message ObjCRetainedMessageRepeated {
+ repeated self new = 1;
+ repeated self alloc = 2;
+ repeated self copy = 3;
+ repeated self mutableCopy = 4;
+}
+
+// Test Handling some MacTypes
+message Point {
+ message Rect {
+ optional int32 TimeValue = 1;
+ }
+}
+
+// Test some weird defaults that we see in protos.
+message ObjcWeirdDefaults {
+ // Set default values that match the protocol buffer defined defaults to
+ // confirm hasDefault and the default values are set correctly.
+ optional string foo = 1 [default = ""];
+ optional bytes bar = 2 [default = ""];
+}
+
+// Used to confirm negative enum values work as expected.
+message EnumTestMsg {
+ enum MyEnum {
+ ZERO = 0;
+ ONE = 1;
+ TWO = 2;
+ NEG_ONE = -1;
+ NEG_TWO = -2;
+ }
+ optional MyEnum foo = 1;
+ optional MyEnum bar = 2 [default = ONE];
+ optional MyEnum baz = 3 [default = NEG_ONE];
+
+ repeated MyEnum mumble = 4;
+}
+
+// Test case for https://github.com/google/protobuf/issues/1453
+// Message with no explicit defaults, but a non zero default for an enum.
+message MessageWithOneBasedEnum {
+ enum OneBasedEnum {
+ ONE = 1;
+ TWO = 2;
+ }
+ optional OneBasedEnum enum_field = 1;
+}
+
+// Message with all bools for testing things related to bool storage.
+message BoolOnlyMessage {
+ optional bool bool_field_1 = 1;
+ optional bool bool_field_2 = 2;
+ optional bool bool_field_3 = 3;
+ optional bool bool_field_4 = 4;
+ optional bool bool_field_5 = 5;
+ optional bool bool_field_6 = 6;
+ optional bool bool_field_7 = 7;
+ optional bool bool_field_8 = 8;
+ optional bool bool_field_9 = 9;
+ optional bool bool_field_10 = 10;
+ optional bool bool_field_11 = 11;
+ optional bool bool_field_12 = 12;
+ optional bool bool_field_13 = 13;
+ optional bool bool_field_14 = 14;
+ optional bool bool_field_15 = 15;
+ optional bool bool_field_16 = 16;
+ optional bool bool_field_17 = 17;
+ optional bool bool_field_18 = 18;
+ optional bool bool_field_19 = 19;
+ optional bool bool_field_20 = 20;
+ optional bool bool_field_21 = 21;
+ optional bool bool_field_22 = 22;
+ optional bool bool_field_23 = 23;
+ optional bool bool_field_24 = 24;
+ optional bool bool_field_25 = 25;
+ optional bool bool_field_26 = 26;
+ optional bool bool_field_27 = 27;
+ optional bool bool_field_28 = 28;
+ optional bool bool_field_29 = 29;
+ optional bool bool_field_30 = 30;
+ optional bool bool_field_31 = 31;
+ optional bool bool_field_32 = 32;
+}
+
+// Reference to a WKT to test (via generated code inspection), the handling
+// of #imports. Within the WKTs, references to each other are just path
+// based imports, but when reference from another proto file, they should be
+// conditional to support the framework import style.
+message WKTRefereceMessage {
+ optional google.protobuf.Any an_any = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto b/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto
new file mode 100644
index 0000000000..aee7bd556b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_objc_unittest;
+
+message TestObjCStartupMessage {
+ extensions 1 to max;
+}
+
+extend TestObjCStartupMessage {
+ // Singular
+ optional int32 optional_int32_extension = 1;
+ repeated int32 repeated_int32_extension = 2;
+}
+
+message TestObjCStartupNested {
+ extend TestObjCStartupMessage {
+ optional string nested_string_extension = 3;
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto
new file mode 100644
index 0000000000..ed835020af
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto
@@ -0,0 +1,128 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+message Message2 {
+ enum Enum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ EXTRA_2 = 20;
+ }
+
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+ optional Message2 optional_message = 18;
+ optional Enum optional_enum = 19;
+
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+ repeated Message2 repeated_message = 48;
+ repeated Enum repeated_enum = 49;
+
+ oneof o {
+ int32 oneof_int32 = 51 [default = 100];
+ int64 oneof_int64 = 52 [default = 101];
+ uint32 oneof_uint32 = 53 [default = 102];
+ uint64 oneof_uint64 = 54 [default = 103];
+ sint32 oneof_sint32 = 55 [default = 104];
+ sint64 oneof_sint64 = 56 [default = 105];
+ fixed32 oneof_fixed32 = 57 [default = 106];
+ fixed64 oneof_fixed64 = 58 [default = 107];
+ sfixed32 oneof_sfixed32 = 59 [default = 108];
+ sfixed64 oneof_sfixed64 = 60 [default = 109];
+ float oneof_float = 61 [default = 110];
+ double oneof_double = 62 [default = 111];
+ bool oneof_bool = 63 [default = true];
+ string oneof_string = 64 [default = "string"];
+ bytes oneof_bytes = 65 [default = "data"];
+ group OneofGroup = 66 {
+ optional int32 a = 67;
+ optional int32 b = 167;
+ }
+ Message2 oneof_message = 68;
+ Enum oneof_enum = 69 [default = BAZ];
+ }
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message2> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message2> map_int32_message = 88;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto
new file mode 100644
index 0000000000..ad2e3620d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto
@@ -0,0 +1,121 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+package protobuf_unittest;
+
+message Message3 {
+ enum Enum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ EXTRA_3 = 30;
+ }
+
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+ // No 'group' in proto3.
+ Message3 optional_message = 18;
+ Enum optional_enum = 19;
+
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+ // No 'group' in proto3.
+ repeated Message3 repeated_message = 48;
+ repeated Enum repeated_enum = 49;
+
+ oneof o {
+ int32 oneof_int32 = 51;
+ int64 oneof_int64 = 52;
+ uint32 oneof_uint32 = 53;
+ uint64 oneof_uint64 = 54;
+ sint32 oneof_sint32 = 55;
+ sint64 oneof_sint64 = 56;
+ fixed32 oneof_fixed32 = 57;
+ fixed64 oneof_fixed64 = 58;
+ sfixed32 oneof_sfixed32 = 59;
+ sfixed64 oneof_sfixed64 = 60;
+ float oneof_float = 61;
+ double oneof_double = 62;
+ bool oneof_bool = 63;
+ string oneof_string = 64;
+ bytes oneof_bytes = 65;
+ // No 'group' in proto3.
+ Message3 oneof_message = 68;
+ Enum oneof_enum = 69;
+ }
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message3> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message3> map_int32_message = 88;
+}
diff --git a/third_party/protobuf/objectivec/generate_well_known_types.sh b/third_party/protobuf/objectivec/generate_well_known_types.sh
new file mode 100755
index 0000000000..36c346031c
--- /dev/null
+++ b/third_party/protobuf/objectivec/generate_well_known_types.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Run this script to regenerate *.pbobjc.{h,m} for the well known types after
+# the protocol compiler changes.
+
+# HINT: Flags passed to generate_well_known_types.sh will be passed directly
+# to make when building protoc. This is particularly useful for passing
+# -j4 to run 4 jobs simultaneously.
+
+set -eu
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/.."
+
+# Flag for continuous integration to check that everything is current.
+CHECK_ONLY=0
+if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then
+ CHECK_ONLY=1
+ shift
+fi
+
+pushd "${ProtoRootDir}" > /dev/null
+
+if test ! -e src/google/protobuf/stubs/common.h; then
+ cat >&2 << __EOF__
+Could not find source code. Make sure you are running this script from the
+root of the distribution tree.
+__EOF__
+ exit 1
+fi
+
+if test ! -e src/Makefile; then
+ cat >&2 << __EOF__
+Could not find src/Makefile. You must run ./configure (and perhaps
+./autogen.sh) first.
+__EOF__
+ exit 1
+fi
+
+# Make sure the compiler is current.
+cd src
+make $@ protoc
+
+declare -a RUNTIME_PROTO_FILES=( \
+ google/protobuf/any.proto \
+ google/protobuf/api.proto \
+ google/protobuf/duration.proto \
+ google/protobuf/empty.proto \
+ google/protobuf/field_mask.proto \
+ google/protobuf/source_context.proto \
+ google/protobuf/struct.proto \
+ google/protobuf/timestamp.proto \
+ google/protobuf/type.proto \
+ google/protobuf/wrappers.proto)
+
+# Generate to a temp directory to see if they match.
+TMP_DIR=$(mktemp -d)
+trap "rm -rf ${TMP_DIR}" EXIT
+./protoc --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]}
+set +e
+diff -r "${TMP_DIR}/google" "${ProtoRootDir}/objectivec/google" > /dev/null
+if [[ $? -eq 0 ]] ; then
+ echo "Generated source for WellKnownTypes is current."
+ exit 0
+fi
+set -e
+
+# If check only mode, error out.
+if [[ "${CHECK_ONLY}" == 1 ]] ; then
+ echo "ERROR: The WKTs need to be regenerated! Run $0"
+ exit 1
+fi
+
+# Copy them over.
+echo "Copying over updated WellKnownType sources."
+cp -r "${TMP_DIR}/google/." "${ProtoRootDir}/objectivec/google/"
diff --git a/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h
new file mode 100644
index 0000000000..d236e4b20e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h
@@ -0,0 +1,163 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/any.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBAnyRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBAnyRoot : GPBRootObject
+@end
+
+#pragma mark - GPBAny
+
+typedef GPB_ENUM(GPBAny_FieldNumber) {
+ GPBAny_FieldNumber_TypeURL = 1,
+ GPBAny_FieldNumber_Value = 2,
+};
+
+/**
+ * `Any` contains an arbitrary serialized protocol buffer message along with a
+ * URL that describes the type of the serialized message.
+ *
+ * Protobuf library provides support to pack/unpack Any values in the form
+ * of utility functions or additional generated methods of the Any type.
+ *
+ * Example 1: Pack and unpack a message in C++.
+ *
+ * Foo foo = ...;
+ * Any any;
+ * any.PackFrom(foo);
+ * ...
+ * if (any.UnpackTo(&foo)) {
+ * ...
+ * }
+ *
+ * Example 2: Pack and unpack a message in Java.
+ *
+ * Foo foo = ...;
+ * Any any = Any.pack(foo);
+ * ...
+ * if (any.is(Foo.class)) {
+ * foo = any.unpack(Foo.class);
+ * }
+ *
+ * Example 3: Pack and unpack a message in Python.
+ *
+ * foo = Foo(...)
+ * any = Any()
+ * any.Pack(foo)
+ * ...
+ * if any.Is(Foo.DESCRIPTOR):
+ * any.Unpack(foo)
+ * ...
+ *
+ * The pack methods provided by protobuf library will by default use
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
+ * methods only use the fully qualified type name after the last '/'
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
+ * name "y.z".
+ *
+ *
+ * JSON
+ * ====
+ * The JSON representation of an `Any` value uses the regular
+ * representation of the deserialized, embedded message, with an
+ * additional field `\@type` which contains the type URL. Example:
+ *
+ * package google.profile;
+ * message Person {
+ * string first_name = 1;
+ * string last_name = 2;
+ * }
+ *
+ * {
+ * "\@type": "type.googleapis.com/google.profile.Person",
+ * "firstName": <string>,
+ * "lastName": <string>
+ * }
+ *
+ * If the embedded message type is well-known and has a custom JSON
+ * representation, that representation will be embedded adding a field
+ * `value` which holds the custom JSON in addition to the `\@type`
+ * field. Example (for message [google.protobuf.Duration][]):
+ *
+ * {
+ * "\@type": "type.googleapis.com/google.protobuf.Duration",
+ * "value": "1.212s"
+ * }
+ **/
+@interface GPBAny : GPBMessage
+
+/**
+ * A URL/resource name whose content describes the type of the
+ * serialized protocol buffer message.
+ *
+ * For URLs which use the scheme `http`, `https`, or no scheme, the
+ * following restrictions and interpretations apply:
+ *
+ * * If no scheme is provided, `https` is assumed.
+ * * The last segment of the URL's path must represent the fully
+ * qualified name of the type (as in `path/google.protobuf.Duration`).
+ * The name should be in a canonical form (e.g., leading "." is
+ * not accepted).
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+ * value in binary format, or produce an error.
+ * * Applications are allowed to cache lookup results based on the
+ * URL, or have them precompiled into a binary to avoid any
+ * lookup. Therefore, binary compatibility needs to be preserved
+ * on changes to types. (Use versioned type names to manage
+ * breaking changes.)
+ *
+ * Schemes other than `http`, `https` (or the empty scheme) might be
+ * used with implementation specific semantics.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
+
+/** Must be a valid serialized protocol buffer of the above specified type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m
new file mode 100644
index 0000000000..d210643f05
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m
@@ -0,0 +1,112 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/any.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBAnyRoot
+
+@implementation GPBAnyRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBAnyRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBAnyRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBAny
+
+@implementation GPBAny
+
+@dynamic typeURL;
+@dynamic value;
+
+typedef struct GPBAny__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *typeURL;
+ NSData *value;
+} GPBAny__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "typeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBAny_FieldNumber_TypeURL,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBAny__storage_, typeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBAny_FieldNumber_Value,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBAny__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBytes,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBAny class]
+ rootClass:[GPBAnyRoot class]
+ file:GPBAnyRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBAny__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\001\001\004\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h
new file mode 100644
index 0000000000..742a812211
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h
@@ -0,0 +1,299 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/api.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBMethod;
+@class GPBMixin;
+@class GPBOption;
+@class GPBSourceContext;
+GPB_ENUM_FWD_DECLARE(GPBSyntax);
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBApiRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBApiRoot : GPBRootObject
+@end
+
+#pragma mark - GPBApi
+
+typedef GPB_ENUM(GPBApi_FieldNumber) {
+ GPBApi_FieldNumber_Name = 1,
+ GPBApi_FieldNumber_MethodsArray = 2,
+ GPBApi_FieldNumber_OptionsArray = 3,
+ GPBApi_FieldNumber_Version = 4,
+ GPBApi_FieldNumber_SourceContext = 5,
+ GPBApi_FieldNumber_MixinsArray = 6,
+ GPBApi_FieldNumber_Syntax = 7,
+};
+
+/**
+ * Api is a light-weight descriptor for a protocol buffer service.
+ **/
+@interface GPBApi : GPBMessage
+
+/**
+ * The fully qualified name of this api, including package name
+ * followed by the api's simple name.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** The methods of this api, in unspecified order. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMethod*> *methodsArray;
+/** The number of items in @c methodsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger methodsArray_Count;
+
+/** Any metadata attached to the API. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/**
+ * A version string for this api. If specified, must have the form
+ * `major-version.minor-version`, as in `1.10`. If the minor version
+ * is omitted, it defaults to zero. If the entire version field is
+ * empty, the major version is derived from the package name, as
+ * outlined below. If the field is not empty, the version in the
+ * package name will be verified to be consistent with what is
+ * provided here.
+ *
+ * The versioning schema uses [semantic
+ * versioning](http://semver.org) where the major version number
+ * indicates a breaking change and the minor version an additive,
+ * non-breaking change. Both version numbers are signals to users
+ * what to expect from different versions, and should be carefully
+ * chosen based on the product plan.
+ *
+ * The major version is also reflected in the package name of the
+ * API, which must end in `v<major-version>`, as in
+ * `google.feature.v1`. For major versions 0 and 1, the suffix can
+ * be omitted. Zero major versions must only be used for
+ * experimental, none-GA apis.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *version;
+
+/**
+ * Source context for the protocol buffer service represented by this
+ * message.
+ **/
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** Included APIs. See [Mixin][]. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMixin*> *mixinsArray;
+/** The number of items in @c mixinsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger mixinsArray_Count;
+
+/** The source syntax of the service. */
+@property(nonatomic, readwrite) enum GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBApi's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBApi_Syntax_RawValue(GPBApi *message);
+/**
+ * Sets the raw value of an @c GPBApi's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBApi_Syntax_RawValue(GPBApi *message, int32_t value);
+
+#pragma mark - GPBMethod
+
+typedef GPB_ENUM(GPBMethod_FieldNumber) {
+ GPBMethod_FieldNumber_Name = 1,
+ GPBMethod_FieldNumber_RequestTypeURL = 2,
+ GPBMethod_FieldNumber_RequestStreaming = 3,
+ GPBMethod_FieldNumber_ResponseTypeURL = 4,
+ GPBMethod_FieldNumber_ResponseStreaming = 5,
+ GPBMethod_FieldNumber_OptionsArray = 6,
+ GPBMethod_FieldNumber_Syntax = 7,
+};
+
+/**
+ * Method represents a method of an api.
+ **/
+@interface GPBMethod : GPBMessage
+
+/** The simple name of this method. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** A URL of the input message type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *requestTypeURL;
+
+/** If true, the request is streamed. */
+@property(nonatomic, readwrite) BOOL requestStreaming;
+
+/** The URL of the output message type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *responseTypeURL;
+
+/** If true, the response is streamed. */
+@property(nonatomic, readwrite) BOOL responseStreaming;
+
+/** Any metadata attached to the method. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source syntax of this method. */
+@property(nonatomic, readwrite) enum GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBMethod's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBMethod_Syntax_RawValue(GPBMethod *message);
+/**
+ * Sets the raw value of an @c GPBMethod's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBMethod_Syntax_RawValue(GPBMethod *message, int32_t value);
+
+#pragma mark - GPBMixin
+
+typedef GPB_ENUM(GPBMixin_FieldNumber) {
+ GPBMixin_FieldNumber_Name = 1,
+ GPBMixin_FieldNumber_Root = 2,
+};
+
+/**
+ * Declares an API to be included in this API. The including API must
+ * redeclare all the methods from the included API, but documentation
+ * and options are inherited as follows:
+ *
+ * - If after comment and whitespace stripping, the documentation
+ * string of the redeclared method is empty, it will be inherited
+ * from the original method.
+ *
+ * - Each annotation belonging to the service config (http,
+ * visibility) which is not set in the redeclared method will be
+ * inherited.
+ *
+ * - If an http annotation is inherited, the path pattern will be
+ * modified as follows. Any version prefix will be replaced by the
+ * version of the including API plus the [root][] path if specified.
+ *
+ * Example of a simple mixin:
+ *
+ * package google.acl.v1;
+ * service AccessControl {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v1/{resource=**}:getAcl";
+ * }
+ * }
+ *
+ * package google.storage.v2;
+ * service Storage {
+ * rpc GetAcl(GetAclRequest) returns (Acl);
+ *
+ * // Get a data record.
+ * rpc GetData(GetDataRequest) returns (Data) {
+ * option (google.api.http).get = "/v2/{resource=**}";
+ * }
+ * }
+ *
+ * Example of a mixin configuration:
+ *
+ * apis:
+ * - name: google.storage.v2.Storage
+ * mixins:
+ * - name: google.acl.v1.AccessControl
+ *
+ * The mixin construct implies that all methods in `AccessControl` are
+ * also declared with same name and request/response types in
+ * `Storage`. A documentation generator or annotation processor will
+ * see the effective `Storage.GetAcl` method after inherting
+ * documentation and annotations as follows:
+ *
+ * service Storage {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v2/{resource=**}:getAcl";
+ * }
+ * ...
+ * }
+ *
+ * Note how the version in the path pattern changed from `v1` to `v2`.
+ *
+ * If the `root` field in the mixin is specified, it should be a
+ * relative path under which inherited HTTP paths are placed. Example:
+ *
+ * apis:
+ * - name: google.storage.v2.Storage
+ * mixins:
+ * - name: google.acl.v1.AccessControl
+ * root: acls
+ *
+ * This implies the following inherited HTTP annotation:
+ *
+ * service Storage {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
+ * }
+ * ...
+ * }
+ **/
+@interface GPBMixin : GPBMessage
+
+/** The fully qualified name of the API which is included. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * If non-empty specifies a path under which inherited HTTP paths
+ * are rooted.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *root;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m
new file mode 100644
index 0000000000..58b47157de
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m
@@ -0,0 +1,356 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/api.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Api.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+ #import <Protobuf/Type.pbobjc.h>
+#else
+ #import "google/protobuf/Api.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+ #import "google/protobuf/Type.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBApiRoot
+
+@implementation GPBApiRoot
+
+// No extensions in the file and none of the imports (direct or indirect)
+// defined extensions, so no need to generate +extensionRegistry.
+
+@end
+
+#pragma mark - GPBApiRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBApiRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBApi
+
+@implementation GPBApi
+
+@dynamic name;
+@dynamic methodsArray, methodsArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic version;
+@dynamic hasSourceContext, sourceContext;
+@dynamic mixinsArray, mixinsArray_Count;
+@dynamic syntax;
+
+typedef struct GPBApi__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *methodsArray;
+ NSMutableArray *optionsArray;
+ NSString *version;
+ GPBSourceContext *sourceContext;
+ NSMutableArray *mixinsArray;
+} GPBApi__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBApi_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "methodsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBMethod),
+ .number = GPBApi_FieldNumber_MethodsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, methodsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBApi_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "version",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBApi_FieldNumber_Version,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, version),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBApi_FieldNumber_SourceContext,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "mixinsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBMixin),
+ .number = GPBApi_FieldNumber_MixinsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, mixinsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBApi_FieldNumber_Syntax,
+ .hasIndex = 3,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBApi class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBApi__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBApi_Syntax_RawValue(GPBApi *message) {
+ GPBDescriptor *descriptor = [GPBApi descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBApi_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBApi_Syntax_RawValue(GPBApi *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBApi descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBApi_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBMethod
+
+@implementation GPBMethod
+
+@dynamic name;
+@dynamic requestTypeURL;
+@dynamic requestStreaming;
+@dynamic responseTypeURL;
+@dynamic responseStreaming;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic syntax;
+
+typedef struct GPBMethod__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSString *requestTypeURL;
+ NSString *responseTypeURL;
+ NSMutableArray *optionsArray;
+} GPBMethod__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "requestTypeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_RequestTypeURL,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, requestTypeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "requestStreaming",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_RequestStreaming,
+ .hasIndex = 2,
+ .offset = 3, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "responseTypeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_ResponseTypeURL,
+ .hasIndex = 4,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, responseTypeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "responseStreaming",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_ResponseStreaming,
+ .hasIndex = 5,
+ .offset = 6, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBMethod_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBMethod_FieldNumber_Syntax,
+ .hasIndex = 7,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBMethod class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBMethod__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\002\002\007\244\241!!\000\004\010\244\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBMethod_Syntax_RawValue(GPBMethod *message) {
+ GPBDescriptor *descriptor = [GPBMethod descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBMethod_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBMethod_Syntax_RawValue(GPBMethod *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBMethod descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBMethod_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBMixin
+
+@implementation GPBMixin
+
+@dynamic name;
+@dynamic root;
+
+typedef struct GPBMixin__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *name;
+ NSString *root;
+} GPBMixin__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMixin_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBMixin__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "root",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMixin_FieldNumber_Root,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBMixin__storage_, root),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBMixin class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBMixin__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h
new file mode 100644
index 0000000000..e70138a01e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h
@@ -0,0 +1,128 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/duration.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBDurationRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBDurationRoot : GPBRootObject
+@end
+
+#pragma mark - GPBDuration
+
+typedef GPB_ENUM(GPBDuration_FieldNumber) {
+ GPBDuration_FieldNumber_Seconds = 1,
+ GPBDuration_FieldNumber_Nanos = 2,
+};
+
+/**
+ * A Duration represents a signed, fixed-length span of time represented
+ * as a count of seconds and fractions of seconds at nanosecond
+ * resolution. It is independent of any calendar and concepts like "day"
+ * or "month". It is related to Timestamp in that the difference between
+ * two Timestamp values is a Duration and it can be added or subtracted
+ * from a Timestamp. Range is approximately +-10,000 years.
+ *
+ * Example 1: Compute Duration from two Timestamps in pseudo code.
+ *
+ * Timestamp start = ...;
+ * Timestamp end = ...;
+ * Duration duration = ...;
+ *
+ * duration.seconds = end.seconds - start.seconds;
+ * duration.nanos = end.nanos - start.nanos;
+ *
+ * if (duration.seconds < 0 && duration.nanos > 0) {
+ * duration.seconds += 1;
+ * duration.nanos -= 1000000000;
+ * } else if (durations.seconds > 0 && duration.nanos < 0) {
+ * duration.seconds -= 1;
+ * duration.nanos += 1000000000;
+ * }
+ *
+ * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
+ *
+ * Timestamp start = ...;
+ * Duration duration = ...;
+ * Timestamp end = ...;
+ *
+ * end.seconds = start.seconds + duration.seconds;
+ * end.nanos = start.nanos + duration.nanos;
+ *
+ * if (end.nanos < 0) {
+ * end.seconds -= 1;
+ * end.nanos += 1000000000;
+ * } else if (end.nanos >= 1000000000) {
+ * end.seconds += 1;
+ * end.nanos -= 1000000000;
+ * }
+ *
+ * Example 3: Compute Duration from datetime.timedelta in Python.
+ *
+ * td = datetime.timedelta(days=3, minutes=10)
+ * duration = Duration()
+ * duration.FromTimedelta(td)
+ **/
+@interface GPBDuration : GPBMessage
+
+/**
+ * Signed seconds of the span of time. Must be from -315,576,000,000
+ * to +315,576,000,000 inclusive.
+ **/
+@property(nonatomic, readwrite) int64_t seconds;
+
+/**
+ * Signed fractions of a second at nanosecond resolution of the span
+ * of time. Durations less than one second are represented with a 0
+ * `seconds` field and a positive or negative `nanos` field. For durations
+ * of one second or more, a non-zero value for the `nanos` field must be
+ * of the same sign as the `seconds` field. Must be from -999,999,999
+ * to +999,999,999 inclusive.
+ **/
+@property(nonatomic, readwrite) int32_t nanos;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m
new file mode 100644
index 0000000000..bafb64a04f
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m
@@ -0,0 +1,107 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/duration.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Duration.pbobjc.h>
+#else
+ #import "google/protobuf/Duration.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBDurationRoot
+
+@implementation GPBDurationRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBDurationRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBDurationRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBDuration
+
+@implementation GPBDuration
+
+@dynamic seconds;
+@dynamic nanos;
+
+typedef struct GPBDuration__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t nanos;
+ int64_t seconds;
+} GPBDuration__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "seconds",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDuration_FieldNumber_Seconds,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBDuration__storage_, seconds),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ {
+ .name = "nanos",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDuration_FieldNumber_Nanos,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBDuration__storage_, nanos),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBDuration class]
+ rootClass:[GPBDurationRoot class]
+ file:GPBDurationRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBDuration__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h
new file mode 100644
index 0000000000..bd49cfdbc3
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h
@@ -0,0 +1,70 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/empty.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBEmptyRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBEmptyRoot : GPBRootObject
+@end
+
+#pragma mark - GPBEmpty
+
+/**
+ * A generic empty message that you can re-use to avoid defining duplicated
+ * empty messages in your APIs. A typical example is to use it as the request
+ * or the response type of an API method. For instance:
+ *
+ * service Foo {
+ * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
+ * }
+ *
+ * The JSON representation for `Empty` is empty JSON object `{}`.
+ **/
+@interface GPBEmpty : GPBMessage
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m
new file mode 100644
index 0000000000..506b500e04
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m
@@ -0,0 +1,83 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/empty.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Empty.pbobjc.h>
+#else
+ #import "google/protobuf/Empty.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBEmptyRoot
+
+@implementation GPBEmptyRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBEmptyRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBEmptyRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBEmpty
+
+@implementation GPBEmpty
+
+
+typedef struct GPBEmpty__storage_ {
+ uint32_t _has_storage_[1];
+} GPBEmpty__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEmpty class]
+ rootClass:[GPBEmptyRoot class]
+ file:GPBEmptyRoot_FileDescriptor()
+ fields:NULL
+ fieldCount:0
+ storageSize:sizeof(GPBEmpty__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h
new file mode 100644
index 0000000000..07e6081852
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h
@@ -0,0 +1,271 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/field_mask.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBFieldMaskRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBFieldMaskRoot : GPBRootObject
+@end
+
+#pragma mark - GPBFieldMask
+
+typedef GPB_ENUM(GPBFieldMask_FieldNumber) {
+ GPBFieldMask_FieldNumber_PathsArray = 1,
+};
+
+/**
+ * `FieldMask` represents a set of symbolic field paths, for example:
+ *
+ * paths: "f.a"
+ * paths: "f.b.d"
+ *
+ * Here `f` represents a field in some root message, `a` and `b`
+ * fields in the message found in `f`, and `d` a field found in the
+ * message in `f.b`.
+ *
+ * Field masks are used to specify a subset of fields that should be
+ * returned by a get operation or modified by an update operation.
+ * Field masks also have a custom JSON encoding (see below).
+ *
+ * # Field Masks in Projections
+ *
+ * When used in the context of a projection, a response message or
+ * sub-message is filtered by the API to only contain those fields as
+ * specified in the mask. For example, if the mask in the previous
+ * example is applied to a response message as follows:
+ *
+ * f {
+ * a : 22
+ * b {
+ * d : 1
+ * x : 2
+ * }
+ * y : 13
+ * }
+ * z: 8
+ *
+ * The result will not contain specific values for fields x,y and z
+ * (their value will be set to the default, and omitted in proto text
+ * output):
+ *
+ *
+ * f {
+ * a : 22
+ * b {
+ * d : 1
+ * }
+ * }
+ *
+ * A repeated field is not allowed except at the last position of a
+ * paths string.
+ *
+ * If a FieldMask object is not present in a get operation, the
+ * operation applies to all fields (as if a FieldMask of all fields
+ * had been specified).
+ *
+ * Note that a field mask does not necessarily apply to the
+ * top-level response message. In case of a REST get operation, the
+ * field mask applies directly to the response, but in case of a REST
+ * list operation, the mask instead applies to each individual message
+ * in the returned resource list. In case of a REST custom method,
+ * other definitions may be used. Where the mask applies will be
+ * clearly documented together with its declaration in the API. In
+ * any case, the effect on the returned resource/resources is required
+ * behavior for APIs.
+ *
+ * # Field Masks in Update Operations
+ *
+ * A field mask in update operations specifies which fields of the
+ * targeted resource are going to be updated. The API is required
+ * to only change the values of the fields as specified in the mask
+ * and leave the others untouched. If a resource is passed in to
+ * describe the updated values, the API ignores the values of all
+ * fields not covered by the mask.
+ *
+ * If a repeated field is specified for an update operation, the existing
+ * repeated values in the target resource will be overwritten by the new values.
+ * Note that a repeated field is only allowed in the last position of a `paths`
+ * string.
+ *
+ * If a sub-message is specified in the last position of the field mask for an
+ * update operation, then the existing sub-message in the target resource is
+ * overwritten. Given the target message:
+ *
+ * f {
+ * b {
+ * d : 1
+ * x : 2
+ * }
+ * c : 1
+ * }
+ *
+ * And an update message:
+ *
+ * f {
+ * b {
+ * d : 10
+ * }
+ * }
+ *
+ * then if the field mask is:
+ *
+ * paths: "f.b"
+ *
+ * then the result will be:
+ *
+ * f {
+ * b {
+ * d : 10
+ * }
+ * c : 1
+ * }
+ *
+ * However, if the update mask was:
+ *
+ * paths: "f.b.d"
+ *
+ * then the result would be:
+ *
+ * f {
+ * b {
+ * d : 10
+ * x : 2
+ * }
+ * c : 1
+ * }
+ *
+ * In order to reset a field's value to the default, the field must
+ * be in the mask and set to the default value in the provided resource.
+ * Hence, in order to reset all fields of a resource, provide a default
+ * instance of the resource and set all fields in the mask, or do
+ * not provide a mask as described below.
+ *
+ * If a field mask is not present on update, the operation applies to
+ * all fields (as if a field mask of all fields has been specified).
+ * Note that in the presence of schema evolution, this may mean that
+ * fields the client does not know and has therefore not filled into
+ * the request will be reset to their default. If this is unwanted
+ * behavior, a specific service may require a client to always specify
+ * a field mask, producing an error if not.
+ *
+ * As with get operations, the location of the resource which
+ * describes the updated values in the request message depends on the
+ * operation kind. In any case, the effect of the field mask is
+ * required to be honored by the API.
+ *
+ * ## Considerations for HTTP REST
+ *
+ * The HTTP kind of an update operation which uses a field mask must
+ * be set to PATCH instead of PUT in order to satisfy HTTP semantics
+ * (PUT must only be used for full updates).
+ *
+ * # JSON Encoding of Field Masks
+ *
+ * In JSON, a field mask is encoded as a single string where paths are
+ * separated by a comma. Fields name in each path are converted
+ * to/from lower-camel naming conventions.
+ *
+ * As an example, consider the following message declarations:
+ *
+ * message Profile {
+ * User user = 1;
+ * Photo photo = 2;
+ * }
+ * message User {
+ * string display_name = 1;
+ * string address = 2;
+ * }
+ *
+ * In proto a field mask for `Profile` may look as such:
+ *
+ * mask {
+ * paths: "user.display_name"
+ * paths: "photo"
+ * }
+ *
+ * In JSON, the same mask is represented as below:
+ *
+ * {
+ * mask: "user.displayName,photo"
+ * }
+ *
+ * # Field Masks and Oneof Fields
+ *
+ * Field masks treat fields in oneofs just as regular fields. Consider the
+ * following message:
+ *
+ * message SampleMessage {
+ * oneof test_oneof {
+ * string name = 4;
+ * SubMessage sub_message = 9;
+ * }
+ * }
+ *
+ * The field mask can be:
+ *
+ * mask {
+ * paths: "name"
+ * }
+ *
+ * Or:
+ *
+ * mask {
+ * paths: "sub_message"
+ * }
+ *
+ * Note that oneof type names ("test_oneof" in this case) cannot be used in
+ * paths.
+ **/
+@interface GPBFieldMask : GPBMessage
+
+/** The set of field mask paths. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *pathsArray;
+/** The number of items in @c pathsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger pathsArray_Count;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m
new file mode 100644
index 0000000000..b0915af450
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m
@@ -0,0 +1,96 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/field_mask.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/FieldMask.pbobjc.h>
+#else
+ #import "google/protobuf/FieldMask.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBFieldMaskRoot
+
+@implementation GPBFieldMaskRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBFieldMaskRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBFieldMaskRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBFieldMask
+
+@implementation GPBFieldMask
+
+@dynamic pathsArray, pathsArray_Count;
+
+typedef struct GPBFieldMask__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableArray *pathsArray;
+} GPBFieldMask__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "pathsArray",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBFieldMask_FieldNumber_PathsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBFieldMask__storage_, pathsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBFieldMask class]
+ rootClass:[GPBFieldMaskRoot class]
+ file:GPBFieldMaskRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBFieldMask__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h
new file mode 100644
index 0000000000..799d190ac6
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h
@@ -0,0 +1,73 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/source_context.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBSourceContextRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBSourceContextRoot : GPBRootObject
+@end
+
+#pragma mark - GPBSourceContext
+
+typedef GPB_ENUM(GPBSourceContext_FieldNumber) {
+ GPBSourceContext_FieldNumber_FileName = 1,
+};
+
+/**
+ * `SourceContext` represents information about the source of a
+ * protobuf element, like the file in which it is defined.
+ **/
+@interface GPBSourceContext : GPBMessage
+
+/**
+ * The path-qualified name of the .proto file that contained the associated
+ * protobuf element. For example: `"google/protobuf/source_context.proto"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *fileName;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m
new file mode 100644
index 0000000000..83bfa3460b
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m
@@ -0,0 +1,96 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/source_context.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/SourceContext.pbobjc.h>
+#else
+ #import "google/protobuf/SourceContext.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBSourceContextRoot
+
+@implementation GPBSourceContextRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBSourceContextRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBSourceContextRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBSourceContext
+
+@implementation GPBSourceContext
+
+@dynamic fileName;
+
+typedef struct GPBSourceContext__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *fileName;
+} GPBSourceContext__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "fileName",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBSourceContext_FieldNumber_FileName,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBSourceContext__storage_, fileName),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBSourceContext class]
+ rootClass:[GPBSourceContextRoot class]
+ file:GPBSourceContextRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBSourceContext__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h
new file mode 100644
index 0000000000..3fc80caa5a
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h
@@ -0,0 +1,200 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/struct.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBListValue;
+@class GPBStruct;
+@class GPBValue;
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Enum GPBNullValue
+
+/**
+ * `NullValue` is a singleton enumeration to represent the null value for the
+ * `Value` type union.
+ *
+ * The JSON representation for `NullValue` is JSON `null`.
+ **/
+typedef GPB_ENUM(GPBNullValue) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBNullValue_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Null value. */
+ GPBNullValue_NullValue = 0,
+};
+
+GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBNullValue_IsValidValue(int32_t value);
+
+#pragma mark - GPBStructRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBStructRoot : GPBRootObject
+@end
+
+#pragma mark - GPBStruct
+
+typedef GPB_ENUM(GPBStruct_FieldNumber) {
+ GPBStruct_FieldNumber_Fields = 1,
+};
+
+/**
+ * `Struct` represents a structured data value, consisting of fields
+ * which map to dynamically typed values. In some languages, `Struct`
+ * might be supported by a native representation. For example, in
+ * scripting languages like JS a struct is represented as an
+ * object. The details of that representation are described together
+ * with the proto support for the language.
+ *
+ * The JSON representation for `Struct` is JSON object.
+ **/
+@interface GPBStruct : GPBMessage
+
+/** Unordered map of dynamically typed values. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary<NSString*, GPBValue*> *fields;
+/** The number of items in @c fields without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger fields_Count;
+
+@end
+
+#pragma mark - GPBValue
+
+typedef GPB_ENUM(GPBValue_FieldNumber) {
+ GPBValue_FieldNumber_NullValue = 1,
+ GPBValue_FieldNumber_NumberValue = 2,
+ GPBValue_FieldNumber_StringValue = 3,
+ GPBValue_FieldNumber_BoolValue = 4,
+ GPBValue_FieldNumber_StructValue = 5,
+ GPBValue_FieldNumber_ListValue = 6,
+};
+
+typedef GPB_ENUM(GPBValue_Kind_OneOfCase) {
+ GPBValue_Kind_OneOfCase_GPBUnsetOneOfCase = 0,
+ GPBValue_Kind_OneOfCase_NullValue = 1,
+ GPBValue_Kind_OneOfCase_NumberValue = 2,
+ GPBValue_Kind_OneOfCase_StringValue = 3,
+ GPBValue_Kind_OneOfCase_BoolValue = 4,
+ GPBValue_Kind_OneOfCase_StructValue = 5,
+ GPBValue_Kind_OneOfCase_ListValue = 6,
+};
+
+/**
+ * `Value` represents a dynamically typed value which can be either
+ * null, a number, a string, a boolean, a recursive struct value, or a
+ * list of values. A producer of value is expected to set one of that
+ * variants, absence of any variant indicates an error.
+ *
+ * The JSON representation for `Value` is JSON value.
+ **/
+@interface GPBValue : GPBMessage
+
+/** The kind of value. */
+@property(nonatomic, readonly) GPBValue_Kind_OneOfCase kindOneOfCase;
+
+/** Represents a null value. */
+@property(nonatomic, readwrite) GPBNullValue nullValue;
+
+/** Represents a double value. */
+@property(nonatomic, readwrite) double numberValue;
+
+/** Represents a string value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *stringValue;
+
+/** Represents a boolean value. */
+@property(nonatomic, readwrite) BOOL boolValue;
+
+/** Represents a structured value. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBStruct *structValue;
+
+/** Represents a repeated `Value`. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBListValue *listValue;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBValue's @c nullValue property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBValue_NullValue_RawValue(GPBValue *message);
+/**
+ * Sets the raw value of an @c GPBValue's @c nullValue property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBValue_NullValue_RawValue(GPBValue *message, int32_t value);
+
+/**
+ * Clears whatever value was set for the oneof 'kind'.
+ **/
+void GPBValue_ClearKindOneOfCase(GPBValue *message);
+
+#pragma mark - GPBListValue
+
+typedef GPB_ENUM(GPBListValue_FieldNumber) {
+ GPBListValue_FieldNumber_ValuesArray = 1,
+};
+
+/**
+ * `ListValue` is a wrapper around a repeated field of values.
+ *
+ * The JSON representation for `ListValue` is JSON array.
+ **/
+@interface GPBListValue : GPBMessage
+
+/** Repeated field of dynamically typed values. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBValue*> *valuesArray;
+/** The number of items in @c valuesArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger valuesArray_Count;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m
new file mode 100644
index 0000000000..f36ec582f9
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m
@@ -0,0 +1,293 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/struct.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Struct.pbobjc.h>
+#else
+ #import "google/protobuf/Struct.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+#pragma mark - GPBStructRoot
+
+@implementation GPBStructRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBStructRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - Enum GPBNullValue
+
+GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "NullValue\000";
+ static const int32_t values[] = {
+ GPBNullValue_NullValue,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBNullValue)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBNullValue_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBNullValue_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBNullValue_NullValue:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBStruct
+
+@implementation GPBStruct
+
+@dynamic fields, fields_Count;
+
+typedef struct GPBStruct__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableDictionary *fields;
+} GPBStruct__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "fields",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBValue),
+ .number = GPBStruct_FieldNumber_Fields,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBStruct__storage_, fields),
+ .flags = GPBFieldMapKeyString,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBStruct class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBStruct__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBValue
+
+@implementation GPBValue
+
+@dynamic kindOneOfCase;
+@dynamic nullValue;
+@dynamic numberValue;
+@dynamic stringValue;
+@dynamic boolValue;
+@dynamic structValue;
+@dynamic listValue;
+
+typedef struct GPBValue__storage_ {
+ uint32_t _has_storage_[2];
+ GPBNullValue nullValue;
+ NSString *stringValue;
+ GPBStruct *structValue;
+ GPBListValue *listValue;
+ double numberValue;
+} GPBValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "nullValue",
+ .dataTypeSpecific.enumDescFunc = GPBNullValue_EnumDescriptor,
+ .number = GPBValue_FieldNumber_NullValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, nullValue),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "numberValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_NumberValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, numberValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeDouble,
+ },
+ {
+ .name = "stringValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_StringValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, stringValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "boolValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_BoolValue,
+ .hasIndex = -1,
+ .offset = 0, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "structValue",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBStruct),
+ .number = GPBValue_FieldNumber_StructValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, structValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "listValue",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBListValue),
+ .number = GPBValue_FieldNumber_ListValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, listValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBValue class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ static const char *oneofs[] = {
+ "kind",
+ };
+ [localDescriptor setupOneofs:oneofs
+ count:(uint32_t)(sizeof(oneofs) / sizeof(char*))
+ firstHasIndex:-1];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBValue_NullValue_RawValue(GPBValue *message) {
+ GPBDescriptor *descriptor = [GPBValue descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBValue_FieldNumber_NullValue];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBValue_NullValue_RawValue(GPBValue *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBValue descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBValue_FieldNumber_NullValue];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+void GPBValue_ClearKindOneOfCase(GPBValue *message) {
+ GPBDescriptor *descriptor = [message descriptor];
+ GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:0];
+ GPBMaybeClearOneof(message, oneof, -1, 0);
+}
+#pragma mark - GPBListValue
+
+@implementation GPBListValue
+
+@dynamic valuesArray, valuesArray_Count;
+
+typedef struct GPBListValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableArray *valuesArray;
+} GPBListValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "valuesArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBValue),
+ .number = GPBListValue_FieldNumber_ValuesArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBListValue__storage_, valuesArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBListValue class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBListValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h
new file mode 100644
index 0000000000..9c83d0945e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h
@@ -0,0 +1,132 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/timestamp.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBTimestampRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBTimestampRoot : GPBRootObject
+@end
+
+#pragma mark - GPBTimestamp
+
+typedef GPB_ENUM(GPBTimestamp_FieldNumber) {
+ GPBTimestamp_FieldNumber_Seconds = 1,
+ GPBTimestamp_FieldNumber_Nanos = 2,
+};
+
+/**
+ * A Timestamp represents a point in time independent of any time zone
+ * or calendar, represented as seconds and fractions of seconds at
+ * nanosecond resolution in UTC Epoch time. It is encoded using the
+ * Proleptic Gregorian Calendar which extends the Gregorian calendar
+ * backwards to year one. It is encoded assuming all minutes are 60
+ * seconds long, i.e. leap seconds are "smeared" so that no leap second
+ * table is needed for interpretation. Range is from
+ * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
+ * By restricting to that range, we ensure that we can convert to
+ * and from RFC 3339 date strings.
+ * See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
+ *
+ * Example 1: Compute Timestamp from POSIX `time()`.
+ *
+ * Timestamp timestamp;
+ * timestamp.set_seconds(time(NULL));
+ * timestamp.set_nanos(0);
+ *
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
+ *
+ * struct timeval tv;
+ * gettimeofday(&tv, NULL);
+ *
+ * Timestamp timestamp;
+ * timestamp.set_seconds(tv.tv_sec);
+ * timestamp.set_nanos(tv.tv_usec * 1000);
+ *
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
+ *
+ * FILETIME ft;
+ * GetSystemTimeAsFileTime(&ft);
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
+ *
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
+ * Timestamp timestamp;
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
+ *
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
+ *
+ * long millis = System.currentTimeMillis();
+ *
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
+ *
+ *
+ * Example 5: Compute Timestamp from current time in Python.
+ *
+ * timestamp = Timestamp()
+ * timestamp.GetCurrentTime()
+ **/
+@interface GPBTimestamp : GPBMessage
+
+/**
+ * Represents seconds of UTC time since Unix epoch
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
+ * 9999-12-31T23:59:59Z inclusive.
+ **/
+@property(nonatomic, readwrite) int64_t seconds;
+
+/**
+ * Non-negative fractions of a second at nanosecond resolution. Negative
+ * second values with fractions must still have non-negative nanos values
+ * that count forward in time. Must be from 0 to 999,999,999
+ * inclusive.
+ **/
+@property(nonatomic, readwrite) int32_t nanos;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m
new file mode 100644
index 0000000000..4ab159fb9c
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m
@@ -0,0 +1,107 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/timestamp.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Timestamp.pbobjc.h>
+#else
+ #import "google/protobuf/Timestamp.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBTimestampRoot
+
+@implementation GPBTimestampRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBTimestampRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBTimestampRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBTimestamp
+
+@implementation GPBTimestamp
+
+@dynamic seconds;
+@dynamic nanos;
+
+typedef struct GPBTimestamp__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t nanos;
+ int64_t seconds;
+} GPBTimestamp__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "seconds",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBTimestamp_FieldNumber_Seconds,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBTimestamp__storage_, seconds),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ {
+ .name = "nanos",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBTimestamp_FieldNumber_Nanos,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBTimestamp__storage_, nanos),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBTimestamp class]
+ rootClass:[GPBTimestampRoot class]
+ file:GPBTimestampRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBTimestamp__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h
new file mode 100644
index 0000000000..1798697080
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h
@@ -0,0 +1,440 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/type.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBAny;
+@class GPBEnumValue;
+@class GPBField;
+@class GPBOption;
+@class GPBSourceContext;
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Enum GPBSyntax
+
+/** The syntax in which a protocol buffer element is defined. */
+typedef GPB_ENUM(GPBSyntax) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBSyntax_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Syntax `proto2`. */
+ GPBSyntax_SyntaxProto2 = 0,
+
+ /** Syntax `proto3`. */
+ GPBSyntax_SyntaxProto3 = 1,
+};
+
+GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBSyntax_IsValidValue(int32_t value);
+
+#pragma mark - Enum GPBField_Kind
+
+/** Basic field types. */
+typedef GPB_ENUM(GPBField_Kind) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBField_Kind_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Field type unknown. */
+ GPBField_Kind_TypeUnknown = 0,
+
+ /** Field type double. */
+ GPBField_Kind_TypeDouble = 1,
+
+ /** Field type float. */
+ GPBField_Kind_TypeFloat = 2,
+
+ /** Field type int64. */
+ GPBField_Kind_TypeInt64 = 3,
+
+ /** Field type uint64. */
+ GPBField_Kind_TypeUint64 = 4,
+
+ /** Field type int32. */
+ GPBField_Kind_TypeInt32 = 5,
+
+ /** Field type fixed64. */
+ GPBField_Kind_TypeFixed64 = 6,
+
+ /** Field type fixed32. */
+ GPBField_Kind_TypeFixed32 = 7,
+
+ /** Field type bool. */
+ GPBField_Kind_TypeBool = 8,
+
+ /** Field type string. */
+ GPBField_Kind_TypeString = 9,
+
+ /** Field type group. Proto2 syntax only, and deprecated. */
+ GPBField_Kind_TypeGroup = 10,
+
+ /** Field type message. */
+ GPBField_Kind_TypeMessage = 11,
+
+ /** Field type bytes. */
+ GPBField_Kind_TypeBytes = 12,
+
+ /** Field type uint32. */
+ GPBField_Kind_TypeUint32 = 13,
+
+ /** Field type enum. */
+ GPBField_Kind_TypeEnum = 14,
+
+ /** Field type sfixed32. */
+ GPBField_Kind_TypeSfixed32 = 15,
+
+ /** Field type sfixed64. */
+ GPBField_Kind_TypeSfixed64 = 16,
+
+ /** Field type sint32. */
+ GPBField_Kind_TypeSint32 = 17,
+
+ /** Field type sint64. */
+ GPBField_Kind_TypeSint64 = 18,
+};
+
+GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBField_Kind_IsValidValue(int32_t value);
+
+#pragma mark - Enum GPBField_Cardinality
+
+/** Whether a field is optional, required, or repeated. */
+typedef GPB_ENUM(GPBField_Cardinality) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBField_Cardinality_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** For fields with unknown cardinality. */
+ GPBField_Cardinality_CardinalityUnknown = 0,
+
+ /** For optional fields. */
+ GPBField_Cardinality_CardinalityOptional = 1,
+
+ /** For required fields. Proto2 syntax only. */
+ GPBField_Cardinality_CardinalityRequired = 2,
+
+ /** For repeated fields. */
+ GPBField_Cardinality_CardinalityRepeated = 3,
+};
+
+GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBField_Cardinality_IsValidValue(int32_t value);
+
+#pragma mark - GPBTypeRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBTypeRoot : GPBRootObject
+@end
+
+#pragma mark - GPBType
+
+typedef GPB_ENUM(GPBType_FieldNumber) {
+ GPBType_FieldNumber_Name = 1,
+ GPBType_FieldNumber_FieldsArray = 2,
+ GPBType_FieldNumber_OneofsArray = 3,
+ GPBType_FieldNumber_OptionsArray = 4,
+ GPBType_FieldNumber_SourceContext = 5,
+ GPBType_FieldNumber_Syntax = 6,
+};
+
+/**
+ * A protocol buffer message type.
+ **/
+@interface GPBType : GPBMessage
+
+/** The fully qualified message name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** The list of fields. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBField*> *fieldsArray;
+/** The number of items in @c fieldsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger fieldsArray_Count;
+
+/** The list of types appearing in `oneof` definitions in this type. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *oneofsArray;
+/** The number of items in @c oneofsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger oneofsArray_Count;
+
+/** The protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source context. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** The source syntax. */
+@property(nonatomic, readwrite) GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBType's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBType_Syntax_RawValue(GPBType *message);
+/**
+ * Sets the raw value of an @c GPBType's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBType_Syntax_RawValue(GPBType *message, int32_t value);
+
+#pragma mark - GPBField
+
+typedef GPB_ENUM(GPBField_FieldNumber) {
+ GPBField_FieldNumber_Kind = 1,
+ GPBField_FieldNumber_Cardinality = 2,
+ GPBField_FieldNumber_Number = 3,
+ GPBField_FieldNumber_Name = 4,
+ GPBField_FieldNumber_TypeURL = 6,
+ GPBField_FieldNumber_OneofIndex = 7,
+ GPBField_FieldNumber_Packed = 8,
+ GPBField_FieldNumber_OptionsArray = 9,
+ GPBField_FieldNumber_JsonName = 10,
+ GPBField_FieldNumber_DefaultValue = 11,
+};
+
+/**
+ * A single field of a message type.
+ **/
+@interface GPBField : GPBMessage
+
+/** The field type. */
+@property(nonatomic, readwrite) GPBField_Kind kind;
+
+/** The field cardinality. */
+@property(nonatomic, readwrite) GPBField_Cardinality cardinality;
+
+/** The field number. */
+@property(nonatomic, readwrite) int32_t number;
+
+/** The field name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * The field type URL, without the scheme, for message or enumeration
+ * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
+
+/**
+ * The index of the field type in `Type.oneofs`, for message or enumeration
+ * types. The first type has index 1; zero means the type is not in the list.
+ **/
+@property(nonatomic, readwrite) int32_t oneofIndex;
+
+/** Whether to use alternative packed wire representation. */
+@property(nonatomic, readwrite) BOOL packed;
+
+/** The protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The field JSON name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *jsonName;
+
+/** The string value of the default value of this field. Proto2 syntax only. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *defaultValue;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBField's @c kind property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBField_Kind_RawValue(GPBField *message);
+/**
+ * Sets the raw value of an @c GPBField's @c kind property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBField_Kind_RawValue(GPBField *message, int32_t value);
+
+/**
+ * Fetches the raw value of a @c GPBField's @c cardinality property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBField_Cardinality_RawValue(GPBField *message);
+/**
+ * Sets the raw value of an @c GPBField's @c cardinality property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value);
+
+#pragma mark - GPBEnum
+
+typedef GPB_ENUM(GPBEnum_FieldNumber) {
+ GPBEnum_FieldNumber_Name = 1,
+ GPBEnum_FieldNumber_EnumvalueArray = 2,
+ GPBEnum_FieldNumber_OptionsArray = 3,
+ GPBEnum_FieldNumber_SourceContext = 4,
+ GPBEnum_FieldNumber_Syntax = 5,
+};
+
+/**
+ * Enum type definition.
+ **/
+@interface GPBEnum : GPBMessage
+
+/** Enum type name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** Enum value definitions. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumValue*> *enumvalueArray;
+/** The number of items in @c enumvalueArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger enumvalueArray_Count;
+
+/** Protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source context. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** The source syntax. */
+@property(nonatomic, readwrite) GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBEnum's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBEnum_Syntax_RawValue(GPBEnum *message);
+/**
+ * Sets the raw value of an @c GPBEnum's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBEnum_Syntax_RawValue(GPBEnum *message, int32_t value);
+
+#pragma mark - GPBEnumValue
+
+typedef GPB_ENUM(GPBEnumValue_FieldNumber) {
+ GPBEnumValue_FieldNumber_Name = 1,
+ GPBEnumValue_FieldNumber_Number = 2,
+ GPBEnumValue_FieldNumber_OptionsArray = 3,
+};
+
+/**
+ * Enum value definition.
+ **/
+@interface GPBEnumValue : GPBMessage
+
+/** Enum value name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** Enum value number. */
+@property(nonatomic, readwrite) int32_t number;
+
+/** Protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+@end
+
+#pragma mark - GPBOption
+
+typedef GPB_ENUM(GPBOption_FieldNumber) {
+ GPBOption_FieldNumber_Name = 1,
+ GPBOption_FieldNumber_Value = 2,
+};
+
+/**
+ * A protocol buffer option, which can be attached to a message, field,
+ * enumeration, etc.
+ **/
+@interface GPBOption : GPBMessage
+
+/**
+ * The option's name. For protobuf built-in options (options defined in
+ * descriptor.proto), this is the short name. For example, `"map_entry"`.
+ * For custom options, it should be the fully-qualified name. For example,
+ * `"google.api.http"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * The option's value packed in an Any message. If the value is a primitive,
+ * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+ * should be used. If the value is an enum, it should be stored as an int32
+ * value using the google.protobuf.Int32Value type.
+ **/
+@property(nonatomic, readwrite, strong, null_resettable) GPBAny *value;
+/** Test to see if @c value has been set. */
+@property(nonatomic, readwrite) BOOL hasValue;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m
new file mode 100644
index 0000000000..7a949388f8
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m
@@ -0,0 +1,701 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/type.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Type.pbobjc.h>
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+#else
+ #import "google/protobuf/Type.pbobjc.h"
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBTypeRoot
+
+@implementation GPBTypeRoot
+
+// No extensions in the file and none of the imports (direct or indirect)
+// defined extensions, so no need to generate +extensionRegistry.
+
+@end
+
+#pragma mark - GPBTypeRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - Enum GPBSyntax
+
+GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "SyntaxProto2\000SyntaxProto3\000";
+ static const int32_t values[] = {
+ GPBSyntax_SyntaxProto2,
+ GPBSyntax_SyntaxProto3,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBSyntax)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBSyntax_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBSyntax_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBSyntax_SyntaxProto2:
+ case GPBSyntax_SyntaxProto3:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBType
+
+@implementation GPBType
+
+@dynamic name;
+@dynamic fieldsArray, fieldsArray_Count;
+@dynamic oneofsArray, oneofsArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic hasSourceContext, sourceContext;
+@dynamic syntax;
+
+typedef struct GPBType__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *fieldsArray;
+ NSMutableArray *oneofsArray;
+ NSMutableArray *optionsArray;
+ GPBSourceContext *sourceContext;
+} GPBType__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBType_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBType__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "fieldsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBField),
+ .number = GPBType_FieldNumber_FieldsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, fieldsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "oneofsArray",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBType_FieldNumber_OneofsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, oneofsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBType_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBType_FieldNumber_SourceContext,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBType__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBType_FieldNumber_Syntax,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBType__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBType class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBType__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBType_Syntax_RawValue(GPBType *message) {
+ GPBDescriptor *descriptor = [GPBType descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBType_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBType_Syntax_RawValue(GPBType *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBType descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBType_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBField
+
+@implementation GPBField
+
+@dynamic kind;
+@dynamic cardinality;
+@dynamic number;
+@dynamic name;
+@dynamic typeURL;
+@dynamic oneofIndex;
+@dynamic packed;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic jsonName;
+@dynamic defaultValue;
+
+typedef struct GPBField__storage_ {
+ uint32_t _has_storage_[1];
+ GPBField_Kind kind;
+ GPBField_Cardinality cardinality;
+ int32_t number;
+ int32_t oneofIndex;
+ NSString *name;
+ NSString *typeURL;
+ NSMutableArray *optionsArray;
+ NSString *jsonName;
+ NSString *defaultValue;
+} GPBField__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "kind",
+ .dataTypeSpecific.enumDescFunc = GPBField_Kind_EnumDescriptor,
+ .number = GPBField_FieldNumber_Kind,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBField__storage_, kind),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "cardinality",
+ .dataTypeSpecific.enumDescFunc = GPBField_Cardinality_EnumDescriptor,
+ .number = GPBField_FieldNumber_Cardinality,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBField__storage_, cardinality),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "number",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Number,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBField__storage_, number),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Name,
+ .hasIndex = 3,
+ .offset = (uint32_t)offsetof(GPBField__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "typeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_TypeURL,
+ .hasIndex = 4,
+ .offset = (uint32_t)offsetof(GPBField__storage_, typeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "oneofIndex",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_OneofIndex,
+ .hasIndex = 5,
+ .offset = (uint32_t)offsetof(GPBField__storage_, oneofIndex),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "packed",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Packed,
+ .hasIndex = 6,
+ .offset = 7, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBField_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBField__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "jsonName",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_JsonName,
+ .hasIndex = 8,
+ .offset = (uint32_t)offsetof(GPBField__storage_, jsonName),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "defaultValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_DefaultValue,
+ .hasIndex = 9,
+ .offset = (uint32_t)offsetof(GPBField__storage_, defaultValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBField class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBField__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\001\006\004\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBField_Kind_RawValue(GPBField *message) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Kind];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBField_Kind_RawValue(GPBField *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Kind];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+int32_t GPBField_Cardinality_RawValue(GPBField *message) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Cardinality];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Cardinality];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - Enum GPBField_Kind
+
+GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "TypeUnknown\000TypeDouble\000TypeFloat\000TypeInt"
+ "64\000TypeUint64\000TypeInt32\000TypeFixed64\000Type"
+ "Fixed32\000TypeBool\000TypeString\000TypeGroup\000Ty"
+ "peMessage\000TypeBytes\000TypeUint32\000TypeEnum\000"
+ "TypeSfixed32\000TypeSfixed64\000TypeSint32\000Typ"
+ "eSint64\000";
+ static const int32_t values[] = {
+ GPBField_Kind_TypeUnknown,
+ GPBField_Kind_TypeDouble,
+ GPBField_Kind_TypeFloat,
+ GPBField_Kind_TypeInt64,
+ GPBField_Kind_TypeUint64,
+ GPBField_Kind_TypeInt32,
+ GPBField_Kind_TypeFixed64,
+ GPBField_Kind_TypeFixed32,
+ GPBField_Kind_TypeBool,
+ GPBField_Kind_TypeString,
+ GPBField_Kind_TypeGroup,
+ GPBField_Kind_TypeMessage,
+ GPBField_Kind_TypeBytes,
+ GPBField_Kind_TypeUint32,
+ GPBField_Kind_TypeEnum,
+ GPBField_Kind_TypeSfixed32,
+ GPBField_Kind_TypeSfixed64,
+ GPBField_Kind_TypeSint32,
+ GPBField_Kind_TypeSint64,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBField_Kind)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBField_Kind_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBField_Kind_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBField_Kind_TypeUnknown:
+ case GPBField_Kind_TypeDouble:
+ case GPBField_Kind_TypeFloat:
+ case GPBField_Kind_TypeInt64:
+ case GPBField_Kind_TypeUint64:
+ case GPBField_Kind_TypeInt32:
+ case GPBField_Kind_TypeFixed64:
+ case GPBField_Kind_TypeFixed32:
+ case GPBField_Kind_TypeBool:
+ case GPBField_Kind_TypeString:
+ case GPBField_Kind_TypeGroup:
+ case GPBField_Kind_TypeMessage:
+ case GPBField_Kind_TypeBytes:
+ case GPBField_Kind_TypeUint32:
+ case GPBField_Kind_TypeEnum:
+ case GPBField_Kind_TypeSfixed32:
+ case GPBField_Kind_TypeSfixed64:
+ case GPBField_Kind_TypeSint32:
+ case GPBField_Kind_TypeSint64:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - Enum GPBField_Cardinality
+
+GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "CardinalityUnknown\000CardinalityOptional\000C"
+ "ardinalityRequired\000CardinalityRepeated\000";
+ static const int32_t values[] = {
+ GPBField_Cardinality_CardinalityUnknown,
+ GPBField_Cardinality_CardinalityOptional,
+ GPBField_Cardinality_CardinalityRequired,
+ GPBField_Cardinality_CardinalityRepeated,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBField_Cardinality)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBField_Cardinality_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBField_Cardinality_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBField_Cardinality_CardinalityUnknown:
+ case GPBField_Cardinality_CardinalityOptional:
+ case GPBField_Cardinality_CardinalityRequired:
+ case GPBField_Cardinality_CardinalityRepeated:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBEnum
+
+@implementation GPBEnum
+
+@dynamic name;
+@dynamic enumvalueArray, enumvalueArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic hasSourceContext, sourceContext;
+@dynamic syntax;
+
+typedef struct GPBEnum__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *enumvalueArray;
+ NSMutableArray *optionsArray;
+ GPBSourceContext *sourceContext;
+} GPBEnum__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnum_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "enumvalueArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBEnumValue),
+ .number = GPBEnum_FieldNumber_EnumvalueArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, enumvalueArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBEnum_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBEnum_FieldNumber_SourceContext,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBEnum_FieldNumber_Syntax,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEnum class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBEnum__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBEnum_Syntax_RawValue(GPBEnum *message) {
+ GPBDescriptor *descriptor = [GPBEnum descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBEnum_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBEnum_Syntax_RawValue(GPBEnum *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBEnum descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBEnum_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBEnumValue
+
+@implementation GPBEnumValue
+
+@dynamic name;
+@dynamic number;
+@dynamic optionsArray, optionsArray_Count;
+
+typedef struct GPBEnumValue__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t number;
+ NSString *name;
+ NSMutableArray *optionsArray;
+} GPBEnumValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnumValue_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "number",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnumValue_FieldNumber_Number,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, number),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBEnumValue_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEnumValue class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBEnumValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBOption
+
+@implementation GPBOption
+
+@dynamic name;
+@dynamic hasValue, value;
+
+typedef struct GPBOption__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *name;
+ GPBAny *value;
+} GPBOption__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBOption_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBOption__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "value",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBAny),
+ .number = GPBOption_FieldNumber_Value,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBOption__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBOption class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBOption__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h
new file mode 100644
index 0000000000..3cb9fe77dc
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h
@@ -0,0 +1,215 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/wrappers.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBWrappersRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBWrappersRoot : GPBRootObject
+@end
+
+#pragma mark - GPBDoubleValue
+
+typedef GPB_ENUM(GPBDoubleValue_FieldNumber) {
+ GPBDoubleValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `double`.
+ *
+ * The JSON representation for `DoubleValue` is JSON number.
+ **/
+@interface GPBDoubleValue : GPBMessage
+
+/** The double value. */
+@property(nonatomic, readwrite) double value;
+
+@end
+
+#pragma mark - GPBFloatValue
+
+typedef GPB_ENUM(GPBFloatValue_FieldNumber) {
+ GPBFloatValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `float`.
+ *
+ * The JSON representation for `FloatValue` is JSON number.
+ **/
+@interface GPBFloatValue : GPBMessage
+
+/** The float value. */
+@property(nonatomic, readwrite) float value;
+
+@end
+
+#pragma mark - GPBInt64Value
+
+typedef GPB_ENUM(GPBInt64Value_FieldNumber) {
+ GPBInt64Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `int64`.
+ *
+ * The JSON representation for `Int64Value` is JSON string.
+ **/
+@interface GPBInt64Value : GPBMessage
+
+/** The int64 value. */
+@property(nonatomic, readwrite) int64_t value;
+
+@end
+
+#pragma mark - GPBUInt64Value
+
+typedef GPB_ENUM(GPBUInt64Value_FieldNumber) {
+ GPBUInt64Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `uint64`.
+ *
+ * The JSON representation for `UInt64Value` is JSON string.
+ **/
+@interface GPBUInt64Value : GPBMessage
+
+/** The uint64 value. */
+@property(nonatomic, readwrite) uint64_t value;
+
+@end
+
+#pragma mark - GPBInt32Value
+
+typedef GPB_ENUM(GPBInt32Value_FieldNumber) {
+ GPBInt32Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `int32`.
+ *
+ * The JSON representation for `Int32Value` is JSON number.
+ **/
+@interface GPBInt32Value : GPBMessage
+
+/** The int32 value. */
+@property(nonatomic, readwrite) int32_t value;
+
+@end
+
+#pragma mark - GPBUInt32Value
+
+typedef GPB_ENUM(GPBUInt32Value_FieldNumber) {
+ GPBUInt32Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `uint32`.
+ *
+ * The JSON representation for `UInt32Value` is JSON number.
+ **/
+@interface GPBUInt32Value : GPBMessage
+
+/** The uint32 value. */
+@property(nonatomic, readwrite) uint32_t value;
+
+@end
+
+#pragma mark - GPBBoolValue
+
+typedef GPB_ENUM(GPBBoolValue_FieldNumber) {
+ GPBBoolValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `bool`.
+ *
+ * The JSON representation for `BoolValue` is JSON `true` and `false`.
+ **/
+@interface GPBBoolValue : GPBMessage
+
+/** The bool value. */
+@property(nonatomic, readwrite) BOOL value;
+
+@end
+
+#pragma mark - GPBStringValue
+
+typedef GPB_ENUM(GPBStringValue_FieldNumber) {
+ GPBStringValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `string`.
+ *
+ * The JSON representation for `StringValue` is JSON string.
+ **/
+@interface GPBStringValue : GPBMessage
+
+/** The string value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *value;
+
+@end
+
+#pragma mark - GPBBytesValue
+
+typedef GPB_ENUM(GPBBytesValue_FieldNumber) {
+ GPBBytesValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `bytes`.
+ *
+ * The JSON representation for `BytesValue` is JSON string.
+ **/
+@interface GPBBytesValue : GPBMessage
+
+/** The bytes value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m
new file mode 100644
index 0000000000..5479eb127b
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m
@@ -0,0 +1,439 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/wrappers.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Wrappers.pbobjc.h>
+#else
+ #import "google/protobuf/Wrappers.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBWrappersRoot
+
+@implementation GPBWrappersRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBWrappersRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBWrappersRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBDoubleValue
+
+@implementation GPBDoubleValue
+
+@dynamic value;
+
+typedef struct GPBDoubleValue__storage_ {
+ uint32_t _has_storage_[1];
+ double value;
+} GPBDoubleValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDoubleValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBDoubleValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeDouble,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBDoubleValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBDoubleValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBFloatValue
+
+@implementation GPBFloatValue
+
+@dynamic value;
+
+typedef struct GPBFloatValue__storage_ {
+ uint32_t _has_storage_[1];
+ float value;
+} GPBFloatValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBFloatValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBFloatValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeFloat,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBFloatValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBFloatValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBInt64Value
+
+@implementation GPBInt64Value
+
+@dynamic value;
+
+typedef struct GPBInt64Value__storage_ {
+ uint32_t _has_storage_[1];
+ int64_t value;
+} GPBInt64Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBInt64Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBInt64Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBInt64Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBInt64Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBUInt64Value
+
+@implementation GPBUInt64Value
+
+@dynamic value;
+
+typedef struct GPBUInt64Value__storage_ {
+ uint32_t _has_storage_[1];
+ uint64_t value;
+} GPBUInt64Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBUInt64Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBUInt64Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeUInt64,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBUInt64Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBUInt64Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBInt32Value
+
+@implementation GPBInt32Value
+
+@dynamic value;
+
+typedef struct GPBInt32Value__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t value;
+} GPBInt32Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBInt32Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBInt32Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBInt32Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBInt32Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBUInt32Value
+
+@implementation GPBUInt32Value
+
+@dynamic value;
+
+typedef struct GPBUInt32Value__storage_ {
+ uint32_t _has_storage_[1];
+ uint32_t value;
+} GPBUInt32Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBUInt32Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBUInt32Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeUInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBUInt32Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBUInt32Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBBoolValue
+
+@implementation GPBBoolValue
+
+@dynamic value;
+
+typedef struct GPBBoolValue__storage_ {
+ uint32_t _has_storage_[1];
+} GPBBoolValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBBoolValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = 1, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBBoolValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBBoolValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBStringValue
+
+@implementation GPBStringValue
+
+@dynamic value;
+
+typedef struct GPBStringValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *value;
+} GPBStringValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBStringValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBStringValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBStringValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBStringValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBBytesValue
+
+@implementation GPBBytesValue
+
+@dynamic value;
+
+typedef struct GPBBytesValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSData *value;
+} GPBBytesValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBBytesValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBBytesValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBytes,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBBytesValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBBytesValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)