Пример #1
0
    async def done_caller(self, future, method_index, retdata):
        # INFO_MSG("Future %i preparing to done" % method_index)
        # method = self.entity_class.get_method_by_id(method_index)

        method = self.entity_info.get_method(self.context_name, method_index)
        _, returns = method.signature

        serialized_rets = BinarySerialization(retdata)
        rets = tuple()
        for param_index, ret_type in enumerate(returns):
            try:
                ret = ret_type.deserialize(
                    serialized_rets.get_data()[param_index])
            except SerializationError:
                ERROR_MSG(
                    f"Failed to return result by method {method.name}, return value {param_index} invalid"
                )
                raise
            if isinstance(ret, AsyncObj):
                ret = await ret
            rets += ret,

        if len(rets) == 1:
            rets = rets[0]

        try:
            future.set_result(rets)
        except asyncio.InvalidStateError:
            ERROR_MSG(
                f"Failed to done future {future} (of method {method}), retdata: {retdata}"
            )
Пример #2
0
    def send_method_call(self, method_index, future_id, *args, **kwargs):
        if not self:
            WARN_MSG("Call to invalid mailbox %s" % self, depth=1)
            return

        method_info = self.entity_info.get_method(self.context_name,
                                                  method_index)
        params, _ = method_info.signature
        name = method_info.name

        serialized_params = BinarySerialization()

        for param_index, (param_name, param_type) in enumerate(params):
            param = param_type.instantiate(args[param_index])
            serialized_params << param.serialize()

        serialized_call = BinarySerialization()
        serialized_call << self.remote_id
        serialized_call << Globals.generator_signature
        serialized_call << method_index
        serialized_call << future_id
        serialized_call << Globals.access_token
        serialized_call << serialized_params

        message = BinarySerialization()
        message << ConnectionMessageTypes.rmi_call
        message << serialized_call

        self.send_data(message.get_archive())
Пример #3
0
 def serialize(self):
     sr = BinarySerialization()
     sr << str(self.get_endpoint()[0])
     sr << self.get_endpoint()[1]
     sr << self.get_id()
     sr << self.get_context()
     sr << self.get_class_name()
     return sr.get_archive()
Пример #4
0
 def serialize(self):
     serialized = BinarySerialization()
     count = len(self)
     serialized << count
     for index, item in enumerate(self):
         if not isinstance(item, self.base):
             item = self.base.instantiate(item)
         serialized << item.serialize()
     return serialized.get_archive()
Пример #5
0
 def deserialize(cls, serialized_value):
     result = cls()
     serialized = BinarySerialization(serialized_value)
     proxy = serialized.proxy()
     for field_name, field_type in cls.fields:
         ds = proxy >> bytes
         value = field_type.deserialize(ds)
         result[field_name] = value
     return result
Пример #6
0
async def _async_UnrealEngine4_go_to(asset_path):
    global EditorTCPClient

    from Core.TCP.TestProtocolClient import create_connection
    if EditorTCPClient is None or not is_valid(EditorTCPClient):
        _, EditorTCPClient = await create_connection(("127.0.0.1", 6666), None)
    bs = BinarySerialization()
    bs << "open_asset"
    bs << asset_path
    EditorTCPClient.send(bs.get_archive())
Пример #7
0
 def serialize(self):
     sr = BinarySerialization()
     sr << self
     sr << self.key
     sr << self.namespace
     sr << len(self.format_values)
     for value in self.format_values:
         if isinstance(value, FText):
             sr << TextFormatValueType.Simple
             sr << str(value)
         else:
             sr << TextFormatValueType.Text
             sr << value.serialize()
     return sr.get_archive()
Пример #8
0
 def deserialize(cls, serialized_value):
     srp = BinarySerialization(serialized_value).proxy()
     ds = srp >> str
     if "::" in ds:
         ds = ds.split("::")[1]
     deserialized = cls(ds)
     return deserialized
Пример #9
0
    def serialize(self):
        serialized = BinarySerialization()
        for field_name, field_type in self.fields:
            # if field_name.lower() in self:
            #     value = self.get(field_name.lower(), None)
            # else:
            #     value = self.get(field_name, None)

            if field_name in self:
                value = self[field_name]
                if not isinstance(value, field_type):
                    value = field_type.instantiate(value)
            else:
                value = field_type.instantiate() if field_name not in self.defaults else field_type.instantiate(self.defaults[field_name])

            serialized << value.serialize()
        return serialized.get_archive()
Пример #10
0
 def deserialize(cls, serialized_value):
     sr = BinarySerialization(serialized_value).proxy()
     count = sr >> int
     ds = cls()
     for i in range(count):
         item = cls.base.deserialize(sr >> bytes)
         ds.add(item)
     return ds
Пример #11
0
 def serialize(self):
     serialized = BinarySerialization()
     count = len(self)
     serialized << count
     for key in self.keys():
         if not isinstance(key, self.base_key):
             key = self.base_key.instantiate(key)
         serialized << key.serialize()
     for value in self.values():
         if not isinstance(value, self.base_value):
             try:
                 value = self.base_value.instantiate(value)
             except TypeError:
                 print(self.base_value, value)
                 raise
         serialized << value.serialize()
     return serialized.get_archive()
Пример #12
0
    def replicate_value(self, value):
        if not self.with_partial_replication or not value.replication_buffer:
            serialized = value.serialize()
            self.client.UpdateClientEntityVariable(self.entity_id, self.owner_property_name, serialized)
        else:
            sr = BinarySerialization()
            sr << SliceReplicationDataType.Map
            for rep_kind, rep_data in value.replication_buffer:
                if rep_kind == SliceReplicationKind.Nop:
                    continue

                sr << rep_kind
                if rep_kind == SliceReplicationKind.Full:
                    sr << value.serialize()
                elif rep_kind == SliceReplicationKind.Clear:
                    pass
                elif rep_kind == SliceReplicationKind.EditEntry:
                    sr << value.serialize_entry(rep_data)
                elif rep_kind == SliceReplicationKind.RemoveEntry:
                    sr << value.serialize_key(rep_data[0])
            self.client.UpdateClientEntityVariableSlice(self.entity_id, self.owner_property_name, sr.get_archive())
Пример #13
0
    async def load_persistents(self):
        if not is_valid(self.db):
            self.failed = True
            return

        class_name = self.__class__.__name__
        serialized_data = await self.db.GetEntityData(self.dbid, class_name)
        srp = BinarySerialization(serialized_data).proxy()
        for prop_name, prop_info in self.properties.items():
            if Persistent in prop_info.specifiers:
                if not issubclass(prop_info.prop_type, BaseEntity):
                    prop_value = srp >> bytes
                    if "FDateTime" in prop_info.prop_type.__name__:
                        print(",,,")
                    deserialized = prop_info.prop_type.deserialize(prop_value)
                    T = prop_info.prop_type
                    value = T.instantiate(deserialized)

                    value.set_db_interface(
                        DatabaseVariableProxy(self.db, self.dbid, class_name,
                                              prop_name, prop_info))

                    value.initialize_property(self, prop_name)
                    self.properties_locks[prop_name] = asyncio.Lock()
                else:
                    prop_value = srp >> int32
                    value = EntitiesDispatcher().get_by_dbid(prop_value)
                    if value is None:
                        is_new_entity = False
                        if prop_value == 0:
                            prop_value = await self.db.CreateDefaultEntity(
                                prop_info.prop_type.__name__)
                            is_new_entity = True

                        value = await prop_info.prop_type(prop_value,
                                                          outer=self)
                        value.initialize_property(self, prop_name)
                        value.set_db_interface(
                            DatabaseVariableProxy(self.db, self.dbid,
                                                  class_name, prop_name,
                                                  prop_info))

                        if is_new_entity:
                            await value.on_entity_created()

                        if is_new_entity:
                            await value.async_save()

                # ERROR_MSG("Lolz %s %s" % (prop_name, value))
                # if issubclass(prop_info.prop_type, BaseEntity):
                #     if value
                self.set_property_value(prop_name, value)
Пример #14
0
    def deserialize(cls, serialized_value):
        sr = BinarySerialization(serialized_value).proxy()
        count = sr >> int

        keys = list()
        values = list()
        for i in range(count):
            item = cls.base_key.deserialize(sr >> bytes)
            keys.append(item)
        for i in range(count):
            item = cls.base_value.deserialize(sr >> bytes)
            values.append(item)
        return cls({keys[i]: values[i] for i in range(count)})
Пример #15
0
    async def GetEntityData(self, entity_dbid: int32, entity_class: FString) -> FBytes:
        """
        Получение бинарных данных о сущности
        @param entity_dbid: ДБИД сущности
        @param entity_class: класс сущности
        @return: сериализованные байты (по классу)
        """
        properties = ConfigurationGenerator().generated_entities_info.get_by_name(entity_class).get_properties('base', only_persistent=True)

        props_templ = ", ".join([f'"{key}"' for key in properties.keys()])

        res = await self.driver.exec_raw(""" SELECT {0} 
                                             FROM "class_{1}"
                                             WHERE db_id={2}; """.format(props_templ, entity_class, entity_dbid))
        sr = BinarySerialization()
        for data in res:
            values = tuple(data.values())
            for index, (prop_name, prop_data) in enumerate(properties.items()):
                print(prop_name, prop_data)
                T = self.find_type(prop_data.typename, BaseEntity)
                value = values[index]
                value = T.pg_null(value)
                sr << T.serializable_value(value).serialize()
            return sr.get_archive()
Пример #16
0
    def deserialize(cls, serialized_value):
        srp = BinarySerialization(serialized_value).proxy()
        endpoint = [None, None]
        try:
            endpoint[0] = srp >> str
            endpoint[1] = srp >> int
            id          = srp >> int
            context     = srp >> str
            cls_name    = srp >> str
        except Exception as e:
            ERROR_MSG("Failed to deserialize mailbox: %s", srp)
            raise


        # symbol = SymbolsRegistry().get_by_context(context, cls_name)
        # return Mailbox(symbol, endpoint, id, context)
        return cls.get_mailbox_class()(context, cls_name, endpoint, id)
Пример #17
0
    def deserialize(cls, serialized_value):
        srp = BinarySerialization(serialized_value).proxy()
        text = srp >> str
        key = srp >> str
        namespace = srp >> str
        format_values_count = srp >> int
        format_values = list()

        for i in range(0, format_values_count):
            value_type = srp >> int
            if value_type == TextFormatValueType.Simple:
                serialized_value = srp >> str
                value = serialized_value
            elif value_type == TextFormatValueType.Text:
                serialized_value = srp >> bytes
                value = FText.deserialize(serialized_value)
            else:
                raise SerializationError("Cannot deserialize FText")
            format_values.append(value)

        result = FText(text)
        result.init_text(namespace=namespace, key=key)
        result.format_values = format_values
        return result
Пример #18
0
    async def handle_message(self, data):
        """ Обработка входящего сообщения """

        try:
            message_proxy = BinarySerialization(data).proxy()
        except Exception as e:
            ERROR_MSG("Unable to make proxy for data %s: %s" % (data, e))
            return
        try:
            message_type = message_proxy >> int
            message_data = message_proxy >> bytes
        except:
            print(message_proxy)


        if message_type == ConnectionMessageTypes.rmi_call:
            proxy = BinarySerialization(message_data).proxy()
            entity_id    = proxy >> int
            gen_sig      = proxy >> str
            method_index = proxy >> int
            future_id    = proxy >> int
            access_token = proxy >> str
            params       = proxy >> bytes
            if gen_sig == Globals.generator_signature:
                await EntitiesDispatcher().execute_rmi(self.client_connection, entity_id, method_index, future_id, access_token, params)
            else:
                EntitiesDispatcher().remote_response_error(self.client_connection, entity_id, future_id, "Generator signature mismatch")

        elif message_type == ConnectionMessageTypes.rmi_future:
            proxy = BinarySerialization(message_data).proxy()
            entity_id    = proxy >> int
            method_index = proxy >> int
            future_id    = proxy >> int
            returns      = proxy >> bytes
            if future_id != -1:
                EntitiesDispatcher().yield_rmi_result(future_id, entity_id, method_index, returns)

        elif message_type == ConnectionMessageTypes.rmi_error:
            proxy = BinarySerialization(message_data).proxy()
            error_source  = proxy >> str
            error_message = proxy >> str
            future_id     = proxy >> int

            WARN_MSG("Error from %s: %s" % (error_source, error_message))

            if future_id != -1:
                EntitiesDispatcher().yield_rmi_error(future_id)

        elif message_type == ConnectionMessageTypes.rmi_exception:
            proxy = BinarySerialization(message_data).proxy()
            exception_source  = proxy >> str
            exception_class   = proxy >> str
            exception_args    = proxy >> str
            future_id         = proxy >> int

            WARN_MSG("Exception from %s: %s" % (exception_source, exception_class))

            if future_id != -1:
                EntitiesDispatcher().yield_rmi_exception(future_id, exception_class, exception_args)

        await asyncio.sleep(0.1)
Пример #19
0
 def serialize(self):
     sr = BinarySerialization()
     sr << self._names[int(self)]
     return sr.get_archive()
Пример #20
0
 def deserialize(cls, serialized_value):
     srp = BinarySerialization(serialized_value).proxy()
     deserialized = srp >> str
     return json.loads(deserialized)
Пример #21
0
 def serialize(self):
     serialized = BinarySerialization()
     serialized << json.dumps(self)
     return serialized.get_archive()
Пример #22
0
 def serialize_key(cls, key):
     return BinarySerialization() << cls.base_key.serializable_value(key).serialize()
Пример #23
0
 def serialize_entry(cls, key_value):
     key, value = key_value
     return BinarySerialization() << cls.base_key.serializable_value(key).serialize() << cls.base_value.serializable_value(value).serialize()