struct msg
{
uint32_t msgtype;
uint32_t param1;
uint32_t param2;
};
struct msg a;
a.msgtype = 123456;
a.param1 = 12345;
a.param2 = 12345;
struct msg ba;
NSData *msgData = [[NSData alloc]initWithBytes:&a length:sizeof(a)];
[msgData getBytes:&ba length:sizeof(ba)];
NSLog(@"a:%u", ba.msgtype);
NSLog(@"ba:%u", a.msgtype );
转载于:https://my.oschina.net/u/1580121/blog/269062