Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] Decoding ArrayDimensions

Kevin,

Ok! I think I now have some understanding of the flattening!

So from part 6 of the Spec where the Variant type is explained, there is this field called ArrayDimensionsLength which is of type Int32. So this value will be 3 for a 3-d array and 2 for a 2-d array and so on. Is that correct? And the next element which is the actual ArrayDimensions and my understanding is that it represents the size of elements in each dimension. So in example.,

If ArrayDimensionsLength is 3 - Means it is a 3-d array
then the ArrayDimensions would be for example., 2 3 2 - means that the first dimension has 2 elements, the second dimension has 3 elements and the 3rd dimension has 2 elements. Is this correct?

On Thu, Aug 15, 2019 at 6:48 PM Joe San <codeintheopen@xxxxxxxxx> wrote:
Ok! Just saw that there is a ArrayUtil test. I will look into it to understand!

On Thu, Aug 15, 2019 at 6:24 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
There's not enough elements to unflatten that into a 3-dimension array. You'd need 8 elements. You can run the code or unit tests to see the output yourself.

On Thu, Aug 15, 2019 at 9:18 AM Joe San <codeintheopen@xxxxxxxxx> wrote:
Ok so that means if I have a flat array like this:

flatArr = (1,2,3)
arrDimensions = [2,2,2]

So how does this gets unflattened? Can you please illustrate? If not, can you let me know where in the Spec is an example given to understand arraydimensions?

On Thu, Aug 15, 2019 at 6:09 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
Joe,

`unflatten` is the dual to `flatten` from the same ArrayUtil. It's just unflattening a previously-flattened array.

Multi-dimensional arrays inside Variants are always flattened to a single dimension before being serialized. OPC UA Part 6 discusses this.


On Thu, Aug 15, 2019 at 8:58 AM Joe San <codeintheopen@xxxxxxxxx> wrote:
I was trying to understand the idea behind the unflatten method for the ArrayDimensions that is implemented in milo! Can you give me a small example for what the recursive method is doing in the ArrayUtil.java class?

It is these two methods what I'm trying to understand!

public static Object unflatten(Object array, int[] dimensions) {
Class<?> type = getType(array);

return unflatten(type, array, dimensions, 0);
}

private static Object unflatten(Class<?> type, Object array, int[] dimensions, int offset) {
if (dimensions.length == 1) {
Object a = Array.newInstance(type, dimensions[0]);

for (int i = 0; i < dimensions[0]; i++) {
Array.set(a, i, Array.get(array, offset + i));
}

return a;
} else {
Object a = Array.newInstance(type, dimensions);

int[] tail = Arrays.copyOfRange(dimensions, 1, dimensions.length);

for (int i = 0; i < dimensions[0]; i++) {
Object element = unflatten(type, array, tail, offset + i * length(tail));
Array.set(a, i, element);
}

return a;
}
}
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev

Back to the top