mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +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
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue