Commit d3d66d79 authored by Paul Yang's avatar Paul Yang

Merge pull request #503 from thomasvl/add_nonnill_markup

Add nonnull/nullable/null_resettable markup to ObjC library.
parents 5b3a8e76 8c88957e
......@@ -37,6 +37,8 @@
// Note: These are not meant to be subclassed.
NS_ASSUME_NONNULL_BEGIN
//%PDDM-EXPAND DECLARE_ARRAYS()
// This block of code is generated, do not edit it directly.
......@@ -321,21 +323,21 @@
@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+ (instancetype)array;
+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func;
+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
rawValue:(int32_t)value;
+ (instancetype)arrayWithValueArray:(GPBEnumArray *)array;
+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
capacity:(NSUInteger)count;
- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func;
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
// Initializes the array, copying the values.
- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
rawValues:(const int32_t [])values
count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithValueArray:(GPBEnumArray *)array;
- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
capacity:(NSUInteger)count;
// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
......@@ -392,6 +394,8 @@
//%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)
......@@ -444,21 +448,21 @@
//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
//%
//%+ (instancetype)array;
//%+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func;
//%+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
//% rawValue:(TYPE)value;
//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array;
//%+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
//% capacity:(NSUInteger)count;
//%
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func;
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
//%
//%// Initializes the array, copying the values.
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
//% rawValues:(const TYPE [])values
//% count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array;
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
//% capacity:(NSUInteger)count;
//%
//%// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
......
......@@ -33,6 +33,8 @@
@class GPBMessage;
@class GPBExtensionRegistry;
NS_ASSUME_NONNULL_BEGIN
// Reads and decodes protocol message fields.
// Subclassing of GPBCodedInputStream is NOT supported.
@interface GPBCodedInputStream : NSObject
......@@ -64,7 +66,7 @@
// Read an embedded message field value from the stream.
- (void)readMessage:(GPBMessage *)message
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
// Reads and discards a single field, given its tag value. Returns NO if the
// tag is an endgroup tag, in which case nothing is skipped. Otherwise,
......@@ -81,3 +83,5 @@
- (void)checkLastTagWas:(int32_t)value;
@end
NS_ASSUME_NONNULL_END
......@@ -44,6 +44,8 @@
@class GPBUInt64Array;
@class GPBUnknownFieldSet;
NS_ASSUME_NONNULL_BEGIN
@interface GPBCodedOutputStream : NSObject
// Creates a new stream to write into data. Data must be sized to fit or it
......@@ -53,12 +55,10 @@
+ (instancetype)streamWithOutputStream:(NSOutputStream *)output
bufferSize:(size_t)bufferSize;
- (instancetype)initWithOutputStream:(NSOutputStream *)output;
- (instancetype)initWithData:(NSMutableData *)data;
- (instancetype)initWithOutputStream:(NSOutputStream *)output;
- (instancetype)initWithOutputStream:(NSOutputStream *)output
bufferSize:(size_t)bufferSize;
- (instancetype)initWithOutputStream:(NSOutputStream *)output
data:(NSMutableData *)data;
- (void)flush;
......@@ -294,6 +294,8 @@ size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value)
CF_EXTERN_C_END
NS_ASSUME_NONNULL_END
// Write methods for types that can be in packed arrays.
//%PDDM-DEFINE _WRITE_PACKABLE_DECLS(NAME, ARRAY_TYPE, TYPE)
//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE)value;
......
......@@ -184,6 +184,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state,
return [self initWithOutputStream:output 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])) {
......
......@@ -38,6 +38,8 @@
@class GPBFileDescriptor;
@class GPBOneofDescriptor;
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, GPBFileSyntax) {
GPBFileSyntaxUnknown = 0,
GPBFileSyntaxProto2 = 2,
......@@ -53,20 +55,20 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@interface GPBDescriptor : NSObject<NSCopying>
@property(nonatomic, readonly, copy) NSString *name;
@property(nonatomic, readonly, strong) NSArray *fields;
@property(nonatomic, readonly, strong) NSArray *oneofs;
@property(nonatomic, readonly, strong) NSArray *enums;
@property(nonatomic, readonly) const GPBExtensionRange *extensionRanges;
@property(nonatomic, readonly, strong, nullable) NSArray *fields;
@property(nonatomic, readonly, strong, nullable) NSArray *oneofs;
@property(nonatomic, readonly, strong, nullable) NSArray *enums;
@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
@property(nonatomic, readonly) NSUInteger extensionRangesCount;
@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
@property(nonatomic, readonly) Class messageClass;
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
- (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
- (GPBOneofDescriptor *)oneofWithName:(NSString *)name;
- (GPBEnumDescriptor *)enumWithName:(NSString *)name;
- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
- (nullable GPBEnumDescriptor *)enumWithName:(NSString *)name;
@end
......@@ -81,8 +83,8 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly) NSString *name;
@property(nonatomic, readonly) NSArray *fields;
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
- (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
@end
@interface GPBFieldDescriptor : NSObject
......@@ -99,21 +101,21 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly) GPBDataType mapKeyDataType;
@property(nonatomic, readonly, getter=isPackable) BOOL packable;
@property(nonatomic, readonly, assign) GPBOneofDescriptor *containingOneof;
@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
@property(nonatomic, readonly) GPBFieldOptions *fieldOptions;
@property(nonatomic, readonly, nullable) GPBFieldOptions *fieldOptions;
// Message properties
@property(nonatomic, readonly, assign) Class msgClass;
@property(nonatomic, readonly, assign, nullable) Class msgClass;
// Enum properties
@property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
- (BOOL)isValidEnumValue:(int32_t)value;
// For now, this will return nil if it doesn't know the name to use for
// TextFormat.
- (NSString *)textFormatName;
- (nullable NSString *)textFormatName;
@end
......@@ -122,10 +124,10 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly, copy) NSString *name;
@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
- (NSString *)enumNameForValue:(int32_t)number;
- (BOOL)getValue:(int32_t *)outValue forEnumName:(NSString *)name;
- (nullable NSString *)enumNameForValue:(int32_t)number;
- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
- (NSString *)textFormatNameForValue:(int32_t)number;
- (nullable NSString *)textFormatNameForValue:(int32_t)number;
@end
......@@ -137,6 +139,8 @@ typedef NS_ENUM(NSInteger, GPBFieldType) {
@property(nonatomic, readonly, getter=isPackable) BOOL packable;
@property(nonatomic, readonly, assign) Class msgClass;
@property(nonatomic, readonly) NSString *singletonName;
@property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
@property(nonatomic, readonly) id defaultValue;
@end
NS_ASSUME_NONNULL_END
This diff is collapsed.
......@@ -33,6 +33,8 @@
@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 an
// ExtensionRegistry in which you have registered any extensions that you want
......@@ -57,7 +59,9 @@
- (void)addExtension:(GPBExtensionDescriptor *)extension;
- (void)addExtensions:(GPBExtensionRegistry *)registry;
- (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber;
- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
fieldNumber:(NSInteger)fieldNumber;
@end
NS_ASSUME_NONNULL_END
......@@ -40,6 +40,8 @@
@class GPBFieldDescriptor;
@class GPBUnknownFieldSet;
NS_ASSUME_NONNULL_BEGIN
CF_EXTERN_C_BEGIN
// NSError domain used for errors.
......@@ -66,7 +68,7 @@ CF_EXTERN_C_END
// The main cases are methods that take no arguments, or setFoo:/hasFoo: type
// methods.
@property(nonatomic, readonly) GPBUnknownFieldSet *unknownFields;
@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields;
// Are all required fields in the message and all embedded messages set.
@property(nonatomic, readonly, getter=isInitialized) BOOL initialized;
......@@ -80,18 +82,18 @@ CF_EXTERN_C_END
// if one is missing, the parse will fail (returning nil, filling in errorPtr).
+ (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
+ (instancetype)parseFromData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
error:(NSError **)errorPtr;
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry
(nullable GPBExtensionRegistry *)extensionRegistry
error:(NSError **)errorPtr;
// Create a message based on delimited input. If there is a data parse
// error, nil is returned and if not NULL, errorPtr is filled in.
+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry
(nullable GPBExtensionRegistry *)extensionRegistry
error:(NSError **)errorPtr;
// If there is a data parse error, nil is returned and if not NULL, errorPtr is
......@@ -100,11 +102,11 @@ CF_EXTERN_C_END
// if one is missing, the parse will fail (returning nil, filling in errorPtr).
- (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
- (instancetype)initWithData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
error:(NSError **)errorPtr;
- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry
(nullable GPBExtensionRegistry *)extensionRegistry
error:(NSError **)errorPtr;
// Serializes the message and writes it to output.
......@@ -121,11 +123,11 @@ CF_EXTERN_C_END
// while generating the data, nil is returned.
// NOTE: In DEBUG ONLY, the message is also checked for all required field,
// if one is missing, nil will be returned.
- (NSData *)data;
- (nullable NSData *)data;
// Same as -[data], except a delimiter is added to the start of the data
// indicating the size of the message data that follows.
- (NSData *)delimitedData;
- (nullable NSData *)delimitedData;
// Returns the size of the object if it were serialized.
// This is not a cached value. If you are following a pattern like this:
......@@ -149,16 +151,14 @@ CF_EXTERN_C_END
// repeated. If the extension is a Message one will be auto created for you
// and returned similar to fields.
- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension;
- (id)getExtension:(GPBExtensionDescriptor *)extension;
- (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value;
- (nullable id)getExtension:(GPBExtensionDescriptor *)extension;
- (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)value;
- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value;
- (void)setExtension:(GPBExtensionDescriptor *)extension
index:(NSUInteger)index
value:(id)value;
- (void)clearExtension:(GPBExtensionDescriptor *)extension;
- (void)setUnknownFields:(GPBUnknownFieldSet *)unknownFields;
// Resets all fields to their default values.
- (void)clear;
......@@ -166,10 +166,12 @@ CF_EXTERN_C_END
// message.
// NOTE: This will throw if there is an error parsing the data.
- (void)mergeFromData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
// Merges the fields from another message (of the same type) into this
// message.
- (void)mergeFrom:(GPBMessage *)other;
@end
NS_ASSUME_NONNULL_END
......@@ -32,6 +32,8 @@
@class GPBExtensionRegistry;
NS_ASSUME_NONNULL_BEGIN
// All Root Objects derive from GPBRootObject. It supplies a registry
// for derived classes to register their extensions to.
@interface GPBRootObject : NSObject
......@@ -40,3 +42,5 @@
+ (GPBExtensionRegistry *)extensionRegistry;
@end
NS_ASSUME_NONNULL_END
......@@ -36,6 +36,7 @@
#import <CoreFoundation/CoreFoundation.h>
#import "GPBDescriptor.h"
#import "GPBExtensionRegistry.h"
#import "GPBUtilities_PackagePrivate.h"
@interface GPBExtensionDescriptor (GPBRootObject)
......@@ -97,6 +98,7 @@ static CFHashCode GPBRootExtensionKeyHash(const void *value) {
static OSSpinLock gExtensionSingletonDictionaryLock_ = OS_SPINLOCK_INIT;
static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL;
+ (void)initialize {
// Ensure the global is started up.
......@@ -113,6 +115,7 @@ static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
gExtensionSingletonDictionary =
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &keyCallBacks,
&kCFTypeDictionaryValueCallBacks);
gDefaultExtensionRegistry = [[GPBExtensionRegistry alloc] init];
}
if ([self superclass] == [GPBRootObject class]) {
......@@ -126,7 +129,7 @@ static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
+ (GPBExtensionRegistry *)extensionRegistry {
// Is overridden in all the subclasses that provide extensions to provide the
// per class one.
return nil;
return gDefaultExtensionRegistry;
}
+ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field {
......
......@@ -35,6 +35,8 @@
@class GPBUInt64Array;
@class GPBUnknownFieldSet;
NS_ASSUME_NONNULL_BEGIN
@interface GPBUnknownField : NSObject<NSCopying>
@property(nonatomic, readonly, assign) int32_t number;
......@@ -54,3 +56,5 @@
- (void)addGroup:(GPBUnknownFieldSet *)value;
@end
NS_ASSUME_NONNULL_END
......@@ -32,10 +32,12 @@
@class GPBUnknownField;
NS_ASSUME_NONNULL_BEGIN
@interface GPBUnknownFieldSet : NSObject<NSCopying>
- (BOOL)hasField:(int32_t)number;
- (GPBUnknownField *)getField:(int32_t)number;
- (nullable GPBUnknownField *)getField:(int32_t)number;
- (NSUInteger)countOfFields;
- (void)addField:(GPBUnknownField *)field;
......@@ -44,3 +46,5 @@
- (NSArray *)sortedFields;
@end
NS_ASSUME_NONNULL_END
......@@ -36,13 +36,16 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
// Generates a string that should be a valid "Text Format" for the C++ version
// of Protocol Buffers. lineIndent can be nil if no additional line indent is
// needed. The comments provide the names according to the ObjC library, they
// most likely won't exactly match the original .proto file.
NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent);
NSString *GPBTextFormatForMessage(GPBMessage *message,
NSString * __nullable lineIndent);
NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
NSString *lineIndent);
NSString * __nullable lineIndent);
//
// Test if the given field is set on a message.
......@@ -128,6 +131,8 @@ void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dicti
// objects.
NSData *GPBEmptyNSData(void) __attribute__((pure));
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
......
......@@ -1497,7 +1497,7 @@ static void AppendTextFormatForMessage(GPBMessage *message,
}
NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent) {
if (message == nil) return nil;
if (message == nil) return @"";
if (lineIndent == nil) lineIndent = @"";
NSMutableString *buildString = [NSMutableString string];
......@@ -1507,7 +1507,7 @@ NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent) {
NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
NSString *lineIndent) {
if (unknownSet == nil) return nil;
if (unknownSet == nil) return @"";
if (lineIndent == nil) lineIndent = @"";
NSMutableString *result = [NSMutableString string];
......
......@@ -33,6 +33,8 @@
#import "google/protobuf/Timestamp.pbobjc.h"
#import "google/protobuf/Duration.pbobjc.h"
NS_ASSUME_NONNULL_BEGIN
// Extension to GPBTimestamp to work with standard Foundation time/date types.
@interface GPBTimestamp (GBPWellKnownTypes)
@property(nonatomic, readwrite, strong) NSDate *date;
......@@ -46,3 +48,5 @@
@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970;
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970;
@end
NS_ASSUME_NONNULL_END
......@@ -32,6 +32,8 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
typedef enum {
GPBWireFormatVarint = 0,
GPBWireFormatFixed64 = 1,
......@@ -65,4 +67,6 @@ GPBWireFormat GPBWireFormatForType(GPBDataType dataType, BOOL isPacked)
(GPBWireFormatMakeTag(GPBWireFormatMessageSetMessage, \
GPBWireFormatLengthDelimited))
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
......@@ -446,7 +446,7 @@ class GPBBridgeTests: XCTestCase {
let data = msg.data()
let msg2 = Message2(data: data, error:nil)
let msg2 = Message2(data: data!, error:nil)
XCTAssertTrue(msg2 !== msg) // New instance
XCTAssertEqual(msg.optionalInt32, Int32(100))
XCTAssertEqual(msg.optionalInt64, Int64(101))
......
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBAnyRoot
......@@ -88,13 +89,15 @@ typedef GPB_ENUM(GPBAny_FieldNumber) {
// namespace should use `type.googleapis.com/full.type.name` (without
// schema and path). A type service will eventually become available which
// serves those URLs (projected Q2/15).
@property(nonatomic, readwrite, copy) NSString *typeURL;
@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
// Must be valid serialized data of the above specified type.
@property(nonatomic, readwrite, copy) NSData *value;
@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -13,6 +13,7 @@ CF_EXTERN_C_BEGIN
@class GPBSourceContext;
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBApiRoot
......@@ -40,16 +41,16 @@ typedef GPB_ENUM(GPBApi_FieldNumber) {
// The fully qualified name of this api, including package name
// followed by the api's simple name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// The methods of this api, in unspecified order.
// |methodsArray| contains |GPBMethod|
@property(nonatomic, readwrite, strong) NSMutableArray *methodsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *methodsArray;
@property(nonatomic, readonly) NSUInteger methodsArray_Count;
// Any metadata attached to the API.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
// A version string for this api. If specified, must have the form
......@@ -74,12 +75,12 @@ typedef GPB_ENUM(GPBApi_FieldNumber) {
// experimental, none-GA apis.
//
// See also: [design doc](http://go/api-versioning).
@property(nonatomic, readwrite, copy) NSString *version;
@property(nonatomic, readwrite, copy, null_resettable) NSString *version;
// Source context for the protocol buffer service represented by this
// message.
@property(nonatomic, readwrite) BOOL hasSourceContext;
@property(nonatomic, readwrite, strong) GPBSourceContext *sourceContext;
@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
@end
......@@ -98,27 +99,29 @@ typedef GPB_ENUM(GPBMethod_FieldNumber) {
@interface GPBMethod : GPBMessage
// The simple name of this method.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// A URL of the input message type.
@property(nonatomic, readwrite, copy) NSString *requestTypeURL;
@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) NSString *responseTypeURL;
@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.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBDurationRoot
......@@ -86,6 +87,8 @@ typedef GPB_ENUM(GPBDuration_FieldNumber) {
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBEmptyRoot
......@@ -36,6 +37,8 @@ CF_EXTERN_C_BEGIN
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBFieldMaskRoot
......@@ -151,11 +152,13 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) {
// The set of field mask paths.
// |pathsArray| contains |NSString|
@property(nonatomic, readwrite, strong) NSMutableArray *pathsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *pathsArray;
@property(nonatomic, readonly) NSUInteger pathsArray_Count;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBSourceContextRoot
......@@ -35,10 +36,12 @@ typedef GPB_ENUM(GPBSourceContext_FieldNumber) {
// The path-qualified name of the .proto file that contained the associated
// protobuf element. For example: `"google/protobuf/source.proto"`.
@property(nonatomic, readwrite, copy) NSString *fileName;
@property(nonatomic, readwrite, copy, null_resettable) NSString *fileName;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -14,6 +14,8 @@ CF_EXTERN_C_BEGIN
@class GPBListValue;
@class GPBStruct;
NS_ASSUME_NONNULL_BEGIN
#pragma mark - Enum GPBNullValue
// `NullValue` is a singleton enumeration to represent the null
......@@ -28,7 +30,6 @@ GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void);
BOOL GPBNullValue_IsValidValue(int32_t value);
#pragma mark - GPBStructRoot
@interface GPBStructRoot : GPBRootObject
......@@ -56,7 +57,7 @@ typedef GPB_ENUM(GPBStruct_FieldNumber) {
// Map of dynamically typed values.
// |fields| values are |GPBValue|
@property(nonatomic, readwrite, strong) NSMutableDictionary *fields;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *fields;
@property(nonatomic, readonly) NSUInteger fields_Count;
@end
......@@ -97,16 +98,16 @@ typedef GPB_ENUM(GPBValue_Kind_OneOfCase) {
@property(nonatomic, readwrite) double numberValue;
// Represents a string value.
@property(nonatomic, readwrite, copy) NSString *stringValue;
@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) GPBStruct *structValue;
@property(nonatomic, readwrite, strong, null_resettable) GPBStruct *structValue;
// Represents a repeated `Value`.
@property(nonatomic, readwrite, strong) GPBListValue *listValue;
@property(nonatomic, readwrite, strong, null_resettable) GPBListValue *listValue;
@end
......@@ -126,11 +127,13 @@ typedef GPB_ENUM(GPBListValue_FieldNumber) {
// Repeated field of dynamically typed values.
// |valuesArray| contains |GPBValue|
@property(nonatomic, readwrite, strong) NSMutableArray *valuesArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *valuesArray;
@property(nonatomic, readonly) NSUInteger valuesArray_Count;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBTimestampRoot
......@@ -97,6 +98,8 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) {
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -14,6 +14,8 @@ CF_EXTERN_C_BEGIN
@class GPBAny;
@class GPBSourceContext;
NS_ASSUME_NONNULL_BEGIN
#pragma mark - Enum GPBField_Kind
// Kind represents a basic field type.
......@@ -101,7 +103,6 @@ GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void);
BOOL GPBField_Cardinality_IsValidValue(int32_t value);
#pragma mark - GPBTypeRoot
@interface GPBTypeRoot : GPBRootObject
......@@ -127,27 +128,27 @@ typedef GPB_ENUM(GPBType_FieldNumber) {
@interface GPBType : GPBMessage
// The fully qualified message name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// The list of fields.
// |fieldsArray| contains |GPBField|
@property(nonatomic, readwrite, strong) NSMutableArray *fieldsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *fieldsArray;
@property(nonatomic, readonly) NSUInteger fieldsArray_Count;
// The list of oneof definitions.
// The list of oneofs declared in this Type
// |oneofsArray| contains |NSString|
@property(nonatomic, readwrite, strong) NSMutableArray *oneofsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *oneofsArray;
@property(nonatomic, readonly) NSUInteger oneofsArray_Count;
// The proto options.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
// The source context.
@property(nonatomic, readwrite) BOOL hasSourceContext;
@property(nonatomic, readwrite, strong) GPBSourceContext *sourceContext;
@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
@end
......@@ -177,11 +178,11 @@ typedef GPB_ENUM(GPBField_FieldNumber) {
@property(nonatomic, readwrite) int32_t number;
// The field name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// The type URL (without the scheme) when the type is MESSAGE or ENUM,
// such as `type.googleapis.com/google.protobuf.Empty`.
@property(nonatomic, readwrite, copy) NSString *typeURL;
@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
// Index in Type.oneofs. Starts at 1. Zero means no oneof mapping.
@property(nonatomic, readwrite) int32_t oneofIndex;
......@@ -191,7 +192,7 @@ typedef GPB_ENUM(GPBField_FieldNumber) {
// The proto options.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
@end
......@@ -215,21 +216,21 @@ typedef GPB_ENUM(GPBEnum_FieldNumber) {
@interface GPBEnum : GPBMessage
// Enum type name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// Enum value definitions.
// |enumvalueArray| contains |GPBEnumValue|
@property(nonatomic, readwrite, strong) NSMutableArray *enumvalueArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *enumvalueArray;
@property(nonatomic, readonly) NSUInteger enumvalueArray_Count;
// Proto options for the enum type.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
// The source context.
@property(nonatomic, readwrite) BOOL hasSourceContext;
@property(nonatomic, readwrite, strong) GPBSourceContext *sourceContext;
@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
@end
......@@ -245,14 +246,14 @@ typedef GPB_ENUM(GPBEnumValue_FieldNumber) {
@interface GPBEnumValue : GPBMessage
// Enum value name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// Enum value number.
@property(nonatomic, readwrite) int32_t number;
// Proto options for the enum value.
// |optionsArray| contains |GPBOption|
@property(nonatomic, readwrite, strong) NSMutableArray *optionsArray;
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray;
@property(nonatomic, readonly) NSUInteger optionsArray_Count;
@end
......@@ -268,14 +269,16 @@ typedef GPB_ENUM(GPBOption_FieldNumber) {
@interface GPBOption : GPBMessage
// Proto option name.
@property(nonatomic, readwrite, copy) NSString *name;
@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
// Proto option value.
@property(nonatomic, readwrite) BOOL hasValue;
@property(nonatomic, readwrite, strong) GPBAny *value;
@property(nonatomic, readwrite, strong, null_resettable) GPBAny *value;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -11,6 +11,7 @@
CF_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
#pragma mark - GPBWrappersRoot
......@@ -131,7 +132,7 @@ typedef GPB_ENUM(GPBStringValue_FieldNumber) {
@interface GPBStringValue : GPBMessage
// The string value.
@property(nonatomic, readwrite, copy) NSString *value;
@property(nonatomic, readwrite, copy, null_resettable) NSString *value;
@end
......@@ -145,10 +146,12 @@ typedef GPB_ENUM(GPBBytesValue_FieldNumber) {
@interface GPBBytesValue : GPBMessage
// The bytes value.
@property(nonatomic, readwrite, copy) NSData *value;
@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
@end
NS_ASSUME_NONNULL_END
CF_EXTERN_C_END
// @@protoc_insertion_point(global_scope)
......@@ -331,7 +331,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
}
printer->Print(
variables_,
"@property(nonatomic, readwrite, $property_storage_attribute$) $property_type$ *$name$$storage_attribute$;\n");
"@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$;\n");
if (IsInitName(variables_.find("name")->second)) {
// 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
......@@ -379,7 +379,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
variables_,
"$comments$"
"$array_comment$"
"@property(nonatomic, readwrite, strong) $array_storage_type$ *$name$$storage_attribute$;\n"
"@property(nonatomic, readwrite, strong, null_resettable) $array_storage_type$ *$name$$storage_attribute$;\n"
"@property(nonatomic, readonly) NSUInteger $name$_Count;\n");
if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC.
......
......@@ -117,10 +117,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
printer->Print(
"// @@protoc_insertion_point(imports)\n"
"\n"
"CF_EXTERN_C_BEGIN\n"
"\n");
printer->Print("CF_EXTERN_C_BEGIN\n\n");
set<string> fwd_decls;
for (vector<MessageGenerator *>::iterator iter = message_generators_.begin();
iter != message_generators_.end(); ++iter) {
......@@ -134,6 +134,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
printer->Print("\n");
}
printer->Print(
"NS_ASSUME_NONNULL_BEGIN\n"
"\n");
// need to write out all enums first
for (vector<EnumGenerator *>::iterator iter = enum_generators_.begin();
iter != enum_generators_.end(); ++iter) {
......@@ -148,7 +152,6 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
// For extensions to chain together, the Root gets created even if there
// are no extensions.
printer->Print(
"\n"
"#pragma mark - $root_class_name$\n"
"\n"
"@interface $root_class_name$ : GPBRootObject\n"
......@@ -182,11 +185,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
(*iter)->GenerateMessageHeader(printer);
}
printer->Print("CF_EXTERN_C_END\n");
printer->Print(
"\n"
"// @@protoc_insertion_point(global_scope)\n");
"NS_ASSUME_NONNULL_END\n"
"\n"
"CF_EXTERN_C_END\n"
"\n"
"// @@protoc_insertion_point(global_scope)\n");
}
void FileGenerator::GenerateSource(io::Printer *printer) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment