Re: NSData. add 6 bytes to NSData
Re: NSData. add 6 bytes to NSData
- Subject: Re: NSData. add 6 bytes to NSData
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sat, 04 Jul 2009 11:38:09 -0700
On Jul 4, 2009, at 10:56 AM, Scott Andrew wrote:
In all honesty the easiest way is to do it in C. Add a 4 byte
variable to the top of your packet header.. When building the packet
set it to 0.. That solves your problem of getting data into the
packet.
But if you want to add something to the beginning, using
NSMutableData, you have to first create the NSMutableData packet
with 4 bytes of 0s then call [data appendBytes].. So something like
so (not perfect)..
Maybe I missed your point, but you can easily insert bytes in an
NSMutableData. Check the documentation for -[NSMutableData
replaceBytesInRange:withBytes:length:].
On Jul 4, 2009, at 9:23 AM, Carlo Gulliani wrote:
NSMutableData *data = [NSData dataWithBytes:&packet length:sizeof
(packet)];
Note that this is /not/ an NSMutableData, in spite of the declaration,
since you've used NSData to create it. Use [NSMutableData
dataWithBytes:length:] to create a mutable data instance.
--
Adam
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden