Re: Assigning Binary Data From Network To Variables
Re: Assigning Binary Data From Network To Variables
- Subject: Re: Assigning Binary Data From Network To Variables
- From: Nick Zitzmann <email@hidden>
- Date: Sat, 5 Jan 2008 15:03:42 -0700
On Jan 5, 2008, at 12:27 AM, Bridger Maxwell wrote:
I am very new to Cocoa, so I apologize if this question seems very
basic.
Right now I am trying to read data from a program that is sending
data in
the "TUIO" protocol. I have read the data from the socket, and
assigned it
to a NSData object with this code:
NSData *messageData = [[notification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
Now how do I translate that data to integer and float values?
Try something like this (warning, written in Mail, untested, use at
your own risk, but this ought to work):
long long offset = 0;
int32_t someIntValue;
float32_t someFloatValue;
[messageData getBytes:&someIntValue range:NSMakeRange(offset,
sizeof(int32_t))];
offset += sizeof(int32_t);
[messageData getBytes:&someFloatValue range:NSMakeRange(offset,
sizeof(float32_t))];
offset += sizeof(float32_t);
Don't forget to flip those bits around on the appropriate
architectures if you're building a universal binary. There are some
NSSwap... functions in Foundation that will do that.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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