From: Andrew McGeachie Date: Wed, 21 Jul 2010 19:51:04 +0000 (+0000) Subject: THRIFT-821. Add a method to get a copy of the TMemoryBuffer's buffer. X-Git-Tag: 0.4.0~48 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=c892ac555e74db0b3be99093fb6ffec5468ad316;p=common%2Fthrift.git THRIFT-821. Add a method to get a copy of the TMemoryBuffer's buffer. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@966385 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cocoa/src/transport/TMemoryBuffer.h b/lib/cocoa/src/transport/TMemoryBuffer.h index 45a5e178..fa4d3713 100644 --- a/lib/cocoa/src/transport/TMemoryBuffer.h +++ b/lib/cocoa/src/transport/TMemoryBuffer.h @@ -25,4 +25,5 @@ NSUInteger mOffset; } - (id)initWithData:(NSData *)data; +- (NSData *)getBuffer; @end diff --git a/lib/cocoa/src/transport/TMemoryBuffer.m b/lib/cocoa/src/transport/TMemoryBuffer.m index 7912bcd7..869010a4 100644 --- a/lib/cocoa/src/transport/TMemoryBuffer.m +++ b/lib/cocoa/src/transport/TMemoryBuffer.m @@ -23,6 +23,14 @@ #define GARBAGE_BUFFER_SIZE 4096 // 4KiB @implementation TMemoryBuffer +- (id)init { + if (self = [super init]) { + mBuffer = [[NSMutableData alloc] init]; + mOffset = 0; + } + return self; +} + - (id)initWithData:(NSData *)data { if (self = [super init]) { mBuffer = [data mutableCopy]; @@ -52,6 +60,10 @@ // noop } +- (NSData *)getBuffer { + return [[mBuffer copy] autorelease]; +} + - (void)dealloc { [mBuffer release]; [super dealloc];