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

Function extensionobject_from_binary

opcua/ua/ua_binary.py:414–442  ·  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

412
413
414def extensionobject_from_binary(data):
415 """
416 Convert binary-coded ExtensionObject to a Python object.
417 Returns an object, or None if TypeId is zero
418 """
419 typeid = nodeid_from_binary(data)
420 Encoding = ord(data.read(1))
421 body = None
422 if Encoding & (1 << 0):
423 length = Primitives.Int32.unpack(data)
424 if length < 1:
425 body = Buffer(b"")
426 else:
427 body = data.copy(length)
428 data.skip(length)
429 if typeid.Identifier == 0:
430 return None
431 elif typeid in ua.extension_object_classes:
432 klass = ua.extension_object_classes[typeid]
433 if body is None:
434 raise UaError("parsing ExtensionObject {0} without data".format(klass.__name__))
435 return from_binary(klass, body)
436 else:
437 e = ua.ExtensionObject()
438 e.TypeId = typeid
439 e.Encoding = Encoding
440 if body is not None:
441 e.Body = body.read(len(body))
442 return e
443
444
445def extensionobject_to_binary(obj):

Callers 3

test_extension_objectMethod · 0.90
unpack_uatypeFunction · 0.70

Calls 8

readMethod · 0.95
BufferClass · 0.90
UaErrorClass · 0.90
nodeid_from_binaryFunction · 0.85
from_binaryFunction · 0.85
copyMethod · 0.80
skipMethod · 0.80
unpackMethod · 0.45

Tested by 2

test_extension_objectMethod · 0.72