Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
DataTypeConverter parseVariant is unable to convert a String to a Variant/ByteString
August 29, 2024
11:06, EEST
Avatar
rocket science
Member
Members
Forum Posts: 88
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Hi,

is there a reason why DataTypeConverter parseVariant connot convert to a ByteString?

Argument[] inputArguments = uaMethod.getInputArguments();
UaDataType dataType = (UaDataType) client.getAddressSpace().getType(inputArguments[0].getDataType());
// dataType.getJavaClass() –> ByteString

Variant var = client.getAddressSpace().getDataTypeConverter().parseVariant(“someString”, dataType); // -> throws an Exception (with SDK 4-10-2)

August 29, 2024
12:19, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

It doesn’t exist originally because in short the Table 125 “Conversion rules” in https://reference.opcfoundation.org/Core/Part4/v105/docs/7.7.3 for the FilterOperator ‘Cast’ doesn’t have any defined conversion for String->ByteString. That was the original purpose of the DataTypeConverter. (Though seems the spec would allow server-specific ones for that). SDK does repurpose the DataTypeConverter for other uses, but that is the history, but regardless it is a best-effort helper, it cannot handle all types, but may serve as a starting point e.g. for UI that for e.g. a “Write component” just has a textbox.

In theory one such conversion could maybe be added. However, it is ambiguous what it should do. One could e.g. transform the String to it’s UTF-8 Bytes (or any other possible encoding). One could assume it being in Hex. One could assume it to be Base64. As far as I know, it is not even possible to 100% correct-guess between Hex and Base64 (since 0x…. would also be possibly a valid Base64-string). And since it would be actually used somewhere, that other end most likely has clearly defined requirements about the ByteStrings content, but the SDK cannot know that. Thus, personally at least currently I think it may be better that the conversion just throws instead of potentially doing the wrong thing.

Also I’ll note that version of the SDK is a bit old, though it wont change the above. But e.g. assuming recent enough version there are:
com.prosysopc.ua.stack.builtintypes.ByteString.fromHex(String)
com.prosysopc.ua.stack.utils.CryptoUtil.base64Decode(String) (or the one in core Java) -> com.prosysopc.ua.stack.builtintypes.ByteString.valueOf(byte…)
that you can use since the application (or it’s user) would know more. If you are building an UI, you could even have options that allow entering all different ways (treat as UTF-8 bytes, Hex, Base64 and possibly more).

September 12, 2024
19:13, EEST
Avatar
rocket science
Member
Members
Forum Posts: 88
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Thank you for the explanation.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
44 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 726

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_gallery

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1