Structuresare encoded as a sequence of fields in the order that they appear in the definition. The encoding for each field is determined by the built-in type for the field.

All fields specified in the structure shall be encoded. If optional fields exist in the Structure, then see 5.2.7.

Structuresdo not have a null value. If an encoder is written in a programming language that allows structures to have null values, then the encoder shall create a new instance with DefaultValuesfor all fields and serialize that. Encoders shall not generate an encoding error in this situation.

The following is an example of a structure using C/C++ syntax:

struct Type2

{

Int32 A;

Int32 B;

};

struct Type1

{

Int32 X;

Byte NoOfY;

Type2* Y;

Int32 Z;

UInt16 W[10];

Byte M[2,3,4];

};

In the C/C++ example above, the Y field is a pointer to an array with a length stored in NoOfY. When encoding an array, the length is part of the array encoding so the NoOfY field is not encoded. That said, encoders and decoders use NoOfY during encoding. W is a fixed length array with an implicitly defined length of 10. This length is always encoded with the array. M is a fixed length multidimensional array. The length of each dimension is always encoded with the array.

An instance of Type1which contains an array of two Type2instances would be encoded as 28-byte sequence. If the instance of Type1was encoded in an ExtensionObjectit would have an additional prefix shown in Table 18which would make the total length 101 bytes The TypeId, Encoding and the Lengthare fields defined by the ExtensionObject. The encoding of the Type2instances do not include any type identifier because it is explicitly defined in Type1.

Table 18– Sample OPC UA Binary Encoded structure

Field

Bytes

Value

Type Id

4

The identifier for the ‘Type1’ Binary Encoding Node

Encoding

1

0x1 for ByteString

Length

4

28

X

4

The value of field ‘X’

Y.Length

4

2

Y.A

4

The value of field ‘Y[0].A’

Y.B

4

The value of field ‘Y[0].B’

Y.A

4

The value of field ‘Y[1].A’

Y.B

4

The value of field ‘Y[1].B’

Z

4

The value of field ‘Z’

W.Length

4

10

W

20

The value of field ‘W’.

M.Dimensions.Length

4

3

M.Dimensions

12

The sequence [2,3,4] encoded as a Int32.

M.Values

24

The values in ‘M’ encoded sequentially as described in 5.2.2.16.

The Valueof the DataTypeDefinition Attributefor a DataType Nodedescribing Type1 is shown in Table 19.

Table 19–DataTypeDefinition for “Type1” from Sample

Name

Type

Description

defaultEncodingId

NodeId

NodeId of the “Type1_Encoding_DefaultBinary” Node.

baseDataType

NodeId

“i=22” [Structure]

structureType

StructureType

Structure_0 [Structure without optional fields]

fields [0]

StructureField

name

String

“X”

description

LocalizedText

Description of X

dataType

NodeId

“i=6” [Int32]

valueRank

Int32

-1 (Scalar)

arrayDimensions

UInt32[]

null

maxStringLength

UInt32

0

isOptional

Boolean

false

fields [1]

StructureField

name

String

“Y“

description

LocalizedText

Description of Y-Array

dataType

NodeId

NodeId of the Type2 DataType Node (e.g. “ns=3; s=MyType2”)

valueRank

Int32

1 (OneDimension)

arrayDimensions

UInt32[]

{ 0 }

maxStringLength

UInt32

0

isOptional

Boolean

false

fields [2]

StructureField

name

String

“Z“

description

LocalizedText

Description of Z

dataType

NodeId

“i=6” [Int32]

valueRank

Int32

-1 (Scalar)

arrayDimensions

UInt32[]

null

maxStringLength

UInt32

0

isOptional

Boolean

false

fields [3]

StructureField

name

String

“W“

description

LocalizedText

Description of W

dataType

NodeId

“i=5” [UInt16]

valueRank

Int32

1 (OneDimension)

arrayDimensions

UInt32[]

{ 10 }

maxStringLength

UInt32

0

isOptional

Boolean

false

fields [4]

StructureField

name

String

“M“

description

LocalizedText

Description of M

dataType

NodeId

“i=3” [Byte]

valueRank

Int32

3

arrayDimensions

UInt32[]

{ 2, 3, 4 }

maxStringLength

UInt32

0

isOptional

Boolean

false

The Valueof the DataTypeDefinition Attributefor a DataType Nodedescribing Type2 is shown in Table 20.

Table 20–DataTypeDefinition for “Type2” from Sample

Name

Type

Description

defaultEncodingId

NodeId

NodeId of the “Type2_Encoding_DefaultBinary” Node.

baseDataType

NodeId

“i=22” [Structure]

structureType

StructureType

Structure_0 [Structure without optional fields]

fields [0]

StructureField

name

String

“A“

description

LocalizedText

Description of A

dataType

NodeId

“i=6” [Int32]

valueRank

Int32

-1 (Scalar)

arrayDimensions

UInt32[]

null

maxStringLength

UInt32

0

isOptional

Boolean

false

fields [1]

StructureField

name

String

“B“

description

LocalizedText

Description of B

dataType

NodeId

“i=6” [Int32]

valueRank

Int32

-1 (Scalar)

arrayDimensions

UInt32[]

null

maxStringLength

UInt32

0

isOptional

Boolean

false