public TestTableWithUnionAndMoreFields ReadTestTableWithUnionAndMoreFields(byte[] buffer) { var test = SerializationTests.TestTableWithUnionAndMoreFields.GetRootAsTestTableWithUnionAndMoreFields( new ByteBuffer(buffer)); var result = new TestTableWithUnionAndMoreFields() { IntProp = test.IntProp, DoubleProp = test.DoubleProp, StringProp = test.StringProp, FloatProp = test.FloatProp }; 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_TestTableWithUnionAndMoreFields_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 TestTableWithUnionAndMoreFields() { IntProp = 512, StringProp = "Hello, world!", FloatProp = 3.125f, DoubleProp = 3.14, UnionProp = table1 }; var buffer = FlatBuffersConvert.SerializeObject(obj); var oracle = new SerializationTestOracle(); var oracleResult = oracle.ReadTestTableWithUnionAndMoreFields(buffer); Assert.AreEqual(512, oracleResult.IntProp); Assert.AreEqual("Hello, world!", oracleResult.StringProp); Assert.AreEqual(3.125f, oracleResult.FloatProp); Assert.AreEqual(3.14, oracleResult.DoubleProp); Assert.IsInstanceOf <TestTable1>(oracleResult.UnionProp); var oracleResult1 = oracleResult.UnionProp as TestTable1; Assert.IsNotNull(oracleResult1); Assert.AreEqual(intProp, oracleResult1.IntProp); Assert.AreEqual(byteProp, oracleResult1.ByteProp); Assert.AreEqual(shortProp, oracleResult1.ShortProp); }