先传送结构体大小,再传数据。注意结构体内存对齐。
/*send*/
Parcel data, reply;
char *p = (char *)(&obj)
data.writeInt(sizeof(obj));
for (int i = 0; i < sizeof(obj);++i) {
data.writeByte(p[i]);
}
/*recv*/
Parcel data, reply;
int size = data.readInt();
char *buf = (char *)(&obj);
for (int i = 0; i < size; ++i) {
buf[i] = data.readByte();
}