public void Serialize_TestTableWithUnion_And_TestTable2_CanBeReadByOracle()
        {
            const string stringProp = "Hello, FlatBuffers!";

            var table2 = new TestTable2()
            {
                StringProp = stringProp
            };

            var obj = new TestTableWithUnion()
            {
                IntProp   = 512,
                UnionProp = table2
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnion(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual(typeof(TestTable2), oracleResult.UnionProp.GetType());

            var oracleResult2 = oracleResult.UnionProp as TestTable2;

            Assert.IsNotNull(oracleResult2);
            Assert.AreEqual(stringProp, oracleResult2.StringProp);
        }
Exemplo n.º 2
0
        public TestTableWithUnion ReadTestTableWithUnion(byte[] buffer)
        {
            var test =
                SerializationTests.TestTableWithUnion.GetRootAsTestTableWithUnion(
                    new ByteBuffer(buffer));

            var result = new TestTableWithUnion()
            {
                IntProp = test.IntProp
            };

            var unionType = test.UnionPropType;

            if (unionType == TestUnion.TestTable1)
            {
                var obj = new SerializationTests.TestTable1();
                var res = test.GetUnionProp(obj);
                result.UnionProp = new TestTable1()
                {
                    IntProp = res.IntProp, ByteProp = res.ByteProp, ShortProp = res.ShortProp
                };
            }
            if (unionType == TestUnion.TestTable2)
            {
                var obj = new SerializationTests.TestTable2();
                var res = test.GetUnionProp(obj);
                result.UnionProp = new TestTable2 {
                    StringProp = res.StringProp
                };
            }
            return(result);
        }
        public void Serialize_TestTableWithUnion_And_TestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var table1 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithUnion()
            {
                IntProp   = 512,
                UnionProp = table1
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnion(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual(typeof(TestTable1), oracleResult.UnionProp.GetType());

            var oracleResult1 = oracleResult.UnionProp as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }