activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rousseau <steve.co...@excite.com>
Subject NMS byte order for doubles
Date Wed, 10 Jan 2007 08:41:34 GMT

I've found a byte-order problem sending a double from Java ActiveMQ to a
NMS/CSharp receiver:

(NMS) ActiveMQ.OpenWire.OpenWireBinaryReader has no definition for
ReadDouble(), and by default calls the MS .NET BinaryReader.ReadDouble()
which reads the bytes in the wrong order. Here is the fix:

add a new method to OpenWireBinaryReader.cs:

        public override double ReadDouble()
        {
            return EndianSupport.SwitchEndian(base.ReadBytes(8));
        }

add a new method to EndianSupport.cs:

        public static double SwitchEndian(byte[] bytes)
        {
            //Reverse byte array
            byte[] reverse = new byte[8];
            reverse[0] = bytes[7];
            reverse[1] = bytes[6];
            reverse[2] = bytes[5];
            reverse[3] = bytes[4];
            reverse[4] = bytes[3];
            reverse[5] = bytes[2];
            reverse[6] = bytes[1];
            reverse[7] = bytes[0];
            BinaryReader br = new BinaryReader(new MemoryStream(reverse));
            return br.ReadDouble();
        }

If anyone knows a cleaner way of doing this, please let me know.

thx
/Steve
-- 
View this message in context: http://www.nabble.com/NMS-byte-order-for-doubles-tf2951266.html#a8253895
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Mime
View raw message