Protobuf 图片传输完 无法解析是咋回事?

2019-05-19 23:19:43 +08:00
 NJTechhemengjie

protobuf 消息里用 bytes 存的图片数据 但是在 Server 上拼回来的图片无法解析 没有丢包的情况,大小拼的是正确的 是 string 类型的原因吗?

void Combine()
{
    vector<ProtoMsg> 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();
}

3568 次点击
所在节点    Linux
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/565634

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX