aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-10-19 15:42:39 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-10-19 15:43:21 -0700
commit422d3296b2d4fb3f8aa0991c2ffa895251ad8e91 (patch)
tree6ebfe78c33a6164ad3330e6926a11adcef375bf5
parente542e006eb4ffcd0c19488428a3cfe5605bf41e5 (diff)
Annotate Nullability
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.h12
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m2
-rw-r--r--src/objective-c/ProtoRPC/ProtoRPC.h14
-rw-r--r--src/objective-c/ProtoRPC/ProtoRPC.m14
-rw-r--r--src/objective-c/tests/GRPCClientTests.m6
-rw-r--r--src/objective-c/tests/InteropTests.m6
6 files changed, 31 insertions, 23 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h
index 9fdcd93a30..c862609b21 100644
--- a/src/objective-c/GRPCClient/GRPCCall.h
+++ b/src/objective-c/GRPCClient/GRPCCall.h
@@ -39,6 +39,8 @@
#include "GRPCCallOptions.h"
+NS_ASSUME_NONNULL_BEGIN
+
#pragma mark gRPC errors
/** Domain of NSError objects produced by gRPC. */
@@ -154,13 +156,13 @@ extern NSString * const kGRPCTrailersKey;
@optional
/** Issued when initial metadata is received from the server. */
-- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata;
+- (void)receivedInitialMetadata:(NSDictionary * _Nullable)initialMetadata;
/**
* Issued when a message is received from the server. The message is the raw data received from the
* server, with decompression and without proto deserialization.
*/
-- (void)receivedRawMessage:(NSData *)message;
+- (void)receivedRawMessage:(NSData * _Nullable)message;
/**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a
@@ -168,7 +170,7 @@ extern NSString * const kGRPCTrailersKey;
* is non-nil and contains the corresponding error information, including gRPC error codes and
* error descriptions.
*/
-- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error;
+- (void)closedWithTrailingMetadata:(NSDictionary * _Nullable)trailingMetadata error:(NSError * _Nullable)error;
@required
@@ -226,7 +228,7 @@ extern NSString * const kGRPCTrailersKey;
*/
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler
- callOptions:(GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER;
+ callOptions:(GRPCCallOptions * _Nullable)callOptions NS_DESIGNATED_INITIALIZER;
/**
* Convenience initializer for a call that uses default call options (see GRPCCallOptions.m for
* the default options).
@@ -267,6 +269,8 @@ extern NSString * const kGRPCTrailersKey;
@end
+NS_ASSUME_NONNULL_END
+
/**
* This interface is deprecated. Please use \a GRPCcall2.
*
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index bd4b4e10f0..1782078961 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -97,7 +97,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCResponseHandler>)responseHandler
- callOptions:(GRPCCallOptions *)callOptions {
+ callOptions:(GRPCCallOptions * _Nullable)callOptions {
if (requestOptions.host.length == 0 || requestOptions.path.length == 0) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."];
}
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.h b/src/objective-c/ProtoRPC/ProtoRPC.h
index 34a519bee5..3a7fd58fb1 100644
--- a/src/objective-c/ProtoRPC/ProtoRPC.h
+++ b/src/objective-c/ProtoRPC/ProtoRPC.h
@@ -21,6 +21,8 @@
#import "ProtoMethod.h"
+NS_ASSUME_NONNULL_BEGIN
+
@class GPBMessage;
/** An object can implement this protocol to receive responses from server from a call. */
@@ -29,12 +31,12 @@
@optional
/** Issued when initial metadata is received from the server. */
-- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata;
+- (void)receivedInitialMetadata:(NSDictionary * _Nullable)initialMetadata;
/**
* Issued when a message is received from the server. The message is the deserialized proto object.
*/
-- (void)receivedProtoMessage:(GPBMessage *)message;
+- (void)receivedProtoMessage:(GPBMessage * _Nullable)message;
/**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a
@@ -42,7 +44,7 @@
* is non-nil and contains the corresponding error information, including gRPC error codes and
* error descriptions.
*/
-- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error;
+- (void)closedWithTrailingMetadata:(NSDictionary * _Nullable)trailingMetadata error:(NSError * _Nullable)error;
@required
@@ -68,7 +70,7 @@
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler
- callOptions:(GRPCCallOptions *)callOptions
+ callOptions:(GRPCCallOptions * _Nullable)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/**
@@ -93,7 +95,7 @@
*/
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler
- callOptions:(GRPCCallOptions *)callOptions
+ callOptions:(GRPCCallOptions * _Nullable)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/**
@@ -117,6 +119,8 @@
@end
+NS_ASSUME_NONNULL_END
+
__attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC
: GRPCCall
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m
index 44e9bfde0a..f6e3298f62 100644
--- a/src/objective-c/ProtoRPC/ProtoRPC.m
+++ b/src/objective-c/ProtoRPC/ProtoRPC.m
@@ -34,7 +34,7 @@
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler
- callOptions:(GRPCCallOptions *)callOptions
+ callOptions:(GRPCCallOptions * _Nullable)callOptions
responseClass:(Class)responseClass {
if ((self = [super init])) {
_call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions
@@ -70,7 +70,7 @@
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler
- callOptions:(GRPCCallOptions *)callOptions
+ callOptions:(GRPCCallOptions * _Nullable)callOptions
responseClass:(Class)responseClass {
if (requestOptions.host.length == 0 || requestOptions.path.length == 0) {
[NSException raise:NSInvalidArgumentException format:@"Neither host nor path can be nil."];
@@ -153,8 +153,8 @@
});
}
-- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata {
- if (_handler) {
+- (void)receivedInitialMetadata:(NSDictionary * _Nullable)initialMetadata {
+ if (_handler && initialMetadata != nil) {
id<GRPCProtoResponseHandler> handler = _handler;
if ([handler respondsToSelector:@selector(initialMetadata:)]) {
dispatch_async(handler.dispatchQueue, ^{
@@ -164,8 +164,8 @@
}
}
-- (void)receivedRawMessage:(NSData *)message {
- if (_handler) {
+- (void)receivedRawMessage:(NSData * _Nullable)message {
+ if (_handler && message != nil) {
id<GRPCProtoResponseHandler> handler = _handler;
NSError *error = nil;
GPBMessage *parsed = [_responseClass parseFromData:message error:&error];
@@ -188,7 +188,7 @@
}
}
-- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
+- (void)closedWithTrailingMetadata:(NSDictionary * _Nullable)trailingMetadata error:(NSError * _Nullable)error {
if (_handler) {
id<GRPCProtoResponseHandler> handler = _handler;
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index 985e105b81..0a9ec97c48 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -114,19 +114,19 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
return self;
}
-- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata {
+- (void)receivedInitialMetadata:(NSDictionary * _Nullable)initialMetadata {
if (_initialMetadataCallback) {
_initialMetadataCallback(initialMetadata);
}
}
-- (void)receivedProtoMessage:(GPBMessage *)message {
+- (void)receivedProtoMessage:(GPBMessage * _Nullable)message {
if (_messageCallback) {
_messageCallback(message);
}
}
-- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
+- (void)closedWithTrailingMetadata:(NSDictionary * _Nullable)trailingMetadata error:(NSError * _Nullable)error {
if (_closeCallback) {
_closeCallback(trailingMetadata, error);
}
diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m
index a9f33aab6f..fb49bb99e0 100644
--- a/src/objective-c/tests/InteropTests.m
+++ b/src/objective-c/tests/InteropTests.m
@@ -102,19 +102,19 @@ BOOL isRemoteInteropTest(NSString *host) {
return self;
}
-- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata {
+- (void)receivedInitialMetadata:(NSDictionary * _Nullable)initialMetadata {
if (_initialMetadataCallback) {
_initialMetadataCallback(initialMetadata);
}
}
-- (void)receivedProtoMessage:(GPBMessage *)message {
+- (void)receivedProtoMessage:(GPBMessage * _Nullable)message {
if (_messageCallback) {
_messageCallback(message);
}
}
-- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
+- (void)closedWithTrailingMetadata:(NSDictionary * _Nullable)trailingMetadata error:(NSError * _Nullable)error {
if (_closeCallback) {
_closeCallback(trailingMetadata, error);
}