You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2022/11/23 17:06:56 UTC

[plc4x] branch develop updated: fix(plc4j/opcua): not to get String.length but to calculate length in UTF-8 for Pascal string length (support node id contains unicode characters) (#668)

This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0bc5655226 fix(plc4j/opcua): not to get String.length but to calculate length in UTF-8 for Pascal string length (support node id contains unicode characters) (#668)
0bc5655226 is described below

commit 0bc5655226a8d36ba4acb212aef6fc21e82e2899
Author: modraedlau <mo...@aliyun.com>
AuthorDate: Thu Nov 24 01:06:50 2022 +0800

    fix(plc4j/opcua): not to get String.length but to calculate length in UTF-8 for Pascal string length (support node id contains unicode characters) (#668)
    
    Co-authored-by: liumin_it <li...@noblelift.cn>
    
    Thanks modraedlau and liumin_it
---
 .../java/opcua/readwrite/utils/StaticHelper.java   | 29 ++++++++++++++++++++++
 protocols/opcua/src/main/xslt/opc-manual.xsl       |  4 +--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java
new file mode 100644
index 0000000000..e31cb71331
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/readwrite/utils/StaticHelper.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, (byte) Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, (byte) WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, (byte) either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.opcua.readwrite.utils;
+
+import java.nio.charset.StandardCharsets;
+
+public class StaticHelper {
+
+    // Calculating length in UTF-8
+    public static int utf8Length(String stringValue) {
+        return stringValue == null ? -1 : stringValue.getBytes(StandardCharsets.UTF_8).length;
+    }
+}
diff --git a/protocols/opcua/src/main/xslt/opc-manual.xsl b/protocols/opcua/src/main/xslt/opc-manual.xsl
index f4f930deb9..4df879dcb9 100644
--- a/protocols/opcua/src/main/xslt/opc-manual.xsl
+++ b/protocols/opcua/src/main/xslt/opc-manual.xsl
@@ -381,9 +381,9 @@
 ]
 
 [type PascalString
-    [implicit int 32 sLength          'stringValue.length == 0 ? -1 : stringValue.length']
+    [implicit int 32 sLength          'STATIC_CALL("utf8Length", stringValue) == 0 ? -1 : STATIC_CALL("utf8Length", stringValue)']
     [simple vstring 'sLength == -1 ? 0 : sLength * 8' stringValue]
-    [virtual  int 32 stringLength     'stringValue.length == -1 ? 0 : stringValue.length']
+    [virtual  int 32 stringLength     'STATIC_CALL("utf8Length", stringValue) == -1 ? 0 : STATIC_CALL("utf8Length", stringValue)']
 ]
 
 [type PascalByteString