summaryrefslogtreecommitdiff
path: root/lib/cocoa
diff options
context:
space:
mode:
authorMark Slee <mcslee@apache.org>2007-09-14 19:44:30 +0000
committerMark Slee <mcslee@apache.org>2007-09-14 19:44:30 +0000
commit33a7d898ca8d40d02cbd6a5b7547b7fa3958c3cf (patch)
treee96beab79b6538313bb89bcadeac0d3ee76c3fd2 /lib/cocoa
parentae8f1d3f2341660a84a9b64e05c1ee4bec6df581 (diff)
downloadthrift-33a7d898ca8d40d02cbd6a5b7547b7fa3958c3cf.tar.gz
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
Diffstat (limited to 'lib/cocoa')
-rw-r--r--lib/cocoa/TApplicationException.h8
-rw-r--r--lib/cocoa/TBinaryProtocol.m45
-rw-r--r--lib/cocoa/TException.h10
-rw-r--r--lib/cocoa/TProtocol.h30
-rw-r--r--lib/cocoa/TProtocolUtil.m10
-rw-r--r--lib/cocoa/TTransport.h6
6 files changed, 59 insertions, 50 deletions
diff --git a/lib/cocoa/TApplicationException.h b/lib/cocoa/TApplicationException.h
index bb6428205..1fee06e4a 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 @@ enum {
};
// 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 cd239dee8..2d2ca8eaf 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 @@ int32_t VERSION_MASK = 0xffff0000;
}
-- (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 @@ int32_t VERSION_MASK = 0xffff0000;
}
} 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 @@ int32_t VERSION_MASK = 0xffff0000;
- (void) readMessageEnd {}
-- (void) readStructBeginWithName: (NSString **) name
+- (void) readStructBeginReturningName: (NSString **) name
{
if (name != NULL) {
*name = nil;
@@ -97,9 +94,9 @@ int32_t VERSION_MASK = 0xffff0000;
- (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 VERSION_MASK = 0xffff0000;
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 @@ int32_t VERSION_MASK = 0xffff0000;
- (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 @@ int32_t VERSION_MASK = 0xffff0000;
- (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 95eaa8348..ce3b4a5af 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 96d3af6af..bc64789ed 100644
--- a/lib/cocoa/TProtocol.h
+++ b/lib/cocoa/TProtocol.h
@@ -30,17 +30,17 @@ enum {
- (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 @@ enum {
- (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 @@ enum {
- (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 746790f57..cf32aad6b 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 bb0270e05..1fa04f4c0 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