aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@teboring-macpro.roam.corp.google.com>2015-05-25 12:48:03 -0700
committerGravatar Bo Yang <teboring@teboring-macpro.roam.corp.google.com>2015-05-25 12:48:03 -0700
commit50a765ba03ddf311a4facc78104903e3ba5b3e8b (patch)
tree01b36604d8f6a9579fa160e43477f381f22524d7 /objectivec
parentad0a5cab521d86fcadb8991427395e77daca71a6 (diff)
Fix bugs in objective-c.
Diffstat (limited to 'objectivec')
-rw-r--r--objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj4
-rw-r--r--objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj4
-rw-r--r--objectivec/Tests/GPBMessageTests+Serialization.m7
-rw-r--r--objectivec/Tests/unittest_runtime_proto3.proto5
-rw-r--r--objectivec/google/protobuf/Descriptor.pbobjc.h65
-rw-r--r--objectivec/google/protobuf/Descriptor.pbobjc.m136
6 files changed, 212 insertions, 9 deletions
diff --git a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
index f18ba2f8..38100fae 100644
--- a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
@@ -725,7 +725,7 @@
INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = UnitTests;
- SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
@@ -742,7 +742,7 @@
INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = UnitTests;
- SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
};
name = Release;
};
diff --git a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
index d6e621e6..0773acb1 100644
--- a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
@@ -875,7 +875,7 @@
"\"$(DEVELOPER_DIR)/usr/lib\"",
);
PRODUCT_NAME = UnitTests;
- SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
@@ -903,7 +903,7 @@
"\"$(DEVELOPER_DIR)/usr/lib\"",
);
PRODUCT_NAME = UnitTests;
- SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
};
diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m
index 8867f56d..0859f14c 100644
--- a/objectivec/Tests/GPBMessageTests+Serialization.m
+++ b/objectivec/Tests/GPBMessageTests+Serialization.m
@@ -177,6 +177,13 @@ static NSData *DataFromCStr(const char *str) {
XCTAssertEqual([field.varintList valueAtIndex:0],
(uint64_t)Message3_Enum_Extra3);
+ // TODO(teboring): This test could fail without explicitly marking the repeated_enum in Message3
+ // to be unpacked. This is becaucse proto3 repeated primitive field is packed by default. However,
+ // the proto2 primitive repeated field is still unpacked by default. Previously, parsing of the
+ // repeated_enum field would fail. To fix it:
+ // 1) Objective-C implementation of parsing should be able to parse packed field for unpacked
+ // field and vice versa.
+ // 2) repeated_packed_enum in Message3 should be removed, because it's unnecessary now.
field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray];
XCTAssertEqual(field.varintList.count, 1U);
XCTAssertEqual([field.varintList valueAtIndex:0],
diff --git a/objectivec/Tests/unittest_runtime_proto3.proto b/objectivec/Tests/unittest_runtime_proto3.proto
index feb7029d..a081fa7e 100644
--- a/objectivec/Tests/unittest_runtime_proto3.proto
+++ b/objectivec/Tests/unittest_runtime_proto3.proto
@@ -75,7 +75,10 @@ message Message3 {
repeated bytes repeated_bytes = 45;
// No 'group' in proto3.
repeated Message3 repeated_message = 48;
- repeated Enum repeated_enum = 49;
+ // TODO(teboring): In proto3, repeated primitive field is packed by default.
+ // testProto2UnknownEnumToUnknownField needs repeated_enum to be unpacked.
+ // Remove this option when testProto2UnknownEnumToUnknownField.
+ repeated Enum repeated_enum = 49 [packed=false];
repeated Enum repeated_packed_enum = 50 [packed=true];
oneof o {
diff --git a/objectivec/google/protobuf/Descriptor.pbobjc.h b/objectivec/google/protobuf/Descriptor.pbobjc.h
index 19a82fd1..5a53abbc 100644
--- a/objectivec/google/protobuf/Descriptor.pbobjc.h
+++ b/objectivec/google/protobuf/Descriptor.pbobjc.h
@@ -111,6 +111,23 @@ GPBEnumDescriptor *GPBFieldOptions_CType_EnumDescriptor(void);
BOOL GPBFieldOptions_CType_IsValidValue(int32_t value);
+#pragma mark - Enum GPBFieldOptions_JSType
+
+typedef GPB_ENUM(GPBFieldOptions_JSType) {
+ // Use the default type.
+ GPBFieldOptions_JSType_JsNormal = 0,
+
+ // Use JavaScript strings.
+ GPBFieldOptions_JSType_JsString = 1,
+
+ // Use JavaScript numbers.
+ GPBFieldOptions_JSType_JsNumber = 2,
+};
+
+GPBEnumDescriptor *GPBFieldOptions_JSType_EnumDescriptor(void);
+
+BOOL GPBFieldOptions_JSType_IsValidValue(int32_t value);
+
#pragma mark - GPBDescriptorRoot
@@ -218,6 +235,8 @@ typedef GPB_ENUM(GPBDescriptorProto_FieldNumber) {
GPBDescriptorProto_FieldNumber_ExtensionArray = 6,
GPBDescriptorProto_FieldNumber_Options = 7,
GPBDescriptorProto_FieldNumber_OneofDeclArray = 8,
+ GPBDescriptorProto_FieldNumber_ReservedRangeArray = 9,
+ GPBDescriptorProto_FieldNumber_ReservedNameArray = 10,
};
// Describes a message type.
@@ -247,6 +266,14 @@ typedef GPB_ENUM(GPBDescriptorProto_FieldNumber) {
@property(nonatomic, readwrite) BOOL hasOptions;
@property(nonatomic, readwrite, strong) GPBMessageOptions *options;
+// |reservedRangeArray| contains |GPBDescriptorProto_ReservedRange|
+@property(nonatomic, readwrite, strong) NSMutableArray *reservedRangeArray;
+
+// Reserved field names, which may not be used by fields in the same message.
+// A given name may only be reserved once.
+// |reservedNameArray| contains |NSString|
+@property(nonatomic, readwrite, strong) NSMutableArray *reservedNameArray;
+
@end
#pragma mark - GPBDescriptorProto_ExtensionRange
@@ -266,6 +293,28 @@ typedef GPB_ENUM(GPBDescriptorProto_ExtensionRange_FieldNumber) {
@end
+#pragma mark - GPBDescriptorProto_ReservedRange
+
+typedef GPB_ENUM(GPBDescriptorProto_ReservedRange_FieldNumber) {
+ GPBDescriptorProto_ReservedRange_FieldNumber_Start = 1,
+ GPBDescriptorProto_ReservedRange_FieldNumber_End = 2,
+};
+
+// Range of reserved tag numbers. Reserved tag numbers may not be used by
+// fields or extension ranges in the same message. Reserved ranges may
+// not overlap.
+@interface GPBDescriptorProto_ReservedRange : GPBMessage
+
+// Inclusive.
+@property(nonatomic, readwrite) BOOL hasStart;
+@property(nonatomic, readwrite) int32_t start;
+
+// Exclusive.
+@property(nonatomic, readwrite) BOOL hasEnd;
+@property(nonatomic, readwrite) int32_t end;
+
+@end
+
#pragma mark - GPBFieldDescriptorProto
typedef GPB_ENUM(GPBFieldDescriptorProto_FieldNumber) {
@@ -654,6 +703,7 @@ typedef GPB_ENUM(GPBFieldOptions_FieldNumber) {
GPBFieldOptions_FieldNumber_Packed = 2,
GPBFieldOptions_FieldNumber_Deprecated = 3,
GPBFieldOptions_FieldNumber_Lazy = 5,
+ GPBFieldOptions_FieldNumber_Jstype = 6,
GPBFieldOptions_FieldNumber_Weak = 10,
GPBFieldOptions_FieldNumber_UninterpretedOptionArray = 999,
};
@@ -670,10 +720,23 @@ typedef GPB_ENUM(GPBFieldOptions_FieldNumber) {
// The packed option can be enabled for repeated primitive fields to enable
// a more efficient representation on the wire. Rather than repeatedly
// writing the tag and type for each element, the entire array is encoded as
-// a single length-delimited blob.
+// a single length-delimited blob. In proto3, only explicit setting it to
+// false will avoid using packed encoding.
@property(nonatomic, readwrite) BOOL hasPacked;
@property(nonatomic, readwrite) BOOL packed;
+// The jstype option determines the JavaScript type used for values of the
+// field. The option is permitted only for 64 bit integral and fixed types
+// (int64, uint64, sint64, fixed64, sfixed64). By default these types are
+// represented as JavaScript strings. This avoids loss of precision that can
+// happen when a large value is converted to a floating point JavaScript
+// numbers. Specifying JS_NUMBER for the jstype causes the generated
+// JavaScript code to use the JavaScript "number" type instead of strings.
+// This option is an enum to permit additional types to be added,
+// e.g. goog.math.Integer.
+@property(nonatomic, readwrite) BOOL hasJstype;
+@property(nonatomic, readwrite) GPBFieldOptions_JSType jstype;
+
// Should this field be parsed lazily? Lazy applies only to message-type
// fields. It means that when the outer message is initially parsed, the
// inner message's contents will not be parsed but instead stored in encoded
diff --git a/objectivec/google/protobuf/Descriptor.pbobjc.m b/objectivec/google/protobuf/Descriptor.pbobjc.m
index 2fc1953c..7f1bdd49 100644
--- a/objectivec/google/protobuf/Descriptor.pbobjc.m
+++ b/objectivec/google/protobuf/Descriptor.pbobjc.m
@@ -273,6 +273,8 @@ typedef struct GPBFileDescriptorProto_Storage {
@dynamic extensionRangeArray;
@dynamic oneofDeclArray;
@dynamic hasOptions, options;
+@dynamic reservedRangeArray;
+@dynamic reservedNameArray;
typedef struct GPBDescriptorProto_Storage {
uint32_t _has_storage_[1];
@@ -284,6 +286,8 @@ typedef struct GPBDescriptorProto_Storage {
NSMutableArray *extensionArray;
GPBMessageOptions *options;
NSMutableArray *oneofDeclArray;
+ NSMutableArray *reservedRangeArray;
+ NSMutableArray *reservedNameArray;
} GPBDescriptorProto_Storage;
// This method is threadsafe because it is initially called
@@ -380,6 +384,28 @@ typedef struct GPBDescriptorProto_Storage {
.typeSpecific.className = GPBStringifySymbol(GPBOneofDescriptorProto),
.fieldOptions = NULL,
},
+ {
+ .name = "reservedRangeArray",
+ .number = GPBDescriptorProto_FieldNumber_ReservedRangeArray,
+ .hasIndex = GPBNoHasBit,
+ .flags = GPBFieldRepeated,
+ .type = GPBTypeMessage,
+ .offset = offsetof(GPBDescriptorProto_Storage, reservedRangeArray),
+ .defaultValue.valueMessage = nil,
+ .typeSpecific.className = GPBStringifySymbol(GPBDescriptorProto_ReservedRange),
+ .fieldOptions = NULL,
+ },
+ {
+ .name = "reservedNameArray",
+ .number = GPBDescriptorProto_FieldNumber_ReservedNameArray,
+ .hasIndex = GPBNoHasBit,
+ .flags = GPBFieldRepeated,
+ .type = GPBTypeString,
+ .offset = offsetof(GPBDescriptorProto_Storage, reservedNameArray),
+ .defaultValue.valueMessage = nil,
+ .typeSpecific.className = NULL,
+ .fieldOptions = NULL,
+ },
};
descriptor = [GPBDescriptor allocDescriptorForClass:[GPBDescriptorProto class]
rootClass:[GPBDescriptorRoot class]
@@ -461,6 +487,67 @@ typedef struct GPBDescriptorProto_ExtensionRange_Storage {
@end
+#pragma mark - GPBDescriptorProto_ReservedRange
+
+@implementation GPBDescriptorProto_ReservedRange
+
+@dynamic hasStart, start;
+@dynamic hasEnd, end;
+
+typedef struct GPBDescriptorProto_ReservedRange_Storage {
+ uint32_t _has_storage_[1];
+ int32_t start;
+ int32_t end;
+} GPBDescriptorProto_ReservedRange_Storage;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "start",
+ .number = GPBDescriptorProto_ReservedRange_FieldNumber_Start,
+ .hasIndex = 0,
+ .flags = GPBFieldOptional,
+ .type = GPBTypeInt32,
+ .offset = offsetof(GPBDescriptorProto_ReservedRange_Storage, start),
+ .defaultValue.valueInt32 = 0,
+ .typeSpecific.className = NULL,
+ .fieldOptions = NULL,
+ },
+ {
+ .name = "end",
+ .number = GPBDescriptorProto_ReservedRange_FieldNumber_End,
+ .hasIndex = 1,
+ .flags = GPBFieldOptional,
+ .type = GPBTypeInt32,
+ .offset = offsetof(GPBDescriptorProto_ReservedRange_Storage, end),
+ .defaultValue.valueInt32 = 0,
+ .typeSpecific.className = NULL,
+ .fieldOptions = NULL,
+ },
+ };
+ descriptor = [GPBDescriptor allocDescriptorForClass:[GPBDescriptorProto_ReservedRange class]
+ rootClass:[GPBDescriptorRoot class]
+ file:GPBDescriptorRoot_FileDescriptor()
+ fields:fields
+ fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
+ oneofs:NULL
+ oneofCount:0
+ enums:NULL
+ enumCount:0
+ ranges:NULL
+ rangeCount:0
+ storageSize:sizeof(GPBDescriptorProto_ReservedRange_Storage)
+ wireFormat:NO];
+ }
+ return descriptor;
+}
+
+@end
+
#pragma mark - GPBFieldDescriptorProto
@implementation GPBFieldDescriptorProto
@@ -1462,6 +1549,7 @@ typedef struct GPBMessageOptions_Storage {
@dynamic hasCtype, ctype;
@dynamic hasPacked, packed;
+@dynamic hasJstype, jstype;
@dynamic hasLazy, lazy;
@dynamic hasDeprecated, deprecated;
@dynamic hasWeak, weak;
@@ -1474,6 +1562,7 @@ typedef struct GPBFieldOptions_Storage {
BOOL lazy;
BOOL weak;
GPBFieldOptions_CType ctype;
+ GPBFieldOptions_JSType jstype;
NSMutableArray *uninterpretedOptionArray;
} GPBFieldOptions_Storage;
@@ -1508,7 +1597,7 @@ typedef struct GPBFieldOptions_Storage {
{
.name = "deprecated",
.number = GPBFieldOptions_FieldNumber_Deprecated,
- .hasIndex = 3,
+ .hasIndex = 4,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, deprecated),
@@ -1519,7 +1608,7 @@ typedef struct GPBFieldOptions_Storage {
{
.name = "lazy",
.number = GPBFieldOptions_FieldNumber_Lazy,
- .hasIndex = 2,
+ .hasIndex = 3,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, lazy),
@@ -1528,9 +1617,20 @@ typedef struct GPBFieldOptions_Storage {
.fieldOptions = NULL,
},
{
+ .name = "jstype",
+ .number = GPBFieldOptions_FieldNumber_Jstype,
+ .hasIndex = 2,
+ .flags = GPBFieldOptional | GPBFieldHasDefaultValue | GPBFieldHasEnumDescriptor,
+ .type = GPBTypeEnum,
+ .offset = offsetof(GPBFieldOptions_Storage, jstype),
+ .defaultValue.valueEnum = GPBFieldOptions_JSType_JsNormal,
+ .typeSpecific.enumDescFunc = GPBFieldOptions_JSType_EnumDescriptor,
+ .fieldOptions = NULL,
+ },
+ {
.name = "weak",
.number = GPBFieldOptions_FieldNumber_Weak,
- .hasIndex = 4,
+ .hasIndex = 5,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, weak),
@@ -1552,6 +1652,7 @@ typedef struct GPBFieldOptions_Storage {
};
static GPBMessageEnumDescription enums[] = {
{ .enumDescriptorFunc = GPBFieldOptions_CType_EnumDescriptor },
+ { .enumDescriptorFunc = GPBFieldOptions_JSType_EnumDescriptor },
};
static GPBExtensionRange ranges[] = {
{ .start = 1000, .end = 536870912 },
@@ -1604,6 +1705,35 @@ BOOL GPBFieldOptions_CType_IsValidValue(int32_t value__) {
}
}
+#pragma mark - Enum GPBFieldOptions_JSType
+
+GPBEnumDescriptor *GPBFieldOptions_JSType_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static GPBMessageEnumValueDescription values[] = {
+ { .name = "JsNormal", .number = GPBFieldOptions_JSType_JsNormal },
+ { .name = "JsString", .number = GPBFieldOptions_JSType_JsString },
+ { .name = "JsNumber", .number = GPBFieldOptions_JSType_JsNumber },
+ };
+ descriptor = [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBFieldOptions_JSType)
+ values:values
+ valueCount:sizeof(values) / sizeof(GPBMessageEnumValueDescription)
+ enumVerifier:GPBFieldOptions_JSType_IsValidValue];
+ }
+ return descriptor;
+}
+
+BOOL GPBFieldOptions_JSType_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBFieldOptions_JSType_JsNormal:
+ case GPBFieldOptions_JSType_JsString:
+ case GPBFieldOptions_JSType_JsNumber:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
#pragma mark - GPBEnumOptions
@implementation GPBEnumOptions