Exemplo n.º 1
0
/**
 * @inheritDoc
 */
void PlayerInputObject::createShot(void) {
    Proto::Object shotProto;
    shotProto.set_id(ObjectId::gen().str());
    shotProto.set_name("Shot");
    shotProto.set_template_("ShotTemplate");

    auto physicSystemObject = shotProto.add_systemobjects();
    physicSystemObject->set_systemtype(Proto::SystemType::Physic);
    physicSystemObject->set_type("Movable");

    auto positionProperty = physicSystemObject->add_properties();
    positionProperty->set_name("Position");
    getVector3(&m_position, positionProperty->mutable_value());
    auto orientationProperty = physicSystemObject->add_properties();
    orientationProperty->set_name("Orientation");
    getQuaternion(&m_orientation, orientationProperty->mutable_value());

    auto networkSystemObject = shotProto.add_systemobjects();
    networkSystemObject->set_systemtype(Proto::SystemType::Network);
    networkSystemObject->set_type("Replicable");

    m_createObjectQueue->push_back(shotProto);
    PostChanges(System::Changes::Generic::CreateObject);
}
Exemplo n.º 2
0
idgs::ResultCode ActorMessage::toRpcBuffer() {
  idgs::ResultCode code = RC_SUCCESS;
  // encode payload
  protobuf::SerdesMode mode = (protobuf::SerdesMode) ((int32_t) getRpcMessage()->serdes_type());
  if (payload.get() && (!rpcMessage->has_payload())) {
    if (!protobuf::ProtoSerdesHelper::serialize(mode, payload.get(), getRpcMessage()->mutable_payload())) {
      LOG(ERROR)<< "serialize actor message payload error! " << payload->DebugString();
      code = RC_ERROR;
      return code;
    }
  }

      // encode attachments
  if (attachments.size() != rpcMessage->attachments_size()) {
    for (auto it = attachments.begin(); it != attachments.end(); ++it) {
      auto a = getRpcMessage()->add_attachments();
      a->set_name(it->first);
      protobuf::ProtoSerdesHelper::serialize(mode, it->second.get(), a->mutable_value());
    }
  }

  // encode whole message
  int32_t size = 0;
  size = getRpcMessage()->ByteSize();
  freeRpcBuffer();
  rpcBuffer = new idgs::net::RpcBuffer();
  rpcBuffer->setBodyLength(size);
  rpcBuffer->reserveBuffer();

  if (!protobuf::ProtoSerdes<DEFAULT_PB_SERDES>::serialize(rpcMessage.get(), rpcBuffer->getBody(), size)) {
    LOG(ERROR)<< "serialize actor message error! " << getRpcMessage()->DebugString();
    code = RC_ERROR;
    return code;
  }

  return code;
}
Exemplo n.º 3
0
/// encode the message to byte array.
std::string ClientActorMessage::toBuffer() {
  // encode payload
  protobuf::SerdesMode mode = (protobuf::SerdesMode) ((int32_t) rpcMessage->serdes_type());
  if (payload.get()) {
    if (!protobuf::ProtoSerdesHelper::serialize(mode, payload.get(), rpcMessage->mutable_payload())) {
      LOG(ERROR)<< "parse actor message payload error! " << payload->DebugString();
      return "";
    }
  }

      // encode attachments
  for (auto it = attachments.begin(); it != attachments.end(); ++it) {
    auto a = rpcMessage->add_attachments();
    a->set_name(it->first);
    protobuf::ProtoSerdesHelper::serialize(mode, it->second.get(), a->mutable_value());

    // @todo remove
//        if (rawAttachments.find(it->first) == rawAttachments.end()) {
//          protobuf::ProtoSerdesHelper::serialize(mode, it->second.get(), &rawAttachments[it->first]);
//        }
  }

  std::string s;
  google::protobuf::TextFormat::PrintToString(*rpcMessage.get(), &s);
  DVLOG(3) << "==============to buffer==============";
  DVLOG(3) << s;
  DVLOG(3) << "============//to buffer==============";

  // encode whole message
  std::string result;
  if (!protobuf::ProtoSerdes<DEFAULT_PB_SERDES>::serialize(rpcMessage.get(), &result)) {
    LOG(ERROR)<< "parse actor message error! " << rpcMessage->DebugString();
    return "";
  }
  return result;
}
void StoreMigrationSourceActor::handleMigrationRequest(const idgs::actor::ActorMessagePtr& msg) {
  // migration data
  if (it->hasNext()) {
    std::shared_ptr<pb::MigrationData> payload = std::make_shared<pb::MigrationData>();

    size_t cnt = 0;
    auto mode = static_cast<protobuf::SerdesMode>(msg->getSerdesType());
    while (it->hasNext() && cnt < batchSize) {
      auto data = payload->add_data();
      data->set_operation_name(OP_INTERNAL_INSERT);
      protobuf::ProtoSerdesHelper::serialize(mode, it->key().get(), data->mutable_key());
      protobuf::ProtoSerdesHelper::serialize(mode, it->value().get().get(), data->mutable_value());

      ++ cnt;
      it->next();
    }

    auto reqMsg = msg->createResponse();
    reqMsg->setOperationName(MIGRATION_DATA);
    reqMsg->setPayload(payload);
    idgs::actor::postMessage(reqMsg);

    return;
  }

  // migration store cache
  if (!redoLog.empty()) {
    std::shared_ptr<pb::MigrationData> payload = std::make_shared<pb::MigrationData>();

    auto mode = static_cast<protobuf::SerdesMode>(msg->getSerdesType());
    size_t cnt = 0;

    while (!redoLog.empty() && cnt < batchSize) {
      MigrationRedoLog info;
      redoLog.try_pop(info);

      if (!info.key) {
        continue;
      }

      auto data = payload->add_data();
      data->set_operation_name(info.opName);
      protobuf::ProtoSerdesHelper::serialize(mode, info.key.get(), data->mutable_key());
      if (info.value) {
        protobuf::ProtoSerdesHelper::serialize(mode, info.value.get(), data->mutable_value());
      }

      ++ cnt;
    }

    auto reqMsg = msg->createResponse();
    reqMsg->setOperationName(MIGRATION_DATA);
    reqMsg->setPayload(payload);
    idgs::actor::postMessage(reqMsg);

    return;
  }

  auto& wrapper = pstore->getStoreConfig();
  auto& schemaName = wrapper->getSchema();
  auto& storeName = wrapper->getStoreConfig().name();

  auto payload = std::make_shared<pb::StoreMigrationComplete>();
  payload->set_schema_name(schemaName);
  payload->set_store_name(storeName);
  payload->set_data_size(map->size());

  auto respMsg = msg->createResponse();
  respMsg->setOperationName(STORE_MIGRATION_COMPLETE);
  respMsg->setPayload(payload);
  DVLOG(2) << "store " << schemaName << "." << storeName << " of partition " << partId << " migration complete on source member ";
  idgs::actor::sendMessage(respMsg);

  terminate();
}
Exemplo n.º 5
0
bool ProtoMessage::toString(std::string& result)
{
	if (m_protoMsg == nullptr)
	{
		return false;
	}

	m_protoMsg->Clear();
	for (auto itKeyMapData = m_keyMapData.begin(); itKeyMapData != m_keyMapData.end(); ++itKeyMapData)
	{
		auto& key = itKeyMapData->first;
		auto protoKeyMapData = m_protoMsg->add_keymapdata();
		protoKeyMapData->set_key(key);
		auto protoMapData = protoKeyMapData->mutable_mapdata();
		auto& mapData = itKeyMapData->second;
		for (auto itData = mapData.begin(); itData != mapData.end(); ++itData)
		{
			auto& dataKey = itData->first;
			const Variant& dataValue = itData->second;
			auto mapKeyValue = protoMapData->add_mapkeyvalue();
			mapKeyValue->set_key(dataKey);
			auto variantValue = mapKeyValue->mutable_value();
			std::string blob;
			dataValue.toBlob(blob);
			variantValue->set_data(blob);
			variantValue->set_type((int32_t)dataValue.type());
		}
	}

	for (auto itKeyListData = m_keyListData.begin(); itKeyListData != m_keyListData.end(); ++itKeyListData)
	{
		auto& key = itKeyListData->first;
		auto protokeyListData = m_protoMsg->add_keylistdata();
		protokeyListData->set_key(key);
		auto protoListData = protokeyListData->mutable_listdata();
		auto& listData = itKeyListData->second;
		for (auto itData = listData.begin(); itData != listData.end(); ++itData)
		{
			const Variant& dataValue = *itData;
			auto variantValue = protoListData->add_value();
			std::string blob;
			dataValue.toBlob(blob);
			variantValue->set_data(blob);
			variantValue->set_type((int32_t)dataValue.type());
		}
	}

	for (auto itKeyTableData = m_keyTableData.begin(); itKeyTableData != m_keyTableData.end(); ++itKeyTableData)
	{
		auto& key = itKeyTableData->first;
		auto protoKeyTableData = m_protoMsg->add_keytabledata();
		protoKeyTableData->set_key(key);
		auto protoTableData = protoKeyTableData->mutable_tabledata();
		auto& tableData = itKeyTableData->second;
		int32_t lineIndex = -1;
		while (lineIndex++ != tableData.size() - 1)
		{
			auto list = protoTableData->add_listdata();
			auto& listData = tableData[lineIndex];
			int32_t dataIndex = -1;
			while (dataIndex++ != listData.size() - 1)
			{
				const Variant& dataValue = listData[dataIndex];
				auto variantValue = list->add_value();
				std::string blob;
				dataValue.toBlob(blob);
				variantValue->set_data(blob);
				variantValue->set_type((int32_t)dataValue.type());
			}
		}
	}
	return m_protoMsg->SerializeToString(&result);
}
Exemplo n.º 6
0
bool ProtoMessage::from(const std::string& data)
{
	if (m_protoMsg == nullptr || !m_protoMsg->ParseFromString(data))
	{
		return false;
	}
	clearMap();
	clearList();
	clearTable();
	
	int32_t index = -1;
	while (index++ != m_protoMsg->keymapdata_size() - 1)
	{
		auto protokeyMapData = m_protoMsg->mutable_keymapdata(index);
		const int32_t& key = protokeyMapData->key();
		auto mapData = protokeyMapData->mutable_mapdata();
		int32_t dataIndex = -1;
		while (dataIndex++ != mapData->mapkeyvalue_size() - 1)
		{
			auto mapKeyValue = mapData->mutable_mapkeyvalue(dataIndex);
			const int32_t& dataKey = mapKeyValue->key();
			auto variantValue = mapKeyValue->mutable_value();
			m_keyMapData[key][dataKey] = Variant(variantValue->data(), (Variant::VariantType)(variantValue->type()), true);
		}
	}

	index = -1;
	while (index++ != m_protoMsg->keylistdata_size() - 1)
	{
		auto protokeyListData = m_protoMsg->mutable_keylistdata(index);
		const int32_t& key = protokeyListData->key();
		auto listData = protokeyListData->mutable_listdata();
		int32_t dataIndex = -1;
		while (dataIndex++ != listData->value_size() - 1)
		{
			auto variantValue = listData->mutable_value(dataIndex);
			m_keyListData[key].push_back(Variant(variantValue->data(), (Variant::VariantType)(variantValue->type()), true));
		}
	}

	index = -1;
	while (index++ != m_protoMsg->keytabledata_size() - 1)
	{
		auto protokeyTableData = m_protoMsg->mutable_keytabledata(index);
		const int32_t& key = protokeyTableData->key();
		auto tableData = protokeyTableData->mutable_tabledata();
		std::vector<std::vector<Variant>> vecData;
		int32_t lineIndex = -1;
		while (lineIndex++ != tableData->listdata_size() - 1)
		{
			std::vector<Variant> vecLine;
			auto list = tableData->mutable_listdata(lineIndex);
			int32_t dataIndex = -1;
			while (dataIndex++ != list->value_size() - 1)
			{
				auto variantValue = list->mutable_value(dataIndex);
				vecLine.push_back(Variant(variantValue->data(), (Variant::VariantType)(variantValue->type()), true));
			}
			vecData.push_back(vecLine);
		}
		m_keyTableData[key] = vecData;
	}

	return true;
}