Reading a legacy file format
Reading a legacy file format
- Subject: Reading a legacy file format
- From: David Sinclair <email@hidden>
- Date: Mon, 7 Apr 2003 18:28:38 -0700
Hi. I have an issue similar to the current "Long to C-String" thread,
though not quite. I have a legacy file format that uses Pascal
records, and want to read it in to instance variables of an object. I
saw a few approaches in the archives, but wasn't sure what was best in
this situation. Would the best way be to define a struct for the
format, then use calls like the following to read the data? Or is
there a better way?
NSFileHandle *fileHandle = [NSFileHandle
fileHandleForReadingAtPath:fileName];
NSData *data = [fileHandle readDataOfLength:100];
RecordStruct record;
[DemoObject *demo = [[DemoObject alloc] init];
[data getBytes:&record];
[demo setFoo:record.foo];
[demo setBar:record.bar];
[demo setZap:record.zap];
// ...etc...
Another issue is how to convert Pascal strings to NSStrings; there
doesn't seem to be a method to do that directly. Is there some C
function like ptoc or similar that will do the Pascal to C conversion,
then use NSString's stringWithCString, or should I roll my own? Or
read the length byte and use stringWithCString:length:?
--
David Sinclair, Dejal Systems, LLC - email@hidden
Let Dejal Simon keep an eye on your sites for changes or failures!
http://www.dejal.com/simon/
_______________________________________________
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.