NSData encode decode
NSData encode decode
- Subject: NSData encode decode
- From: James Maxwell <email@hidden>
- Date: Thu, 2 Apr 2009 15:40:16 -0700
I'm having some real trouble with encoding/decoding a 2D float matrix
wrapped in an NSData.
I'm doing this:
- (void) encodeWithCoder:(NSCoder*) coder
{
NSUInteger mGraphSize = [[[[self containerNode] spatialPooler]
quantizationCentres] count] * [[[[self containerNode] spatialPooler]
quantizationCentres] count] * sizeof(float);
[coder encodeObject:[self containerNode] forKey:@"containerNode"];
[coder encodeObject:[self chains] forKey:@"chains"];
[coder encodeInt:[self maxGroups] forKey:@"maxGroups"];
[coder encodeInt:[self transitionMemorySize]
forKey:@"transitionMemorySize"];
[coder encodeInt:[self maxChainLength] forKey:@"maxChainLength"];
[coder encodeInt:[self runMode] forKey:@"runMode"];
[coder encodeBytes:[[self normalizedMarkovGraph] bytes]
length:mGraphSize forKey:@"normalizedMarkovGraph"];
}
- (id) initWithCoder:(NSCoder*) coder
{
NSUInteger mGraphSize;
[self setDefaults];
[self setContainerNode:[coder decodeObjectForKey:@"containerNode"]];
[self setChains:[coder decodeObjectForKey:@"chains"]];
[self setMaxGroups:[coder decodeIntForKey:@"maxGroups"]];
[self setTransitionMemorySize:[coder
decodeIntForKey:@"transitionMemorySize"]];
[self setMaxChainLength:[coder decodeIntForKey:@"maxChainLength"]];
[self setRunMode:[coder decodeIntForKey:@"runMode"]];
[self setNormalizedMarkovGraph:[NSData dataWithBytes:[coder
decodeBytesForKey:@"normalizedMarkovGraph" returnedLength:&mGraphSize]
length:mGraphSize]];
[self calculateMarkovChainModulus];
return self;
}
It appears to save correctly, though it's pretty much impossible to
know until I re-load the data... But no crashes on saving. When I open
it, I gdb pops up at the [self setNormalizedMarkovGraph...] line with
this:
#0 0x9694ee17 in objc_exception_throw
#1 0x9374eeeb in +[NSException raise:format:arguments:]
Probably that error doesn't say anything, but I'm confused anyway. Any
help appreciated.
cheers,
J.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden