mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
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:
parent
26fef76e05
commit
1cec513cbe
1 changed files with 42 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue