unpack data given an uatype as a string or a python class having a ua_types memeber
(uatype, data)
| 467 | |
| 468 | |
| 469 | def from_binary(uatype, data): |
| 470 | """ |
| 471 | unpack data given an uatype as a string or a python class having a ua_types memeber |
| 472 | """ |
| 473 | if isinstance(uatype, (str, unicode)) and uatype.startswith("ListOf"): |
| 474 | utype = uatype[6:] |
| 475 | if hasattr(ua.VariantType, utype): |
| 476 | vtype = getattr(ua.VariantType, utype) |
| 477 | return unpack_uatype_array(vtype, data) |
| 478 | size = Primitives.Int32.unpack(data) |
| 479 | return [from_binary(utype, data) for _ in range(size)] |
| 480 | elif isinstance(uatype, (str, unicode)) and hasattr(ua.VariantType, uatype): |
| 481 | vtype = getattr(ua.VariantType, uatype) |
| 482 | return unpack_uatype(vtype, data) |
| 483 | elif isinstance(uatype, (str, unicode)) and hasattr(Primitives, uatype): |
| 484 | return getattr(Primitives, uatype).unpack(data) |
| 485 | else: |
| 486 | return struct_from_binary(uatype, data) |
| 487 | |
| 488 | |
| 489 | def struct_from_binary(objtype, data): |
no test coverage detected