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

Function to_binary

opcua/ua/ua_binary.py:265–286  ·  view source on GitHub ↗

Pack a python object to binary given a string defining its type

(uatype, val)

Source from the content-addressed store, hash-verified

263
264
265def to_binary(uatype, val):
266 """
267 Pack a python object to binary given a string defining its type
268 """
269 if uatype.startswith("ListOf"):
270 #if isinstance(val, (list, tuple)):
271 return list_to_binary(uatype[6:], val)
272 elif isinstance(uatype, (str, unicode)) and hasattr(ua.VariantType, uatype):
273 vtype = getattr(ua.VariantType, uatype)
274 return pack_uatype(vtype, val)
275 elif isinstance(uatype, (str, unicode)) and hasattr(Primitives, uatype):
276 return getattr(Primitives, uatype).pack(val)
277 elif isinstance(val, (IntEnum, Enum)):
278 return Primitives.UInt32.pack(val.value)
279 elif isinstance(val, ua.NodeId):
280 return nodeid_to_binary(val)
281 elif isinstance(val, ua.Variant):
282 return variant_to_binary(val)
283 elif hasattr(val, "ua_types"):
284 return struct_to_binary(val)
285 else:
286 raise UaError("No known way to pack {} of type {} to ua binary".format(val, uatype))
287
288
289def list_to_binary(uatype, val):

Callers 2

struct_to_binaryFunction · 0.85
list_to_binaryFunction · 0.85

Calls 7

UaErrorClass · 0.90
list_to_binaryFunction · 0.85
pack_uatypeFunction · 0.85
nodeid_to_binaryFunction · 0.85
variant_to_binaryFunction · 0.85
struct_to_binaryFunction · 0.85
packMethod · 0.45

Tested by

no test coverage detected