コード例 #1
0
        public void TestMediumImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(string), typeof(Int16), typeof(UInt32), typeof(Int16), typeof(string) });
            Byte[] export = serializer.SerializeData(new object[] { "abcd", 100, 100000, 900, "defghi" });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { "abcd", (UInt16)100, (UInt32)100000, (UInt16)900, "defghi" }, import, "defghi");
            Assert.AreEqual(20, offset);
        }
コード例 #2
0
        public void TestManyParse()
        {
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(VarByte), typeof(UInt16) });
            object[] TestData= new object[]{ 5, 1, 2, 3, 4, 5 };

            Byte[] export = serializer.SerializeData(TestData);
            int offset=0;
            object[] import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);

            serializer.SetSerializableTypes(new Type[] { typeof(VarUInt32), typeof(string), typeof(Int16), typeof(VarUInt16), typeof(Byte) });
            TestData = new object[] { 5, "a", "b", "c", "d", "e", 10, 3, 1, 2, 3 };
            export = serializer.SerializeData(TestData);
            offset = 0;
            import = serializer.DeserializeData(export, 0, ref offset);

            Assert.AreEqual(TestData, import);
        }
コード例 #3
0
        public void TestMediumExportSerialization()
        {
            BinarySerializer serializer = new BinarySerializer();

            serializer.SetSerializableTypes(new Type[] { typeof(UInt16), typeof(UInt32) });
            Byte[] output = serializer.SerializeData(new object[] { 1, 100000 });
            string CompareData = GetBinaryString(SumByteArrays(GetData(1, typeof(UInt16)), GetData(100000, typeof(UInt32))));
            Assert.AreEqual(GetBinaryString(output), CompareData);

            serializer.SetSerializableTypes(new Type[] { typeof(string) });
            output = serializer.SerializeData(new object[] { "abcd" });
            Assert.AreEqual(new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', 0 }, output);

            serializer.SetSerializableTypes(new Type[] { typeof(string), typeof(Int16), typeof(UInt32), typeof(Int16), typeof(string) });
            output = serializer.SerializeData(new object[] { "abcd", 100, 100000, 900, "defghi" });
            CompareData = GetBinaryString(SumByteArrays(new byte[] { (byte)'a', (byte)'b', (byte)'c', (byte)'d', 0 }, GetData(100, typeof(Int16)), GetData(100000, typeof(Int32)), GetData(900, typeof(Int16)), new byte[] { (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', 0 }));
            Assert.AreEqual(GetBinaryString(output), CompareData);
        }
コード例 #4
0
        public void TestClassParse()
        {
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(test2) });
            test2 t2= new test2();
            t2.a1=1;
            t2.a2=2;
            t2.a3=3;
            t2.a4=4;

            int off = 0;
            byte[] serData= serializer.SerializeData(new object[] { t2 });
            test2 desData = (test2)serializer.DeserializeData(serData, 0, ref off)[0];

            Assert.AreEqual(t2.a1, desData.a1);
            Assert.AreEqual(t2.a2, desData.a2);
            Assert.AreEqual(t2.a3, desData.a3);
            Assert.AreEqual(t2.a4, desData.a4);
        }
コード例 #5
0
        public void TestByteSerialize()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer();
            serializer.SetSerializableTypes(new Type[] { typeof(Byte[]) });

            Byte[] input = new Byte[] { 1, 2, 3, 4, 5 };
            Byte[] export = serializer.SerializeData(new object[] { input });

            object[] import = serializer.DeserializeData(export, 0, ref offset);
            Assert.AreEqual(input, import[0]);
        }
コード例 #6
0
        public void TestBasicImport()
        {
            int offset = 0;
            BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(UInt16) });
            Byte[] export = serializer.SerializeData(new object[] { 1 });
            object[] import = serializer.DeserializeData(export,0,ref offset);

            Assert.AreEqual(new object[] { (UInt16)1 }, import);
            Assert.AreEqual(2, offset);
        }
コード例 #7
0
 public void TestBasicExportSerialization()
 {
     BinarySerializer serializer = new BinarySerializer(new Type[] { typeof(UInt16) });
     Byte[] output = serializer.SerializeData(new object[] { 1 });
     Assert.AreEqual(GetBinaryString(output), "0000000000000001");
 }
コード例 #8
0
 public static Byte[] GetData(object data, Type type)
 {
     BinarySerializer serializer = new BinarySerializer(new Type[] { type });
     Byte[] output = serializer.SerializeData(new object[] { data });
     return output;
 }