activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rousseau <>
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.

View this message in context:
Sent from the ActiveMQ - Dev mailing list archive at

View raw message