| 362 | |
| 363 | |
| 364 | def variant_to_binary(var): |
| 365 | b = [] |
| 366 | encoding = var.VariantType.value & 0b111111 |
| 367 | if var.is_array or isinstance(var.Value, (list, tuple)): |
| 368 | var.is_array = True |
| 369 | encoding = set_bit(encoding, 7) |
| 370 | if var.Dimensions is not None: |
| 371 | encoding = set_bit(encoding, 6) |
| 372 | b.append(Primitives.Byte.pack(encoding)) |
| 373 | b.append(pack_uatype_array(var.VariantType, ua.flatten(var.Value))) |
| 374 | if var.Dimensions is not None: |
| 375 | b.append(pack_uatype_array(ua.VariantType.Int32, var.Dimensions)) |
| 376 | else: |
| 377 | b.append(Primitives.Byte.pack(encoding)) |
| 378 | b.append(pack_uatype(var.VariantType, var.Value)) |
| 379 | |
| 380 | return b"".join(b) |
| 381 | |
| 382 | |
| 383 | def variant_from_binary(data): |