From 8ce5039c5d7a854f2c0bd3a848d566e2c5aa864c Mon Sep 17 00:00:00 2001 From: Kevin Herron Date: Sun, 26 Jan 2025 14:43:46 -0800 Subject: [PATCH] ~ dynamic OptionSet cleanup --- .../sdk/core/types/DynamicOptionSetType.java | 57 +++++++++++++------ .../types/codec/DynamicOptionSetCodec.java | 6 +- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicOptionSetType.java b/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicOptionSetType.java index 906d877c3..b49959de7 100644 --- a/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicOptionSetType.java +++ b/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/DynamicOptionSetType.java @@ -15,7 +15,6 @@ import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.StringJoiner; @@ -32,16 +31,16 @@ public final class DynamicOptionSetType extends DynamicType implements UaStructu private final Lazy> lazyFieldMap = new Lazy<>(); - private final DataType dataType; - private final LinkedHashMap members; + private volatile ByteString value; + private volatile ByteString validBits; - public DynamicOptionSetType(DataType dataType) { - this(dataType, new LinkedHashMap<>()); - } + private final DataType dataType; - public DynamicOptionSetType(DataType dataType, LinkedHashMap members) { + public DynamicOptionSetType(DataType dataType, ByteString value, ByteString validBits) { this.dataType = dataType; - this.members = members; + + this.value = value; + this.validBits = validBits; } @Override @@ -59,24 +58,50 @@ public EnumDefinition getDataTypeDefinition() { return (EnumDefinition) requireNonNull(dataType.getDataTypeDefinition()); } - public LinkedHashMap getMembers() { - return members; - } - + /** + * Get the value of the option set. + * + *

The value is an array of bytes representing the bits in the option set. The length depends + * on the number of bits, and the number of bytes may be larger than needed for the valid bits. + * + * @return the value of the option set. + */ public ByteString getValue() { - return (ByteString) getMembers().get("Value"); + return value; } + /** + * Get the valid bits of the option set. + * + *

The value is an array of bytes the same length as the value, where each bit represents + * whether the corresponding bit in the value is valid. + * + * @return the valid bits of the option set. + */ public ByteString getValidBits() { - return (ByteString) getMembers().get("ValidBits"); + return validBits; } + /** + * Set the value of the option set. + * + * @param value the value of the option set. + */ public void setValue(ByteString value) { - getMembers().put("Value", value); + requireNonNull(value); + + this.value = value; } + /** + * Set the valid bits of the option set. + * + * @param validBits the valid bits of the option set. + */ public void setValidBits(ByteString validBits) { - getMembers().put("ValidBits", validBits); + requireNonNull(validBits); + + this.validBits = validBits; } /** diff --git a/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/codec/DynamicOptionSetCodec.java b/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/codec/DynamicOptionSetCodec.java index 828ba8f2a..edc7949cf 100644 --- a/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/codec/DynamicOptionSetCodec.java +++ b/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/types/codec/DynamicOptionSetCodec.java @@ -38,11 +38,7 @@ public DynamicOptionSetType decodeType(EncodingContext context, UaDecoder decode ByteString value = decoder.decodeByteString("Value"); ByteString validBits = decoder.decodeByteString("ValidBits"); - var optionSet = new DynamicOptionSetType(dataType); - optionSet.setValue(value); - optionSet.setValidBits(validBits); - - return optionSet; + return new DynamicOptionSetType(dataType, value, validBits); } @Override