On May 28, 2014, at 10:24 PM, Uli Kusterer wrote:
> That said, if you want to be really endian-safe, use an XML file format saved
> as UTF-8 like Property Lists. Most portable format there is. :-)
Thanks a lot. I have to go rinse out my mouth now.
--
Scott Ribe
scott_r...@elevated-dev.com
htt
On May 28, 2014, at 11:24 PM, Uli Kusterer wrote:
> Or change struct alignment or the size of ints or … I’ve been programming for
> a couple of days, I’ve taken this into account. But I’d rather retroactively
> go and fix something (you have to re-test when porting to a new platform
> anyway)
On May 27, 2014, at 3:51 PM, Greg Parker wrote:
> On May 27, 2014, at 12:52 PM, Charles Srstka wrote:
>> On May 27, 2014, at 2:08 PM, Greg Parker wrote:
>>> On May 26, 2014, at 8:28 PM, Charles Srstka
>>> wrote:
On May 26, 2014, at 7:43 PM, Uli Kusterer
wrote:
> Regarding endi
On 26 May 2014, at 20:28, Charles Srstka wrote:
> On May 26, 2014, at 7:43 PM, Uli Kusterer
> wrote:
>> Regarding endian-swapping, that depends on the file format. If you wrote
>> that file yourself, you don’t usually need to do any swapping.
>
> That's true. For example, back in the PowerPC d
On 28 May 2014, at 5:52 am, Charles Srstka wrote:
> a) 'bar' is a later addition to the file format, added some time after the
> app was ported to Intel, and thus is in little-endian format whereas the
> older parts of the file are in big-endian (and yes, I've seen formats that do
> this), or
On May 27, 2014, at 12:08 PM, Greg Parker wrote:
> Untested code is incorrect code. Don't write endian-swapping code that you
> can't test because you aren't using any other-endian platforms today.
I disagree. There is a strong, longstanding convention for cross-platform
binary data formats
On May 27, 2014, at 12:52 PM, Charles Srstka wrote:
> On May 27, 2014, at 2:08 PM, Greg Parker wrote:
>> On May 26, 2014, at 8:28 PM, Charles Srstka wrote:
>>> On May 26, 2014, at 7:43 PM, Uli Kusterer
>>> wrote:
Regarding endian-swapping, that depends on the file format. If you wrote
>>
On May 27, 2014, at 2:08 PM, Greg Parker wrote:
> On May 26, 2014, at 8:28 PM, Charles Srstka wrote:
>> On May 26, 2014, at 7:43 PM, Uli Kusterer
>> wrote:
>>> Regarding endian-swapping, that depends on the file format. If you wrote
>>> that file yourself, you don’t usually need to do any swa
On May 26, 2014, at 8:28 PM, Charles Srstka wrote:
> On May 26, 2014, at 7:43 PM, Uli Kusterer
> wrote:
>> Regarding endian-swapping, that depends on the file format. If you wrote
>> that file yourself, you don’t usually need to do any swapping.
>
> That's true. For example, back in the PowerP
On May 26, 2014, at 7:43 PM, Uli Kusterer wrote:
> Regarding endian-swapping, that depends on the file format. If you wrote that
> file yourself, you don’t usually need to do any swapping.
That's true. For example, back in the PowerPC days, we never had to endian-swap
our file formats, because
On 27 May 2014, at 10:13 am, Jens Alfke 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
standpoi
On 26 May 2014, at 16:20, Graham Cox wrote:
> On 27 May 2014, at 12:54 am, Roland King 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, w
On May 26, 2014, at 4:20 PM, Graham Cox wrote:
> 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).
No, it’s extr
On 27 May 2014, at 12:54 am, Roland King 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 fe
On May 26, 2014, at 6:02 AM, Pax <45rpmli...@googlemail.com> wrote:
> When this gets run, I get EXC_BAD_ACCESS code = 2 here. I'm demonstrably
> reading less data than the file contains, and I've been able to read through
> the file successfully up to this point. Please could someone suggest
On May 26, 2014, at 10:06 AM, Pax <45rpmli...@googlemail.com> wrote:
> As I say though, I think that the solution I posted is the better solution
> anyway - since who wants a copy, with the additional overhead that a copy
> entails, when you don't need to have one?
Absolutely. (For read-only ac
Shameful. I need more sleep! :-) I also need to reread my code more carefully
before asking questions.
As I say though, I think that the solution I posted is the better solution
anyway - since who wants a copy, with the additional overhead that a copy
entails, when you don't need to have on
On May 26, 2014, at 9:32 AM, Uli Kusterer wrote:
> Oh, and as Roland wrote, don’t forget to free() the pointer once you’re done
> with it.
But, just to be 100% clear, *not* the one you get from calling the bytes method
;-)
--
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com
Too true. That was a lot of bugs in 4 lines!
> On 26 May, 2014, at 11:18 pm, Scott Ribe wrote:
>
>> On May 26, 2014, at 9:05 AM, Roland King wrote:
>>
>> The first one of those is ok...
>
> No, it's not--take a closer look ;-)
>
>> unsigned char* databuffer = (unsigned char*)malloc(datasize)
On 26 May 2014, at 06:44, Pax <45rpmli...@googlemail.com> wrote:
> Apologies - the obvious important detail, and I missed it out entirely. I
> have tried both of the following with the same result:
>
> unsigned char* databuffer = (unsigned char*)malloc(datasize);
> [datastream getBytes:&data
On May 26, 2014, at 9:05 AM, Roland King wrote:
> The first one of those is ok...
No, it's not--take a closer look ;-)
> unsigned char* databuffer = (unsigned char*)malloc(datasize);
> [datastream getBytes:&databuffer range:NSMakeRange(positionCounter,
> datasize)];
--
Scott Ribe
scott_r...
The first one of those is ok - as long as you remember to free databuffer
later. The second is wrong, the argument to getBytes:range: has to be an
allocated buffer of size at least the length of the range you pass in. That
second one is just copying data to a random place in memory, probably zer
On May 26, 2014, at 8:43 AM, Pax <45rpmli...@googlemail.com> wrote:
> I should, I know, find out what was going wrong initially - but since I'd
> rather not have a copy anyway, this really is the all-round better solution.
What was wrong was that instead of passing the address of the buffer you
So you have
unsigned char *bytes;
and then
datasize = (unsigned int)bytes;
which sets datasize to the address of bytes cast to an unsigned integer which
has nothing to do with the data in bytes at all and in some cases just
truncates the address (OSX for instance)
datasize = *((unsigned in
Just to answer my own question, I find that:
bytes=[[datastream subdataWithRange:NSMakeRange(positionCounter,
datasize)]bytes];
Works perfectly.
I should, I know, find out what was going wrong initially - but since I'd
rather not have a copy anyway, this really is the all-round better solution
Well,
I find your code to be a bit confusing, but I’d say that both of those are
wrong. I think that what you need is:
unsigned char* databuffer = (unsigned char*)malloc(datasize);
[datastream getBytes:databuffer range:NSMakeRange(positionCounter,
datasize)]; // Packet content
On May 26,
Apologies - the obvious important detail, and I missed it out entirely. I have
tried both of the following with the same result:
unsigned char* databuffer = (unsigned char*)malloc(datasize);
[datastream getBytes:&databuffer range:NSMakeRange(positionCounter,
datasize)]; // Packet content
Apologies - the obvious important detail, and I missed it out entirely. I have
tried both of the following with the same result:
unsigned char* databuffer = (unsigned char*)malloc(datasize);
[datastream getBytes:&databuffer range:NSMakeRange(positionCounter,
datasize)]; // Packet content
On 26 May 2014, at 06:02, Pax <45rpmli...@googlemail.com> wrote:
> This is my snippet of code:
>[datastream getBytes:&bytes
> range:NSMakeRange(positionCounter, datasize)]; // Length of packet content
>positionCounter+= datasize;
What is bytes declared as,
29 matches
Mail list logo