On Fri, 31 Dec 2010 03:28:12 -0500, Daniel Gibson <metalcae...@gmail.com> wrote:

Am 30.12.2010 23:17, schrieb Andrei Alexandrescu:
On 12/30/10 3:59 PM, Dmitry Olshansky wrote:
On 28.12.2010 16:08, Daniel Gibson wrote:
[snip]
## UnbufferedInputTransport:

I'd like "void readFully(ubyte[] buffer)" which reads buffer.length
bytes or throws an exception if that is not possible
This would also fix busy-waiting (it'd block until buffer.length bytes
are available).

Also "size_t read(void* buffer, size_t length)" (and the same for
readFully()) would be nice, so one can read from the stream to buffers
of arbitrary type without too much casting. Is probably especially
handy when used with (data from) extern(C) functions and such.

Also, for convenience: "ubyte[] read(size_t length)" (does something
like "return read(new ubyte[length]);"
and "ubyte[] readFully(size_t length)"

This, I guess, would be provided by free functions in the same module,
there is no point in requiring to implement them inside the stream
itself.

## UnbufferedOutputTransport:

I'd like "void write(void *buffer, size_t length)" - for the same
reason as read(void* buffer, size_t length).

Ditto

What's wrong with void[]?

Andrei

For example:

void put(int i) {
        write(&i, int.sizeof);
}

is shorter and easier than

void put(int i) {
        void *tmp = cast(void*)(&i);
        void[] arr = tmp[0..int.sizeof];
        write(arr);
}

This can be significantly shortened:

write((&i)[0..1]);

Remember, all arrays implicitly cast to void[], which is why you use it for input parameters.

-Steve

Reply via email to