[phobos] Improvement of stream
Andrei Alexandrescu
andrei at erdani.com
Sat Sep 4 23:31:22 PDT 2010
On 07/06/2010 05:35 AM, Shin Fujishiro wrote:
> Can handles (optionally or necessarily) have low-level I/O primitives
> like rawRead() and rawWrite()?
>
> class SomeHandle
> {
> void open();
> void close();
> ByChunk byChunk(size_t n);
> ByChar byChar();
>
> size_t rawRead(ubyte[] buffer); // low-level input primitive
> }
I think that's fine.
> byChunk etc. would suffice for usual purposes. But sometimes we want
> to read some user-defined structure from a handle. With the rawRead
> primitive, I can create my own input range for reading a sequence of
> variable-length packets from a handle:
>
> ByPacket byPacket(SomeHandle handle);
>
> // This input range uses rawRead() for reading Packets.
> struct ByPacket
> {
> @property bool empty();
> @property Packet front();
> void popFront();
> }
> struct Packet
> {
> uint signature;
> ubyte[] content;
> uint checksum;
> }
Agreed.
Andrei
More information about the phobos
mailing list