首页 > iOS字节序问题

iOS字节序问题

socket跟服务端通讯,怎么可以讲NSData 转化成big-endian数据呢?

+ (NSData *)payloadWithZipStatus:(int8_t)zipped
                       cryptType:(int8_t)crypType
                     messageType:(int16_t)messageType
              protocolBufferData:(NSData *)pbData {

    int32_t length = (int32_t)[pbData length];

    NSMutableData *outData = [[NSMutableData alloc] initWithCapacity:(8 + pbData.length)];

    [outData appendBytes:&zipped length:1];
    [outData appendBytes:&crypType length:1];
    [outData appendBytes:&length length:4];
    [outData appendBytes:&messageType length:2];
    [outData appendData:pbData];

    return outData;
}


CFSwapInt16HostToBig() CFSwapInt32HostToBig() 等等 拿走不谢

【热门文章】
【热门文章】