Create() public static méthode

Create standard Safe Packer instancde wrapping specified Stream with DefaultCompatibilityOptions.
You can specify any derived Stream class like FileStream, MemoryStream, NetworkStream, UnmanagedMemoryStream, or so.
is null.
public static Create ( Stream stream ) : Packer
stream Stream object. This stream will be closed when is called.
Résultat Packer
Exemple #1
0
        private static void TestBoolean(bool val)
        {
            var output = new MemoryStream();

            Packer.Create(output).Pack(val);
            MessagePackObject obj = UnpackOne(output);

            Assert.AreEqual(val, obj.AsBoolean());
            Assert.AreEqual(val, ( bool )obj);
            Assert.IsTrue(obj.IsTypeOf <bool>().GetValueOrDefault());
        }
Exemple #2
0
        private static void TestStringStrict(String val)
        {
            var output = new MemoryStream();

            Packer.Create(output).PackString(val);
            MessagePackObject obj = UnpackOne(output);

            Assert.AreEqual(val, obj.AsString());
            Assert.AreEqual(val, ( string )obj);
            Assert.IsTrue(obj.IsTypeOf <string>().GetValueOrDefault());
        }
Exemple #3
0
 public void TestPackItems_Null_AsNil()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack(default(MessagePackObject[]));
             Assert.AreEqual(
                 new byte[] { 0xC0 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #4
0
 private static void TestCore <T>(Action <Packer, T> method, T arg, byte[] expected)
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             method(packer, arg);
             Assert.AreEqual(
                 expected,
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NullableBoolean_Null_AsNil()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(default(System.Boolean?  ));
             Assert.AreEqual(
                 new byte[] { 0xC0 },
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NullableUInt16_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(UInt16.MaxValue);
             Assert.AreEqual(
                 new byte[] { 0xCD }.Concat(BitConverter.GetBytes(UInt16.MaxValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_DoubleNegativeInfinity_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(Double.NegativeInfinity);
             Assert.AreEqual(
                 new byte[] { 0xCB }.Concat(BitConverter.GetBytes(Double.NegativeInfinity).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_Nil_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(default(object));
             Assert.AreEqual(
                 new byte[] { 0xC0 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #9
0
 public void TestPackT_SinglePositiveInfinity_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Single>(Single.PositiveInfinity);
             Assert.AreEqual(
                 new byte[] { 0xCA }.Concat(BitConverter.GetBytes(Single.PositiveInfinity).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
Exemple #10
0
 public void TestPackT_True_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Boolean>(true);
             Assert.AreEqual(
                 new byte[] { 0xC3 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #11
0
 public void TestPackT_PositiveFixNumMaxValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Int32>((127));
             Assert.AreEqual(
                 new byte[] { 0x7F },
                 buffer.ToArray()
                 );
         }
 }
Exemple #12
0
 public void TestPackT_PlusOne_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Int32>((1));
             Assert.AreEqual(
                 new byte[] { 0x01 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #13
0
 public void TestPackT_UInt16MaxValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.UInt16>(UInt16.MaxValue);
             Assert.AreEqual(
                 new byte[] { 0xCD }.Concat(BitConverter.GetBytes(UInt16.MaxValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
Exemple #14
0
 public void TestPackT_SByteMinValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.SByte>(SByte.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xD0, 0x80 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #15
0
 public void TestPack_NullableInt64_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack(Int64.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xD3 }.Concat(BitConverter.GetBytes(Int64.MinValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_PositiveFixNumMaxValuePlusOne_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject((( byte )128));
             Assert.AreEqual(
                 new byte[] { 0xCC, 0x80 },
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_False_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(false);
             Assert.AreEqual(
                 new byte[] { 0xC2 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #18
0
 public void TestPackT_NullableSingle_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Single?>(Single.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xCA }.Concat(BitConverter.GetBytes(Single.MinValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_SingleEpsilon_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(Single.Epsilon);
             Assert.AreEqual(
                 new byte[] { 0xCA }.Concat(BitConverter.GetBytes(Single.Epsilon).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
Exemple #20
0
 public void TestPackT_NullableUInt16_Null_AsNil()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.UInt16?>(default(System.UInt16?  ));
             Assert.AreEqual(
                 new byte[] { 0xC0 },
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NullableSByte_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(SByte.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xD0, 0x80 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #22
0
 public void TestPackT_NullableByte_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Byte?>(Byte.MaxValue);
             Assert.AreEqual(
                 new byte[] { 0xCC, 0xFF },
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NullableBoolean_NotNull_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(true);
             Assert.AreEqual(
                 new byte[] { 0xC3 },
                 buffer.ToArray()
                 );
         }
 }
Exemple #24
0
 public void TestPackT_Int32MinValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <System.Int32>(Int32.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xD2 }.Concat(BitConverter.GetBytes(Int32.MinValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_Int16MinValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(Int16.MinValue);
             Assert.AreEqual(
                 new byte[] { 0xD1 }.Concat(BitConverter.GetBytes(Int16.MinValue).Reverse()).ToArray(),
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_ByteMaxValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject(Byte.MaxValue);
             Assert.AreEqual(
                 new byte[] { 0xCC, 0xFF },
                 buffer.ToArray()
                 );
         }
 }
Exemple #27
0
 public void TestPackItems_NotNull__AsArray()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack(new int[] { 1, 2, 3 });
             Assert.AreEqual(
                 new byte[] { 0x93, 1, 2, 3 },
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NegativeFixNumMinValueMinusOne_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject((( sbyte )-33));
             Assert.AreEqual(
                 new byte[] { 0xD0, unchecked (( byte )( sbyte )-33) },
                 buffer.ToArray()
                 );
         }
 }
Exemple #29
0
 private static void TestPackTCore <T>(T value, byte[] expected)
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.Pack <T>(value);
             Assert.AreEqual(
                 expected,
                 buffer.ToArray()
                 );
         }
 }
 public void TestPack_NegativeFixNumMinValue_AsValue()
 {
     using (var buffer = new MemoryStream())
         using (var packer = Packer.Create(buffer))
         {
             packer.PackObject((-32));
             Assert.AreEqual(
                 new byte[] { 0xE0 },
                 buffer.ToArray()
                 );
         }
 }