Data Types

This page summarizes the Lua representations used by the OPC UA stack. Values are ordinary Lua values unless a table structure is shown.

Built-in Types

OPC UA type

Lua representation

Notes

SByte

number

Signed 8-bit integer.

Byte

number

Unsigned 8-bit integer.

Int16

number

Signed 16-bit integer.

UInt16

number

Unsigned 16-bit integer.

Int32

number

Signed 32-bit integer.

UInt32

number

Unsigned 32-bit integer.

Int64

number

Signed 64-bit integer.

UInt64

number

Unsigned 64-bit integer.

Float

number

32-bit floating-point value.

Double

number

64-bit floating-point value.

DateTime

number

Unix timestamp in seconds, usually from compat.gettime() or os.time(). Encoders convert this to the OPC UA wire format.

String

string

UTF-8 string.

ByteString

string

Binary byte sequence stored in a Lua string.

Guid

string

GUID string, for example 12345678-1234-1234-1234-123456789012.

StatusCode

number

OPC UA status code, for example ua.StatusCode.Good.

LocalizedText

Localized text is represented as a table.

Field

Type

Description

Locale

string, optional

Locale name such as "en-US". If omitted, the default locale is used.

Text

string

Localized text content.

local text = {Locale = "en-US", Text = "This is localized text"}
local textDefaultLocale = {Text = "This is localized text"}

QualifiedName

A QualifiedName is the service identifier of a node. It combines a namespace index with a name.

Field

Type

Description

ns

number

Namespace index.

Name

string

Name within the namespace.

local qualifiedName = {ns = 1, Name = "Node Name"}

NodeId

A NodeId is encoded as a string:

[ns=<namespace_index>;]<type>=<value>

Part

Value

Description

namespace_index

unsigned 16-bit integer

Optional. Omit when the namespace index is 0.

type

i, s, g, or b

Identifier type: integer, string, GUID, or opaque byte string.

value

type-specific string

Decimal integer, UTF-8 string, lowercase GUID, or base64 byte string.

Type code

Identifier type

Example

i

Integer

i=85 or ns=2;i=1001

s

String

ns=2;s=Temperature

g

GUID

ns=2;g=12345678-1234-1234-1234-123456789012

b

Opaque byte string

ns=2;b=AQIDBA==

Additional examples are available in node_id.lua. The official syntax is described in the OPC Foundation NodeId reference.

NodeId helpers

Function

Parameters

Return value

toString(id, ns)

id is a number, string, GUID, byte array, or bytes. ns is a namespace index or nil.

Encoded NodeId string.

toString({id = value, ns = number})

Table form of the same parameters.

Encoded NodeId string.

fromString(string)

Encoded NodeId string.

Table with ns and id fields.

Variant

A Variant wraps a value with an OPC UA type. It can represent a scalar or an array.

Field

Type

Description

Type

ua.VariantType

Type of the stored value.

Value

any supported Lua value

Value to encode.

IsArray

boolean, optional

Set to true when Value is an array.

ArrayDimensions

number array, optional

Dimensions for array values.

local uint32 = {Type = ua.VariantType.UInt32, Value = 0}
local uint32Array = {
  Type = ua.VariantType.UInt32,
  Value = {1, 2, 3, 4},
  IsArray = true,
  ArrayDimensions = {4}
}

VariantType constants

Name

Value

Name

Value

Null

0

Boolean

1

SByte

2

Byte

3

Int16

4

UInt16

5

Int32

6

UInt32

7

Int64

8

UInt64

9

Float

10

Double

11

String

12

DateTime

13

Guid

14

ByteString

15

XmlElement

16

NodeId

17

ExpandedNodeId

18

StatusCode

19

QualifiedName

20

LocalizedText

21

ExtensionObject

22

DataValue

23

Variant

24

DiagnosticInfo

25

DataValue

A DataValue is a Variant value plus optional status and timestamp fields.

Field

Type

Description

Type

ua.VariantType

Type of Value.

Value

any supported Lua value

Value to encode.

StatusCode

status code, optional

Value status, for example ua.StatusCode.Good.

SourceTimestamp

DateTime, optional

Source timestamp.

ServerTimestamp

DateTime, optional

Server timestamp.

SourcePicoseconds

UInt16, optional

Fractional source timestamp precision.

ServerPicoseconds

UInt16, optional

Fractional server timestamp precision.

local dataValue = {
  Type = ua.VariantType.UInt32,
  Value = 100,
  StatusCode = ua.StatusCode.Good,
  SourceTimestamp = os.time()
}

ExtensionObject

An ExtensionObject represents a structured value. It is also used when a field can contain one of several structure types, such as node attributes for AddNodes.

Field

Type

Description

TypeId

NodeId

NodeId of the structure type. This is the decoded structure NodeId, not the binary, XML, or JSON encoding NodeId.

Body

table, ByteString, XML string, or JSON string

Decoded body table when the structure is known. Otherwise, the body is left opaque and must be decoded by application code.

local extensionObject = {
  TypeId = "i=338", -- BuildInfo
  Body = {
    ProductUri = ua.Version.ProductUri,
    ManufacturerName = ua.Version.ManufacturerName,
    ProductName = ua.Version.ProductName,
    SoftwareVersion = ua.Version.Version,
    BuildNumber = ua.Version.BuildNumber,
    BuildDate = compat.gettime()
  }
}

Service Structures

ActivateSessionResponse

Field

Type

Description

ServerNonce

ByteString

Random value that should not be reused.

Results

StatusCode array

User identity token validation results.

AddNodesResponse

Field

Type

Description

Results[]

array

One result per requested node.

Results[].StatusCode

StatusCode

Status of the add operation.

Results[].AddedNodeId

NodeId

Server-assigned NodeId, or nil if the operation failed.

BrowseParameters

Field

Type

Description

RequestedMaxReferencesPerNode

UInt32

Maximum number of references to return. 0 means unlimited.

NodesToBrowse[]

array

Nodes to browse.

NodesToBrowse[].NodeId

NodeId

Node to browse.

NodesToBrowse[].ReferenceTypeId

NodeId

Reference type to follow.

NodesToBrowse[].BrowseDirection

ua.BrowseDirection

Browse direction.

NodesToBrowse[].NodeClassMask

ua.NodeClass

Node classes to include.

NodesToBrowse[].ResultMask

ua.BrowseResultMask

Fields to include in the response.

NodesToBrowse[].IncludeSubtypes

boolean

Include subtypes of ReferenceTypeId.

BrowseResult

Field

Type

Description

Results[]

array

One result per requested node.

Results[].StatusCode

StatusCode

Browse status for the requested node.

Results[].References[]

array

References returned by the browse operation.

References[].NodeId

NodeId

Target node identifier.

References[].ReferenceTypeId

NodeId

Reference type identifier.

References[].IsForward

boolean

Reference direction.

References[].BrowseName

QualifiedName

Service name of the node.

References[].DisplayName

LocalizedText

User-facing node label.

References[].NodeClass

Int32

Node class.

References[].TypeDefinition

NodeId

Node type definition.

CloseSecureChannelResponse

Empty table.

CloseSessionResponse

Empty table.

CreateSessionResponse

Field

Type

Description

ResponseHeader

table

Standard OPC UA response header.

SessionId

NodeId

Unique NodeId assigned by the server to the session.

AuthenticationToken

NodeId

Unique token assigned by the server to the session.

RevisedSessionTimeout

Double

Actual maximum session idle time in milliseconds.

ServerNonce

ByteString

Random value that should not be reused in another request.

ServerCertificate

ByteString

Server application instance certificate.

ServerEndpoints

array

Endpoint descriptions supported by the server.

ServerSignature

table

Signature generated with the server certificate private key.

MaxRequestMessageSize

UInt32

Maximum request body size in bytes.

FindServersResponse

Field

Type

Description

Servers[]

array

Servers that match the request criteria.

ApplicationUri

string

Application URI.

ProductUri

string

Product URI.

ApplicationName

LocalizedText

Human-readable application name.

ApplicationType

number

OPC UA application type.

GatewayServerUri

string

Gateway server URI, if used.

DiscoveryProfileUri

string

Discovery profile URI, if used.

DiscoveryUrls

string array

Discovery endpoint URLs.

GetEndpointsResponse

Field

Type

Description

Endpoints[]

array

Endpoint descriptions.

EndpointUrl

string

Endpoint URL.

Server

table

Server application description.

ServerCertificate

ByteString

Server certificate.

SecurityMode

number

Message security mode.

SecurityPolicyUri

string

Security policy URI.

UserIdentityTokens

array

Supported user identity token policies.

TransportProfileUri

string

Transport profile URI.

SecurityLevel

Byte

Relative endpoint security level.

OpenSecureChannelResponse

Field

Type

Description

ResponseHeader

table

Standard OPC UA response header.

SecurityToken

table

Secure channel token.

SecurityToken.ChannelId

UInt32

Unique SecureChannel identifier.

SecurityToken.TokenId

UInt32

Unique token identifier within the channel.

SecurityToken.CreatedAt

DateTime

Token creation time.

SecurityToken.RevisedLifetime

UInt32

Token lifetime in milliseconds.

ReadResponse

Field

Type

Description

Results[]

DataValue array

Attribute values returned by the server.

WriteResponse

Field

Type

Description

Results[]

StatusCode array

Results for the nodes written by the request.