From df4f203ee5b4aec8715b55d7618325e23e632eb3 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 29 Jan 1999 11:37:20 +0000 Subject: [PATCH] Added encodeDataObject: and decodeDataObject git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3622 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/NSArchiver.m | 22 ++++++++++++++++++++++ Source/NSUnarchiver.m | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/ChangeLog b/ChangeLog index d91c3e8fb..b15a21d05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jan 29 11:00:00 1999 Richard Frith-Macdonald + + * src/NSArchiver.m: Implemented ([-encodeDataObject:]) + * src/NSUnarchiver.m: Implemented ([-decodeDataObject]) + 1999-01-28 Adam Fedor * GNUmakefile (SUBPROJECTS): Change directory names diff --git a/Source/NSArchiver.m b/Source/NSArchiver.m index f99c24f54..0459e049b 100644 --- a/Source/NSArchiver.m +++ b/Source/NSArchiver.m @@ -674,6 +674,28 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:); } } +- (void) encodeDataObject: (NSData*)anObject +{ + unsigned l = [anObject length]; + + (*eValImp)(self, eValSel, @encode(unsigned int), &l); + if (l) + { + const void *b = [anObject bytes]; + unsigned char c = 0; /* Type tag */ + + /* + * The type tag 'c' is used to specify an encoding scheme for the + * actual data - at present we have '0' meaning raw data. In the + * future we might want zipped data for instance. + */ + (*eValImp)(self, eValSel, @encode(unsigned char), &c); + [self encodeArrayOfObjCType: @encode(unsigned char) + count: l + at: b]; + } +} + - (void) encodeObject: (id)anObject { if (anObject == nil) diff --git a/Source/NSUnarchiver.m b/Source/NSUnarchiver.m index 703519111..45fb66cad 100644 --- a/Source/NSUnarchiver.m +++ b/Source/NSUnarchiver.m @@ -950,6 +950,39 @@ mapClassName(NSUnarchiverObjectInfo *info) } } +- (NSData*) decodeDataObject +{ + unsigned l; + + (*dValImp)(self, dValSel, @encode(unsigned int), &l); + if (l) + { + unsigned char c; + + (*dValImp)(self, dValSel, @encode(unsigned char), &c); + if (c == 0) + { + void *b; + NSData *d; + + b = NSZoneMalloc(zone, l); + d = [[NSData allocWithZone: zone] initWithBytesNoCopy: b + length: l + fromZone: zone]; + [d autorelease]; + [self decodeArrayOfObjCType: @encode(unsigned char) + count: l + at: b]; + return d; + } + else + [NSException raise: NSInternalInconsistencyException + format: @"Decoding data object with unknown type"]; + } + else + return [NSData data]; +} + /* * The [-decodeObject] method is implemented purely for performance - * It duplicates the code for handling objects in the