I have some existing code that takes a stream of bytes from a TCP/IP connection and converts it into a cluster. It works fine but I think it’s going to become unmanageable as new fields are added to the network packet protocol
While looking around for a better solution I found this thread on NI’s forums that discusses different conversion methods. There are a number of options suggested here, including using Type Cast, Join Number or Unflatten From String
I’ve chosen to use Unflatten from String because it can convert the whole network packet in a single node, and also handles big or little endian conversion
New and Improved
This is the improved version, which replaces my custom “4 Little Endian Bytes To …” conversion VIs with Unflatten from String to convert the byte stream into a cluster. In this case the ‘data includes array or string size’ boolean is False, as the data doesn’t have a size header. This header would only exist if the byte string was generated by Flatten To String
I’ve added a new cluster typedef to define the format of the raw data coming in from the network, which is shown to the left
The packet format includes a number of reserved ‘Padding’ bytes which are currently unused, but still need to be parsed to get to the data further into the packet
I’ve set up the default value for each control as its offset in the packet. This lines up with the documentation for the network protocol, and will make this easier to understand next time I need to work on the cluster.