Exemplo n.º 1
0
        public static int WriteFixFloat64(Span <byte> buffer, double value)
        {
            var binary = new DoubleBinary(value);

            if (BitConverter.IsLittleEndian)
            {
                buffer[8] = binary.Byte0;
                buffer[7] = binary.Byte1;
                buffer[6] = binary.Byte2;
                buffer[5] = binary.Byte3;
                buffer[4] = binary.Byte4;
                buffer[3] = binary.Byte5;
                buffer[2] = binary.Byte6;
                buffer[1] = binary.Byte7;
            }
            else
            {
                buffer[8] = binary.Byte7;
                buffer[7] = binary.Byte6;
                buffer[6] = binary.Byte5;
                buffer[5] = binary.Byte4;
                buffer[4] = binary.Byte3;
                buffer[3] = binary.Byte2;
                buffer[2] = binary.Byte1;
                buffer[1] = binary.Byte0;
            }
            buffer[0] = DataCodes.Float64;

            return(DataLengths.Float64);
        }
Exemplo n.º 2
0
        public void Write(double value, IMsgPackWriter writer, MsgPackContext context)
        {
            var binary = new DoubleBinary(value);

            writer.Write(DataTypes.Double);
            if (BitConverter.IsLittleEndian)
            {
                writer.Write(binary.byte7);
                writer.Write(binary.byte6);
                writer.Write(binary.byte5);
                writer.Write(binary.byte4);
                writer.Write(binary.byte3);
                writer.Write(binary.byte2);
                writer.Write(binary.byte1);
                writer.Write(binary.byte0);
            }
            else
            {
                writer.Write(binary.byte0);
                writer.Write(binary.byte1);
                writer.Write(binary.byte2);
                writer.Write(binary.byte3);
                writer.Write(binary.byte4);
                writer.Write(binary.byte5);
                writer.Write(binary.byte6);
                writer.Write(binary.byte7);
            }
        }
Exemplo n.º 3
0
 public static bool TryReadFixFloat64(ReadOnlySpan <byte> buffer, out double value, out int readSize)
 {
     readSize = DataLengths.Float64;
     value    = default;
     if (buffer.Length < readSize)
     {
         return(false);
     }
     if (buffer[0] != DataCodes.Float64)
     {
         return(false);
     }
     value = new DoubleBinary(buffer.Slice(1, 8)).Value;
     return(true);
 }
Exemplo n.º 4
0
        public void Write(double value, IMsgPackWriter writer)
        {
            var binary = new DoubleBinary(value);

            byte[] bytes;
            if (BitConverter.IsLittleEndian)
            {
                bytes = new[]
                {
                    (byte)DataTypes.Double,
                    binary.byte7,
                    binary.byte6,
                    binary.byte5,
                    binary.byte4,
                    binary.byte3,
                    binary.byte2,
                    binary.byte1,
                    binary.byte0
                };
            }
            else
            {
                bytes = new[]
                {
                    (byte)DataTypes.Double,
                    binary.byte0,
                    binary.byte1,
                    binary.byte2,
                    binary.byte3,
                    binary.byte4,
                    binary.byte5,
                    binary.byte6,
                    binary.byte7
                };
            }

            writer.Write(bytes);
        }
Exemplo n.º 5
0
 public static string GetBinaryIEEE754(this double number)
 => DoubleBinary.GetBinaryIEEE754(number);