Skip to main content

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

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

Back to the top