I suspect the question was asked somewhere before.
If so just give a link.
Anyway:
class IoContext {
...
ubyte[] buf;
...
this(uint bufSize) {
buf = new ubyte[bufSize];
}
}
The buffer contains (ascii) string terminated with '\n'.
In order to print it not as an array of numbers (buf is 1024 bytes long),
but as usual string I do
char[] s = cast(char[])ioCtx.buf[0 .. strlen(cast(char*)ioCtx.buf.ptr) - 1];
// -1 is to eliminate terminating '\n'
writefln("got '%s' from '%s:%d'", s, client.addr, client.port);
Is there some more concise/elegant way to do that?
Of course, I could use old good printf() instead:
printf(
"got '%s' from '%s:%d'\n",
ioCtx.buf.ptr, // '\n' still there
toStringz(client.addr),
client.port
);
but I want to use D stdlib, not libc.