On Thu, 14 Oct 2010 21:42:04 +0400, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:
With generic element type:
interface InputBinaryTransport(T) : TransportBase
if (!hasPointers!T && !is(T == class))
{
/// Reads up to target.length items into target,
/// returns number of items read. If target.length < 1 throws.
size_t read(T[] target);
/// Appends to target up until delimiter is found or end of stream.
/// The delimiter is included in the target. Returns number
/// of items read.
size_t appendDelim(ref T[] target, in T[] delimiter);
}
The rest of the transport interfaces stays the same.
Andrei
This interface requires buffering and thus needs to be built on top of the
lower-level stream interface because Stream shouldn't do buffering
internally.
But anyway, why would you need to read exactly one type of data from a
stream? Why can't "read" be a template? Why does InputBinaryTransport have
to be an interface and not a concrete implementation? It can be
implemented uniformally on top of a generic stream.