On 26 May 2014, at 16:20, Graham Cox <graham....@bigpond.com> wrote: > On 27 May 2014, at 12:54 am, Roland King <r...@rols.org> wrote: >> datasize = *((unsigned int*)bytes); >> >> is a bit closer to what you might want but is endian-unaware. > > That's just as wrong - you are using the first few bytes of the data as the > length, which it certainly isn't (except for possibly a very few special > cases that just so happen to have the length as the first field of the data).
It’s not a general truth, true, but from what the OP mentioned, he’s sequentially reading stuff from his big NSData: > datasize = (unsigned int)bytes; //This is the length of > the data indicated in the data structure from the capture. So there you need to correctly cast the start of the data into a pointer to the right size of int (in general, you’d use some stable type like uint32_t instead of unsigned int for portability, though), and then de-reference it to read. Regarding endian-swapping, that depends on the file format. If you wrote that file yourself, you don’t usually need to do any swapping. Cheers, -- Uli Kusterer “The Witnesses of TeachText are everywhere...” http://zathras.de _______________________________________________ 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