Reputation: 302
How can I read a uint from a connected socket directly without having to do any conversion.
Effectively, what is the D equivalent to read(sock, &four_byte_var, 4)
. I can't seem to convert a uint
to anything that the D standard library socket.receive(void[])
will accept.
Upvotes: 1
Views: 205
Reputation: 25187
You need to pass a slice that surrounds the variable:
uint n;
socket.receive((&n)[0..1]);
Note that this approach is endian-sensitive.
Upvotes: 3
Reputation: 6055
It's pretty easy with std.socketstream
:
auto stream = new SocketStream(socket);
uint foo;
stream.read(foo);
Note: the std.stream
and std.socketstream
modules will be replaced by a new interface (well, that might take a while).
Upvotes: 1