parsing error when sending double from android to php with hessian

253 views Asked by At

I want to send a double value from my android client to the PHP server using hessian but either the writeDouble function on the client or the parseDouble function on the server has an error. (We transmit many different data types correctly, only the double give us trouble :))

The double values are longitude and latitude for example:

sent from android client: 14,30485725402832

received at server: 1.0474191691834E-321

android encoding:

public void writeDouble(double value) throws IOException
{
   long bits = Double.doubleToLongBits(value);

   os.write('D');
   os.write((byte) (bits >> 56));
   os.write((byte) (bits >> 48));
   os.write((byte) (bits >> 40));
   os.write((byte) (bits >> 32));
   os.write((byte) (bits >> 24));
   os.write((byte) (bits >> 16));
   os.write((byte) (bits >> 8));
   os.write((byte) (bits));
}

php decoding:

function parseDouble($code, $num){
            $bytes = $this->read(8);
            if(HessianUtils::$littleEndian)
                    $bytes = strrev($bytes);
            $double = unpack("dflt", $bytes);
    return $double['flt'];
    }

btw: we also have an iPhone client send the double - works fine ...

iphone encoding:

(void)encodeDouble:(double)realv forKey:(NSString*)key;
{
   if (key) [self writeTypedObject:key];
   [self writeChar:'D'];
   [self writeInt64:(int64_t)(*((double*)(&realv)))];
}
1

There are 1 answers

2
Russell Zahniser On BEST ANSWER

Given that iOS is little-endian, I think you want to encode your double in the opposite order in the Java code.