You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/09/02 14:51:27 UTC

[plc4x] 02/05: chore(plc4j/api): Added a map of "options" to the browse request item

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

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

commit ed44fde98540098e676423294fb34fd2f13e1ea3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Fri Sep 2 16:49:03 2022 +0200

    chore(plc4j/api): Added a map of "options" to the browse request item
---
 .../java/spi/messages/DefaultPlcBrowseItem.java    | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
index 457d8c2ee..233b48bc5 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
@@ -22,7 +22,6 @@ import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonTypeInfo;
 import org.apache.plc4x.java.api.messages.PlcBrowseItem;
-import org.apache.plc4x.java.api.messages.PlcDiscoveryItem;
 import org.apache.plc4x.java.api.types.PlcValueType;
 import org.apache.plc4x.java.api.value.PlcValue;
 import org.apache.plc4x.java.spi.generation.SerializationException;
@@ -48,6 +47,8 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
 
     private final List<PlcBrowseItem> children;
 
+    private final Map<String, PlcValue> options;
+
     @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
     public DefaultPlcBrowseItem(@JsonProperty("address") String address,
                                 @JsonProperty("name") String name,
@@ -55,7 +56,8 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
                                 @JsonProperty("readable") boolean readable,
                                 @JsonProperty("writable") boolean writable,
                                 @JsonProperty("subscribable") boolean subscribable,
-                                @JsonProperty("children") List<PlcBrowseItem> children) {
+                                @JsonProperty("children") List<PlcBrowseItem> children,
+                                @JsonProperty("options") Map<String, PlcValue> options) {
         this.address = address;
         this.name = name;
         this.dataType = dataType;
@@ -63,6 +65,7 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
         this.writable = writable;
         this.subscribable = subscribable;
         this.children = children;
+        this.options = options;
     }
 
     @Override
@@ -97,6 +100,11 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
         return children;
     }
 
+    @Override
+    public Map<String, PlcValue> getOptions() {
+        return options;
+    }
+
     @Override
     public void serialize(WriteBuffer writeBuffer) throws SerializationException {
         writeBuffer.pushContext(getClass().getSimpleName());
@@ -113,6 +121,18 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
             }
             writeBuffer.popContext("children");
         }
+        if(options != null && !options.isEmpty()) {
+            writeBuffer.pushContext("options");
+            for (Map.Entry<String, PlcValue> optionEntry : options.entrySet()) {
+                writeBuffer.pushContext("option");
+                writeBuffer.writeString("name", optionEntry.getKey().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getKey());
+                // TODO: Find out how to serialize a PlcValue
+                //writeBuffer.writeString("value", optionEntry.getValue().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getValue());
+                ((DefaultPlcBrowseItem) optionEntry).serialize(writeBuffer);
+                writeBuffer.popContext("option");
+            }
+            writeBuffer.popContext("options");
+        }
         writeBuffer.popContext(getClass().getSimpleName());
     }