03-31-2020 07:49 AM - edited 03-31-2020 07:52 AM
I'm looking to turn a long array of u8 received from a 3rd party application into a cluster of status elements (cluster of clusters)
I don't like how I'm repeating the split 1d array and array to cluster conversion. Although this works for 3 elements, I wouldn't want to do it for 20. Can I set up the conversion in a more extensible way?
Solved! Go to Solution.
03-31-2020 08:08 AM - edited 03-31-2020 08:08 AM
Hi JScherer,
the conversion can be made much simpler:
When you want to repeat a process step you should use a loop!
So place the conversion into a (while) loop and repeat until the remaining array is empty (or smaller then needs to be). You can also use a FOR loop when you calculate the number of conversions from array size…
03-31-2020 10:20 AM
Well, the problem is that you can't really use a loop efficiently, because clusters are fixed in size and you cannot e.g. have an array where each element is a cluster with a different number of elements.
Maybe you want to re-think your data structures. For example you could have an output array where each element is a cluster of an array. Now each element can be of different size.
03-31-2020 12:19 PM - edited 03-31-2020 12:19 PM
To steal from altenbach, you can do this with post-card sized code. You just need the Byte Array To String followed by the Unflatten From String.
03-31-2020 12:27 PM - edited 03-31-2020 12:36 PM
@crossrulz wrote:
To steal from altenbach, you can do this with post-card sized code.
Gerd already mentioned something very similar, but it was hard to notice because he also left the original code next to it. 😉
And, no you were not stealing anything because my solution would have looked as follows:
03-31-2020 01:54 PM
Hi,
@altenbach wrote:
@crossrulz wrote:
To steal from altenbach, you can do this with post-card sized code.
Gerd already mentioned something very similar, but it was hard to notice because he also left the original code next to it. 😉
Yes, by decision to allow comparison of original convoluted approach with that simple TypeCast replacement…
03-31-2020 02:40 PM
@GerdW wrote:
Yes, by decision to allow comparison of original convoluted approach with that simple TypeCast replacement…
I am just not a fan of the Type Cast function. I have been burned too many times by Little Endian formats. So I always go for the Unflatten From String to guard against that (simply add a constant to state the Endianness instead of adding who knows how much code to swap bytes and words, etc).
03-31-2020 02:44 PM
Yes, I would probably wire the size input to a case structure and only cast if the size=9. 😄
(Also note that unflatten also has an output for the remaining string that could be checked for length.)
04-01-2020 05:54 AM
@altenbach wrote:
(Also note that unflatten also has an output for the remaining string that could be checked for length.)
I have also used it to "chain" conversions.