EDIT: TL; DR . In C family languages, you can represent arbitrary data (ints, floats, doubles, structs) as byte streams by casting and pack them into streams or buffers. And you can do the opposite to return the data. And, of course, you can change the bytes for correct fidelity.
Is this possible in idiomatic fast?
Now the original question:
If I were writing in C / C ++ / ObjC, I could pass the struct to unsigned char * and write my bytes to FILE * or memcpy them to the buffer. The same goes for ints, double, etc. I know that there are problems with the content, but this is for the iOS application, and I do not expect the rule of law to change in the near future for the platform. A system like Swift is not like it would allow this behavior (by distinguishing arbitrary data with unsigned 8-bit ints and passing an address), but I don't know.
I am learning Swift and would like an idiomatic way to write my data. Please note that my numbers are high and will ultimately be sent by wire, so it should be compact, so there are no text formats like JSON.
I could use NSKeyedArchiver, but I want to find out here. Also, I don't want to decommission the Android client at some point in the future, so simple binary coding seems to be where it is.
Any suggestions?
source share