Skip to content

datatype

Canonical path: o6.datatype

datatype

datatype(
    *,
    ns=None,
    nodeId=None,
    browseName=None,
    displayName=None,
    description=None,
    writeMask=None,
    userWriteMask=None,
    rolePermissions=None,
    accessRestrictions=0,
    isAbstract=False,
    defaultEncodingId=None,
    parent=None
)

Declare an OPC UA structure DataType from an annotated Python class.

The decorated class is a wire layout: every annotated attribute becomes a field of the type's StructureDefinition, and the layout is registered with open62541, so values encode and decode as a real structure instead of an opaque ExtensionObject. Python builtins map to their OPC UA counterparts, the sized o6 aliases pin an exact width, list[T] becomes a 1-D array of T, and another declared DataType nests as that type.

Python inheritance is the HasSubtype chain, so a subtype inherits its parent's fields. Deriving from ns0.datatypes.Union makes the StructureType a Union, in which assigning one field clears the previously selected one. As soon as one field is optional, the StructureType becomes StructureWithOptionalFields and unset optional fields read back as None. Per-field metadata that the annotation cannot express is attached with o6.field.

A user-supplied __init__, __repr__, and other methods are preserved; when they are absent, the native initializer and a field-listing repr are used.

Parameters:

Name Type Description Default
ns Optional[str]

Shortname of the declaring namespace. Inferred from nodeId when that carries a namespace, otherwise required.

None
nodeId Optional[str]

NodeId of the DataType node. Allocated in the declaring namespace when omitted.

None
browseName Optional[str]

BrowseName of the node. Defaults to the class name.

None
displayName Optional[str]

DisplayName of the node. Defaults to the BrowseName.

None
description Optional[str]

Description attribute. Defaults to the class docstring.

None
writeMask Optional[int]

WriteMask attribute of the node.

None
userWriteMask Optional[int]

UserWriteMask attribute of the node.

None
rolePermissions Optional[Mapping[Any, int]]

RolePermissions, as a mapping of role to o6.Permission mask.

None
accessRestrictions int

AccessRestrictions attribute of the node.

0
isAbstract bool

Declare the structure abstract. It keeps a complete DataTypeDefinition for browsing clients but cannot be instantiated, and a field annotated with it is encoded as an ExtensionObject so it can carry any concrete subtype.

False
defaultEncodingId Optional[str]

NodeId of the Default Binary encoding node. Allocated alongside the DataType when omitted.

None
parent Optional[Any]

Node or declaration that owns the DataType node. Defaults to the HasSubtype parent implied by the Python base class.

None

Raises:

Type Description
TypeError

The decorated object is not a class, the class has no annotated fields, or a field's rank cannot be represented as a structure member.

See @o6.datatype — structures.