Merge more cocoa changes from Andrew McGeachie

Reviewed By: dreiss

Test Plan: To be provided later by McGeachie. Compiler builds fine. Does not affect other libraries.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665259 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cocoa/TApplicationException.h b/lib/cocoa/TApplicationException.h
index bb64282..1fee06e 100644
--- a/lib/cocoa/TApplicationException.h
+++ b/lib/cocoa/TApplicationException.h
@@ -1,3 +1,6 @@
+#import "TException.h"
+#import "TProtocol.h"
+
 enum {
   TApplicationException_UNKNOWN = 0,
   TApplicationException_UNKNOWN_METHOD = 1,
@@ -8,12 +11,13 @@
 };
 
 // FIXME
-@interface TApplicationException : NSException {
+@interface TApplicationException : TException {
+  int mType;
 }
 
 + (TApplicationException *) read: (id <TProtocol>) protocol;
 
 + (TApplicationException *) exceptionWithType: (int) type
-                                      message: (NSString *) message;
+                                       reason: (NSString *) message;
 
 @end
diff --git a/lib/cocoa/TBinaryProtocol.m b/lib/cocoa/TBinaryProtocol.m
index cd239de..2d2ca8e 100644
--- a/lib/cocoa/TBinaryProtocol.m
+++ b/lib/cocoa/TBinaryProtocol.m
@@ -1,4 +1,5 @@
 #import "TBinaryProtocol.h"
+#import "TProtocolException.h"
 
 int32_t VERSION_1 = 0x80010000;
 int32_t VERSION_MASK = 0xffff0000;
@@ -38,17 +39,15 @@
 }
 
 
-- (void) readMessageBeginWithName: (NSString **) name
-                             type: (int *) type
-                       sequenceID: (int *) sequenceID
+- (void) readMessageBeginReturningName: (NSString **) name
+                                  type: (int *) type
+                            sequenceID: (int *) sequenceID
 {
   int size = [self readI32];
   if (size < 0) {
     int version = size & VERSION_MASK;
     if (version != VERSION_1) {
-      @throw [NSException exceptionWithName: @"TProtocolException"
-                          reason: @"Bad version in readMessageBegin"
-                          userInfo: nil];
+      @throw [TProtocolException exceptionWithName: @"Bad version in readMessageBegin"];
     }
     if (type != NULL) {
       *type = version & 0x00FF;
@@ -63,9 +62,7 @@
     }
   } else {
     if (mStrictRead) {
-      @throw [NSException exceptionWithName: @"TProtocolException"
-                          reason: @"Missing version in readMessageBegin, old client?"
-                          userInfo: nil];
+      @throw [TProtocolException exceptionWithName: @"Missing version in readMessageBegin, old client?"];
     }
     NSString * messageName = [self readStringBody: size];
     if (name != NULL) {
@@ -86,7 +83,7 @@
 - (void) readMessageEnd {}
 
 
-- (void) readStructBeginWithName: (NSString **) name
+- (void) readStructBeginReturningName: (NSString **) name
 {
   if (name != NULL) {
     *name = nil;
@@ -97,9 +94,9 @@
 - (void) readStructEnd {}
 
 
-- (void) readFieldBeginWithName: (NSString **) name
-                           type: (int *) fieldType
-                        fieldID: (int *) fieldID
+- (void) readFieldBeginReturningName: (NSString **) name
+                                type: (int *) fieldType
+                             fieldID: (int *) fieldID
 {
   if (name != NULL) {
     *name = nil;
@@ -189,19 +186,19 @@
   int32_t size = [self readI32];
   uint8_t * buff = malloc(size);
   if (buff == NULL) {
-    @throw [NSException exceptionWithName: @"Out of memory" 
-                        reason: [NSString stringWithFormat: @"Unable to allocate %d bytes trying to read binary data.",
-                                          size]
-                        userInfo: nil];
+    @throw [TProtocolException 
+             exceptionWithName: @"Out of memory" 
+             reason: [NSString stringWithFormat: @"Unable to allocate %d bytes trying to read binary data.",
+                               size]];
   }
   [mTransport readAll: buff offset: 0 length: size];
   return [NSData dataWithBytesNoCopy: buff length: size];
 }
 
 
-- (void) readMapBeginWithKeyType: (int *) keyType
-                       valueType: (int *) valueType
-                            size: (int *) size
+- (void) readMapBeginReturningKeyType: (int *) keyType
+                            valueType: (int *) valueType
+                                 size: (int *) size
 {
   int kt = [self readByte];
   int vt = [self readByte];
@@ -220,8 +217,8 @@
 - (void) readMapEnd {}
 
 
-- (void) readSetBeginWithElementType: (int *) elementType
-                                size: (int *) size
+- (void) readSetBeginReturningElementType: (int *) elementType
+                                     size: (int *) size
 {
   int et = [self readByte];
   int s = [self readI32];
@@ -237,8 +234,8 @@
 - (void) readSetEnd {}
 
 
-- (void) readListBeginWithElementType: (int *) elementType
-                                 size: (int *) size
+- (void) readListBeginReturningElementType: (int *) elementType
+                                      size: (int *) size
 {
   int et = [self readByte];
   int s = [self readI32];
diff --git a/lib/cocoa/TException.h b/lib/cocoa/TException.h
index 95eaa83..ce3b4a5 100644
--- a/lib/cocoa/TException.h
+++ b/lib/cocoa/TException.h
@@ -3,7 +3,13 @@
 @interface TException : NSException {
 }
 
-- (id) initWithType: (int) type
-            message: (NSString *) message;
++ (id) exceptionWithName: (NSString *) name;
+
++ (id) exceptionWithName: (NSString *) name
+                  reason: (NSString *) reason;
+
++ (id) exceptionWithName: (NSString *) name
+                  reason: (NSString *) reason
+                   error: (NSError *) error;
 
 @end
diff --git a/lib/cocoa/TProtocol.h b/lib/cocoa/TProtocol.h
index 96d3af6..bc64789 100644
--- a/lib/cocoa/TProtocol.h
+++ b/lib/cocoa/TProtocol.h
@@ -30,17 +30,17 @@
 
 - (id <TTransport>) transport;
 
-- (void) readMessageBeginWithName: (NSString **) name
-                             type: (int *) type
-                       sequenceID: (int *) sequenceID;
+- (void) readMessageBeginReturningName: (NSString **) name
+                                  type: (int *) type
+                            sequenceID: (int *) sequenceID;
 - (void) readMessageEnd;
 
-- (void) readStructBeginWithName: (NSString **) name;
+- (void) readStructBeginReturningName: (NSString **) name;
 - (void) readStructEnd;
 
-- (void) readFieldBeginWithName: (NSString **) name
-                           type: (int *) fieldType
-                        fieldID: (int *) fieldID;
+- (void) readFieldBeginReturningName: (NSString **) name
+                                type: (int *) fieldType
+                             fieldID: (int *) fieldID;
 - (void) readFieldEnd;
 
 - (NSString *) readString;
@@ -59,19 +59,19 @@
 
 - (NSData *) readBinary;
 
-- (void) readMapBeginWithKeyType: (int *) keyType
-                       valueType: (int *) valueType
-                            size: (int *) size;
+- (void) readMapBeginReturningKeyType: (int *) keyType
+                            valueType: (int *) valueType
+                                 size: (int *) size;
 - (void) readMapEnd;
 
 
-- (void) readSetBeginWithElementType: (int *) elementType
-                                size: (int *) size;
+- (void) readSetBeginReturningElementType: (int *) elementType
+                                     size: (int *) size;
 - (void) readSetEnd;
 
 
-- (void) readListBeginWithElementType: (int *) elementType
-                                 size: (int *) size;
+- (void) readListBeginReturningElementType: (int *) elementType
+                                      size: (int *) size;
 - (void) readListEnd;
 
 
@@ -99,6 +99,8 @@
 
 - (void) writeDouble: (double) value;
 
+- (void) writeBool: (BOOL) value;
+
 - (void) writeBinary: (NSData *) data;
 
 - (void) writeFieldStop;
diff --git a/lib/cocoa/TProtocolUtil.m b/lib/cocoa/TProtocolUtil.m
index 746790f..cf32aad 100644
--- a/lib/cocoa/TProtocolUtil.m
+++ b/lib/cocoa/TProtocolUtil.m
@@ -27,10 +27,10 @@
     [protocol readString];
     break;
   case TType_STRUCT:
-    [protocol readStructBeginWithName: NULL];
+    [protocol readStructBeginReturningName: NULL];
     while (true) {
       int fieldType;
-      [protocol readFieldBeginWithName: nil type: &fieldType fieldID: nil];
+      [protocol readFieldBeginReturningName: nil type: &fieldType fieldID: nil];
       if (fieldType == TType_STOP) {
         break;
       }
@@ -44,7 +44,7 @@
     int keyType;
     int valueType;
     int size;
-    [protocol readMapBeginWithKeyType: &keyType valueType: &valueType size: &size];
+    [protocol readMapBeginReturningKeyType: &keyType valueType: &valueType size: &size];
     int i;
     for (i = 0; i < size; i++) {
       [TProtocolUtil skipType: keyType onProtocol: protocol];
@@ -57,7 +57,7 @@
     {
       int elemType;
       int size;
-      [protocol readSetBeginWithElementType: &elemType size: &size];
+      [protocol readSetBeginReturningElementType: &elemType size: &size];
       int i;
       for (i = 0; i < size; i++) {
         [TProtocolUtil skipType: elemType onProtocol: protocol];
@@ -69,7 +69,7 @@
     {
       int elemType;
       int size;
-      [protocol readListBeginWithElementType: &elemType size: &size];
+      [protocol readListBeginReturningElementType: &elemType size: &size];
       int i;
       for (i = 0; i < size; i++) {
         [TProtocolUtil skipType: elemType onProtocol: protocol];
diff --git a/lib/cocoa/TTransport.h b/lib/cocoa/TTransport.h
index bb0270e..1fa04f4 100644
--- a/lib/cocoa/TTransport.h
+++ b/lib/cocoa/TTransport.h
@@ -1,10 +1,10 @@
 @protocol TTransport <NSObject>
 
   /**
-   * Guarantees that all of len bytes are 
+   * Guarantees that all of len bytes are read
    *
-   * @param buf Array to read into
-   * @param off Index to start reading at
+   * @param buf Buffer to read into
+   * @param off Index in buffer to start storing bytes at
    * @param len Maximum number of bytes to read
    * @return The number of bytes actually read, which must be equal to len
    * @throws TTransportException if there was an error reading data