UnpackDouble() public static méthode

Unpacks System.Double value from the specified Stream.

The processed bytes count can be calculated via P:Stream.Position of source when the P:Stream.CanSeek is true.

When the type of packed value is not known, use UnpackObject(Stream) instead.

/// is null. /// /// The of is false. /// /// is not valid MessagePack stream. /// Note that the state of will be unpredictable espicially it is not seekable. /// /// The unpacked result in the is not compatible to . /// Note that the state of will be unpredictable espicially it is not seekable. ///
public static UnpackDouble ( Stream source ) : Double
source Stream The which contains Message Pack binary stream.
Résultat Double
Exemple #1
0
        public void TestUnpackDouble_ByteArray_DoubleMinValue_AsIs()
        {
            var result = Unpacking.UnpackDouble(new byte[] { 0xCB, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });

            Assert.AreEqual(sizeof(System.Double) + 1, result.ReadCount);
            Assert.IsTrue(Double.MinValue.Equals(result.Value));
        }
Exemple #2
0
        public void TestUnpackDouble_ByteArray_SingleMaxValue_AsIs()
        {
            var result = Unpacking.UnpackDouble(new byte[] { 0xCA, 0x7F, 0x7F, 0xFF, 0xFF });

            Assert.AreEqual(sizeof(System.Single) + 1, result.ReadCount);
            Assert.IsTrue((( double )Single.MaxValue).Equals(result.Value));
        }
Exemple #3
0
        public void TestUnpackDouble_ByteArray_SingleZero_AsIs()
        {
            var result = Unpacking.UnpackDouble(new byte[] { 0xCA, 0x00, 0x00, 0x00, 0x00 });

            Assert.AreEqual(sizeof(System.Single) + 1, result.ReadCount);
            Assert.IsTrue((0.0).Equals(result.Value));
        }
Exemple #4
0
        public void TestUnpackDoubleEpsilon_UnpackDouble_ByteArray()
        {
            var buffer = new byte[] { 0xCB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
            var result = Unpacking.UnpackDouble(buffer);

            Assert.That(result.ReadCount, Is.EqualTo(buffer.Length));
            Assert.That(Double.Epsilon.Equals(result.Value));
        }
Exemple #5
0
        public void TestUnpackDoublePositiveInfinity_UnpackDouble_ByteArray()
        {
            var buffer = new byte[] { 0xCB, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            var result = Unpacking.UnpackDouble(buffer);

            Assert.That(result.ReadCount, Is.EqualTo(buffer.Length));
            Assert.That(Double.IsPositiveInfinity(result.Value));
        }
Exemple #6
0
        public void TestUnpackDoubleNaNNegativeMaxValue_UnpackDouble_ByteArray()
        {
            var buffer = new byte[] { 0xCB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
            var result = Unpacking.UnpackDouble(buffer);

            Assert.That(result.ReadCount, Is.EqualTo(buffer.Length));
            Assert.That(Double.IsNaN(result.Value));
        }
Exemple #7
0
        public void TestUnpackDoubleNegativeZero_UnpackDouble_ByteArray()
        {
            var buffer = new byte[] { 0xCB, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            var result = Unpacking.UnpackDouble(buffer);

            Assert.That(result.ReadCount, Is.EqualTo(buffer.Length));
            Assert.That((-0.0).Equals(result.Value));
        }
Exemple #8
0
        public void TestUnpackDouble_ByteArray_Offset_OffsetIsValid_OffsetIsRespected()
        {
            // Offset 1 is Double 0.
            var result = Unpacking.UnpackDouble(new byte[] { 0xFF, 0xCB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, 1);

            Assert.AreEqual(sizeof(System.Double) + 1, result.ReadCount);
            Assert.AreEqual(0.0, result.Value);
        }
Exemple #9
0
        private static void TestDouble(Double value)
        {
            var output = new MemoryStream();

            Packer.Create(output).Pack(value);
            Assert.AreEqual(value, Unpacking.UnpackDouble(new MemoryStream(output.ToArray())), 10e-10);
            Assert.AreEqual(value, Unpacking.UnpackDouble(output.ToArray()).Value, 10e-10);
        }
Exemple #10
0
 public void TestUnpackDouble_Stream_DoubleMinValue_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCB, 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.AreEqual(sizeof(System.Double) + 1, buffer.Position);
         Assert.IsTrue(Double.MinValue.Equals(result));
     }
 }
Exemple #11
0
 public void TestUnpackDoublePositiveInfinity_UnpackDouble_Stream()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCB, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.That(buffer.Position, Is.EqualTo(buffer.Length));
         Assert.That(Double.IsPositiveInfinity(result));
     }
 }
Exemple #12
0
 public void TestUnpackDoubleNaNNegativeMaxValue_UnpackDouble_Stream()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.That(buffer.Position, Is.EqualTo(buffer.Length));
         Assert.That(Double.IsNaN(result));
     }
 }
Exemple #13
0
 public void TestUnpackDoubleNegativeZero_UnpackDouble_Stream()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCB, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.That(buffer.Position, Is.EqualTo(buffer.Length));
         Assert.That((-0.0).Equals(result));
     }
 }
Exemple #14
0
 public void TestUnpackDoubleEpsilon_UnpackDouble_Stream()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.That(buffer.Position, Is.EqualTo(buffer.Length));
         Assert.That(Double.Epsilon.Equals(result));
     }
 }
Exemple #15
0
 public void TestUnpackDouble_Stream_SingleMaxValue_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCA, 0x7F, 0x7F, 0xFF, 0xFF }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.AreEqual(sizeof(System.Single) + 1, buffer.Position);
         Assert.IsTrue((( double )Single.MaxValue).Equals(result));
     }
 }
Exemple #16
0
 public void TestUnpackDouble_Stream_SingleZero_AsIs()
 {
     using (var buffer = new MemoryStream(new byte[] { 0xCA, 0x00, 0x00, 0x00, 0x00 }))
     {
         var result = Unpacking.UnpackDouble(buffer);
         Assert.AreEqual(sizeof(System.Single) + 1, buffer.Position);
         Assert.IsTrue((0.0).Equals(result));
     }
 }
Exemple #17
0
 public void TestUnpackDouble_ByteArray_Offset_OffsetIsNegative()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Unpacking.UnpackDouble(new byte[] { 0x1 }, -1));
 }
Exemple #18
0
 public void TestUnpackDouble_ByteArray_Offset_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackDouble(default(byte[]), 0));
 }
Exemple #19
0
 public void TestUnpackDouble_ByteArray_Offset_OffsetIsTooBig()
 {
     Assert.Throws <ArgumentException>(() => Unpacking.UnpackDouble(new byte[] { 0x1 }, 1));
 }
Exemple #20
0
 public void TestUnpackDouble_ByteArray_NotDouble()
 {
     Assert.Throws <MessageTypeException>(() => Unpacking.UnpackDouble(new byte[] { 0xC3 }));
 }
Exemple #21
0
 public void TestUnpackDouble_ByteArray_Offset_Empty()
 {
     Assert.Throws <ArgumentException>(() => Unpacking.UnpackDouble(new byte[0], 0));
 }
Exemple #22
0
 public void TestUnpackDouble_Stream_Null()
 {
     Assert.Throws <ArgumentNullException>(() => Unpacking.UnpackDouble(default(Stream)));
 }