Convert binary-coded ExtensionObject to a Python object. Returns an object, or None if TypeId is zero
(data)
| 1 | |
| 2 | def 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 | |
| 32 | def extensionobject_to_binary(obj): |
nothing calls this directly
no test coverage detected