是否可以将boost :: iostreams用于更复杂/结构化的类型?
我想要做的是流图像,但它们应该有一些注释,如宽度,高度,颜色深度......我的第一个想法是使用结构而不是char或wchar
namespace io = boost::iostreams;
struct SingleImageStream{
unsigned int width;
unsigned int height;
unsigned char colordepth;
unsigned char* frame;
};
class SingleImageSource {
public:
typedef struct SingleImageStream char_type;
typedef io::source_tag category;
std::streamsize read(struct SingleImageStream* s, std::streamsize n)
{
char* frame = new char[640*480];
std::fill( frame, frame + sizeof( frame ), 0 );
s->width = 640;
s->height = 480;
std::copy(frame, frame + sizeof(frame), s->frame);
return -1;
}
};
class SingleImageSink {
public:
typedef struct SingleImageStream char_type;
typedef io::sink_tag category;
std::streamsize write(const struct SingleImageStream* s, std::streamsize n)
{
std::cout << "Frame width : " << s->width << " frame height : " << s->height << std::endl;
return n;
}
};
我现在的问题是如何连接源和接收器?
THX
答案 0 :(得分:1)
Boost.Iostreams似乎是这里工作的错误工具。
源和接收机制的目标是允许您指定数据被序列化到的位置 - 例如,您是要写入文件,内存中的位置还是i / o端口。
您要指定的是如何序列化某种数据。 Boost中的正确工具是Boost.Serialization。