技术解析
protobuf 消息里用 bytes 存的图片数据 但是在 Server 上拼回来的图片无法解析 没有丢包的情况,大小拼的是正确的 是 string 类型的原因吗?
void Combine()
{
vector temp = msgs;
msgs.clear();
ProtoHead head = temp.front().head();
int size = head.total_size();
cout << "char:" << size << endl;
char *result = new (std::nothrow) char[size];
int pos = 0;
int cnt = 0;
for (auto pack : temp)
{
cnt++;
int size = pack.body().data_size();
string temp = pack.body().data();
//memcpy(result + pos, &temp, size);
for (auto ele : temp)
result[pos++] = ele;
//pos += size;
//cout << cnt << " " << pos << endl;
pack.release_body();
pack.release_head();
}
ofstream fout(path_out.c_str(), ios::binary);
fout.write(result, sizeof(char) * size);
fout.close();
}