Skip to content

Commit

Permalink
rafactor method
Browse files Browse the repository at this point in the history
  • Loading branch information
tbischoff2 committed Oct 30, 2024
1 parent 8a3bc08 commit 76340cb
Showing 1 changed file with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,12 @@ public TypedValue<?> convert(Variant value, Datatype targetType) throws ValueCon
});
register(Datatype.HEX_BINARY, Identifiers.ByteString, new OpcUaToAasValueConverter() {
public TypedValue<?> convert(Variant value, Datatype targetType) throws ValueConversionException {
if (Objects.isNull(value) || value.isNull()) {
return null;
}
try {
String txt;
if (value.getValue() instanceof ByteString bs) {
txt = ByteBufUtil.hexDump(bs.bytesOrEmpty());
}
else {
txt = value.getValue().toString();
}
return TypedValueFactory.create(targetType, txt);
}
catch (NumberFormatException | ValueFormatException e) {
throw new ValueConversionException(e);
}
return convertByteString(value, targetType);
}
});
register(Datatype.BASE64_BINARY, Identifiers.ByteString, new OpcUaToAasValueConverter() {
public TypedValue<?> convert(Variant value, Datatype targetType) throws ValueConversionException {
if (Objects.isNull(value) || value.isNull()) {
return null;
}
try {
String txt;
if (value.getValue() instanceof ByteString bs) {
txt = ByteBufUtil.hexDump(bs.bytesOrEmpty());
}
else {
txt = value.getValue().toString();
}
return TypedValueFactory.create(targetType, txt);
}
catch (NumberFormatException | ValueFormatException e) {
throw new ValueConversionException(e);
}
return convertByteString(value, targetType);
}
});
}
Expand Down Expand Up @@ -188,6 +158,26 @@ public TypedValue<?> convert(Variant value, Datatype targetType) throws ValueCon
return converter.convert(value, targetType);
}


private TypedValue<?> convertByteString(Variant value, Datatype targetType) throws ValueConversionException {
if (Objects.isNull(value) || value.isNull()) {
return null;
}
try {
String txt;
if (value.getValue() instanceof ByteString bs) {
txt = ByteBufUtil.hexDump(bs.bytesOrEmpty());
}
else {
txt = value.getValue().toString();
}
return TypedValueFactory.create(targetType, txt);
}
catch (NumberFormatException | ValueFormatException e) {
throw new ValueConversionException(e);
}
}

private static class DefaultConverter implements AasToOpcUaValueConverter, OpcUaToAasValueConverter {

@Override
Expand Down

0 comments on commit 76340cb

Please sign in to comment.