Commit 0c6d1123 authored by oroulet's avatar oroulet Committed by oroulet

correctly import/export BytestringNodeId

parent dd351f57
...@@ -487,7 +487,7 @@ class NodeId: ...@@ -487,7 +487,7 @@ class NodeId:
identifier = uuid.UUID(f"urn:uuid:{v}") identifier = uuid.UUID(f"urn:uuid:{v}")
elif k == "b": elif k == "b":
ntype = NodeIdType.ByteString ntype = NodeIdType.ByteString
identifier = v identifier = bytes(v, 'utf-8')
elif k == "srv": elif k == "srv":
srv = int(v) srv = int(v)
elif k == "nsu": elif k == "nsu":
...@@ -502,6 +502,7 @@ class NodeId: ...@@ -502,6 +502,7 @@ class NodeId:
string = [] string = []
if self.NamespaceIndex != 0: if self.NamespaceIndex != 0:
string.append(f"ns={self.NamespaceIndex}") string.append(f"ns={self.NamespaceIndex}")
identifier = self.Identifier
ntype = None ntype = None
if self.NodeIdType == NodeIdType.Numeric: if self.NodeIdType == NodeIdType.Numeric:
ntype = "i" ntype = "i"
...@@ -515,7 +516,8 @@ class NodeId: ...@@ -515,7 +516,8 @@ class NodeId:
ntype = "g" ntype = "g"
elif self.NodeIdType == NodeIdType.ByteString: elif self.NodeIdType == NodeIdType.ByteString:
ntype = "b" ntype = "b"
string.append(f"{ntype}={self.Identifier}") identifier = identifier.decode()
string.append(f"{ntype}={identifier}")
return ";".join(string) return ";".join(string)
def to_binary(self): def to_binary(self):
......
...@@ -337,7 +337,15 @@ def test_nodeid_guid_string(): ...@@ -337,7 +337,15 @@ def test_nodeid_guid_string():
s = n.to_string() s = n.to_string()
n2 = ua.NodeId.from_string(s) n2 = ua.NodeId.from_string(s)
s2 = n2.to_string() s2 = n2.to_string()
print(n, n2, s, s2) assert n == n2
assert s == s2
def test_nodeid_bytestring():
n = ua.ByteStringNodeId(Identifier=b"qwerty", NamespaceIndex=1)
s = n.to_string()
n2 = ua.NodeId.from_string(s)
s2 = n2.to_string()
assert n == n2 assert n == n2
assert s == s2 assert s == s2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment