1

I'm deserializing a stream of binary Java data using x86 VC++ (constraints imposed by project specification) and am having a devil of a time correctly parsing the value of a serialzed double.

Assumptions:

  • That a Java double is best represented by a VC++ x86 long double.

What I've tried:

  • Straight deserialization and byteswapped deserialization. Neither return the correct value. (Able to deserialize integers fine once they're byteswapped big-endian to little-endian.)
  • The Java serialization docs were no help.

What I fear:

  • That the exponent and mantessa are each byte-swapped somehow.

Thanks in advance for the help.

Ken

kseier
  • 55
  • 6
  • An x86 double is probably a better choice than a long double. – Tavian Barnes Aug 30 '13 at 17:31
  • Have you tried manually comparing the bytes in Java and C++ representations of sample numbers? Java's using IEEE 754 internally, so it should map reasonably cleanly, and tends to use network byte order for communications (including serialization). Also, are you sure that you're reading the `double` contents and not stepping across bounds to hit the `BLOCKDATA` descriptors? – chrylis -cautiouslyoptimistic- Aug 30 '13 at 17:34
  • @chrylis - Working on bit comparison now. Both platforms subscribe to IEEE754, but obviously there's something that doesn't line up. I'm sure I'm not running into BOCKDATA: retrieving data before and after double fields works fine. – kseier Aug 30 '13 at 17:57
  • @Tavian Barnes - What's your rationale for the x86 double. Wouldn't that lead to a loss of precision? In any event, I'm receiving the data as a x64 double, so I still need to be able to parse it from that format. – kseier Aug 30 '13 at 17:58

1 Answers1

0

The answer is that it's a simple byteswap. However using the built in C++ _byteswap functions performas an implicit cast to a unsigned integer, which mangles the data in the double.

Using one of the byteswap solutions from How to byteswap a double? did the trick.

Community
  • 1
  • 1
kseier
  • 55
  • 6