Convert binary-coded ExtensionObject to a Python object. Returns an object, or None if TypeId is zero
(data)
| 412 | |
| 413 | |
| 414 | def 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 | |
| 445 | def extensionobject_to_binary(obj): |