deprecating std.stream, std.cstream, std.socketstream

Christophe Travert travert at phare.normalesup.org
Wed May 16 07:03:42 PDT 2012


"Steven Schveighoffer" , dans le message (digitalmars.D:167548), a
> My new design supports this.  I have a function called readUntil:
> 
> https://github.com/schveiguy/phobos/blob/new-io2/std/io.d#L832
> 
> Essentially, it reads into its buffer until the condition is satisfied.   
> Therefore, you are not double buffering.  The return value is a slice of  
> the buffer.
> 
> There is a way to opt-out of reading any data if you determine you cannot  
> do a full read.  Just return 0 from the delegate.

Maybe I already told this some time ago, but I am not very comfortable 
with this design. The process delegate has to maintain an internal 
state, if you want to avoid reading everything again. It will be 
difficult to implement those process delegates. Do you have an example 
of moderately complicated reading process to show us it is not too 
complicated?

To avoid this issue, the design could be reversed: A method that would 
like to read a certain amount of character could take a delegate from 
the stream, which provides additionnal bytes of data.

Example:
// create a T by reading from stream. returns true if the T was 
// successfully created, and false otherwise.
bool readFrom(const(ubyte)[] delegate(size_t consumed) stream, out T t);

The stream delegate returns a buffer of data to read from when called 
with consumed==0. It must return additionnal data when called 
repeatedly. When it is called with a consumed != 0, the corresponding 
amount of consumed bytes can be discared from the buffer.

This "stream" delegate (if should have a better name) should not be more 
difficult to implement than readUntil, but makes it more easy to use by 
the client. Did I miss some important information ?

-- 
Christophe


More information about the Digitalmars-d mailing list