Re: Specific byte size data type?
Re: Specific byte size data type?
- Subject: Re: Specific byte size data type?
- From: Esteban <email@hidden>
- Date: Wed, 6 Mar 2002 18:10:29 -0800
This sounds to me like a job for a C struct or bit field
You can do this by creating a struct bit field like so...
struct protocol_data {
unsigned header:8
unsigned field1:16
unsigned field2:24
...
};
You specify the bit field members as bits, hence 1 byte = 8 bits, and
header is 8 bits long. Bit field members must be unsigned or int. Make
sure the bits add up to a multiple of 8.
I'd probably go find an adequate c++ or c book, pdf, or online manual,
to make sure everything is set up right, and learn the best ways to get
at the data and deal with it (unions, etc)
I dont know of an equivalent Objective C way of doing this, but you
could give NSData a try and just set different ranges to access
different parts of the protocol data. Although with ranges you can only
access 1 byte minimum. You can have a bit field member of 2 bits, in a
bit field stucture.
-Esteban Uribe
On Wednesday, March 6, 2002, at 07:57 AM, Andrew Baldwin wrote:
I need to read packets from the network and I want to save the data
into a structure with variables which will be of a specific size (a 1
byte header, a 2 or 3 byte field, followed by another field, etc. all
conforming to a protocol I'm implementing). How can I do this in
cocoa -- what types should I use?
Thanks in advance for helping a newbie.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.