FROM : Nick Zitzmann
DATE : Sat Jan 05 23:03:42 2008
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/>
DATE : Sat Jan 05 23:03:42 2008
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/>
| Related mails | Author | Date |
|---|---|---|
| Bridger Maxwell | Jan 5, 08:27 | |
| Nick Zitzmann | Jan 5, 23:03 |






Cocoa mail archive

