From e101b26a1ee487b40ed7c049e9da466150d9e698 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 28 Jun 2000 10:43:37 +0000 Subject: [PATCH] hande data objects git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6839 72102866-910b-0410-8b05-ffd578937521 --- Source/NSPortCoder.m | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Source/NSPortCoder.m b/Source/NSPortCoder.m index cdec56a9e..ef7d4ee6c 100644 --- a/Source/NSPortCoder.m +++ b/Source/NSPortCoder.m @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -213,6 +214,20 @@ static BOOL debug_connected_coder = NO; return; } +- (void) encodeDataObject: (NSData*)anObject +{ + unsigned l = [anObject length]; + + [self encodeValueOfObjCType: @encode(unsigned) at: &l]; + if (l) + { + const void *b = [anObject bytes]; + + [self encodeArrayOfObjCType: @encode(unsigned char) + count: l + at: b]; + } +} @end @@ -351,6 +366,33 @@ static BOOL debug_connected_coder = NO; [self release]; } +- (NSData*) decodeDataObject +{ + unsigned l; + + [self decodeValueOfObjCType: @encode(unsigned) at: &l]; + if (l) + { + void *b; + NSData *d; + NSZone *z; + +#if GS_WITH_GC + z = GSAtomicMallocZone(); +#else + z = NSDefaultMallocZone(); +#endif + b = NSZoneMalloc(z, l); + [self decodeArrayOfObjCType: @encode(unsigned char) + count: l + at: b]; + d = [[NSData alloc] initWithBytesNoCopy: b length: l fromZone: z]; + IF_NO_GC(AUTORELEASE(d)); + return d; + } + return [NSData data]; +} + @end