[Spread-users] byte-order/endiness for payload

John Lane Schultz jschultz at spreadconcepts.com
Mon May 11 22:07:50 EDT 2009


If your platforms do use the same internal representation for floating
points, which is fairly likely in reality, then I believe an in-place
re-ordering of bytes to get the right endianness will serve your needs.
Spread provides you with some info on whether or not the endianness differs
between sender and receiver if you'd rather conditionally endian flip
between big and little endianness (I don't think that other weirder
endiannesses are really supported by Spread).

Another way you could do it would be to explicitly deconstruct the float
into its sign bit, the biased exponent, the significand/mantissa, send them
as integers and then reconstruct the floating point representation on your
target platform from those integers.

http://en.wikipedia.org/wiki/IEEE_754
http://en.wikipedia.org/wiki/IEEE_754-1985

If the platforms truly do internally represent floating point numbers
differently, then it is highly likely that you won't get a "perfect"
transmission of the data in all cases.  I don't know if your application
cares about that or if close enough is good enough.  Also, knowing how each
of your various exotic platforms represents their floating points and then
converting between them could be quite complicated.  In such a case, if it
is truly important then I would depend on some external library to do this
for you as others have suggested.

Cheers!

---
John Lane Schultz
Spread Concepts LLC
Phn: 443 838 2200 

-----Original Message-----
From: spread-users-bounces at lists.spread.org
[mailto:spread-users-bounces at lists.spread.org] On Behalf Of Joseph VanAndel
Sent: Monday, May 11, 2009 8:02 PM
To: spread-users at lists.spread.org
Subject: [Spread-users] byte-order/endiness for payload

What techniques do spread users use to handle byte-order and alignment  
issues for messages sent via spread?

For example, if I'm sending a set of parameters

struct example {
     int param1;
     int param2;
     float f1;
     float f2;
};
from one computer to another computer with different byte order and/or  
alignment, I can't simply send the byte representation of the structure.

For integers, I could use the htohl() calls, but there is no standard  
implementation (that I know of) for network byte order for floats or  
doubles.  I could also use Sun's xdr or send the parameters using XML.

Any other suggestions?

_______________________________________________
Spread-users mailing list
Spread-users at lists.spread.org
http://lists.spread.org/mailman/listinfo/spread-users






More information about the Spread-users mailing list