aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/GPBDescriptor.m
diff options
context:
space:
mode:
Diffstat (limited to 'objectivec/GPBDescriptor.m')
-rw-r--r--objectivec/GPBDescriptor.m47
1 files changed, 33 insertions, 14 deletions
diff --git a/objectivec/GPBDescriptor.m b/objectivec/GPBDescriptor.m
index 3c3844da..ad46ef4f 100644
--- a/objectivec/GPBDescriptor.m
+++ b/objectivec/GPBDescriptor.m
@@ -411,7 +411,7 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
}
- (NSString *)name {
- return @(name_);
+ return (NSString * _Nonnull)@(name_);
}
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
@@ -548,7 +548,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
// descriptor structure.
const uint8_t *bytes = (const uint8_t *)defaultValue_.valueData;
if (bytes) {
- uint32_t length = *((uint32_t *)bytes);
+ uint32_t length;
+ memcpy(&length, bytes, sizeof(length));
length = ntohl(length);
bytes += sizeof(length);
defaultValue_.valueData =
@@ -581,7 +582,7 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
}
- (NSString *)name {
- return @(description_->name);
+ return (NSString * _Nonnull)@(description_->name);
}
- (BOOL)isRequired {
@@ -829,13 +830,9 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
}
- (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 [self getEnumNameForIndex:i];
}
}
return nil;
@@ -885,8 +882,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
}
- (NSString *)textFormatNameForValue:(int32_t)number {
- if (nameOffsets_ == NULL) [self calcValueNameOffsets];
-
// Find the EnumValue descriptor and its index.
BOOL foundIt = NO;
uint32_t valueDescriptorIndex;
@@ -901,16 +896,39 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
if (!foundIt) {
return nil;
}
+ return [self getEnumTextFormatNameForIndex:valueDescriptorIndex];
+}
+
+- (uint32_t)enumNameCount {
+ return valueCount_;
+}
+
+- (NSString *)getEnumNameForIndex:(uint32_t)index {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+ if (index >= valueCount_) {
+ return nil;
+ }
+ const char *valueName = valueNames_ + nameOffsets_[index];
+ NSString *fullName = [NSString stringWithFormat:@"%@_%s", name_, valueName];
+ return fullName;
+}
+
+- (NSString *)getEnumTextFormatNameForIndex:(uint32_t)index {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ if (index >= valueCount_) {
+ return nil;
+ }
NSString *result = nil;
// Naming adds an underscore between enum name and value name, skip that also.
- const char *valueName = valueNames_ + nameOffsets_[valueDescriptorIndex];
+ const char *valueName = valueNames_ + nameOffsets_[index];
NSString *shortName = @(valueName);
// See if it is in the map of special format handling.
if (extraTextFormatInfo_) {
result = GPBDecodeTextFormatName(extraTextFormatInfo_,
- (int32_t)valueDescriptorIndex, shortName);
+ (int32_t)index, shortName);
}
// Logic here needs to match what objectivec_enum.cc does in the proto
// compiler.
@@ -963,7 +981,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
const uint8_t *bytes =
(const uint8_t *)description->defaultValue.valueData;
if (bytes) {
- uint32_t length = *((uint32_t *)bytes);
+ uint32_t length;
+ memcpy(&length, bytes, sizeof(length));
// The length is stored in network byte order.
length = ntohl(length);
bytes += sizeof(length);
@@ -996,7 +1015,7 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
}
- (NSString *)singletonName {
- return @(description_->singletonName);
+ return (NSString * _Nonnull)@(description_->singletonName);
}
- (const char *)singletonNameC {