ADD: added new version of protobuf
This commit is contained in:
@@ -40,7 +40,8 @@
|
||||
|
||||
static void checkNumber(int32_t number) {
|
||||
if (number == 0) {
|
||||
[NSException raise:NSInvalidArgumentException format:@"Zero is not a valid field number."];
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Zero is not a valid field number."];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +50,8 @@ static void checkNumber(int32_t number) {
|
||||
CFMutableDictionaryRef fields_;
|
||||
}
|
||||
|
||||
static void CopyWorker(__unused const void *key, const void *value, void *context) {
|
||||
static void CopyWorker(const void *key, const void *value, void *context) {
|
||||
#pragma unused(key)
|
||||
GPBUnknownField *field = value;
|
||||
GPBUnknownFieldSet *result = context;
|
||||
|
||||
@@ -109,7 +111,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
|
||||
- (GPBUnknownField *)getField:(int32_t)number {
|
||||
ssize_t key = number;
|
||||
GPBUnknownField *result = fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
|
||||
GPBUnknownField *result =
|
||||
fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -122,7 +125,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
size_t count = CFDictionaryGetCount(fields_);
|
||||
ssize_t keys[count];
|
||||
GPBUnknownField *values[count];
|
||||
CFDictionaryGetKeysAndValues(fields_, (const void **)keys, (const void **)values);
|
||||
CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
|
||||
(const void **)values);
|
||||
struct GPBFieldPair {
|
||||
ssize_t key;
|
||||
GPBUnknownField *value;
|
||||
@@ -131,11 +135,12 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
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);
|
||||
});
|
||||
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;
|
||||
};
|
||||
@@ -149,7 +154,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
size_t count = CFDictionaryGetCount(fields_);
|
||||
ssize_t keys[count];
|
||||
GPBUnknownField *values[count];
|
||||
CFDictionaryGetKeysAndValues(fields_, (const void **)keys, (const void **)values);
|
||||
CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
|
||||
(const void **)values);
|
||||
if (count > 1) {
|
||||
struct GPBFieldPair {
|
||||
ssize_t key;
|
||||
@@ -160,11 +166,12 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
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);
|
||||
});
|
||||
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];
|
||||
@@ -175,16 +182,17 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
NSMutableString *description =
|
||||
[NSMutableString stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self];
|
||||
NSMutableString *description = [NSMutableString
|
||||
stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self];
|
||||
NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" ");
|
||||
[description appendString:textFormat];
|
||||
[description appendString:@"}"];
|
||||
return description;
|
||||
}
|
||||
|
||||
static void GPBUnknownFieldSetSerializedSize(__unused const void *key, const void *value,
|
||||
static void GPBUnknownFieldSetSerializedSize(const void *key, const void *value,
|
||||
void *context) {
|
||||
#pragma unused(key)
|
||||
GPBUnknownField *field = value;
|
||||
size_t *result = context;
|
||||
*result += [field serializedSize];
|
||||
@@ -193,13 +201,16 @@ static void GPBUnknownFieldSetSerializedSize(__unused const void *key, const voi
|
||||
- (size_t)serializedSize {
|
||||
size_t result = 0;
|
||||
if (fields_) {
|
||||
CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize, &result);
|
||||
CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize,
|
||||
&result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void GPBUnknownFieldSetWriteAsMessageSetTo(__unused const void *key, const void *value,
|
||||
static void GPBUnknownFieldSetWriteAsMessageSetTo(const void *key,
|
||||
const void *value,
|
||||
void *context) {
|
||||
#pragma unused(key)
|
||||
GPBUnknownField *field = value;
|
||||
GPBCodedOutputStream *output = context;
|
||||
[field writeAsMessageSetExtensionToOutput:output];
|
||||
@@ -207,12 +218,15 @@ static void GPBUnknownFieldSetWriteAsMessageSetTo(__unused const void *key, cons
|
||||
|
||||
- (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output {
|
||||
if (fields_) {
|
||||
CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo, output);
|
||||
CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo,
|
||||
output);
|
||||
}
|
||||
}
|
||||
|
||||
static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *key,
|
||||
const void *value, void *context) {
|
||||
static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
|
||||
const void *value,
|
||||
void *context) {
|
||||
#pragma unused(key)
|
||||
GPBUnknownField *field = value;
|
||||
size_t *result = context;
|
||||
*result += [field serializedSizeAsMessageSetExtension];
|
||||
@@ -221,14 +235,16 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke
|
||||
- (size_t)serializedSizeAsMessageSet {
|
||||
size_t result = 0;
|
||||
if (fields_) {
|
||||
CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result);
|
||||
CFDictionaryApplyFunction(
|
||||
fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSData *)data {
|
||||
NSMutableData *data = [NSMutableData dataWithLength:self.serializedSize];
|
||||
GPBCodedOutputStream *output = [[GPBCodedOutputStream alloc] initWithData:data];
|
||||
GPBCodedOutputStream *output =
|
||||
[[GPBCodedOutputStream alloc] initWithData:data];
|
||||
[self writeToCodedOutputStream:output];
|
||||
[output release];
|
||||
return data;
|
||||
@@ -244,8 +260,8 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke
|
||||
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);
|
||||
fields_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL,
|
||||
&kCFTypeDictionaryValueCallBacks);
|
||||
}
|
||||
ssize_t key = number;
|
||||
CFDictionarySetValue(fields_, (const void *)key, field);
|
||||
@@ -253,7 +269,8 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke
|
||||
|
||||
- (GPBUnknownField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create {
|
||||
ssize_t key = number;
|
||||
GPBUnknownField *existing = fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil;
|
||||
GPBUnknownField *existing =
|
||||
fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil;
|
||||
if (!existing && create) {
|
||||
existing = [[GPBUnknownField alloc] initWithNumber:number];
|
||||
// This retains existing.
|
||||
@@ -263,8 +280,10 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke
|
||||
return existing;
|
||||
}
|
||||
|
||||
static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const void *value,
|
||||
static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
|
||||
const void *value,
|
||||
void *context) {
|
||||
#pragma unused(key)
|
||||
GPBUnknownField *field = value;
|
||||
GPBUnknownFieldSet *self = context;
|
||||
|
||||
@@ -285,7 +304,8 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const
|
||||
|
||||
- (void)mergeUnknownFields:(GPBUnknownFieldSet *)other {
|
||||
if (other && other->fields_) {
|
||||
CFDictionaryApplyFunction(other->fields_, GPBUnknownFieldSetMergeUnknownFields, self);
|
||||
CFDictionaryApplyFunction(other->fields_,
|
||||
GPBUnknownFieldSetMergeUnknownFields, self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +362,8 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const
|
||||
}
|
||||
|
||||
- (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData {
|
||||
[[self mutableFieldForNumber:number create:YES] addLengthDelimited:messageData];
|
||||
[[self mutableFieldForNumber:number create:YES]
|
||||
addLengthDelimited:messageData];
|
||||
}
|
||||
|
||||
- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
|
||||
|
||||
Reference in New Issue
Block a user