public void TestUnionVector()
        {
            var fbb      = new FlatBufferBuilder(100);
            var rapunzel = Rapunzel.CreateRapunzel(fbb, 40).Value;

            var characterTypes = new[]
            {
                Character.MuLan,
                Character.Belle,
                Character.Other,
            };
            var characterTypesOffset = Movie.CreateCharactersTypeVector(fbb, characterTypes);

            var characters = new[]
            {
                Attacker.CreateAttacker(fbb, 10).Value,
                BookReader.CreateBookReader(fbb, 20).Value,
                fbb.CreateSharedString("Chip").Value,
            };
            var charactersOffset = Movie.CreateCharactersVector(fbb, characters);

            var movieOffset = Movie.CreateMovie(
                fbb,
                Character.Rapunzel,
                rapunzel,
                characterTypesOffset,
                charactersOffset);

            Movie.FinishMovieBuffer(fbb, movieOffset);

            var movie = Movie.GetRootAsMovie(fbb.DataBuffer);

            Assert.AreEqual(Character.Rapunzel, movie.MainCharacterType);
            Assert.AreEqual(40, movie.MainCharacter <Rapunzel>().Value.HairLength);

            Assert.AreEqual(3, movie.CharactersLength);
            Assert.AreEqual(Character.MuLan, movie.CharactersType(0));
            Assert.AreEqual(10, movie.Characters <Attacker>(0).Value.SwordAttackDamage);
            Assert.AreEqual(Character.Belle, movie.CharactersType(1));
            Assert.AreEqual(20, movie.Characters <BookReader>(1).Value.BooksRead);
            Assert.AreEqual(Character.Other, movie.CharactersType(2));
            Assert.AreEqual("Chip", movie.CharactersAsString(2));

            TestObjectAPI(movie);
        }
Esempio n. 2
0
    public static int Pack(FlatBuffers.FlatBufferBuilder builder, CharacterUnion _o)
    {
        switch (_o.Type)
        {
        default: return(0);

        case Character.MuLan: return(Attacker.Pack(builder, _o.AsMuLan()).Value);

        case Character.Rapunzel: return(Rapunzel.Pack(builder, _o.AsRapunzel()).Value);

        case Character.Belle: return(BookReader.Pack(builder, _o.AsBelle()).Value);

        case Character.BookFan: return(BookReader.Pack(builder, _o.AsBookFan()).Value);

        case Character.Other: return(builder.CreateString(_o.AsOther()).Value);

        case Character.Unused: return(builder.CreateString(_o.AsUnused()).Value);
        }
    }