Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
7377eb2b
Commit
7377eb2b
authored
Sep 09, 2016
by
Thomas Van Lenten
Committed by
GitHub
Sep 09, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1970 from thomasvl/objc_any_helpers
Objc any helpers
parents
5d35e609
337ec306
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
557 additions
and
38 deletions
+557
-38
compile_testing_protos.sh
objectivec/DevTools/compile_testing_protos.sh
+1
-0
GPBBootstrap.h
objectivec/GPBBootstrap.h
+1
-1
GPBDescriptor.h
objectivec/GPBDescriptor.h
+9
-0
GPBDescriptor.m
objectivec/GPBDescriptor.m
+113
-1
GPBDescriptor_PackagePrivate.h
objectivec/GPBDescriptor_PackagePrivate.h
+5
-0
GPBWellKnownTypes.h
objectivec/GPBWellKnownTypes.h
+125
-0
GPBWellKnownTypes.m
objectivec/GPBWellKnownTypes.m
+135
-0
GPBDescriptorTests.m
objectivec/Tests/GPBDescriptorTests.m
+29
-0
GPBUnittestProtos.m
objectivec/Tests/GPBUnittestProtos.m
+1
-0
GPBWellKnownTypesTest.m
objectivec/Tests/GPBWellKnownTypesTest.m
+56
-0
Any.pbobjc.h
objectivec/google/protobuf/Any.pbobjc.h
+1
-1
Any.pbobjc.m
objectivec/google/protobuf/Any.pbobjc.m
+1
-0
Api.pbobjc.h
objectivec/google/protobuf/Api.pbobjc.h
+1
-1
Api.pbobjc.m
objectivec/google/protobuf/Api.pbobjc.m
+1
-0
Duration.pbobjc.h
objectivec/google/protobuf/Duration.pbobjc.h
+1
-1
Duration.pbobjc.m
objectivec/google/protobuf/Duration.pbobjc.m
+1
-0
Empty.pbobjc.h
objectivec/google/protobuf/Empty.pbobjc.h
+1
-1
Empty.pbobjc.m
objectivec/google/protobuf/Empty.pbobjc.m
+1
-0
FieldMask.pbobjc.h
objectivec/google/protobuf/FieldMask.pbobjc.h
+1
-1
FieldMask.pbobjc.m
objectivec/google/protobuf/FieldMask.pbobjc.m
+1
-0
SourceContext.pbobjc.h
objectivec/google/protobuf/SourceContext.pbobjc.h
+1
-1
SourceContext.pbobjc.m
objectivec/google/protobuf/SourceContext.pbobjc.m
+1
-0
Struct.pbobjc.h
objectivec/google/protobuf/Struct.pbobjc.h
+1
-1
Struct.pbobjc.m
objectivec/google/protobuf/Struct.pbobjc.m
+1
-0
Timestamp.pbobjc.h
objectivec/google/protobuf/Timestamp.pbobjc.h
+1
-1
Timestamp.pbobjc.m
objectivec/google/protobuf/Timestamp.pbobjc.m
+1
-0
Type.pbobjc.h
objectivec/google/protobuf/Type.pbobjc.h
+1
-1
Type.pbobjc.m
objectivec/google/protobuf/Type.pbobjc.m
+1
-0
Wrappers.pbobjc.h
objectivec/google/protobuf/Wrappers.pbobjc.h
+1
-1
Wrappers.pbobjc.m
objectivec/google/protobuf/Wrappers.pbobjc.m
+1
-0
objectivec_file.cc
src/google/protobuf/compiler/objectivec/objectivec_file.cc
+24
-13
objectivec_helpers.cc
...google/protobuf/compiler/objectivec/objectivec_helpers.cc
+21
-13
objectivec_helpers.h
src/google/protobuf/compiler/objectivec/objectivec_helpers.h
+4
-0
objectivec_message.cc
...google/protobuf/compiler/objectivec/objectivec_message.cc
+13
-0
No files found.
objectivec/DevTools/compile_testing_protos.sh
View file @
7377eb2b
...
@@ -93,6 +93,7 @@ compile_protos() {
...
@@ -93,6 +93,7 @@ compile_protos() {
# sources can be generated from them.
# sources can be generated from them.
CORE_PROTO_FILES
=(
CORE_PROTO_FILES
=(
src/google/protobuf/any_test.proto
src/google/protobuf/unittest_arena.proto
src/google/protobuf/unittest_arena.proto
src/google/protobuf/unittest_custom_options.proto
src/google/protobuf/unittest_custom_options.proto
src/google/protobuf/unittest_enormous_descriptor.proto
src/google/protobuf/unittest_enormous_descriptor.proto
...
...
objectivec/GPBBootstrap.h
View file @
7377eb2b
...
@@ -99,4 +99,4 @@
...
@@ -99,4 +99,4 @@
// regenerated.
// regenerated.
//
//
// Meant to be used internally by generated code.
// Meant to be used internally by generated code.
#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 3000
1
#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 3000
2
objectivec/GPBDescriptor.h
View file @
7377eb2b
...
@@ -81,6 +81,13 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
...
@@ -81,6 +81,13 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
@property
(
nonatomic
,
readonly
,
getter
=
isWireFormat
)
BOOL
wireFormat
;
@property
(
nonatomic
,
readonly
,
getter
=
isWireFormat
)
BOOL
wireFormat
;
/** The class of this message. */
/** The class of this message. */
@property
(
nonatomic
,
readonly
)
Class
messageClass
;
@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.
* Gets the field for the given number.
...
@@ -118,6 +125,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
...
@@ -118,6 +125,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/** The package declared in the proto file. */
/** The package declared in the proto file. */
@property
(
nonatomic
,
readonly
,
copy
)
NSString
*
package
;
@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. */
/** The syntax of the proto file. */
@property
(
nonatomic
,
readonly
)
GPBFileSyntax
syntax
;
@property
(
nonatomic
,
readonly
)
GPBFileSyntax
syntax
;
...
...
objectivec/GPBDescriptor.m
View file @
7377eb2b
...
@@ -42,8 +42,10 @@
...
@@ -42,8 +42,10 @@
#pragma clang diagnostic push
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
// The address
of this variable is used as a key for obj
_getAssociatedObject.
// The address
es of these variables are used as keys for objc
_getAssociatedObject.
static
const
char
kTextFormatExtraValueKey
=
0
;
static
const
char
kTextFormatExtraValueKey
=
0
;
static
const
char
kParentClassNameValueKey
=
0
;
static
const
char
kClassNameSuffixKey
=
0
;
// Utility function to generate selectors on the fly.
// Utility function to generate selectors on the fly.
static
SEL
SelFromStrings
(
const
char
*
prefix
,
const
char
*
middle
,
static
SEL
SelFromStrings
(
const
char
*
prefix
,
const
char
*
middle
,
...
@@ -215,10 +217,102 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
...
@@ -215,10 +217,102 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
extensionRangesCount_
=
count
;
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
{
-
(
NSString
*
)
name
{
return
NSStringFromClass
(
messageClass_
);
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
{
-
(
id
)
copyWithZone
:
(
NSZone
*
)
zone
{
#pragma unused(zone)
#pragma unused(zone)
return
[
self
retain
];
return
[
self
retain
];
...
@@ -255,12 +349,26 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
...
@@ -255,12 +349,26 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
@implementation
GPBFileDescriptor
{
@implementation
GPBFileDescriptor
{
NSString
*
package_
;
NSString
*
package_
;
NSString
*
objcPrefix_
;
GPBFileSyntax
syntax_
;
GPBFileSyntax
syntax_
;
}
}
@synthesize
package
=
package_
;
@synthesize
package
=
package_
;
@synthesize
objcPrefix
=
objcPrefix_
;
@synthesize
syntax
=
syntax_
;
@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
-
(
instancetype
)
initWithPackage
:(
NSString
*
)
package
syntax
:(
GPBFileSyntax
)
syntax
{
syntax
:(
GPBFileSyntax
)
syntax
{
self
=
[
super
init
];
self
=
[
super
init
];
...
@@ -273,6 +381,7 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
...
@@ -273,6 +381,7 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
-
(
void
)
dealloc
{
-
(
void
)
dealloc
{
[
package_
release
];
[
package_
release
];
[
objcPrefix_
release
];
[
super
dealloc
];
[
super
dealloc
];
}
}
...
@@ -416,6 +525,9 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
...
@@ -416,6 +525,9 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
// Extra type specific data.
// Extra type specific data.
if
(
isMessage
)
{
if
(
isMessage
)
{
const
char
*
className
=
coreDesc
->
dataTypeSpecific
.
className
;
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
);
msgClass_
=
objc_getClass
(
className
);
NSAssert
(
msgClass_
,
@"Class %s not defined"
,
className
);
NSAssert
(
msgClass_
,
@"Class %s not defined"
,
className
);
}
else
if
(
dataType
==
GPBDataTypeEnum
)
{
}
else
if
(
dataType
==
GPBDataTypeEnum
)
{
...
...
objectivec/GPBDescriptor_PackagePrivate.h
View file @
7377eb2b
...
@@ -168,10 +168,15 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
...
@@ -168,10 +168,15 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
firstHasIndex
:(
int32_t
)
firstHasIndex
;
firstHasIndex
:(
int32_t
)
firstHasIndex
;
-
(
void
)
setupExtraTextInfo
:(
const
char
*
)
extraTextFormatInfo
;
-
(
void
)
setupExtraTextInfo
:(
const
char
*
)
extraTextFormatInfo
;
-
(
void
)
setupExtensionRanges
:(
const
GPBExtensionRange
*
)
ranges
count
:(
int32_t
)
count
;
-
(
void
)
setupExtensionRanges
:(
const
GPBExtensionRange
*
)
ranges
count
:(
int32_t
)
count
;
-
(
void
)
setupContainingMessageClassName
:(
const
char
*
)
msgClassName
;
-
(
void
)
setupMessageClassNameSuffix
:(
NSString
*
)
suffix
;
@end
@end
@interface
GPBFileDescriptor
()
@interface
GPBFileDescriptor
()
-
(
instancetype
)
initWithPackage
:
(
NSString
*
)
package
objcPrefix
:
(
NSString
*
)
objcPrefix
syntax
:
(
GPBFileSyntax
)
syntax
;
-
(
instancetype
)
initWithPackage
:(
NSString
*
)
package
-
(
instancetype
)
initWithPackage
:(
NSString
*
)
package
syntax
:(
GPBFileSyntax
)
syntax
;
syntax
:(
GPBFileSyntax
)
syntax
;
@end
@end
...
...
objectivec/GPBWellKnownTypes.h
View file @
7377eb2b
...
@@ -37,15 +37,32 @@
...
@@ -37,15 +37,32 @@
#endif
#endif
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
#import <Protobuf/Any.pbobjc.h>
#import <Protobuf/Duration.pbobjc.h>
#import <Protobuf/Duration.pbobjc.h>
#import <Protobuf/Timestamp.pbobjc.h>
#import <Protobuf/Timestamp.pbobjc.h>
#else
#else
#import "google/protobuf/Any.pbobjc.h"
#import "google/protobuf/Duration.pbobjc.h"
#import "google/protobuf/Duration.pbobjc.h"
#import "google/protobuf/Timestamp.pbobjc.h"
#import "google/protobuf/Timestamp.pbobjc.h"
#endif
#endif
NS_ASSUME_NONNULL_BEGIN
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.
* Category for GPBTimestamp to work with standard Foundation time/date types.
**/
**/
...
@@ -82,6 +99,8 @@ NS_ASSUME_NONNULL_BEGIN
...
@@ -82,6 +99,8 @@ NS_ASSUME_NONNULL_BEGIN
@end
@end
#pragma mark - GPBDuration
/**
/**
* Category for GPBDuration to work with standard Foundation time type.
* Category for GPBDuration to work with standard Foundation time type.
**/
**/
...
@@ -106,4 +125,110 @@ NS_ASSUME_NONNULL_BEGIN
...
@@ -106,4 +125,110 @@ NS_ASSUME_NONNULL_BEGIN
@end
@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
NS_ASSUME_NONNULL_END
objectivec/GPBWellKnownTypes.m
View file @
7377eb2b
...
@@ -34,6 +34,13 @@
...
@@ -34,6 +34,13 @@
#import "GPBWellKnownTypes.h"
#import "GPBWellKnownTypes.h"
#import "GPBUtilities_PackagePrivate.h"
NSString
*
const
GPBWellKnownTypesErrorDomain
=
GPBNSStringifySymbol
(
GPBWellKnownTypesErrorDomain
);
static
NSString
*
kTypePrefixGoogleApisCom
=
@"type.googleapis.com/"
;
static
NSTimeInterval
TimeIntervalSince1970FromSecondsAndNanos
(
int64_t
seconds
,
static
NSTimeInterval
TimeIntervalSince1970FromSecondsAndNanos
(
int64_t
seconds
,
int32_t
nanos
)
{
int32_t
nanos
)
{
return
seconds
+
(
NSTimeInterval
)
nanos
/
1e9
;
return
seconds
+
(
NSTimeInterval
)
nanos
/
1e9
;
...
@@ -48,6 +55,30 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
...
@@ -48,6 +55,30 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
return
(
int32_t
)
nanos
;
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
)
@implementation
GPBTimestamp
(
GBPWellKnownTypes
)
-
(
instancetype
)
initWithDate
:(
NSDate
*
)
date
{
-
(
instancetype
)
initWithDate
:(
NSDate
*
)
date
{
...
@@ -87,6 +118,8 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
...
@@ -87,6 +118,8 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
@end
@end
#pragma mark - GPBDuration
@implementation
GPBDuration
(
GBPWellKnownTypes
)
@implementation
GPBDuration
(
GBPWellKnownTypes
)
-
(
instancetype
)
initWithTimeIntervalSince1970
:(
NSTimeInterval
)
timeIntervalSince1970
{
-
(
instancetype
)
initWithTimeIntervalSince1970
:(
NSTimeInterval
)
timeIntervalSince1970
{
...
@@ -113,3 +146,105 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
...
@@ -113,3 +146,105 @@ static int32_t SecondsAndNanosFromTimeIntervalSince1970(NSTimeInterval time,
}
}
@end
@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
objectivec/Tests/GPBDescriptorTests.m
View file @
7377eb2b
...
@@ -34,12 +34,41 @@
...
@@ -34,12 +34,41 @@
#import "GPBDescriptor.h"
#import "GPBDescriptor.h"
#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestObjc.pbobjc.h"
#import "google/protobuf/Descriptor.pbobjc.h"
@interface
DescriptorTests
:
GPBTestCase
@interface
DescriptorTests
:
GPBTestCase
@end
@end
@implementation
DescriptorTests
@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
{
-
(
void
)
testFieldDescriptor
{
GPBDescriptor
*
descriptor
=
[
TestAllTypes
descriptor
];
GPBDescriptor
*
descriptor
=
[
TestAllTypes
descriptor
];
...
...
objectivec/Tests/GPBUnittestProtos.m
View file @
7377eb2b
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
//
a
descriptor
as
it
doesn
'
t
use
the
classes
/
enums
.
//
a
descriptor
as
it
doesn
'
t
use
the
classes
/
enums
.
#
import
"
google
/
protobuf
/
Descriptor
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
Descriptor
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
AnyTest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
MapProto2Unittest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
MapProto2Unittest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
MapUnittest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
MapUnittest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
Unittest
.
pbobjc
.
m
"
#
import
"
google
/
protobuf
/
Unittest
.
pbobjc
.
m
"
...
...
objectivec/Tests/GPBWellKnownTypesTest.m
View file @
7377eb2b
...
@@ -32,6 +32,8 @@
...
@@ -32,6 +32,8 @@
#import <XCTest/XCTest.h>
#import <XCTest/XCTest.h>
#import "google/protobuf/AnyTest.pbobjc.h"
// A basically random interval into the future for testing with.
// A basically random interval into the future for testing with.
static
const
NSTimeInterval
kFutureOffsetInterval
=
15000
;
static
const
NSTimeInterval
kFutureOffsetInterval
=
15000
;
...
@@ -99,4 +101,58 @@ static const NSTimeInterval kTimeAccuracy = 1e-9;
...
@@ -99,4 +101,58 @@ static const NSTimeInterval kTimeAccuracy = 1e-9;
[
duration2
release
];
[
duration2
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
@end
objectivec/google/protobuf/Any.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Any.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBAnyRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBAnyRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Api.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Api.pbobjc.m
View file @
7377eb2b
...
@@ -45,6 +45,7 @@ static GPBFileDescriptor *GPBApiRoot_FileDescriptor(void) {
...
@@ -45,6 +45,7 @@ static GPBFileDescriptor *GPBApiRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Duration.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Duration.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBDurationRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBDurationRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Empty.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Empty.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBEmptyRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBEmptyRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/FieldMask.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/FieldMask.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBFieldMaskRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBFieldMaskRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/SourceContext.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/SourceContext.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBSourceContextRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBSourceContextRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Struct.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Struct.pbobjc.m
View file @
7377eb2b
...
@@ -42,6 +42,7 @@ static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) {
...
@@ -42,6 +42,7 @@ static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Timestamp.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Timestamp.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBTimestampRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBTimestampRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Type.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Type.pbobjc.m
View file @
7377eb2b
...
@@ -45,6 +45,7 @@ static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) {
...
@@ -45,6 +45,7 @@ static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
objectivec/google/protobuf/Wrappers.pbobjc.h
View file @
7377eb2b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#import "GPBProtocolBuffers.h"
#import "GPBProtocolBuffers.h"
#endif
#endif
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
1
#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 3000
2
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.
#endif
#endif
...
...
objectivec/google/protobuf/Wrappers.pbobjc.m
View file @
7377eb2b
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBWrappersRoot_FileDescriptor(void) {
...
@@ -41,6 +41,7 @@ static GPBFileDescriptor *GPBWrappersRoot_FileDescriptor(void) {
if
(
!
descriptor
)
{
if
(
!
descriptor
)
{
GPBDebugCheckRuntimeVersion
();
GPBDebugCheckRuntimeVersion
();
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
descriptor
=
[[
GPBFileDescriptor
alloc
]
initWithPackage
:
@"google.protobuf"
objcPrefix
:
@"GPB"
syntax
:
GPBFileSyntaxProto3
];
syntax
:
GPBFileSyntaxProto3
];
}
}
return
descriptor
;
return
descriptor
;
...
...
src/google/protobuf/compiler/objectivec/objectivec_file.cc
View file @
7377eb2b
...
@@ -53,7 +53,7 @@ namespace {
...
@@ -53,7 +53,7 @@ namespace {
// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
// is the version check done to ensure generated code works with the current
// is the version check done to ensure generated code works with the current
// runtime being used.
// runtime being used.
const
int32
GOOGLE_PROTOBUF_OBJC_GEN_VERSION
=
3000
1
;
const
int32
GOOGLE_PROTOBUF_OBJC_GEN_VERSION
=
3000
2
;
const
char
*
kHeaderExtension
=
".pbobjc.h"
;
const
char
*
kHeaderExtension
=
".pbobjc.h"
;
...
@@ -463,19 +463,22 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
...
@@ -463,19 +463,22 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
// File descriptor only needed if there are messages to use it.
// File descriptor only needed if there are messages to use it.
if
(
message_generators_
.
size
()
>
0
)
{
if
(
message_generators_
.
size
()
>
0
)
{
string
syntax
;
map
<
string
,
string
>
vars
;
vars
[
"root_class_name"
]
=
root_class_name_
;
vars
[
"package"
]
=
file_
->
package
();
vars
[
"objc_prefix"
]
=
FileClassPrefix
(
file_
);
switch
(
file_
->
syntax
())
{
switch
(
file_
->
syntax
())
{
case
FileDescriptor
:
:
SYNTAX_UNKNOWN
:
case
FileDescriptor
:
:
SYNTAX_UNKNOWN
:
syntax
=
"GPBFileSyntaxUnknown"
;
vars
[
"syntax"
]
=
"GPBFileSyntaxUnknown"
;
break
;
break
;
case
FileDescriptor
:
:
SYNTAX_PROTO2
:
case
FileDescriptor
:
:
SYNTAX_PROTO2
:
syntax
=
"GPBFileSyntaxProto2"
;
vars
[
"syntax"
]
=
"GPBFileSyntaxProto2"
;
break
;
break
;
case
FileDescriptor
:
:
SYNTAX_PROTO3
:
case
FileDescriptor
:
:
SYNTAX_PROTO3
:
syntax
=
"GPBFileSyntaxProto3"
;
vars
[
"syntax"
]
=
"GPBFileSyntaxProto3"
;
break
;
break
;
}
}
printer
->
Print
(
printer
->
Print
(
vars
,
"#pragma mark - $root_class_name$_FileDescriptor
\n
"
"#pragma mark - $root_class_name$_FileDescriptor
\n
"
"
\n
"
"
\n
"
"static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {
\n
"
"static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {
\n
"
...
@@ -483,16 +486,24 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
...
@@ -483,16 +486,24 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety of the singleton.
\n
"
" // about thread safety of the singleton.
\n
"
" static GPBFileDescriptor *descriptor = NULL;
\n
"
" static GPBFileDescriptor *descriptor = NULL;
\n
"
" if (!descriptor) {
\n
"
" if (!descriptor) {
\n
"
" GPBDebugCheckRuntimeVersion();
\n
"
" GPBDebugCheckRuntimeVersion();
\n
"
);
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@
\"
$package$
\"\n
"
if
(
vars
[
"objc_prefix"
].
size
()
>
0
)
{
" syntax:$syntax$];
\n
"
printer
->
Print
(
vars
,
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@
\"
$package$
\"\n
"
" objcPrefix:@
\"
$objc_prefix$
\"\n
"
" syntax:$syntax$];
\n
"
);
}
else
{
printer
->
Print
(
vars
,
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@
\"
$package$
\"\n
"
" syntax:$syntax$];
\n
"
);
}
printer
->
Print
(
" }
\n
"
" }
\n
"
" return descriptor;
\n
"
" return descriptor;
\n
"
"}
\n
"
"}
\n
"
"
\n
"
,
"
\n
"
);
"root_class_name"
,
root_class_name_
,
"package"
,
file_
->
package
(),
"syntax"
,
syntax
);
}
}
for
(
vector
<
EnumGenerator
*>::
iterator
iter
=
enum_generators_
.
begin
();
for
(
vector
<
EnumGenerator
*>::
iterator
iter
=
enum_generators_
.
begin
();
...
...
src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
View file @
7377eb2b
...
@@ -210,10 +210,14 @@ const char* const kReservedWordList[] = {
...
@@ -210,10 +210,14 @@ const char* const kReservedWordList[] = {
hash_set
<
string
>
kReservedWords
=
hash_set
<
string
>
kReservedWords
=
MakeWordsMap
(
kReservedWordList
,
GOOGLE_ARRAYSIZE
(
kReservedWordList
));
MakeWordsMap
(
kReservedWordList
,
GOOGLE_ARRAYSIZE
(
kReservedWordList
));
string
SanitizeNameForObjC
(
const
string
&
input
,
const
string
&
extension
)
{
string
SanitizeNameForObjC
(
const
string
&
input
,
const
string
&
extension
,
string
*
out_suffix_added
)
{
if
(
kReservedWords
.
count
(
input
)
>
0
)
{
if
(
kReservedWords
.
count
(
input
)
>
0
)
{
if
(
out_suffix_added
)
*
out_suffix_added
=
extension
;
return
input
+
extension
;
return
input
+
extension
;
}
}
if
(
out_suffix_added
)
out_suffix_added
->
clear
();
return
input
;
return
input
;
}
}
...
@@ -336,6 +340,12 @@ string BaseFileName(const FileDescriptor* file) {
...
@@ -336,6 +340,12 @@ string BaseFileName(const FileDescriptor* file) {
return
basename
;
return
basename
;
}
}
string
FileClassPrefix
(
const
FileDescriptor
*
file
)
{
// Default is empty string, no need to check has_objc_class_prefix.
string
result
=
file
->
options
().
objc_class_prefix
();
return
result
;
}
string
FilePath
(
const
FileDescriptor
*
file
)
{
string
FilePath
(
const
FileDescriptor
*
file
)
{
string
output
;
string
output
;
string
basename
;
string
basename
;
...
@@ -366,19 +376,13 @@ string FilePathBasename(const FileDescriptor* file) {
...
@@ -366,19 +376,13 @@ string FilePathBasename(const FileDescriptor* file) {
return
output
;
return
output
;
}
}
string
FileClassPrefix
(
const
FileDescriptor
*
file
)
{
// Default is empty string, no need to check has_objc_class_prefix.
string
result
=
file
->
options
().
objc_class_prefix
();
return
result
;
}
string
FileClassName
(
const
FileDescriptor
*
file
)
{
string
FileClassName
(
const
FileDescriptor
*
file
)
{
string
name
=
FileClassPrefix
(
file
);
string
name
=
FileClassPrefix
(
file
);
name
+=
UnderscoresToCamelCase
(
StripProto
(
BaseFileName
(
file
)),
true
);
name
+=
UnderscoresToCamelCase
(
StripProto
(
BaseFileName
(
file
)),
true
);
name
+=
"Root"
;
name
+=
"Root"
;
// There aren't really any reserved words that end in "Root", but playing
// There aren't really any reserved words that end in "Root", but playing
// it safe and checking.
// it safe and checking.
return
SanitizeNameForObjC
(
name
,
"_RootClass"
);
return
SanitizeNameForObjC
(
name
,
"_RootClass"
,
NULL
);
}
}
string
ClassNameWorker
(
const
Descriptor
*
descriptor
)
{
string
ClassNameWorker
(
const
Descriptor
*
descriptor
)
{
...
@@ -400,11 +404,15 @@ string ClassNameWorker(const EnumDescriptor* descriptor) {
...
@@ -400,11 +404,15 @@ string ClassNameWorker(const EnumDescriptor* descriptor) {
}
}
string
ClassName
(
const
Descriptor
*
descriptor
)
{
string
ClassName
(
const
Descriptor
*
descriptor
)
{
return
ClassName
(
descriptor
,
NULL
);
}
string
ClassName
(
const
Descriptor
*
descriptor
,
string
*
out_suffix_added
)
{
// 1. Message names are used as is (style calls for CamelCase, trust it).
// 1. Message names are used as is (style calls for CamelCase, trust it).
// 2. Check for reserved word at the very end and then suffix things.
// 2. Check for reserved word at the very end and then suffix things.
string
prefix
=
FileClassPrefix
(
descriptor
->
file
());
string
prefix
=
FileClassPrefix
(
descriptor
->
file
());
string
name
=
ClassNameWorker
(
descriptor
);
string
name
=
ClassNameWorker
(
descriptor
);
return
SanitizeNameForObjC
(
prefix
+
name
,
"_Class"
);
return
SanitizeNameForObjC
(
prefix
+
name
,
"_Class"
,
out_suffix_added
);
}
}
string
EnumName
(
const
EnumDescriptor
*
descriptor
)
{
string
EnumName
(
const
EnumDescriptor
*
descriptor
)
{
...
@@ -418,7 +426,7 @@ string EnumName(const EnumDescriptor* descriptor) {
...
@@ -418,7 +426,7 @@ string EnumName(const EnumDescriptor* descriptor) {
// yields Fixed_Class, Fixed_Size.
// yields Fixed_Class, Fixed_Size.
string
name
=
FileClassPrefix
(
descriptor
->
file
());
string
name
=
FileClassPrefix
(
descriptor
->
file
());
name
+=
ClassNameWorker
(
descriptor
);
name
+=
ClassNameWorker
(
descriptor
);
return
SanitizeNameForObjC
(
name
,
"_Enum"
);
return
SanitizeNameForObjC
(
name
,
"_Enum"
,
NULL
);
}
}
string
EnumValueName
(
const
EnumValueDescriptor
*
descriptor
)
{
string
EnumValueName
(
const
EnumValueDescriptor
*
descriptor
)
{
...
@@ -433,7 +441,7 @@ string EnumValueName(const EnumValueDescriptor* descriptor) {
...
@@ -433,7 +441,7 @@ string EnumValueName(const EnumValueDescriptor* descriptor) {
const
string
&
name
=
class_name
+
"_"
+
value_str
;
const
string
&
name
=
class_name
+
"_"
+
value_str
;
// There aren't really any reserved words with an underscore and a leading
// There aren't really any reserved words with an underscore and a leading
// capital letter, but playing it safe and checking.
// capital letter, but playing it safe and checking.
return
SanitizeNameForObjC
(
name
,
"_Value"
);
return
SanitizeNameForObjC
(
name
,
"_Value"
,
NULL
);
}
}
string
EnumValueShortName
(
const
EnumValueDescriptor
*
descriptor
)
{
string
EnumValueShortName
(
const
EnumValueDescriptor
*
descriptor
)
{
...
@@ -470,7 +478,7 @@ string UnCamelCaseEnumShortName(const string& name) {
...
@@ -470,7 +478,7 @@ string UnCamelCaseEnumShortName(const string& name) {
string
ExtensionMethodName
(
const
FieldDescriptor
*
descriptor
)
{
string
ExtensionMethodName
(
const
FieldDescriptor
*
descriptor
)
{
const
string
&
name
=
NameFromFieldDescriptor
(
descriptor
);
const
string
&
name
=
NameFromFieldDescriptor
(
descriptor
);
const
string
&
result
=
UnderscoresToCamelCase
(
name
,
false
);
const
string
&
result
=
UnderscoresToCamelCase
(
name
,
false
);
return
SanitizeNameForObjC
(
result
,
"_Extension"
);
return
SanitizeNameForObjC
(
result
,
"_Extension"
,
NULL
);
}
}
string
FieldName
(
const
FieldDescriptor
*
field
)
{
string
FieldName
(
const
FieldDescriptor
*
field
)
{
...
@@ -485,7 +493,7 @@ string FieldName(const FieldDescriptor* field) {
...
@@ -485,7 +493,7 @@ string FieldName(const FieldDescriptor* field) {
result
+=
"_p"
;
result
+=
"_p"
;
}
}
}
}
return
SanitizeNameForObjC
(
result
,
"_p"
);
return
SanitizeNameForObjC
(
result
,
"_p"
,
NULL
);
}
}
string
FieldNameCapitalized
(
const
FieldDescriptor
*
field
)
{
string
FieldNameCapitalized
(
const
FieldDescriptor
*
field
)
{
...
...
src/google/protobuf/compiler/objectivec/objectivec_helpers.h
View file @
7377eb2b
...
@@ -67,6 +67,9 @@ bool IsRetainedName(const string& name);
...
@@ -67,6 +67,9 @@ bool IsRetainedName(const string& name);
// handling under ARC.
// handling under ARC.
bool
IsInitName
(
const
string
&
name
);
bool
IsInitName
(
const
string
&
name
);
// Gets the objc_class_prefix.
string
FileClassPrefix
(
const
FileDescriptor
*
file
);
// Gets the path of the file we're going to generate (sans the .pb.h
// Gets the path of the file we're going to generate (sans the .pb.h
// extension). The path will be dependent on the objectivec package
// extension). The path will be dependent on the objectivec package
// declared in the proto package.
// declared in the proto package.
...
@@ -83,6 +86,7 @@ string FileClassName(const FileDescriptor* file);
...
@@ -83,6 +86,7 @@ string FileClassName(const FileDescriptor* file);
// These return the fully-qualified class name corresponding to the given
// These return the fully-qualified class name corresponding to the given
// descriptor.
// descriptor.
string
ClassName
(
const
Descriptor
*
descriptor
);
string
ClassName
(
const
Descriptor
*
descriptor
);
string
ClassName
(
const
Descriptor
*
descriptor
,
string
*
out_suffix_added
);
string
EnumName
(
const
EnumDescriptor
*
descriptor
);
string
EnumName
(
const
EnumDescriptor
*
descriptor
);
// Returns the fully-qualified name of the enum value corresponding to the
// Returns the fully-qualified name of the enum value corresponding to the
...
...
src/google/protobuf/compiler/objectivec/objectivec_message.cc
View file @
7377eb2b
...
@@ -580,6 +580,19 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
...
@@ -580,6 +580,19 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
" [localDescriptor setupExtensionRanges:ranges
\n
"
" [localDescriptor setupExtensionRanges:ranges
\n
"
" count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];
\n
"
);
" count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];
\n
"
);
}
}
if
(
descriptor_
->
containing_type
()
!=
NULL
)
{
string
parent_class_name
=
ClassName
(
descriptor_
->
containing_type
());
printer
->
Print
(
" [localDescriptor setupContainingMessageClassName:GPBStringifySymbol($parent_name$)];
\n
"
,
"parent_name"
,
parent_class_name
);
}
string
suffix_added
;
ClassName
(
descriptor_
,
&
suffix_added
);
if
(
suffix_added
.
size
()
>
0
)
{
printer
->
Print
(
" [localDescriptor setupMessageClassNameSuffix:@
\"
$suffix$
\"
];
\n
"
,
"suffix"
,
suffix_added
);
}
printer
->
Print
(
printer
->
Print
(
" NSAssert(descriptor == nil, @
\"
Startup recursed!
\"
);
\n
"
" NSAssert(descriptor == nil, @
\"
Startup recursed!
\"
);
\n
"
" descriptor = localDescriptor;
\n
"
" descriptor = localDescriptor;
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment