NSData Behavior as a consumable data stream. Possible?
I am currently doing a lot of data shuffling. I swallow NSData lloonngg byte streams and then parse that data. Parsing is trivial. However, I have to simulate data consumption as I am analyzing not particularly elegant accounting records. This is what a typical method looks like in the NData category that I have implemented:
// Take a 32-bit mini-character number - (uint32_t) getInt32OffsetIncrement: (NSUInteger *) offset {
uint32_t unused;
NSRange myRange = NSMakeRange(*offset, sizeof(unused));
[self getBytes:&unused range:myRange];
*offset += sizeof(unused);
return CFSwapInt32LittleToHost(unused);
}
As you can see, I am fetching the data and then navigating to the NSRange "pointer" in the data stream. When I finished, I used the entire data stream.
Am I missing out on any NSData methods that can fetch data and advance a pointer along the length of the data stream at the same time?
Cheers, Doug
+2
source to share
1 answer