I have the following struct:
typedef enum
{
kPacketTypeJoin = 1,
kPacketTypeServerAcceptedJoin,
kPacketTypeSelectedNumber,
} PacketTypes;
typedef struct
{
PacketTypes type;
NSString *name;
} PacketJoin;
how would I convert a PacketJoin into NSData and back to PacketJoin again?
// make a NSData object
NSData *myData = [NSData dataWithBytes:&myPacketJoin length:sizeof(myPacketJoin)];
// make a new PacketJoin
PacketJoin newJoin;
[myData getBytes:&newJoin length:sizeof(newJoin)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With