【问题标题】:Using boost::archive with boost::iostreams to compress data使用 boost::archive 和 boost::iostreams 来压缩数据
【发布时间】:2011-08-05 02:32:08
【问题描述】:

我想为一个可以选择压缩数据的类编写一个序列化函数。我想使用 boost::iostreams 中提供的压缩工具。有谁知道怎么做?

struct X
{
    X() {}

    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & compression;
        if(compression == 0)
        {
            ar & data;
        }
        else if(compression == 1)
        {
            // use boost::iostream compression
            // facilities to serialize data
        }
    }

    int compression;
    std::vector<int> data;
};

【问题讨论】:

    标签: c++ serialization boost compression


    【解决方案1】:

    我能看到的唯一方法是先压缩数据,然后使用 ar.load_binary 和 ar.save_binary。要压缩数据,您可以使用带有 std::ostringstream 作为接收器的过滤流和适当的压缩过滤器。

    您不希望将压缩推入堆栈(即,在压缩流上构建存档)的任何原因?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多