Skip to content

Commit

Permalink
~ dynamic OptionSet cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Jan 26, 2025
1 parent 17cf876 commit 8ce5039
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,16 +31,16 @@ public final class DynamicOptionSetType extends DynamicType implements UaStructu

private final Lazy<Map<Integer, EnumField>> lazyFieldMap = new Lazy<>();

private final DataType dataType;
private final LinkedHashMap<String, Object> 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<String, Object> members) {
public DynamicOptionSetType(DataType dataType, ByteString value, ByteString validBits) {
this.dataType = dataType;
this.members = members;

this.value = value;
this.validBits = validBits;
}

@Override
Expand All @@ -59,24 +58,50 @@ public EnumDefinition getDataTypeDefinition() {
return (EnumDefinition) requireNonNull(dataType.getDataTypeDefinition());
}

public LinkedHashMap<String, Object> getMembers() {
return members;
}

/**
* Get the value of the option set.
*
* <p>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.
*
* <p>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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ce5039

Please sign in to comment.