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

Function extensionobject_from_binary

schemas/uaprotocol_auto_add.py:2–29  ·  view source on GitHub ↗

Convert binary-coded ExtensionObject to a Python object. Returns an object, or None if TypeId is zero

(data)

Source from the content-addressed store, hash-verified

1
2def extensionobject_from_binary(data):
3 """
4 Convert binary-coded ExtensionObject to a Python object.
5 Returns an object, or None if TypeId is zero
6 """
7 TypeId = NodeId.from_binary(data)
8 Encoding = ord(data.read(1))
9 body = None
10 if Encoding & (1 << 0):
11 length = uabin.Primitives.Int32.unpack(data)
12 if length < 1:
13 body = Buffer(b"")
14 else:
15 body = data.copy(length)
16 data.skip(length)
17 if TypeId.Identifier == 0:
18 return None
19 elif TypeId.Identifier not in ExtensionClasses:
20 e = ExtensionObject()
21 e.TypeId = TypeId
22 e.Encoding = Encoding
23 if body is not None:
24 e.Body = body.read(len(body))
25 return e
26 klass = ExtensionClasses[TypeId.Identifier]
27 if body is None:
28 raise UaError("parsing ExtensionObject {0} without data".format(klass.__name__))
29 return klass.from_binary(body)
30
31
32def extensionobject_to_binary(obj):

Callers

nothing calls this directly

Calls 8

readMethod · 0.95
BufferClass · 0.85
ExtensionObjectClass · 0.85
UaErrorClass · 0.85
from_binaryMethod · 0.80
copyMethod · 0.80
skipMethod · 0.80
unpackMethod · 0.45

Tested by

no test coverage detected