예제 #1
0
 def test_unknown_extension_object(self):
     obj = ua.ExtensionObject()
     obj.Body = b'example of data in custom format'
     obj.TypeId = ua.NodeId.from_string('ns=3;i=42')
     data = ua.utils.Buffer(extensionobject_to_binary(obj))
     obj2 = ua.extensionobject_from_binary(data)
     self.assertEqual(type(obj2), ua.ExtensionObject)
     self.assertEqual(obj2.TypeId, obj.TypeId)
     self.assertEqual(obj2.Body, b'example of data in custom format')
예제 #2
0
 def test_extension_object(self):
     obj = ua.UserNameIdentityToken()
     obj.UserName = "******"
     obj.Password = b"pass"
     obj2 = ua.extensionobject_from_binary(ua.utils.Buffer(extensionobject_to_binary(obj)))
     self.assertEqual(type(obj), type(obj2))
     self.assertEqual(obj.UserName, obj2.UserName)
     self.assertEqual(obj.Password, obj2.Password)
     v1 = ua.Variant(obj)
     v2 = ua.Variant.from_binary(ua.utils.Buffer(v1.to_binary()))
     self.assertEqual(type(v1), type(v2))
     self.assertEqual(v1.VariantType, v2.VariantType)
예제 #3
0
def pack_uatype(vtype, value):
    if hasattr(Primitives, vtype.name):
        return getattr(Primitives, vtype.name).pack(value)
    elif vtype.value > 25:
        return Primitives.Bytes.pack(value)
    elif vtype.name == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        try:
            return value.to_binary()
        except AttributeError:
            raise UaError("{0} could not be packed with value {1}".format(vtype, value))
예제 #4
0
def pack_uatype(vtype, value):
    if hasattr(Primitives, vtype.name):
        return getattr(Primitives, vtype.name).pack(value)
    elif vtype.value > 25:
        return Primitives.Bytes.pack(value)
    elif vtype.name == "ExtensionObject":
        # dependency loop: classes in uaprotocol_auto use Variant defined in this file,
        # but Variant can contain any object from uaprotocol_auto as ExtensionObject.
        # Using local import to avoid import loop
        from opcua.ua import extensionobject_to_binary
        return extensionobject_to_binary(value)
    else:
        try:
            return value.to_binary()
        except AttributeError:
            raise UaError("{0} could not be packed with value {1}".format(
                vtype, value))