Created
April 27, 2009 04:35
-
-
Save davepeck/102331 to your computer and use it in GitHub Desktop.
Two simple Objective-C classes that make it crazy easy to read data from sequential binary files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // BinaryDataScanner.m | |
| // | |
| // Copyright 2009 Dave Peck <davepeck [at] davepeck [dot] org>. All rights reserved. | |
| // http://davepeck.org/ | |
| // | |
| // This class makes it quite a bit easier to read sequential binary files in Objective-C. | |
| // | |
| // This code is released under the BSD license. If you use it in your product, please | |
| // let me know and, if possible, please put me in your credits. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface BinaryDataScanner : NSObject { | |
| BOOL littleEndian; | |
| NSStringEncoding encoding; | |
| NSData *data; | |
| const uint8_t *current; | |
| NSUInteger scanRemain; | |
| } | |
| +(id)binaryDataScannerWithData:(NSData*)data littleEndian:(BOOL)littleEndian defaultEncoding:(NSStringEncoding)defaultEncoding; | |
| -(NSUInteger) remainingBytes; | |
| -(const uint8_t *) currentPointer; | |
| -(void) skipBytes:(NSUInteger)count; | |
| -(uint8_t) readByte; | |
| -(uint16_t) readWord; | |
| -(uint32_t) readDoubleWord; | |
| -(NSString*) readNullTerminatedString; | |
| -(NSString*) readNullTerminatedStringWithEncoding:(NSStringEncoding)overrideEncoding; | |
| -(NSString*) readStringUntilDelimiter:(uint8_t)delim; | |
| -(NSString*) readStringUntilDelimiter:(uint8_t)delim encoding:(NSStringEncoding)overrideEncoding; | |
| -(NSString*) readStringOfLength:(NSUInteger)count handleNullTerminatorAfter:(BOOL)handleNull; | |
| -(NSString*) readStringOfLength:(NSUInteger)count handleNullTerminatorAfter:(BOOL)handleNull encoding:(NSStringEncoding)overrideEncoding; | |
| -(NSArray*) readArrayOfNullTerminatedStrings:(NSUInteger)count; | |
| -(NSArray*) readArrayOfNullTerminatedStrings:(NSUInteger)count encoding:(NSStringEncoding)overrideEncoding; | |
| @end | |
Author
Yeah that UIKit import probably doesn't need to be there.
Hi, can you please tell me on what version of the bsd license is the code released?
Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I"m a newb to Objective C, and am writing for Mac. It seems that UIKit is for iOS...