Ejemplo n.º 1
0
        public void ComplexDictionary()
        {
            var tests = new Dictionary <object, object>
            {
                {
                    "array1",
                    new object[]
                    {
                        "array1_value1",
                        "array1_value2",
                        "array1_value3"
                    }
                },
                { "bool1", true },
                { "double1", 50.5 },
                { "double2", 15.2 },
                { "int1", 50505 },
                { "int2", 50 },
                { 3.14f, 3.14 },
                { 42, 42 },
                { new Dictionary <int, int> {
                      { 1, 2 }
                  }, null },
                { new[] { 1, 2 }, null }
            };

            var data = new byte[]
            {
                138,
                166, 97, 114, 114, 97, 121, 49,
                147,
                173, 97, 114, 114, 97, 121, 49, 95, 118, 97, 108, 117, 101, 49,
                173, 97, 114, 114, 97, 121, 49, 95, 118, 97, 108, 117, 101, 50,
                173, 97, 114, 114, 97, 121, 49, 95, 118, 97, 108, 117, 101, 51,
                165, 98, 111, 111, 108, 49, 195,
                167, 100, 111, 117, 98, 108, 101, 49, 203, 64, 73, 64, 0, 0, 0, 0, 0,
                167, 100, 111, 117, 98, 108, 101, 50, 203, 64, 46, 102, 102, 102, 102, 102, 102,
                164, 105, 110, 116, 49, 205, 197, 73,
                164, 105, 110, 116, 50, 50,
                202, 64, 72, 245, 195, 203, 64, 9, 30, 184, 81, 235, 133, 31,
                42, 42,
                129, 1, 2, 192,
                146, 1, 2, 192
            };

            var settings = new MsgPackContext();

            settings.RegisterConverter(new TestReflectionConverter());
            MsgPackConverter.Serialize(tests, settings).ShouldBe(data);
        }
Ejemplo n.º 2
0
        public void TestDateTime()
        {
            var tests = new List <KeyValuePair <byte[], System.DateTime> >()
            {
                new KeyValuePair <byte[], DateTime>(new byte[] { 211, 247, 96, 128, 10, 8, 74, 128, 0, }, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)),
                new KeyValuePair <byte[], DateTime>(new byte[] { 211, 35, 42, 168, 127, 252, 129, 152, 240, }, new DateTime(9999, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc)),
                new KeyValuePair <byte[], DateTime>(new byte[] { 211, 0, 51, 110, 236, 17, 171, 0, 0, }, new DateTime(2015, 11, 17, 0, 0, 0, 0, DateTimeKind.Utc)),
                new KeyValuePair <byte[], DateTime>(new byte[] { 211, 247, 96, 154, 26, 189, 97, 197, 0, }, new DateTime(1, 2, 3, 4, 5, 6, DateTimeKind.Utc)),
            };

            foreach (var test in tests)
            {
                MsgPackConverter.Deserialize <System.DateTime>(test.Key).ShouldBe(test.Value);
            }
        }
Ejemplo n.º 3
0
        public void TestDateTimeOffset()
        {
            var tests = new List <KeyValuePair <byte[], System.DateTimeOffset> >()
            {
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 247, 96, 128, 10, 8, 74, 128, 0, }, DateTimeOffset.MinValue),
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 35, 42, 168, 127, 252, 129, 191, 255, }, DateTimeOffset.MaxValue),
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 0, 51, 110, 236, 17, 171, 0, 0, }, new DateTimeOffset(2015, 11, 17, 0, 0, 0, TimeSpan.Zero)),
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 247, 96, 154, 26, 189, 97, 197, 0, }, new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.Zero)),
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 247, 96, 153, 182, 40, 44, 229, 0, }, new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.FromHours(12))),
                new KeyValuePair <byte[], DateTimeOffset>(new byte[] { 211, 247, 96, 153, 232, 79, 4, 15, 0, }, new DateTimeOffset(1, 2, 3, 4, 5, 6, TimeSpan.FromMinutes(361))),
            };

            foreach (var test in tests)
            {
                MsgPackConverter.Deserialize <System.DateTimeOffset>(test.Key).ShouldBe(test.Value);
            }
        }
Ejemplo n.º 4
0
        public void SimpleDictionary()
        {
            var test = new Dictionary <int, string>
            {
                { 1, "a" },
                { 2, "b" },
                { 3, "c" },
                { 4, "d" },
                { 5, "e" }
            };

            var bytes = new byte[]
            {
                133,
                1, 161, 97,
                2, 161, 98,
                3, 161, 99,
                4, 161, 100,
                5, 161, 101
            };

            MsgPackConverter.Deserialize <Dictionary <int, string> >(bytes).ShouldBe(test);
        }
Ejemplo n.º 5
0
        public void SimpleArray()
        {
            var tests = new[]
            {
                "a",
                "b",
                "c",
                "d",
                "e"
            };

            var bytes = new byte[]
            {
                149,
                161, 97,
                161, 98,
                161, 99,
                161, 100,
                161, 101
            };

            MsgPackConverter.Serialize(tests).ShouldBe(bytes);
        }
Ejemplo n.º 6
0
        public void TestArrayPack()
        {
            var expected = new object[]
            {
                0,
                50505,
                float.NaN,
                float.MaxValue,
                new[] { true, false, true },
                null,
                new Dictionary <object, object> {
                    { "Ball", "Soccer" }
                }
            };

            var data = new byte[]
            {
                151,
                0,
                205, 197, 73,
                202, 255, 192, 0, 0,
                202, 127, 127, 255, 255,
                147,
                195,
                194,
                195,
                192,
                129,
                164, 66, 97, 108, 108, 166, 83, 111, 99, 99, 101, 114
            };

            var settings = new MsgPackContext();

            settings.RegisterConverter(new TestReflectionConverter());

            MsgPackConverter.Deserialize <object[]>(data, settings).ShouldBe(expected);
        }
Ejemplo n.º 7
0
        public void TestNonFixedArray()
        {
            var array = new[]
            {
                1, 2, 3, 4, 5,
                1, 2, 3, 4, 5,
                1, 2, 3, 4, 5,
                1, 2, 3, 4, 5,
            };

            var bytes = new byte[]
            {
                0xdc,
                0x00,
                0x14,

                0x01, 0x02, 0x03, 0x04, 0x05,
                0x01, 0x02, 0x03, 0x04, 0x05,
                0x01, 0x02, 0x03, 0x04, 0x05,
                0x01, 0x02, 0x03, 0x04, 0x05,
            };

            MsgPackConverter.Deserialize <int[]>(bytes).ShouldBe(array);
        }
Ejemplo n.º 8
0
 public void TestSignedLong(long number, byte[] data)
 {
     MsgPackConverter.Serialize((long?)number).ShouldBe(data);
 }
Ejemplo n.º 9
0
        public void NonFixedDictionary()
        {
            var bytes = new byte[]
            {
                0xde,
                0x00,
                0x14,

                0x01, 0xa1, 0x61,
                0x02, 0xa1, 0x62,
                0x03, 0xa1, 0x63,
                0x04, 0xa1, 0x64,
                0x05, 0xa1, 0x65,

                0x0b, 0xa1, 0x61,
                0x0c, 0xa1, 0x62,
                0x0d, 0xa1, 0x63,
                0x0e, 0xa1, 0x64,
                0x0f, 0xa1, 0x65,

                0x15, 0xa1, 0x61,
                0x16, 0xa1, 0x62,
                0x17, 0xa1, 0x63,
                0x18, 0xa1, 0x64,
                0x19, 0xa1, 0x65,

                0x1f, 0xa1, 0x61,
                0x20, 0xa1, 0x62,
                0x21, 0xa1, 0x63,
                0x22, 0xa1, 0x64,
                0x23, 0xa1, 0x65,
            };

            var test = new Dictionary <int, string>
            {
                { 1, "a" },
                { 2, "b" },
                { 3, "c" },
                { 4, "d" },
                { 5, "e" },

                { 11, "a" },
                { 12, "b" },
                { 13, "c" },
                { 14, "d" },
                { 15, "e" },

                { 21, "a" },
                { 22, "b" },
                { 23, "c" },
                { 24, "d" },
                { 25, "e" },

                { 31, "a" },
                { 32, "b" },
                { 33, "c" },
                { 34, "d" },
                { 35, "e" },
            };

            MsgPackConverter.Deserialize <Dictionary <int, string> >(bytes).ShouldBe(test);
        }
Ejemplo n.º 10
0
 public void WriteNullByteArray()
 {
     MsgPackConverter.Serialize((byte[])null).ShouldBe(new[] { (byte)DataTypes.Null });
 }
Ejemplo n.º 11
0
 public void ReadNullString()
 {
     MsgPackConverter.Deserialize <string>(new[] { (byte)DataTypes.Null }).ShouldBe(null);
 }
Ejemplo n.º 12
0
 public void ReadNullByteArray()
 {
     MsgPackConverter.Deserialize <byte[]>(new[] { (byte)DataTypes.Null }).ShouldBe(null);
 }
Ejemplo n.º 13
0
 public void TetsUnsignedLong(ulong number, byte[] data)
 {
     MsgPackConverter.Serialize(number).ShouldBe(data);
 }
Ejemplo n.º 14
0
 public void TestFloat(float value, byte[] bytes)
 {
     MsgPackConverter.Serialize((float?)value).ShouldBe(bytes);
 }
Ejemplo n.º 15
0
 public void TestDouble(double value, byte[] bytes)
 {
     MsgPackConverter.Serialize((double?)value).ShouldBe(bytes);
 }
Ejemplo n.º 16
0
 public void Test(byte[] value, byte[] data)
 {
     MsgPackConverter.Deserialize <byte[]>(data).ShouldBe(value);
 }
Ejemplo n.º 17
0
 public void WriteNullString()
 {
     MsgPackConverter.Serialize((string)null).ShouldBe(new[] { (byte)DataTypes.Null });
 }
Ejemplo n.º 18
0
 public void WriteNullMap()
 {
     MsgPackConverter.Serialize((IDictionary <int, int>)null).ShouldBe(new[] { (byte)DataTypes.Null });
 }
Ejemplo n.º 19
0
 public void TestSignedByte(sbyte number, byte[] data)
 {
     MsgPackConverter.Serialize(number).ShouldBe(data);
 }
Ejemplo n.º 20
0
 public void TestSignedShort(short number, byte[] data)
 {
     MsgPackConverter.Serialize((short?)number).ShouldBe(data);
 }
Ejemplo n.º 21
0
 public void TetsUnsignedShort(ushort number, byte[] data)
 {
     MsgPackConverter.Serialize(number).ShouldBe(data);
 }
Ejemplo n.º 22
0
 public void TetsUnsignedInt(uint number, byte[] data)
 {
     MsgPackConverter.Serialize((uint?)number).ShouldBe(data);
 }
Ejemplo n.º 23
0
 public void ReadNullMap()
 {
     MsgPackConverter.Deserialize <Dictionary <int, int> >(new[] { (byte)DataTypes.Null }).ShouldBe(null);
 }
Ejemplo n.º 24
0
 public void TetsUnsignedByte(byte number, byte[] data)
 {
     MsgPackConverter.Serialize((byte?)number).ShouldBe(data);
 }
Ejemplo n.º 25
0
 public void TestStringPack(string s, byte[] data)
 {
     MsgPackConverter.Deserialize <string>(data).ShouldBe(s);
 }
Ejemplo n.º 26
0
 public void WriteNullAsNullableUlong()
 {
     MsgPackConverter.Serialize(default(ulong?)).ShouldBe(new[] { (byte)DataTypes.Null });
 }
Ejemplo n.º 27
0
 public void False()
 {
     MsgPackConverter.Serialize((bool?)false).ShouldBe(new[] { (byte)DataTypes.False });
 }
Ejemplo n.º 28
0
 public void True()
 {
     MsgPackConverter.Serialize((bool?)true).ShouldBe(new[] { (byte)DataTypes.True });
 }
Ejemplo n.º 29
0
 public void TestStringPack(string s, byte[] data)
 {
     MsgPackConverter.Serialize(s).ShouldBe(data);
 }
Ejemplo n.º 30
0
 public void TestFloat(float value, byte[] bytes)
 {
     MsgPackConverter.Deserialize <float>(bytes).ShouldBe(value);
 }