Hello,
I`m coding a little library for InSim (programmable interface for Live for
Speed - an online racing simulator) and I`d have to send data in form of
structs to the server, but socket.send() does only permit void[]`s as data.
So how do I send structs? Or how can i convert them?
Regards,
Alex
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Hello,
I`m coding a little library for InSim (programmable interface for Live
for Speed - an online racing simulator) and I`d have to send data in
form of structs to the server, but socket.send() does only permit
void[]`s as data.
So how do I send structs? Or how can i convert them?

Of course, you have to consider Endian issues i.e. sending from a Big
Endian to a Little Endian machine will result in garbage, unless you
convert the endian-ness of the data.
The other option is to convert the struct into some textual representation
and transfer it that way, this uses more bandwidth, but is less
complicated.
Regan
On Wed, 15 Jun 2005 11:54:10 +1200, Regan Heath <regan netwin.co.nz> wrote:

Hello,
I`m coding a little library for InSim (programmable interface for Live
for Speed - an online racing simulator) and I`d have to send data in
form of structs to the server, but socket.send() does only permit
void[]`s as data.
So how do I send structs? Or how can i convert them?

Hello,
I`m coding a little library for InSim (programmable interface for Live
for Speed - an online racing simulator) and I`d have to send data in
form of structs to the server, but socket.send() does only permit
void[]`s as data.
So how do I send structs? Or how can i convert them?

Ok, that's neat.
So in the general case, can one 'cast' anything to a dynamic array of 'x'
using the format ...
(cast(x*)&q)[0..q.sizeof/x.sizeof]
so long as the q.sizeof was an integral multiple of x.sizeof
--
Derek
Melbourne, Australia
15/06/2005 10:13:29 AM

Hello,
I`m coding a little library for InSim (programmable interface for Live
for Speed - an online racing simulator) and I`d have to send data in
form of structs to the server, but socket.send() does only permit
void[]`s as data.
So how do I send structs? Or how can i convert them?

Ok, that's neat.
So in the general case, can one 'cast' anything to a dynamic array of 'x'
using the format ...
(cast(x*)&q)[0..q.sizeof/x.sizeof]
so long as the q.sizeof was an integral multiple of x.sizeof

Yeah, I believe so. Though consider/remember:
char[] a = "regan";
(cast(byte*)&a)[0..a.sizeof/byte.sizeof];
That would be incorrect. You'd need:
(cast(byte*)&a.ptr)[0..a.length];
Regan

Sadly, no, these attempts give these errors:
s.send(cast(void[])foo); //e2ir: cannot cast from oof to void[]
s.send(cast(void[])&foo); //cannot cast oof * to void[]
s.send(cast(void[])&foo[0..foo.sizeof]); //oof cannot be sliced with []
The reason the initial suggestion works is due to the "type X* can be
sliced to give X[]" rule. The other rule is "X[] is implicitly castable to
void[]"... If we combine these rules we get:
s.send((&foo)[0..foo.sizeof]);
Which works!
NOTE: The () are required around &foo, as the [] 'slice' operator has
higher precedence than the & 'address' operator.
Regan

Hello,
I`m coding a little library for InSim (programmable interface for Live for
Speed - an online racing simulator) and I`d have to send data in form of
structs to the server, but socket.send() does only permit void[]`s as data.
So how do I send structs? Or how can i convert them?