hande data objects

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6839 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-06-28 10:43:37 +00:00
parent 26fef76e05
commit 1cec513cbe

View file

@ -35,6 +35,7 @@
#include <base/CStream.h>
#include <base/Port.h>
#include <base/MemoryStream.h>
#include <Foundation/NSData.h>
#include <Foundation/NSException.h>
#include <Foundation/DistributedObjects.h>
@ -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