Goal C JAVA endian

I am using a 64bit Mac and I am sure that Java (1.6 in my case) uses big-endians.

I am trying to connect to my java server from my iPhone in Objective C. Is the iPhone (target C) small or large endian?

If it uses a little endian, how can I convert the size of NSData * to bigEndian so that Java can read it correctly?

int s = [protoToSend serializedSize]; NSData *size = [NSData dataWithBytes:&s length:1]; 

Thank you in advance

+4
source share
1 answer

You can use CoreFoundation byte swapping routines to convert endianess primitive types. If you have an int , you can use CFSwapInt32HostToBig() to replace a 32-bit integer with a byte order of bytes before sending to your Java server.

Wouldn't it be better to ultimately use some standard format (such as JSON, XML, etc.) over the pipe, allowing serialization and deserialization libraries to handle the final problems rather than reinventing the wheel?

+4
source

All Articles