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

Function struct_to_binary

opcua/ua/ua_binary.py:242–262  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

240
241
242def struct_to_binary(obj):
243 packet = []
244 has_switch = hasattr(obj, "ua_switches")
245 if has_switch:
246 for name, switch in obj.ua_switches.items():
247 member = getattr(obj, name)
248 container_name, idx = switch
249 if member is not None:
250 container_val = getattr(obj, container_name)
251 container_val = container_val | 1 << idx
252 setattr(obj, container_name, container_val)
253 for name, uatype in obj.ua_types:
254 val = getattr(obj, name)
255 if uatype.startswith("ListOf"):
256 packet.append(list_to_binary(uatype[6:], val))
257 else:
258 if has_switch and val is None and name in obj.ua_switches:
259 pass
260 else:
261 packet.append(to_binary(uatype, val))
262 return b''.join(packet)
263
264
265def to_binary(uatype, val):

Callers 13

_send_requestMethod · 0.90
send_responseMethod · 0.90
from_header_and_bodyMethod · 0.90
to_binaryMethod · 0.90
test_custom_structsMethod · 0.90
test_textMethod · 0.90
pack_uatypeFunction · 0.85
to_binaryFunction · 0.85

Calls 2

list_to_binaryFunction · 0.85
to_binaryFunction · 0.85

Tested by 5

test_custom_structsMethod · 0.72
test_textMethod · 0.72