mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add some keyed encoding/decoding.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25668 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9c36ec10dd
commit
f10ebd138c
3 changed files with 129 additions and 28 deletions
|
@ -1,3 +1,9 @@
|
|||
2007-12-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSIndexSet.m (-initWithCoder:, -encodeWithCoder)
|
||||
* Source/NSData.m (NSMutableData-initWithCoder:,
|
||||
-encodeWithCoder): Add some keyed encoding/decoding.
|
||||
|
||||
2007-12-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSDebug.m:
|
||||
|
|
|
@ -1525,6 +1525,7 @@ failure:
|
|||
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
// FIXME
|
||||
obj = [coder decodeObject];
|
||||
}
|
||||
else
|
||||
|
@ -1776,13 +1777,22 @@ failure:
|
|||
unsigned length = [self length];
|
||||
void *bytes = [self mutableBytes];
|
||||
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
||||
at: &length];
|
||||
if (length)
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
|
||||
count: length
|
||||
at: bytes];
|
||||
[aCoder encodeBytes: bytes
|
||||
length: length
|
||||
forKey:@"NS.data"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
||||
at: &length];
|
||||
if (length)
|
||||
{
|
||||
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
|
||||
count: length
|
||||
at: bytes];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1800,31 +1810,44 @@ failure:
|
|||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
unsigned l;
|
||||
NSZone *zone;
|
||||
|
||||
#if GS_WITH_GC
|
||||
zone = GSAtomicMallocZone();
|
||||
#else
|
||||
zone = [self zone];
|
||||
#endif
|
||||
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned int) at: &l];
|
||||
if (l)
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
void *b = NSZoneMalloc(zone, l);
|
||||
const uint8_t *data;
|
||||
|
||||
if (b == 0)
|
||||
{
|
||||
NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
|
||||
self = [self initWithBytesNoCopy: b length: l];
|
||||
data = [aCoder decodeBytesForKey: @"NS.data"
|
||||
returnedLength: &l];
|
||||
self = [self initWithBytes: data length: l];
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithBytesNoCopy: 0 length: 0];
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned int) at: &l];
|
||||
if (l)
|
||||
{
|
||||
void *b;
|
||||
NSZone *zone;
|
||||
|
||||
#if GS_WITH_GC
|
||||
zone = GSAtomicMallocZone();
|
||||
#else
|
||||
zone = [self zone];
|
||||
#endif
|
||||
|
||||
b = NSZoneMalloc(zone, l);
|
||||
|
||||
if (b == 0)
|
||||
{
|
||||
NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
|
||||
self = [self initWithBytesNoCopy: b length: l];
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithBytesNoCopy: 0 length: 0];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include <Foundation/NSIndexSet.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
|
@ -274,7 +275,32 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
int rangeCount = 0;
|
||||
|
||||
if (_array != 0)
|
||||
{
|
||||
rangeCount = GSIArrayCount(_array);
|
||||
}
|
||||
|
||||
[aCoder encodeInt: rangeCount forKey: @"NSRangeCount"];
|
||||
|
||||
if (rangeCount == 0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else if (rangeCount == 1)
|
||||
{
|
||||
NSRange r;
|
||||
|
||||
r = GSIArrayItemAtIndex(_array, 0).ext;
|
||||
[aCoder encodeInt: r.location forKey: @"NSLocation"];
|
||||
[aCoder encodeInt: r.length forKey: @"NSLength"];
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME
|
||||
[self notImplemented:_cmd];
|
||||
}
|
||||
}
|
||||
|
||||
- (unsigned int) firstIndex
|
||||
|
@ -456,7 +482,53 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
int rangeCount = 0;
|
||||
|
||||
if ([aCoder containsValueForKey: @"NSRangeCount"])
|
||||
{
|
||||
rangeCount = [aCoder decodeIntForKey: @"NSRangeCount"];
|
||||
}
|
||||
|
||||
if (rangeCount == 0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else if (rangeCount == 1)
|
||||
{
|
||||
unsigned len = 0;
|
||||
unsigned loc = 0;
|
||||
|
||||
if ([aCoder containsValueForKey: @"NSLocation"])
|
||||
{
|
||||
loc = [aCoder decodeIntForKey: @"NSLocation"];
|
||||
}
|
||||
if ([aCoder containsValueForKey: @"NSLength"])
|
||||
{
|
||||
len = [aCoder decodeIntForKey: @"NSLength"];
|
||||
}
|
||||
self = [self initWithIndexesInRange: NSMakeRange(loc, len)];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSData * data = nil;
|
||||
|
||||
if ([aCoder containsValueForKey: @"NSRangeData"])
|
||||
{
|
||||
data = [aCoder decodeIntForKey: @"NSRangeData"];
|
||||
}
|
||||
|
||||
/*
|
||||
FIXME:
|
||||
NSLog(@"Decoded count %d, data %@", rangeCount, data);
|
||||
This is a very strange format:
|
||||
|
||||
5 + 6 + 9 gives <05020901>
|
||||
5 + 6 + 23 gives <05021701>
|
||||
155 + 156 + 223 gives <9b0102df 0101>
|
||||
*/
|
||||
[self notImplemented:_cmd];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue