Streaming transport interfaces: input
anon
foo at bar.com
Thu Oct 14 10:15:24 PDT 2010
Andrei Alexandrescu Wrote:
> Starting a new thread from Denis' question:
>
> > Can we outline basic Stream interface now so that we could move on?
>
> Here's the input transport layer. Transport has no concern for
> formatting - it just moves stuff around.
>
> interface TransportBase
> {
> /// True if stream has no more data.
> @property bool empty();
> /// True if the position property works
> @property bool positionable();
> /// Gives current position in stream
> @property ulong position();
> /// Moves stream to absolute position pos
> @property void position(ulong pos);
> }
>
> interface InputBinaryTransport : TransportBase
> {
> /// Reads up to target.length bytes into target,
> /// returns size of data read. If target.length < 1 throws.
> size_t read(ubyte[] target);
> /// Appends to target up until delimiter is found or end of stream.
> /// The delimiter is included in the target. Returns number
> /// of bytes read.
> size_t appendDelim(ref ubyte[] target, in ubyte[] delimiter);
> }
>
> interface InputTextTransport : TransportBase
> {
> /// Returns the native character size: 1 for UTF-8, 2 for UTF-16,
> /// 4 for UTF-32, 0 for nonstandard native encodings.
> @property size_t nativeUTFWidth();
>
> /// Reads complete UTF code points into target, without going
> /// beyond target.length. Returns number of code units read.
> /// If target.length < 4 throws.
> size_t read(char[] target);
> /// Appends to target up until delimiter is found or end of stream.
> /// The delimiter is included in the target. Returns number of
> /// code units read.
> size_t appendDelim(ref char[] target, in char[] delimiter);
>
> /// Reads complete UTF code points into target, without going
> /// beyond target.length. Returns number of code units read.
> /// If target.length < 2 throws.
> size_t read(wchar[] target);
> /// Appends to target up until delimiter is found or end of stream.
> /// The delimiter is included in the target. Returns number of
> /// code units read.
> size_t appendDelim(ref wchar[] target, in wchar[] delimiter);
>
> /// Reads complete UTF code points into target, without going
> /// beyond target.length. Returns number of code units read.
> /// If target.length < 1 throws.
> size_t read(dchar[] target);
> /// Appends to target up until delimiter is found or end of stream.
> /// The delimiter is included in the target. Returns number of
> /// code units read.
> size_t appendDelim(ref dchar[] target, in dchar[] delimiter);
> }
>
> Please destroy.
>
>
> Andrei
I can't understand why we need binary vs. text modes. Seems to me a silly design decision from the old days when we used 7-bit terminals or something. This always complicates the APIs for no reason.
I'd like to see a two layer design:
- lower UNTYPED layer that deals with transporting bits and bytes and deals with lower level concerns like byte order.
- higher level extend-able TYPED layer with formatters/encoders.
Also, the higher level should be compose-able such that I could read from a gzipped xml utf8 file
More information about the Digitalmars-d
mailing list