Esempio n. 1
0
inline bool operator== (
        const google::protobuf::Message & x,
        const google::protobuf::Message & y)
{
    std::string x_string;
    std::string y_string;
    x.SerializeToString(&x_string);
    y.SerializeToString(&y_string);
    return x_string == y_string;
}
Esempio n. 2
0
 void reply(const google::protobuf::Message& message)
 {
   CHECK(from) << "Attempting to reply without a sender";
   std::string data;
   message.SerializeToString(&data);
   send(from, message);
 }
Esempio n. 3
0
bool NFNetModule::SendMsgPBToAllClient(const uint16_t nMsgID, const google::protobuf::Message& xData)
{
    NFMsg::MsgBase xMsg;
    if (!xData.SerializeToString(xMsg.mutable_msg_data()))
    {
		std::ostringstream stream;
		stream << " SendMsgPBToAllClient";
		stream << " Failed For Serialize of MsgData, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

        return false;
    }

    std::string strMsg;
    if (!xMsg.SerializeToString(&strMsg))
    {
		std::ostringstream stream;
		stream << " SendMsgPBToAllClient";
		stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

        return false;
    }

    return SendMsgToAllClientWithOutHead(nMsgID, strMsg);
}
Esempio n. 4
0
 void send(const process::UPID& to,
           const google::protobuf::Message& message)
 {
   std::string data;
   message.SerializeToString(&data);
   process::Process<T>::send(to, message.GetTypeName(), std::move(data));
 }
Esempio n. 5
0
inline void post(const process::UPID& to,
                 const google::protobuf::Message& message)
{
  std::string data;
  message.SerializeToString(&data);
  post(to, message.GetTypeName(), data.data(), data.size());
}
Esempio n. 6
0
bool write_message(boost::asio::ip::tcp::socket& s, ::google::protobuf::Message& msg)
{
   string msg_str;
   if (!msg.SerializeToString(&msg_str))
      return false;

   bling_pb::header hdr;

   if (typeid(msg) == typeid(bling_pb::get_slave_list))
      hdr.set_msg_id(bling_pb::header::GET_SLAVE_LIST);
   else if (typeid(msg) == typeid(bling_pb::slave_list))
      hdr.set_msg_id(bling_pb::header::SLAVE_LIST);
   else if (typeid(msg) == typeid(bling_pb::set_slave_tlc))
      hdr.set_msg_id(bling_pb::header::SET_SLAVE_TLC);
   else if (typeid(msg) == typeid(bling_pb::start_effect))
      hdr.set_msg_id(bling_pb::header::START_EFFECT);
   else
      cout << "Unidentified message type!!!" << endl;

   hdr.set_len(msg_str.size());
   string hdr_str;
   if (!hdr.SerializeToString(&hdr_str))
      return false;
   if (hdr_str.size() != header_length)
      cout << "Header length=" << hdr_str.size() << endl;
   string tx_buffer = hdr_str + msg_str;
   size_t n = write_string(s, tx_buffer);
   return n == tx_buffer.size();
}
Esempio n. 7
0
bool NFNetModule::SendMsgPB(const uint16_t nMsgID, const google::protobuf::Message& xData, const NFSOCK nSockIndex)
{
	NFMsg::MsgBase xMsg;
	if (!xData.SerializeToString(xMsg.mutable_msg_data()))
	{
		std::ostringstream stream;
		stream << " SendMsgPB Message to  " << nSockIndex;
		stream << " Failed For Serialize of MsgData, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

		return false;
	}

	NFMsg::Ident* pPlayerID = xMsg.mutable_player_id();
	*pPlayerID = NFToPB(NFGUID());

	std::string strMsg;
	if (!xMsg.SerializeToString(&strMsg))
	{
		std::ostringstream stream;
		stream << " SendMsgPB Message to  " << nSockIndex;
		stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

		return false;
	}

	SendMsgWithOutHead(nMsgID, strMsg, nSockIndex);

	return true;
}
Esempio n. 8
0
/*
 * Send a ConfigureDevice() request
 * @param message the request to send
 */
bool OlaConfigurator::SendMessage(const google::protobuf::Message &message) {
  string request_string;
  message.SerializeToString(&request_string);
  return m_client->ConfigureDevice(
      m_alias,
      request_string,
      NewSingleCallback(this, &OlaConfigurator::HandleConfigResponse));
}
Esempio n. 9
0
void AbstractService::sendToUnifier(const std::string &to, ::google::protobuf::Message &msg, unifier::UnifierMessage_Type type) {
	unifier::UnifierMessage w;
	w.set_to(to);
	w.set_type(type);

	std::string payload;
	msg.SerializeToString(&payload);
	w.set_payload(payload);

	sendToUnifier(w);
}
Esempio n. 10
0
event_index_status EventIndex::SetGTIDIndex(const string &gtid, const ::google::protobuf::Message &data_info) {
    string buffer;
    if (!data_info.SerializeToString(&buffer)) {
        ColorLogError("buffer serialize fail");
        return event_index_status::DATA_ERROR;
    }

    //LogVerbose("%s gtid %s", __func__, gtid.c_str());
    leveldb::Status status = level_db_->Put(leveldb::WriteOptions(), gtid, buffer);
    return status.ok() ? event_index_status::OK : event_index_status::DB_ERROR;
}
Esempio n. 11
0
void CNetConn::sendResponse(google::protobuf::Message& msg, uint32_t cmd, uint32_t requestId, uint64_t uid64)
{
	std::string strMsg;
	
    msg.SerializeToString(&strMsg);

    CEpoll::Functor f = boost::bind(&CNetConn::send, this, strMsg, cmd, requestId, uid64);

    getEpoll()->pushFuctor(f);

//	sendResponse(strMsg, cmd, requestId, uid64);
}
Esempio n. 12
0
bool NFNetModule::SendMsgPB(const uint16_t nMsgID, const google::protobuf::Message& xData, const NFSOCK nSockIndex, const std::vector<NFGUID>* pClientIDList)
{
    if (!m_pNet)
    {
		std::ostringstream stream;
		stream << " m_pNet SendMsgPB faailed fd " << nSockIndex;
		stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

        return false;
    }

    NFMsg::MsgBase xMsg;
    if (!xData.SerializeToString(xMsg.mutable_msg_data()))
    {
		std::ostringstream stream;
		stream << " SendMsgPB faailed fd " << nSockIndex;
		stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

        return false;
    }


    NFMsg::Ident* pPlayerID = xMsg.mutable_player_id();
    *pPlayerID = NFToPB(NFGUID());
    if (pClientIDList)
    {
        for (int i = 0; i < pClientIDList->size(); ++i)
        {
            const NFGUID& ClientID = (*pClientIDList)[i];

            NFMsg::Ident* pData = xMsg.add_player_client_list();
            if (pData)
            {
                *pData = NFToPB(ClientID);
            }
        }
    }

    std::string strMsg;
    if (!xMsg.SerializeToString(&strMsg))
    {
		std::ostringstream stream;
		stream << " SendMsgPB faailed fd " << nSockIndex;
		stream << " Failed For Serialize of MsgBase, MessageID " << nMsgID;
		m_pLogModule->LogError(stream, __FUNCTION__, __LINE__);

        return false;
    }

    return SendMsgWithOutHead(nMsgID, strMsg, nSockIndex);
}
Esempio n. 13
0
int             
protobuf_msg_to_msgb_file(const google::protobuf::Message & msg, const std::string & msgbfile) {
    std::string msgb;
    if (!msg.SerializeToString(&msgb)) {
        GLOG_ERR("protomsg msg serialize error !");
        return -1;
    }
    int sz = dcs::writefile(msgbfile, msgb.data(), msgb.length());
    if (sz <= 0) {
        GLOG_SER("write file :%s error :%d", msgbfile.c_str(), sz);
        return -1;
    }
    return 0;
}
Esempio n. 14
0
/**
This function is used to send a protobuf object as a ZMQ message, with optional preappended or postappended data.  It manages serialization and will throw an exception if required fields of the message are missing.
@param inputSocketToSendFrom: The socket to send from
@param inputMessage: The message to send
@param inputDataToPreappend: The data to place in the ZMQ message before the serialized protobuf object
@param inputDataToPostAppend: The data to place in the ZMQ message after the serialized protobuf object

@throws: This function can throw exceptions
*/
void pylongps::sendProtobufMessage(zmq::socket_t &inputSocketToSendFrom, const google::protobuf::Message &inputMessage, const std::string &inputDataToPreappend, const std::string &inputDataToPostAppend)
{
std::string serializedMessage;

SOM_TRY
inputMessage.SerializeToString(&serializedMessage);
SOM_CATCH("Error serializing message to string\n")

std::string dataToSend = inputDataToPreappend + serializedMessage + inputDataToPostAppend;

SOM_TRY
inputSocketToSendFrom.send(dataToSend.c_str(), dataToSend.size());
SOM_CATCH("Error, unable to send message\n")
}
Esempio n. 15
0
void CommonMemoryCache::Set(
    const std::string& key,
    const google::protobuf::Message& message)
{
    std::string buffer;
    if (!message.SerializeToString(&buffer)) {
        LOG(ERROR)
            << "serialize to string failed. message ["
            << message.ShortDebugString() << "]";
        return;
    }

    RWLock::WriterLocker locker(&m_rw_lock);
    m_cache_map[key] = buffer;
}
Esempio n. 16
0
void Client::postData(const std::string& event_name, const google::protobuf::Message& event_data)
{
  std::cerr << "Sending proto\n";
  Forms formParts;
  std::string proto_code;
  event_data.SerializeToString(&proto_code);

  const std::string type_name("type");
  const std::string value_name("value");

  formParts.push_back(new curlpp::FormParts::Content(type_name, event_name));
  formParts.push_back(new curlpp::FormParts::Content(value_name, proto_code));

  request.setOpt(new curlpp::options::HttpPost(formParts));
  request.perform();
}
Esempio n. 17
0
    /// Validates that a protocol request message has been sent
    ///
    /// Expects the request message to have a single protocol envelope with a
    /// single embedded message of the enumeration specified and serialized to
    /// exactly what we specify
    void ExpectRequestMessage(uint32 type, ::google::protobuf::Message &expected)
    {
        ASSERT_TRUE(this->socket != NULL);

        ::zmq::pollitem_t pollitem;
        pollitem.events = ZMQ_POLLIN;
        pollitem.socket = *this->socket;
        pollitem.fd = 0;
        pollitem.revents = 0;

        ASSERT_EQ(1, ::zmq::poll(&pollitem, 1, 1000))
            << "Request message sent in orderly manner";

        MessageContainer messages;
        ASSERT_TRUE(zeromq::ReceiveMessage(*this->socket, messages));

        ASSERT_EQ(1, messages.IdentitiesSize()) << "client sent identities as part of request";
        ASSERT_EQ(1, messages.MessagesSize()) << "client sent 1 message with content";

        message_t msg;
        msg.copy(messages[0]);

        ASSERT_GT(msg.size(), 1) << "sent message has content";

        char msg_version = 0;
        memcpy(&msg_version, msg.data(), 1);
        EXPECT_EQ(0x01, msg_version) << "sent message has protocol header";

        Envelope e;

        EXPECT_NO_THROW(e = Envelope(msg, 1)) << "envelope could be deserialized";

        EXPECT_EQ(1, e.MessageCount()) << "envelope contains one message";
        EXPECT_EQ(::zippylog::message_namespace, e.MessageNamespace(0)) << "message of proper namespace";
        EXPECT_EQ(type, e.MessageType(0)) << "message of proper type";

        EXPECT_EQ(1, e.TagSize()) << "envelope has tag";

        ::google::protobuf::Message *sent = (::google::protobuf::Message *)e.GetMessage(0);
        ASSERT_TRUE(sent != NULL) << "able to deserialize embedded message";

        string serialized_expected, serialized_actual;
        EXPECT_TRUE(expected.SerializeToString(&serialized_expected));
        EXPECT_TRUE(sent->SerializeToString(&serialized_actual));

        EXPECT_EQ(serialized_expected, serialized_actual) << "sent request message matches expected";
    }
Esempio n. 18
0
void NFCNetLogic::SendToServerByPB(const uint16_t nMsgID, google::protobuf::Message& xData)
{
	if(m_bSocketReady)
	{
		g_pNetClientModule->SendToAllServerByPB(nMsgID, xData);
	}
	else
	{
        NFMsg::MsgBase xMsg;
        xData.SerializeToString(xMsg.mutable_msg_data());
        NFMsg::Ident* pPlayerID = xMsg.mutable_player_id();
        *pPlayerID = NFINetModule::NFToPB(NFGUID());

        std::string strMsg;
        xMsg.SerializeToString(&strMsg);
		m_listDelayMsg.push_back(std::make_pair((uint16_t)nMsgID, strMsg));
	}
}
Esempio n. 19
0
int send(int fd, 
         const std::string& name,
         const ::google::protobuf::Message& message,
         uint64_t mid) {
    SocketWriter writer(fd);
    Version_1_Protocol protocol;
    Msg msg;
    message.SerializeToString(msg.mutable_content());
    msg.set_mid(mid);
    msg.set_name(name);
    int ret = protocol.encode(msg, &writer);
    if (ret) {
        LOG_WARN << "encode request error, method["
            << name << "] data[" << message.DebugString()<< "]";
        return 1;
    }
    return writer.write(1000) == SocketWriter::kOk ? 0 : -1;
}
Esempio n. 20
0
/**
This function saves a protobuf object to a file with a proceeded 64 bit Poco::Int64 in network byte order that holds the size of the object to be loaded and deserialized.
@param inputPath: The path to the file to save the object to
@param inputMessageBuffer: The protobuf object to serialize
@return: true if the message could be serialized/saved and false otherwise
*/
bool pylongps::saveProtobufObjectToFile(const std::string &inputPath, google::protobuf::Message &inputMessageBuffer)
{
std::string serializedObject;
try
{
inputMessageBuffer.SerializeToString(&serializedObject);
}
catch(const std::exception &inputException)
{
return false;
}

//Create serialized object size
Poco::Int64 objectSizeNetworkOrder = Poco::ByteOrder::toNetwork(Poco::Int64(serializedObject.size()));

//Save to file
if(!saveStringToFile(std::string((char *) &objectSizeNetworkOrder, sizeof(Poco::Int64)) + serializedObject, inputPath))
{
return false;
}

return true;
}
Esempio n. 21
0
mori::TcpConnBuffer						Codec::Encode( const google::protobuf::Message& msg, const SEncodeContext& context )
{
	assert(msg.IsInitialized());

	CodecProtocol::Codec encodeMsg;
	encodeMsg.set_msgname(msg.GetDescriptor()->full_name());
	encodeMsg.set_clienttype(context.ClientType_);
	if ( context.UserID_ )
	{
		encodeMsg.set_userid(*context.UserID_);
	}
	if ( context.VerifyCode_ )
	{
		encodeMsg.set_verifycode(*context.VerifyCode_);
	}

	std::string msgBuf;
	msg.SerializeToString(&msgBuf);

	auto bContinue = true;
	auto step = 0;
	while ( bContinue )
	{	
		switch (step)
		{
		case 0:
			{
				if ( !context.AESKey_.empty() )
				{
					msgBuf = FastEncrypt::AES_CBCEncrypt(context.AESKey_, msgBuf);
					encodeMsg.set_aeskey(context.AESKey_);
				}

				++step;
			}break;
		case 1:
			{
				if ( !context.RSAKey_.empty() && !context.AESKey_.empty() )
				{
					auto EncryptAESKey = FastEncrypt::RSA_PubEncrypt(context.RSAKey_, context.AESKey_);
					encodeMsg.mutable_aeskey()->swap(EncryptAESKey);
					encodeMsg.set_rsaencode(true);
				}

				++step;
			}
			break;
		case 2:
			{
				if ( context.Compress_ )
				{
					auto compSize = compressBound(msgBuf.size());
					std::string tmpbuf;
					tmpbuf.resize(compSize);

					auto err = compress(reinterpret_cast<Bytef*>(&tmpbuf[0]), &compSize, reinterpret_cast<const Bytef*>(msgBuf.data()), msgBuf.size());
					if ( Z_OK != err )
					{
						assert(0);
						bContinue = false;
					}
					else
					{
						encodeMsg.set_rawsize(msgBuf.size());

						msgBuf.clear();
						tmpbuf.resize(compSize);
						
						msgBuf.swap(tmpbuf);
					}
				}

				++step;
			}
			break;
		default:
			{
				bContinue = false;
			}
			break;
		}
	}

	mori::TcpConnBuffer ret(sizeof(uint32_t)+encodeMsg.ByteSize());

	encodeMsg.SerializeToArray(ret.data()+sizeof(uint32_t), ret.size()-sizeof(uint32_t));
	
	uint32_t* pSize = reinterpret_cast<uint32_t*>(ret.data());
	*pSize = boost::asio::detail::socket_ops::host_to_network_long(encodeMsg.ByteSize());

	ret.reserve(ret.size()+msgBuf.size());
	std::copy(msgBuf.begin(), msgBuf.end(), std::back_inserter(ret));

	return std::move(ret);
}
Esempio n. 22
0
 void SendMessage(const ::google::protobuf::Message &message)
 {
     std::string message_str;
     message.SerializeToString(&message_str);
     iostream_ << message_str.size() << '\n' << message_str;
 }