• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Assigning Binary Data From Network To Variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Assigning Binary Data From Network To Variables (From: "Bridger Maxwell" <email@hidden>)

  • Prev by Date: Re: Simple bindings problem
  • Next by Date: AppleScript enabling my application, is it easier in XCode 3.0 / Objective-C 2.0
  • Previous by thread: Assigning Binary Data From Network To Variables
  • Next by thread: Simple bindings problem
  • Index(es):
    • Date
    • Thread