I’m writing a .NET application that will make an RPC call to a Java application (via a message queue). The data sent in both directions will be large arrays of floating-point numbers. What is the best way to serialize them to send them across the wire? I’d like something more compact than text, but architecture-independent as the server may not be an x86 machine. The Java application can be changed as needed.
Share
Java numeric primitives actually are stored (in the JVM) and written (via
jnava.io.DataOutputStreamandjava.nio.ByteBuffer) in network order and the floating point values are IEEE standard. They are directly interchangeable with C#/.NET. Well, if .NET provided network byte order to read doubles (see below for code).So, you can send and receive any primitive using the two classes mentioned here (and the input counterparts) as long as the .NET side is reading/writing in network byte order as you should always use.
Java side for example:
C# side to retrieve the value:
For writing you do the opposite, C# has to write in network byte order.
And then on the Java side to read these back in:
The C#
IPAddressclass provides network byte order reading/writing methods for all primitives except double and float, but as in my example you can pass through through either a 32-bit or 64-bit int respectively.