On 27 May 2014, at 10:13 am, Jens Alfke <j...@mooseyard.com> wrote:

> No, it’s extremely common to have a data format where a variable-length field 
> is prefixed with its length. That looks like what this code is trying to read.

Alright, but you have to know that. I was looking at the code from a general 
standpoint, where its format was unknown - just a blob of data. Also, just 
reading the bytes blindly doesn't take into account endianness, though you and 
Roland do mention that. 

What I prefer to do when parsing blobs of data like this is declare types that 
represent chunks of the format, such as a struct that matches the header (being 
careful about matching the padding used by the file) then cast or copy the data 
buffer, taking into account endianness, into that type. It makes the code a lot 
more readable, because you are not just reading from a arbitrary offset, but 
are using a named field.

--Graham



_______________________________________________

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