• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ protobuf::Message类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中google::protobuf::Message的典型用法代码示例。如果您正苦于以下问题:C++ Message类的具体用法?C++ Message怎么用?C++ Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: serialize

size_t ProtobufSocketSerializer::serialize(
        const ::google::protobuf::Message &msg, char *&packet) {
    size_t size = PROTOBUF_HEADER_LENGTH + (size_t) msg.ByteSize();
    packet = new char[size]();

    ::google::protobuf::io::ArrayOutputStream aos(packet, (int) size);
    ::google::protobuf::io::CodedOutputStream coded_output(&aos);
    coded_output.WriteLittleEndian32((google::protobuf::uint32) msg.ByteSize());
    msg.SerializeToCodedStream(&coded_output);

    return size;
}
开发者ID:huner15,项目名称:saas,代码行数:12,代码来源:ProtobufSocketSerializer.cpp


示例2: WriteMessage

bool WriteMessage(const shared_ptr<UnixSocketConnection> &connection,
                  uint32_t type,
                  const google::protobuf::Message &response) {
  shared_ptr<vector<char> > data(new vector<char>(response.ByteSize() + sizeof(type)));
  char *ptr = &(*data)[0];
  *reinterpret_cast<uint32_t *>(ptr) = type;
  if (!response.SerializeToArray(ptr + sizeof(type), data->size() - sizeof(type))) {
    WARNING_LOG("serialize message to string failed.");
    return false;
  }
  connection->Write(data);
  return true;
}
开发者ID:duanbing,项目名称:gingko,代码行数:13,代码来源:socket_util.cpp


示例3: Set

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;
}
开发者ID:kanxue,项目名称:horoscope,代码行数:15,代码来源:common_memory_cache.cpp


示例4: reply

 void reply(const google::protobuf::Message& message)
 {
   CHECK(from) << "Attempting to reply without a sender";
   std::string data;
   message.SerializeToString(&data);
   send(from, message);
 }
开发者ID:CodEnFisH,项目名称:mesos,代码行数:7,代码来源:protobuf.hpp


示例5: logic_error

/** Send a message.
 * @param client ID of the client to addresss
 * @param m Message to send, the message must have an CompType enum type to
 * specify component ID and message type.
 */
void
ProtobufStreamServer::send(ClientID client, google::protobuf::Message &m)
{
  const google::protobuf::Descriptor *desc = m.GetDescriptor();
  const google::protobuf::EnumDescriptor *enumdesc = desc->FindEnumTypeByName("CompType");
  if (! enumdesc) {
    throw std::logic_error("Message does not have CompType enum");
  }
  const google::protobuf::EnumValueDescriptor *compdesc =
    enumdesc->FindValueByName("COMP_ID");
  const google::protobuf::EnumValueDescriptor *msgtdesc =
    enumdesc->FindValueByName("MSG_TYPE");
  if (! compdesc || ! msgtdesc) {
    throw std::logic_error("Message CompType enum hs no COMP_ID or MSG_TYPE value");
  }
  int comp_id = compdesc->number();
  int msg_type = msgtdesc->number();
  if (comp_id < 0 || comp_id > std::numeric_limits<uint16_t>::max()) {
    throw std::logic_error("Message has invalid COMP_ID");
  }
  if (msg_type < 0 || msg_type > std::numeric_limits<uint16_t>::max()) {
    throw std::logic_error("Message has invalid MSG_TYPE");
  }

  send(client, comp_id, msg_type, m);
}
开发者ID:sanyaade-teachings,项目名称:fawkes,代码行数:31,代码来源:server.cpp


示例6: mongoproxy_update

int		mongoproxy_update(const google::protobuf::Message & msg, const std::string & fields, const char * cb_data, int cb_size){
    MongoOPReq requpdate;
    std::vector<string> vs;
    dcs::strsplit(fields, ",", vs);
    if (vs.empty()){
        GLOG_ERR("not found the fields define :%s", fields.c_str());
        return -1;
    }
    google::protobuf::Message * tmpmsg = msg.New();
    tmpmsg->CopyFrom(msg);
    auto reflect = tmpmsg->GetReflection();
    auto desc = tmpmsg->GetDescriptor();
    for (int i = 0; i < desc->field_count(); ++i){
        auto field = desc->field(i);
        if (std::find(vs.begin(), vs.end(), field->name()) != vs.end()){
            continue;
        }
        reflect->ClearField(tmpmsg, field);
    }
    string fieldsquery;
    pbjson::pb2json(tmpmsg, fieldsquery);
    delete tmpmsg;
    requpdate.set_q(fieldsquery);
    return _mongoproxy_cmd(MONGO_OP_UPDATE, msg, true, &requpdate, cb_data, cb_size);
}
开发者ID:jj4jj,项目名称:dcpots,代码行数:25,代码来源:mongoproxy_api.cpp


示例7: getValueFilepath

void PersistentData::getValueFilepath(const QString& filepath, google::protobuf::Message& data, Global::DataFolderType dataFolderType, bool humanReadable)
try
{
   QFile file(filepath);
   if (!file.open(QIODevice::ReadOnly))
      throw UnknownValueException();

#if !DEBUG
   if (humanReadable)
   {
#endif
      google::protobuf::io::FileInputStream fileStream(file.handle());
      google::protobuf::TextFormat::Parse(&fileStream, &data);
#if !DEBUG
   }
   else
   {
      data.ParsePartialFromFileDescriptor(file.handle());
   }
#endif
}
catch(Global::UnableToGetFolder& e)
{
   throw PersistentDataIOException(e.errorMessage);
}
开发者ID:PowerKiKi,项目名称:D-LAN,代码行数:25,代码来源:PersistentData.cpp


示例8: ZlibCompress

bool ZlibCompress(const google::protobuf::Message& res, butil::IOBuf* buf) {
    butil::IOBufAsZeroCopyOutputStream wrapper(buf);
    google::protobuf::io::GzipOutputStream::Options zlib_opt;
    zlib_opt.format = google::protobuf::io::GzipOutputStream::ZLIB;
    google::protobuf::io::GzipOutputStream zlib(&wrapper, zlib_opt);
    return res.SerializeToZeroCopyStream(&zlib) && zlib.Close();
}
开发者ID:abners,项目名称:brpc,代码行数:7,代码来源:gzip_compress.cpp


示例9: Send

void NetworkClient::Send(int packetID, const google::protobuf::Message& msg)
{
	int msgSize = msg.ByteSize();
	int bufferSize = Packet::Header::Size + msgSize;

	Packet::Header header;
	header.packetID = packetID;
	header.length = msgSize;

	auto buffer = std::unique_ptr<char[]>(new char[bufferSize]);
	header.Serialize(buffer.get());

	msg.SerializeToArray(buffer.get() + Packet::Header::Size, msgSize);

	conn->Send(bufferSize, buffer.get());
}
开发者ID:skyser2003,项目名称:SWMaestro_1st_Assignment,代码行数:16,代码来源:NetworkClient.cpp


示例10: SendMsgPB

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;
}
开发者ID:ketoo,项目名称:NoahGameFrame,代码行数:31,代码来源:NFNetModule.cpp


示例11: SendMsgPBToAllClient

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);
}
开发者ID:ketoo,项目名称:NoahGameFrame,代码行数:26,代码来源:NFNetModule.cpp


示例12: write_message

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();
}
开发者ID:burundiocibu,项目名称:bling,代码行数:29,代码来源:pb_helpers.cpp


示例13: writeMessageToBuffer

int UDPListener::writeMessageToBuffer(Common::MessageHeader::MessageType type, const google::protobuf::Message& message)
{
   const int bodySize = message.ByteSize();
   Common::MessageHeader header(type, bodySize, this->peerManager->getID());

   if (Common::MessageHeader::HEADER_SIZE + bodySize > static_cast<int>(SETTINGS.get<quint32>("max_udp_datagram_size")))
   {
      L_ERRO(QString("Datagram size too big : %1").arg(Common::MessageHeader::HEADER_SIZE + bodySize));
      return 0;
   }

   Common::MessageHeader::writeHeader(this->buffer, header);
   message.SerializeToArray(this->bodyBuffer, BUFFER_SIZE - Common::MessageHeader::HEADER_SIZE);

   return Common::MessageHeader::HEADER_SIZE + bodySize;
}
开发者ID:Zorvalt,项目名称:D-LAN,代码行数:16,代码来源:UDPListener.cpp


示例14: the

/**
This function gets the (assumed to be set) integer field's value from the message and casts it to a int64_t value.
@param inputMessage: The message to retrieve the integer from
@param inputField: The specific field to retrieve it from

@throw: This function can throw exceptions
*/
int64_t pylongps::getIntegerFieldValue(const google::protobuf::Message &inputMessage, const google::protobuf::FieldDescriptor *inputField)
{
const google::protobuf::Reflection *messageReflection = inputMessage.GetReflection();

int64_t value = 0;

switch(inputField->cpp_type())
{
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
value = messageReflection->GetInt32(inputMessage, inputField);
break;
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
value = messageReflection->GetInt64(inputMessage, inputField);
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
value = messageReflection->GetUInt32(inputMessage, inputField);
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
value = messageReflection->GetUInt64(inputMessage, inputField);
break;
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
value = messageReflection->GetEnum(inputMessage, inputField)->number();
break;

default:
throw SOMException("Non-integer data type\n", INVALID_FUNCTION_INPUT, __FILE__, __LINE__);
break;
}

return value;
}
开发者ID:NosDE,项目名称:pylonGPS,代码行数:38,代码来源:utilityFunctions.cpp


示例15: field

/**
This function binds the value of a protobuf field to a SQLite statement according to the type of the field (can only be a primative type).
@param inputStatement: The statement to bind the field value to
@param inputSQLStatementIndex: The index of the statement field to bind
@param inputMessage: The message to get the value from
@param inputField: The field (from the message) to get the value from

@throw: This function can throw exceptions
*/
void pylongps::bindFieldValueToStatement(sqlite3_stmt &inputStatement, uint32_t inputSQLStatementIndex, const google::protobuf::Message &inputMessage, const google::protobuf::FieldDescriptor *inputField)
{
const google::protobuf::Reflection *messageReflection = inputMessage.GetReflection();

int returnValue = 0;

if(messageReflection->HasField(inputMessage, inputField) == true)
{
switch(inputField->cpp_type())
{
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetInt32(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetInt64(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetUInt32(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetUInt64(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
returnValue = sqlite3_bind_double(&inputStatement, inputSQLStatementIndex, messageReflection->GetDouble(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
returnValue = sqlite3_bind_double(&inputStatement, inputSQLStatementIndex, messageReflection->GetDouble(inputMessage, inputField));
break;
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetBool(inputMessage, inputField));
break;

case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
returnValue = sqlite3_bind_int64(&inputStatement, inputSQLStatementIndex, messageReflection->GetEnum(inputMessage, inputField)->number());
break;

case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
{
std::string buffer;
buffer = messageReflection->GetStringReference(inputMessage, inputField, &buffer);
returnValue = sqlite3_bind_blob64(&inputStatement, inputSQLStatementIndex, (const void*) buffer.c_str(), buffer.size(), SQLITE_TRANSIENT);
}
break;

default:
throw SOMException("Unrecognized data type\n", AN_ASSUMPTION_WAS_VIOLATED_ERROR, __FILE__, __LINE__);
break;
}
}
else
{ //Its a optional field that is not set, so store a NULL value
returnValue = sqlite3_bind_null(&inputStatement, inputSQLStatementIndex);
}

if(returnValue != SQLITE_OK)
{
throw SOMException("Database error occurred (" + std::to_string(returnValue)+ ")\n", SQLITE3_ERROR, __FILE__, __LINE__);
}
}
开发者ID:NosDE,项目名称:pylonGPS,代码行数:68,代码来源:utilityFunctions.cpp


示例16: SendMessageToClient

void CGroupManagerClient::SendMessageToClient(const ::google::protobuf::Message &msg, s32 msgid)
{
    int count = msg.ByteSize();
    byte buf[MAX_MSG_LEN] = {0};
    *((s32*)buf) = msgid;
    if( msg.SerializeToArray(buf+MSG_ID_LEN, MAX_MSG_LEN) )
    {
        if( !SendPkg( buf, count+MSG_ID_LEN ) )
        {
            SERVER_LOG_ERROR( "CGroupManagerClient,SendMessageToGroupServer,SendPkg" );
        }
    }
    else
    {
        SERVER_LOG_ERROR( "CGroupManagerClient,SendMessageToGroupServer,SerializeToArray" );
    }
}
开发者ID:mjssw,项目名称:myproj,代码行数:17,代码来源:GroupManagerClient.cpp


示例17: SendMessage

/*
 * 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));
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:12,代码来源:OlaConfigurator.cpp


示例18: send

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;
}
开发者ID:tigerinsky,项目名称:push,代码行数:18,代码来源:communication.cpp


示例19: writeMessageToBuffer

/**
  * Writes a given protobuff message to the buffer (this->buffer) prefixed by a header.
  * @return the total size (header size + message size). Return 0 if the total size is bigger than 'Protos.Core.Settings.max_udp_datagram_size'.
  */
int UDPListener::writeMessageToBuffer(Common::MessageHeader::MessageType type, const google::protobuf::Message& message)
{
   const Common::MessageHeader header(type, message.ByteSize(), this->getOwnID());

   const int nbBytesWritten = Common::Message::writeMessageToBuffer(this->buffer, this->MAX_UDP_DATAGRAM_PAYLOAD_SIZE, header, &message);
   if (!nbBytesWritten)
      L_ERRO(QString("Datagram size too big: %1, max allowed: %2").arg(Common::MessageHeader::HEADER_SIZE + header.getSize()).arg(this->MAX_UDP_DATAGRAM_PAYLOAD_SIZE));

   return nbBytesWritten;
}
开发者ID:hmartinet,项目名称:D-LAN,代码行数:14,代码来源:UDPListener.cpp


示例20: decode_delimited

 void decode_delimited(pb::Message& message, const std::string& data) {
   pb::io::CodedInputStream stream((pb::uint8*)&data[0], data.size());
   pb::uint64 length;
   if (!stream.ReadVarint64(&length))
     throw DecodeFailed("Failed to decode delimited message (length)");
   if (!message.ParseFromCodedStream(&stream))
     throw DecodeFailed("Failed to decode delimited message");
   if (!stream.ExpectAtEnd())
     throw DecodeFailed("Failed to decode delimited message (did not consume entire buffer)");
 }
开发者ID:Kerbal007,项目名称:krpc,代码行数:10,代码来源:decoder.cpp



注:本文中的google::protobuf::Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ io::Printer类代码示例发布时间:2022-05-31
下一篇:
C++ google::dense_hash_map类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap