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

Function nodeid_to_binary

opcua/ua/ua_binary.py:301–330  ·  view source on GitHub ↗
(nodeid)

Source from the content-addressed store, hash-verified

299
300
301def nodeid_to_binary(nodeid):
302 data = None
303 if nodeid.NodeIdType == ua.NodeIdType.TwoByte:
304 return struct.pack("<BB", nodeid.NodeIdType.value, nodeid.Identifier)
305 elif nodeid.NodeIdType == ua.NodeIdType.FourByte:
306 return struct.pack("<BBH", nodeid.NodeIdType.value, nodeid.NamespaceIndex, nodeid.Identifier)
307 elif nodeid.NodeIdType == ua.NodeIdType.Numeric:
308 data = struct.pack("<BHI", nodeid.NodeIdType.value, nodeid.NamespaceIndex, nodeid.Identifier)
309 elif nodeid.NodeIdType == ua.NodeIdType.String:
310 data = struct.pack("<BH", nodeid.NodeIdType.value, nodeid.NamespaceIndex) + \
311 Primitives.String.pack(nodeid.Identifier)
312 elif nodeid.NodeIdType == ua.NodeIdType.ByteString:
313 data = struct.pack("<BH", nodeid.NodeIdType.value, nodeid.NamespaceIndex) + \
314 Primitives.Bytes.pack(nodeid.Identifier)
315 elif nodeid.NodeIdType == ua.NodeIdType.Guid:
316 data = struct.pack("<BH", nodeid.NodeIdType.value, nodeid.NamespaceIndex) + \
317 Primitives.Guid.pack(nodeid.Identifier)
318 else:
319 raise UaError("Unknown NodeIdType: {} for NodeId: {}".format(nodeid.NodeIdType, nodeid))
320 # Add NamespaceUri and ServerIndex in case we have an ExpandedNodeId
321 if nodeid.NamespaceUri:
322 data = bytearray(data)
323 data[0] = set_bit(data[0], 7)
324 data.extend(Primitives.String.pack(nodeid.NamespaceUri))
325 if nodeid.ServerIndex:
326 if not isinstance(data, bytearray):
327 data = bytearray(data)
328 data[0] = set_bit(data[0], 6)
329 data.extend(Primitives.UInt32.pack(nodeid.ServerIndex))
330 return data
331
332
333def nodeid_from_binary(data):

Callers 7

test_nodeid_nsuMethod · 0.90
test_nodeidMethod · 0.90
test_expandednodeidMethod · 0.90
pack_uatypeFunction · 0.85
to_binaryFunction · 0.85

Calls 3

UaErrorClass · 0.90
set_bitFunction · 0.85
packMethod · 0.45

Tested by 4

test_nodeid_nsuMethod · 0.72
test_nodeidMethod · 0.72
test_expandednodeidMethod · 0.72