RejectedSoftware Forums

Sign up

Vibe.d write question

How can i write hex decimals to stream ?

i have code like this :

import vibe.d;
import std.stdio;

void run(TCPConnection conn)
{

conn.write(0x00);
conn.write(0x00);
conn.write(0x00);

}

shared static this()
{

listenTCP(3724, (conn) => run(conn));

}

thhis will give me an error, no write's callable with arguments

Re: Vibe.d write question

On Wed, 19 Nov 2014 20:34:26 GMT, Jan wrote:

How can i write hex decimals to stream ?

i have code like this :

import vibe.d;
import std.stdio;

void run(TCPConnection conn)
{

conn.write(0x00);
conn.write(0x00);
conn.write(0x00);

}

shared static this()
{

listenTCP(3724, (conn) => run(conn));

}

thhis will give me an error, no write's callable with arguments

Hi,
write defined as void write(in ubyte[] bytes);. So you can try conn.write(conn.write(cast(ubyte[])[0x00, 0x00, 0x00]).

Re: Vibe.d write question

Typo.

conn.write(cast(ubyte[])[0x00, 0x00, 0x00]);

Re: Vibe.d write question

Am 20.11.2014 08:28, schrieb akaDemik:

Typo.

conn.write(cast(ubyte[])[0x00, 0x00, 0x00]);

To improve performance, and to be able to use D's generic range
functionality, I'd also recommend to wrap the connection into a
vibe.stream.wrapper.StreamOutputRange:

auto rng = StreamOutputRange(conn);
rng.put(0x00);
rng.put(0x00);
rng.put(0x00);

This will create a small buffer that will be flushed when full, when
rng.flush() is explicitly called, or when it goes out of scope.