Пример #1
0
    //http://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
    internal byte[] Serialize()
    {
        FlatBufferBuilder fbb = new FlatBufferBuilder(1);

        //serialize players
        GameInitInfoS.StartPlayersVector(fbb, Players.Count);
        var playersOffset = new Offset <PlayerInitInfoS> [Players.Count];

        for (int i = 0; i < Players.Count; i++)
        {
            playersOffset[i] = Players[i].Create(ref fbb);
        }
        //nested tables needs to be CREATED before START
        VectorOffset playersVectorOffset = GameInitInfoS.CreatePlayersVector(fbb, playersOffset);

        //serialize whole game init info
        GameInitInfoS.StartGameInitInfoS(fbb);

        GameInitInfoS.AddMode(fbb, (int)Mode);
        GameInitInfoS.AddMap(fbb, (int)Map);
        GameInitInfoS.AddGameModeValue(fbb, GameModeValue);
        GameInitInfoS.AddPlayers(fbb, playersVectorOffset);

        Offset <GameInitInfoS> gameInfoOffset = GameInitInfoS.EndGameInitInfoS(fbb);

        fbb.Finish(gameInfoOffset.Value);
        byte[] result = fbb.SizedByteArray();
        return(result);
    }
Пример #2
0
 public static Offset <GameInitInfoS> CreateGameInitInfoS(FlatBufferBuilder builder,
                                                          int mode                   = 0,
                                                          int map                    = 0,
                                                          int gameModeValue          = 0,
                                                          VectorOffset playersOffset = default(VectorOffset))
 {
     builder.StartTable(4);
     GameInitInfoS.AddPlayers(builder, playersOffset);
     GameInitInfoS.AddGameModeValue(builder, gameModeValue);
     GameInitInfoS.AddMap(builder, map);
     GameInitInfoS.AddMode(builder, mode);
     return(GameInitInfoS.EndGameInitInfoS(builder));
 }