On Wed, 27 Feb 2013 00:47:35 +0700, Gerriet M. Denkmann said:

>2. NSKeyedArchiver seems to be ok.

One problem I know of with NSKeyedArchiver:

It has methods like encodeInt32:forKey: but no unsigned variants 
<rdar://6083905>.   (Good thing I filed the bug, I'm sure Apple will get right 
on it, eh Gwynne? :)  Sorry, couldn't resist.)

You have to watch out for sign extension.  This may surprise some people:

        uint32_t input = 0xFFFFFFFF; // 4294967295
        NSMutableData* data = [NSMutableData data];
        NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] 
initForWritingWithMutableData:data];
        [archiver encodeInt32:(int32_t)input forKey:@"test"];
        [archiver finishEncoding];
        
        NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] 
initForReadingWithData:data];
        int64_t output = [unarchiver decodeInt64ForKey:@"test"];
        [unarchiver finishDecoding];

The value of output is _not_ 4294967295, it is -1.  This behaves correctly, but 
I bet lots of code out there casts uint32 to int32 like above.  If you want to 
encode a uint32 you need to use encodeInt64: I guess, which is not obvious.  
The lack of encodeUInt64 is worst of all.

Cheers,

-- 
____________________________________________________________
Sean McBride, B. Eng                 s...@rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to