We need to implement a binary protocol using the Swift programming language for Apple apps. We need to pack bytes, shorts, long and doubles into a binary string but it doesn't seem like the Swift language is capable of doing this. So I would just like to confirm if this is the case?
Basically we want to convert the following Java code to Swift code:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(123);
dos.writeByte(123);
dos.writeShort(123);
dos.writeDouble(1.23);
dos.writeFloat(1.23f);
dos.flush();
byte[] binaryData = baos.toByteArray();
// Send the binaryData somewhere! ->>>
It doesn't seem like this is possible using Swift. If so what are the alternatives to work around this issue?