OpenGATE Contents | GATE development concepts: Streams

Problem description

Unfortunately, the greatest feature of unix is not present in every C library and also not in the C standard: streams. C defines FILE structures, POSIX uses generic int descriptors and Windows offers its HANDLE infrastructure when data is transferred.

And each algorithm and encoding library provides its own API to read and write into their native buffers.

Solution

All generic data driven technologies shall provide one binary interface to read and write data byte blocks, named streams.

A stream interface object shall provide a read() method to fill an own buffer with data from the stream implementation, and it shall provide a write() method to append data to and internal buffer implementation.

Also encoders and decoders for different formats shall be covered by a stream interface. And building chains of stream objects will offer a new way of data management

Definition

A gate_stream_t stream interface inherits from gate_object_t to support reference-counting for its lifetime and type-identification. It extends the object interface with at least 4 methods:

If a stream does only support one of both transfer modes, it should return GATE_RESULT_NOTSUPPORTED from the other non-supported method. Input-only stream will only provide read(), while output-only stream will only respond to write().

Following auxiliary stream methods are defined too, but may also be implemented with GATE_RESULT_NOTSUPPORTED result code: