Please consider registering

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
rocket science
Forum Posts: 65
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline


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?


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


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).

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: 267

Currently Online: jl75, Larryorarm
8 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 120

pramanj: 86

ibrahim: 74

rocket science: 65

kapsl: 57

gjevremovic: 49

Xavier: 42

fred: 41

TimK: 41

Fransua33: 39

Member Stats:

Guest Posters: 0

Members: 2891

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1261

Posts: 5369

Newest Members:

allisontz18, Elmer1493vok, AspectMontageAtrox, miloparris0, josettegrenier, berniceiy1, Sylviaser, gilbertstonge93, waldomarriott43, madgeroque72

Moderators: Jouni Aro: 930, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 775, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 39, Niklas Nurminen: 0, Matti Siponen: 207, Lusetti: 0

Administrators: admin: 1