Skip to main content

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

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

Back to the top