4 Convert binary-coded ExtensionObject to a Python object. 5 Returns an object, or None if TypeId is zero 7 TypeId = NodeId.from_binary(data)
8 Encoding = ord(data.read(1))
10 if Encoding & (1 << 0):
11 length = uabin.Primitives.Int32.unpack(data)
15 body = data.copy(length)
17 if TypeId.Identifier == 0:
19 elif TypeId.Identifier
not in ExtensionClasses:
24 e.Body = body.read(len(body))
26 klass = ExtensionClasses[TypeId.Identifier]
28 raise UaError(
"parsing ExtensionObject {0} without data".format(klass.__name__))
29 return klass.from_binary(body)
34 Convert Python object to binary-coded ExtensionObject. 35 If obj is None, convert to empty ExtensionObject (TypeId = 0, no Body). 36 Returns a binary string 38 if isinstance(obj, ExtensionObject):
39 return obj.to_binary()
44 TypeId = FourByteNodeId(getattr(ObjectIds,
"{0}_Encoding_DefaultBinary".format(obj.__class__.__name__)))
46 Body = obj.to_binary()
48 packet.append(TypeId.to_binary())
49 packet.append(uabin.Primitives.UInt8.pack(Encoding))
51 packet.append(uabin.Primitives.Bytes.pack(Body))
52 return b
''.join(packet)
def extensionobject_from_binary(data)
def extensionobject_to_binary(obj)