public void TestUnionUtility()
        {
            var movie = new MovieT
            {
                MainCharacter = CharacterUnion.FromRapunzel(new RapunzelT {
                    HairLength = 40
                }),
                Characters = new System.Collections.Generic.List <CharacterUnion>
                {
                    CharacterUnion.FromMuLan(new AttackerT {
                        SwordAttackDamage = 10
                    }),
                    CharacterUnion.FromBelle(new BookReaderT {
                        BooksRead = 20
                    }),
                    CharacterUnion.FromOther("Chip"),
                },
            };

            var fbb = new FlatBufferBuilder(100);

            Movie.FinishMovieBuffer(fbb, Movie.Pack(fbb, movie));

            TestObjectAPI(Movie.GetRootAsMovie(fbb.DataBuffer));
        }
Esempio n. 2
0
 public void WriteJson(Newtonsoft.Json.JsonWriter writer, CharacterUnion _o, Newtonsoft.Json.JsonSerializer serializer)
 {
     if (_o == null)
     {
         return;
     }
     serializer.Serialize(writer, _o.Value);
 }
Esempio n. 3
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);
        }
    }
Esempio n. 4
0
    public static Offset <Movie> Pack(FlatBufferBuilder builder, MovieT _o)
    {
        if (_o == null)
        {
            return(default(Offset <Movie>));
        }
        var _main_character_type = _o.MainCharacter == null ? Character.NONE : _o.MainCharacter.Type;
        var _main_character      = _o.MainCharacter == null ? 0 : CharacterUnion.Pack(builder, _o.MainCharacter);
        var _characters_type     = default(VectorOffset);

        if (_o.Characters != null)
        {
            var __characters_type = new Character[_o.Characters.Count];
            for (var _j = 0; _j < __characters_type.Length; ++_j)
            {
                __characters_type[_j] = _o.Characters[_j].Type;
            }
            _characters_type = CreateCharactersTypeVector(builder, __characters_type);
        }
        var _characters = default(VectorOffset);

        if (_o.Characters != null)
        {
            var __characters = new int[_o.Characters.Count];
            for (var _j = 0; _j < __characters.Length; ++_j)
            {
                __characters[_j] = CharacterUnion.Pack(builder, _o.Characters[_j]);
            }
            _characters = CreateCharactersVector(builder, __characters);
        }
        return(CreateMovie(
                   builder,
                   _main_character_type,
                   _main_character,
                   _characters_type,
                   _characters));
    }
Esempio n. 5
0
    public CharacterUnion ReadJson(Newtonsoft.Json.JsonReader reader, CharacterUnion _o, Newtonsoft.Json.JsonSerializer serializer)
    {
        if (_o == null)
        {
            return(null);
        }
        switch (_o.Type)
        {
        default: break;

        case Character.MuLan: _o.Value = serializer.Deserialize <AttackerT>(reader); break;

        case Character.Rapunzel: _o.Value = serializer.Deserialize <RapunzelT>(reader); break;

        case Character.Belle: _o.Value = serializer.Deserialize <BookReaderT>(reader); break;

        case Character.BookFan: _o.Value = serializer.Deserialize <BookReaderT>(reader); break;

        case Character.Other: _o.Value = serializer.Deserialize <string>(reader); break;

        case Character.Unused: _o.Value = serializer.Deserialize <string>(reader); break;
        }
        return(_o);
    }
Esempio n. 6
0
    public void UnPackTo(MovieT _o)
    {
        _o.MainCharacter      = new CharacterUnion();
        _o.MainCharacter.Type = this.MainCharacterType;
        switch (this.MainCharacterType)
        {
        default: break;

        case Character.MuLan:
            _o.MainCharacter.Value = this.MainCharacter <Attacker>().HasValue ? this.MainCharacter <Attacker>().Value.UnPack() : null;
            break;

        case Character.Rapunzel:
            _o.MainCharacter.Value = this.MainCharacter <Rapunzel>().HasValue ? this.MainCharacter <Rapunzel>().Value.UnPack() : null;
            break;

        case Character.Belle:
            _o.MainCharacter.Value = this.MainCharacter <BookReader>().HasValue ? this.MainCharacter <BookReader>().Value.UnPack() : null;
            break;

        case Character.BookFan:
            _o.MainCharacter.Value = this.MainCharacter <BookReader>().HasValue ? this.MainCharacter <BookReader>().Value.UnPack() : null;
            break;

        case Character.Other:
            _o.MainCharacter.Value = this.MainCharacterAsString();
            break;

        case Character.Unused:
            _o.MainCharacter.Value = this.MainCharacterAsString();
            break;
        }
        _o.Characters = new List <CharacterUnion>();
        for (var _j = 0; _j < this.CharactersLength; ++_j)
        {
            var _o_Characters = new CharacterUnion();
            _o_Characters.Type = this.CharactersType(_j);
            switch (this.CharactersType(_j))
            {
            default: break;

            case Character.MuLan:
                _o_Characters.Value = this.Characters <Attacker>(_j).HasValue ? this.Characters <Attacker>(_j).Value.UnPack() : null;
                break;

            case Character.Rapunzel:
                _o_Characters.Value = this.Characters <Rapunzel>(_j).HasValue ? this.Characters <Rapunzel>(_j).Value.UnPack() : null;
                break;

            case Character.Belle:
                _o_Characters.Value = this.Characters <BookReader>(_j).HasValue ? this.Characters <BookReader>(_j).Value.UnPack() : null;
                break;

            case Character.BookFan:
                _o_Characters.Value = this.Characters <BookReader>(_j).HasValue ? this.Characters <BookReader>(_j).Value.UnPack() : null;
                break;

            case Character.Other:
                _o_Characters.Value = this.CharactersAsString(_j);
                break;

            case Character.Unused:
                _o_Characters.Value = this.CharactersAsString(_j);
                break;
            }
            _o.Characters.Add(_o_Characters);
        }
    }