My latest app communicates, via TCP, with an embedded device.
The embedded device is programmed in C and sends my Swift app data encapsulated in "messages" which are actually structures defined like this:
In my Swit app they arrive via NWConnection, and are sent to my controller delegate as Data (That's the swift type called Data, not just the general term 'data')
So me question for you harties is this:
How can I unpack this 'Data' into something resembling my C struct - and acess it's members by name.
In Pseudo code I'd like to do something like:
So is this possible? Is it the wrong approach? Is there a better approach?
The embedded device is programmed in C and sends my Swift app data encapsulated in "messages" which are actually structures defined like this:
Code Block typedef struct _MSG_TYPE { uint16_t sig; uint16_t len; // Total length of message, include header and playload; uint16_t type; uint32_t data; // 32 Bits of data. } MSG_t;
In my Swit app they arrive via NWConnection, and are sent to my controller delegate as Data (That's the swift type called Data, not just the general term 'data')
So me question for you harties is this:
How can I unpack this 'Data' into something resembling my C struct - and acess it's members by name.
In Pseudo code I'd like to do something like:
Code Block if let myData = data { myStruct = <cast myData.bytes onto a struct > if myStruct.sig == CORRECT_MSG_SIG { // do soemthig with the message... } }
So is this possible? Is it the wrong approach? Is there a better approach?