是否可以将 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;
}
};
我现在的问题是如何连接源和接收器?
谢谢