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
How to determine if a data type is an array
June 20, 2022
18:05, EEST
Avatar
rocket science
Member
Members
Forum Posts: 88
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Hi,

I wonder how to determine exactly that a data type is an array.

According to the reference (https://reference.opcfoundation.org/v104/Core/docs/Part3/5.6.2/) the value rank can be used to determine if the data type is an array or a scalar type.

For valueRank == -1 it is a scalar data type, for valueRank == 1 it is a one dimensional array and for valueRank > 1 it is an array with the specified number of dimensions-

But for others like 0, -2, -3 the reference points out that it can be scalar, one dimensional or any number of dimensions.

So if I have a node on the server, where the DataType is String and the ValueRank is -2, how can I find out if it will be a scalar data type or an array with how many dimensions?

Thanks!

June 21, 2022
10:39, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

We have some helpers in the Variant class:

Variant.getDimension() (delegates to MultiDimensionArrayUtils.getDimension(class), returns 0 if scalar)
Variant.getArrayDimensions() (delegates to MultiDimensionArrayUtils.getArrayLengths(value), return dimensions in array with length of dimensions or 0 if scalar)

It should be noted that apparently these wont work for null value (results NPE; could probably be improved in a future version), thus please check that first.

This is to say, you only know after you have Read it. As for Writing, it shouldn’t need to be the same dimension, if ValueRank allows (what will actually happen would be server-specific though, but spec-wise any of them should like work).

P.S.
Also I would guess most of the time it will be a scalar, since -2 is the default (it has to be) in the basic VariableTypes, thus an instantiation of those would result in -2 unless changed after that.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
41 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