Suppose we want to extract fields from an input stream composed of variable-length fields. All we know is maximum width of every field and that each field ends with a byte with a value of 1
. We want to extract the packed fields into a fixed format where each field has its maximum width (zero padded if the input field was less than the maximum).
Minimum width of each field is one byte.
For example, we are expecting to receive values for two fields. The maximum width of the first one is 3 bytes, maximum width of the second one is 2 bytes.
Suppose we've got an input vector {X, 1, 1} so we know the value of the first field is {X, 1} and value of the second field is {1}. So in this case the resulting vector should be equal to {0, X, 1, 0, 1}.
Or, we we've got an input vector {1, 1}, so the resulting vector should be equal to {0, 0, 1, 0, 1}.
I think I know a way of doing this with a lookup table. The problem is that we will end up with too big lookup table in case we decide to process more than 64 bits at once.