Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] Decoding ArrayDimensions
  • From: Tony Wei A <tony.a.wei@xxxxxxxxxxxx>
  • Date: Mon, 19 Aug 2019 05:20:51 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ericsson.com; dmarc=pass action=none header.from=ericsson.com; dkim=pass header.d=ericsson.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kbUz9aKAYMJ5nG5ZagSLrTImw0p6UdeEACVKrmY1rwE=; b=Kg0s7DYKp7DZ/7WuZTFcxo149nBhI2JPiZyAxicjxICAuGMEptd2GM34sAUi0HBLgc0g0Mm/ti3MV7RH/irtgJRnEnDo0oc4F4ioSk8qqMzxjiV0R3xmFIlPPQeU3lcbWlpb92TeWPLh9/Ku1EfesAXZNildG+5LGaUJYVb9Gd/GkSOw5wCna2aWGR56/srJ/14ZEw/JDQv9l08i9B0JdkIyHhjvRt7RtmcWGBZEZhi3nnxE4VxYTrhw+ML6acFjk3om2efwpnTxm3luhikX9B5WKPP94PKeFOBcskrxAkO/v6keRaAoCy+VzosXmPThhEYlGmJEUI1I7MKHcH6NAg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Knq67skywYXr+yUyOWwLKLQfGbY7aixGsdF9JR51gcBTkllOrnwwuUIjhiZlhura4gndQ8e5GJ57k3bM3JBYJ3TiNOXQ7mJJ/D0Xd0FXhGG9gJsU3SXwlBK5ud3gLWovd01x2bxBncA8upCrk7Ok8b3KnjeLZ1fXg08bkfwuUSBRYWdIJXmdSKvHfiKoXHoL/LGgMAbIUdZ19DvxEGwAuN58am7YDtIZRlB9wlcsSjqj7BoaAZOV/1wxZTVu8xMH4x1O39JpKbvL8eCUtkzy2AZL6pK6xlkVpLeT8G6MPnk8QHZsp6lfIZSj7v4N1xi4KX/HIP6JXFCGP5jgE98kZg==
  • Delivered-to: milo-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/milo-dev>
  • List-help: <mailto:milo-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/milo-dev>, <mailto:milo-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/milo-dev>, <mailto:milo-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHVU4I9hLHBuP3ES0Cb6tYcnjnc/Kb8YJGAgAACjYCAAAF5gIAABt4AgAAZgoCAAAJcAIAA54OAgAAy1ACABFEhMA==
  • Thread-topic: [milo-dev] Decoding ArrayDimensions

Hi,

 

I use milo client to develop the OPCUA client, when I use method client.browse to find node and recursively browse to children nodes. But it is inefficient and have a high consumption of CPU and memory.

If any other method for this, for example, if I can get all the nodes tree at one time. Thanks!

My code for recursively browsing nodes is as follows:

  private void scanForDevices(OpcUaNode node) {

        log.trace("Scanning node: {}", node);

        List<DeviceMapping> matchedMappings = mappings.entrySet().stream()

                .filter(mappingEntry -> mappingEntry.getKey().matcher(node.getNodeId().getIdentifier().toString()).matches())

                .map(m -> m.getValue()).collect(Collectors.toList());

 

        matchedMappings.forEach(m -> {

            try {

                scanDevice(node, m);

            } catch (Exception e) {

                log.error("Failed to scan device: {}", node.getName(), e);

            }

        });

 

        try {

            BrowseResult browseResult = client.browse(OpcUaUtils.getBrowseDescription(node.getNodeId())).get();

            List<ReferenceDescription> references = toList(browseResult.getReferences());

 

            for (ReferenceDescription rd : references) {

                NodeId nodeId;

                if (rd.getNodeId().isLocal()) {

                    nodeId = rd.getNodeId().local().get();

                } else {

                    log.trace("Ignoring remote node: {}", rd.getNodeId());

                    continue;

                }

                OpcUaNode childNode = new OpcUaNode(node, nodeId, rd.getBrowseName().getName());

 

                scanForDevices(childNode);

            }

        } catch (InterruptedException | ExecutionException e) {

            log.error("Browsing nodeId={} failed: {}", node, e.getMessage(), e);

        }

    }

 

From: milo-dev-bounces@xxxxxxxxxxx <milo-dev-bounces@xxxxxxxxxxx> On Behalf Of Kevin Herron
Sent: Friday, August 16, 2019 07:19 PM
To: milo developer discussions <milo-dev@xxxxxxxxxxx>
Subject: Re: [milo-dev] Decoding ArrayDimensions

 

Joe,

 

There should always be 8 elements in the flattened array for a 3d array with dimensions 2,2,2.

 

All of the elements need to be present in the unflattened array, else the Array Dimensions aren't really accurate are they? 

 

 

On Fri, Aug 16, 2019 at 1:17 AM Joe San <codeintheopen@xxxxxxxxx> wrote:

So for this input, I get ArrayIndexOutOfBounds error: So for cases where some elements in a 3d array max be missing, the implementation fails! Is this possible? Or is it safe to assume that the flat length of the array will always be equal to the dimensions size? For example if the flat length of the array is 8 and it is a 3d array with 2,2,2 as the dimensions, then it is safe to assume that 2x2x2 should be equal to the flat length of the array?

 

{new int[][][]{{{0, 1}, {2, 3},}, {{4, 5}, {6}}}},

 

On Thu, Aug 15, 2019 at 8:28 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:

Joe,

 

That sounds correct, and matches the logic in `OpcUaBinaryStreamDecoder#readVariant`.

 

On Thu, Aug 15, 2019 at 11:20 AM Joe San <codeintheopen@xxxxxxxxx> wrote:

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

_______________________________________________
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