NSData and Primitives
NSData and Primitives
- Subject: NSData and Primitives
- From: Buzz Andersen <email@hidden>
- Date: Sun, 09 Jun 2002 17:46:40 -0600
Hello all,
I am a long-time Java programmer who is currently trying to very hard to
"grok" the whole Objective C/Cocoa way of doing things, so please bear with
me if this question seems too elementary :-)...
Basically, what I have is a file containing a custom binary data format,
from which I would like to read various primitive data types--longs, Unicode
Strings, etc. Now, I have already done Java programs which do this very
thing using methods like "readLong()" in the java.io.DataInputStream class,
but I am unsure of the best way to accomplish a similar thing using NSData,
NSFileHandle, etc.
Basically, my attempts so far go something like this:
NSFileHandle *file;
NSData *buffer;
unsigned char[4] bytes;
unsigned long number;
file = [NSFileHandle fileHandleForReadingAtPath: theFile];
buffer = [file readDataOfLength: sizeof(long)];
[buffer getBytes: bytes];
memcpy(&number, &bytes, sizeof(long));
Is this the best way to do it, or is there a better way using Foundation or
Appkit classes? Is this even a reliable way of doing it (I'm kind of having
trouble figuring out if this method is working properly--the results don't
seem right to me).
Any help would be GREATLY appreciated :-)!
Thanks,
Buzz Andersen
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.