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.

On 26 May 2014, at 15:25, Sandy McGuffog <mcguff...@gmail.com> wrote:

> 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, 2014, at 3:44 PM, 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:&databuffer range:NSMakeRange(positionCounter, 
>> datasize)]; // Packet content
>> 
>> and 
>> 
>>  unsigned char* bytes;
>>  [datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; 
>> // Packet content
>> 
>> Either way, I get the same result.
>> 
>> 
>> 
>> On 26 May 2014, at 14:16, Uli Kusterer <witness.of.teacht...@gmx.net> wrote:
>> 
>>> 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, and what do you initialize it to?
>>> 
>>> 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/mcguffogl%40gmail.com
>> 
>> This email sent to mcguff...@gmail.com
> 

_______________________________________________

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