mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +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
a0b3607dd6
commit
4f380653db
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>
|
2007-12-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSDebug.m:
|
* Source/NSDebug.m:
|
||||||
|
|
|
@ -1525,6 +1525,7 @@ failure:
|
||||||
|
|
||||||
if ([coder allowsKeyedCoding])
|
if ([coder allowsKeyedCoding])
|
||||||
{
|
{
|
||||||
|
// FIXME
|
||||||
obj = [coder decodeObject];
|
obj = [coder decodeObject];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1776,13 +1777,22 @@ failure:
|
||||||
unsigned length = [self length];
|
unsigned length = [self length];
|
||||||
void *bytes = [self mutableBytes];
|
void *bytes = [self mutableBytes];
|
||||||
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
if ([aCoder allowsKeyedCoding])
|
||||||
at: &length];
|
|
||||||
if (length)
|
|
||||||
{
|
{
|
||||||
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
|
[aCoder encodeBytes: bytes
|
||||||
count: length
|
length: length
|
||||||
at: bytes];
|
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
|
- (id) initWithCoder: (NSCoder*)aCoder
|
||||||
{
|
{
|
||||||
unsigned l;
|
unsigned l;
|
||||||
NSZone *zone;
|
|
||||||
|
|
||||||
#if GS_WITH_GC
|
if ([aCoder allowsKeyedCoding])
|
||||||
zone = GSAtomicMallocZone();
|
|
||||||
#else
|
|
||||||
zone = [self zone];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[aCoder decodeValueOfObjCType: @encode(unsigned int) at: &l];
|
|
||||||
if (l)
|
|
||||||
{
|
{
|
||||||
void *b = NSZoneMalloc(zone, l);
|
const uint8_t *data;
|
||||||
|
|
||||||
if (b == 0)
|
data = [aCoder decodeBytesForKey: @"NS.data"
|
||||||
{
|
returnedLength: &l];
|
||||||
NSLog(@"[NSDataMalloc -initWithCoder:] unable to get %lu bytes", l);
|
self = [self initWithBytes: data length: l];
|
||||||
RELEASE(self);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char) count: l at: b];
|
|
||||||
self = [self initWithBytesNoCopy: b length: l];
|
|
||||||
}
|
}
|
||||||
else
|
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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Foundation/NSCoder.h"
|
||||||
#include <Foundation/NSIndexSet.h>
|
#include <Foundation/NSIndexSet.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSZone.h>
|
#include <Foundation/NSZone.h>
|
||||||
|
@ -274,7 +275,32 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
- (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
|
- (unsigned int) firstIndex
|
||||||
|
@ -456,7 +482,53 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder*)aCoder
|
- (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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue