Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ protobuf:如何将GZipOutputStream与CodedOutputStream一起使用?_C++_Sockets_Protocol Buffers - Fatal编程技术网

C++ protobuf:如何将GZipOutputStream与CodedOutputStream一起使用?

C++ protobuf:如何将GZipOutputStream与CodedOutputStream一起使用?,c++,sockets,protocol-buffers,C++,Sockets,Protocol Buffers,对于通过套接字传输数据,我使用下面的“sendData”方法。由于数据量可能非常大(约250000-500000字节),我想使用GZipOutputStream来压缩protobuf消息。我面临的问题是,我无法获得压缩消息的大小来预处理它 如何将GZipOutputStream与CodedOutputStream结合使用 void CommIF::sendData(FVMsg message, vector<int> clients) { google::protobuf:

对于通过套接字传输数据,我使用下面的“sendData”方法。由于数据量可能非常大(约250000-500000字节),我想使用GZipOutputStream来压缩protobuf消息。我面临的问题是,我无法获得压缩消息的大小来预处理它

如何将GZipOutputStream与CodedOutputStream结合使用

void CommIF::sendData(FVMsg message, vector<int> clients)
{   
  google::protobuf::uint32 message_length = message.ByteSize();
  int prefix_length = sizeof(message_length);
  int buffer_length = prefix_length + message_length;
  google::protobuf::uint8 buffer[buffer_length];

  google::protobuf::io::ArrayOutputStream array_output(buffer, buffer_length);
  google::protobuf::io::CodedOutputStream coded_output(&array_output);

  coded_output.WriteLittleEndian32(message_length);
  message.SerializeToCodedStream(&coded_output);

  for (vector<int>::iterator it = clients.begin(); it!=clients.end(); ++it) {
    int client = *it;
    int sent_bytes = write(client, buffer, buffer_length);
    if (sent_bytes != buffer_length) {
      ERROR_LOG("problems sending . Only sent " << sent_bytes << " bytes");
    }
    else
    {
      DBG_LOG("Successfully sent " << sent_bytes << " bytes");
    }
  }
}
void CommIF::sendData(FVMsg消息、向量客户端)
{   
google::protobuf::uint32 message_length=message.ByteSize();
int prefix_length=sizeof(消息长度);
int buffer长度=前缀长度+消息长度;
google::protobuf::uint8缓冲区[缓冲区长度];
google::protobuf::io::ArrayOutputStream数组_输出(缓冲区,缓冲区长度);
google::protobuf::io::CodeDoutput流编码的\u输出(&数组\u输出);
编码输出。WriteliteLendian32(消息长度);
message.SerializeToCodedStream(&coded_输出);
对于(vector::iterator it=clients.begin();it!=clients.end();++it){
int client=*it;
int sent_bytes=写入(客户端、缓冲区、缓冲区长度);
if(已发送字节数!=缓冲区长度){
错误日志(“发送问题。仅发送”