Search code examples
javac#doublemqtttransmission

C# - double-Value transmitted to Java client via byte[]


I am transmitting a double value from a C#-mqtt client to a Java-mqtt client. Mqtt requires its payload to be a byte[] so I in c# I am doing the following:

byte[] vals = BitConverter.GetBytes(sub.value); // c#-sender

and transmitting this over mqtt to a java client, which in turn

double result = ByteBuffer.wrap(vals).getDouble(); // java-receiver

However, while the original double-value is in the range of ~1 to 10, the resulting java value is in the range of 10^-311 to 10^-312.

I am not very familiar with c# at this point and can't find the problem.

Is it an offset problem? LE/BE ? I am pretty much stuck and would love if you could give me a hint.


Solution

  • As mentioned in the comments, try flipping the byte order on the ByteBuffer using the ByteBuffer.order(ByteOrder) method