Buffered Endian Stream Socket?

Kyle Mallory jesuswasirish at gmail.com
Tue Apr 6 18:36:33 PDT 2010


I'm trying to write a series of structs to a stream, which then has to 
be sent over the wire within a single TCP packet, in order for the host, 
an embedded device, to recognize the message.  If there is too little, 
or too much data for a given "command" (packet), the device will throw 
out the entire packet.  Ie, one packet must contain one complete message.

In all of my messages, the first 23 bytes are a common header.  I'm 
playing with having this header be a separate struct, apart from the 
subsequent payload struct.  This will allow me to do simple things like 
(in pseudo-d-code):

	msg.foo = 1234;
	msg.bar = "DMDD";
	hdr.datalen = Payload.sizeof;

	packet.write((&hdr)[0..1]);
	packet.write((&msg)[0..1]);
	socket.send(packet);

Since this is network data originating from various platforms, I also 
need to handle endian issues.

There are a few problems I'm running into with all of this:

I can't find a way to load data into a SocketStream without also issuing 
a Socket.send().  I considered a BufferedStream, or a MemoryStream but 
its not clear if/or how I would go about issuing an explicate send.  Is 
there a preferred way to do this that I'm missing?

Is is possible (or reasonable) to pass in arbitrary structs into 
EndianStream and expect that it will intelligently convert each type in 
the struct?


More information about the Digitalmars-d-learn mailing list