V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
NJTechhemengjie
V2EX  ›  Linux

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

  •  
  •   NJTechhemengjie · 2019-05-19 23:19:43 +08:00 · 3559 次点击
    这是一个创建于 1808 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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();
    }
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1845 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:27 · PVG 08:27 · LAX 17:27 · JFK 20:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.