MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / extensionobject_to_binary

Function extensionobject_to_binary

opcua/ua/ua_binary.py:445–466  ·  view source on GitHub ↗

Convert Python object to binary-coded ExtensionObject. If obj is None, convert to empty ExtensionObject (TypeId=0, no Body). Returns a binary string

(obj)

Source from the content-addressed store, hash-verified

443
444
445def extensionobject_to_binary(obj):
446 """
447 Convert Python object to binary-coded ExtensionObject.
448 If obj is None, convert to empty ExtensionObject (TypeId=0, no Body).
449 Returns a binary string
450 """
451 if isinstance(obj, ua.ExtensionObject):
452 return struct_to_binary(obj)
453 if obj is None:
454 TypeId = ua.NodeId()
455 Encoding = 0
456 Body = None
457 else:
458 TypeId = ua.extension_object_ids[obj.__class__.__name__]
459 Encoding = 0x01
460 Body = struct_to_binary(obj)
461 packet = []
462 packet.append(nodeid_to_binary(TypeId))
463 packet.append(Primitives.Byte.pack(Encoding))
464 if Body:
465 packet.append(Primitives.Bytes.pack(Body))
466 return b''.join(packet)
467
468
469def from_binary(uatype, data):

Callers 3

test_extension_objectMethod · 0.90
pack_uatypeFunction · 0.70

Calls 3

struct_to_binaryFunction · 0.85
nodeid_to_binaryFunction · 0.85
packMethod · 0.45

Tested by 2

test_extension_objectMethod · 0.72