当前位置: 首页>>代码示例>>C#>>正文


C# FlatBufferBuilder.Finish方法代码示例

本文整理汇总了C#中FlatBuffers.FlatBufferBuilder.Finish方法的典型用法代码示例。如果您正苦于以下问题:C# FlatBufferBuilder.Finish方法的具体用法?C# FlatBufferBuilder.Finish怎么用?C# FlatBufferBuilder.Finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FlatBuffers.FlatBufferBuilder的用法示例。


在下文中一共展示了FlatBufferBuilder.Finish方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

        public byte[] Serialize()
        {
            var fbb = new FlatBufferBuilder(1024);
            var msg = MetadataMsg.CreateMetadata(fbb,
                    ColorFrameWidth, ColorFrameHeight,
                    DepthFrameWidth, DepthFrameHeight);
            fbb.Finish(msg.Value);

            return fbb.ToProtocolMessage(MessageIds.Metadata);
        }
开发者ID:wuyuntao,项目名称:Mokap,代码行数:10,代码来源:MetaData.cs

示例2: Serialize

        public byte[] Serialize()
        {
            var fbb = new FlatBufferBuilder(1024);

            var bodies = Array.ConvertAll(Bodies, body => body.Serialize(fbb));
            var msg = BodyFrameDataMsg.CreateBodyFrameData(fbb,
                    RelativeTime.Ticks,
                    BodyFrameDataMsg.CreateBodiesVector(fbb, bodies));
            fbb.Finish(msg.Value);

            return fbb.ToProtocolMessage(MessageIds.BodyFrameData);
        }
开发者ID:wuyuntao,项目名称:Mokap,代码行数:12,代码来源:BodyFrameData.cs

示例3: CommitRequest

    public async Task<Response> CommitRequest(FlatBufferBuilder fbb,
                                              RequestData requestDataType,
                                              int requestDataOffset) {
      PendingRequest request = new PendingRequest();
      request.requestId = nextRequestId++;
      request.responseTask = new TaskCompletionSource<Response>();
      pendingRequests.TryAdd(request.requestId, request);

      int requestOffset =
          Request.CreateRequest(fbb, request.requestId,
                                requestDataType, requestDataOffset);
      fbb.Finish(requestOffset);

      // Update the placeholder size.
      int bufferOffset = fbb.DataBuffer.Position;
      int bufferLength = fbb.DataBuffer.Length - fbb.DataBuffer.Position;
      fbb.DataBuffer.PutInt(bufferOffset - 4, bufferLength);

      // Send request.
      await socket.SendTaskAsync(fbb.DataBuffer.Data, bufferOffset - 4,
                                 bufferLength + 4, SocketFlags.None);

      // Await response.
      var response = await request.responseTask.Task;

      return response;
    }
开发者ID:SaviorXTanren,项目名称:xenia,代码行数:27,代码来源:Debugger.cs

示例4: FinishInputCommandBuffer

 public static void FinishInputCommandBuffer(FlatBufferBuilder builder, Offset<InputCommand> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:wuyuntao,项目名称:DeterministicLockstepNetworking,代码行数:4,代码来源:InputCommand.cs

示例5: MakeGameState

    void MakeGameState(FlatBufferBuilder fbb)
    {
        var playerName = createPlayerName (fbb);
        var resources = TypeAmountVector (fbb, metaPool.playerResources.quantities);
        var workers = createWorkers (fbb);
        var units = TypeLevelVector (fbb, metaPool.unitLevels.values);
        var islands = createIslands (fbb);
        var buildings = createBuildings(fbb);
        var technologies = createTechnologies(fbb);
        var sectors = createSectors(fbb);
        var completedQuests = createCompletedQuests(fbb);
        var currentQuests = createCurrentQuests(fbb);
        var defences = createDefences(fbb);
        var ships = createShips(fbb);

        GameData.StartGameData (fbb);
        GameData.AddPlayerName (fbb, playerName);
        GameData.AddPlayerResources (fbb, resources);
        GameData.AddWorkers (fbb, workers);
        GameData.AddUnitLevels (fbb, units);
        GameData.AddIslands (fbb, islands);
        GameData.AddBuildings (fbb, buildings);
        GameData.AddTrophies(fbb, metaPool.GetTrophies());
        GameData.AddTechnologies(fbb, technologies);
        GameData.AddSectors(fbb, sectors);
        GameData.AddShips (fbb, ships);
        GameData.AddCompletedQuests(fbb, completedQuests);
        GameData.AddCurrentQuests(fbb, currentQuests);
        GameData.AddDefences(fbb, defences);

        if(metaPool.hasIslandNextPirateAttack){
            GameData.AddNextPirateAttack(fbb, metaPool.islandNextPirateAttack.time.GetMicrosecondsFromEpoch());
        }

        if(metaPool.hasLeftOverResources){
            GameData.AddLeftOverResources(fbb, TypeAmountVector (fbb, metaPool.leftOverResources.resources));

        }

        if(corePool.isFortress){
            GameData.AddFortressLevel(fbb, (sbyte)corePool.fortressEntity.level.value);
        }

        Offset<GameData> gameData = GameData.EndGameData (fbb);
        GameStateRoot.StartGameStateRoot (fbb);
        GameStateRoot.AddGameData1 (fbb, gameData);
        Offset<GameStateRoot> root = GameStateRoot.EndGameStateRoot (fbb);
        fbb.Finish (root.Value);
    }
开发者ID:Reimerei,项目名称:port_experiments,代码行数:49,代码来源:FBSerialisationService.cs

示例6: FinishTestMessageBuffer

 public static void FinishTestMessageBuffer(FlatBufferBuilder builder, int offset)
 {
     builder.Finish(offset, "TEST");
 }
开发者ID:zaki,项目名称:unity-benchmarks,代码行数:4,代码来源:TestMessage.cs

示例7: FinishLoginResponseBuffer

 public static void FinishLoginResponseBuffer(FlatBufferBuilder builder, Offset<LoginResponse> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:wuyuntao,项目名称:Synchronica,代码行数:4,代码来源:LoginResponse.cs

示例8: Main

    // Example how to use FlatBuffers to create and read binary buffers.
    static void Main()
    {
        var builder = new FlatBufferBuilder(1);

        // Create some weapons for our Monster ('Sword' and 'Axe').
        var weapon1Name = builder.CreateString("Sword");
        var weapon1Damage = 3;
        var weapon2Name = builder.CreateString("Axe");
        var weapon2Damage = 5;

        // Use the `CreateWeapon()` helper function to create the weapons, since we set every field.
        var weaps = new Offset<Weapon>[2];
        weaps[0] = Weapon.CreateWeapon(builder, weapon1Name, (short)weapon1Damage);
        weaps[1] = Weapon.CreateWeapon(builder, weapon2Name, (short)weapon2Damage);

        // Serialize the FlatBuffer data.
        var name = builder.CreateString("Orc");
        var treasure =  new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        var inv = Monster.CreateInventoryVector(builder, treasure);
        var weapons = Monster.CreateWeaponsVector(builder, weaps);
        var pos = Vec3.CreateVec3(builder, 1.0f, 2.0f, 3.0f);

        Monster.StartMonster(builder);
        Monster.AddPos(builder, pos);
        Monster.AddHp(builder, (short)300);
        Monster.AddName(builder, name);
        Monster.AddInventory(builder, inv);
        Monster.AddColor(builder, Color.Red);
        Monster.AddWeapons(builder, weapons);
        Monster.AddEquippedType(builder, Equipment.Weapon);
        Monster.AddEquipped(builder, weaps[1].Value);
        var orc = Monster.EndMonster(builder);

        builder.Finish(orc.Value); // You could also call `Monster.FinishMonsterBuffer(builder, orc);`.

        // We now have a FlatBuffer that we could store on disk or send over a network.

        // ...Code to store to disk or send over a network goes here...

        // Instead, we are going to access it right away, as if we just received it.

        var buf = builder.DataBuffer;

        // Get access to the root:
        var monster = Monster.GetRootAsMonster(buf);

        // For C#, unlike other languages, most values (except for vectors and unions) are available as
        // properties instead of accessor methods.

        // Note: We did not set the `Mana` field explicitly, so we get back the default value.
        Assert(monster.Mana == 150, "monster.Mana", Convert.ToString(monster.Mana),
           Convert.ToString(150));
        Assert(monster.Hp == 300, "monster.Hp", Convert.ToString(monster.Hp), Convert.ToString(30));
        Assert(monster.Name.Equals("Orc", StringComparison.Ordinal), "monster.Name", monster.Name,
           "Orc");
        Assert(monster.Color == Color.Red, "monster.Color", Convert.ToString(monster.Color),
           Convert.ToString(Color.Red));

        // C# also allows you to use performance-enhanced methods to fill an object that has already
        // been created. These functions are prefixed with "Get". For example: `monster.GetPos()`.
        var myAlreadyCreatedVector = new Vec3();
        monster.GetPos(myAlreadyCreatedVector); // Instead of `var myNewVec3 = monster.Pos`.
        Assert(myAlreadyCreatedVector.X == 1.0f, "myAlreadyCreatedVector.X",
           Convert.ToString(myAlreadyCreatedVector.X), Convert.ToString(1.0f));
        Assert(myAlreadyCreatedVector.Y == 2.0f, "myAlreadyCreatedVector.Y",
           Convert.ToString(myAlreadyCreatedVector.Y), Convert.ToString(2.0f));
        Assert(myAlreadyCreatedVector.Z == 3.0f, "myAlreadyCreatedVector.Z",
           Convert.ToString(myAlreadyCreatedVector.Z), Convert.ToString(3.0f));

        // Get and test the `Inventory` FlatBuffer `vector`.
        for (int i = 0; i < monster.InventoryLength; i++)
        {
          Assert(monster.GetInventory(i) == i, "monster.GetInventory",
             Convert.ToString(monster.GetInventory(i)), Convert.ToString(i));
        }

        // Get and test the `Weapons` FlatBuffer `vector` of `table`s.
        var expectedWeaponNames = new string[] {"Sword", "Axe"};
        var expectedWeaponDamages = new short[] {3, 5};
        for (int i = 0; i < monster.WeaponsLength; i++)
        {
          Assert(monster.GetWeapons(i).Name.Equals(expectedWeaponNames[i], StringComparison.Ordinal),
             "monster.GetWeapons", monster.GetWeapons(i).Name, expectedWeaponNames[i]);
          Assert(monster.GetWeapons(i).Damage == expectedWeaponDamages[i], "monster.GetWeapons",
             Convert.ToString(monster.GetWeapons(i).Damage),
             Convert.ToString(expectedWeaponDamages[i]));
        }

        // Get and test the `Equipped` FlatBuffer `union`.
        Assert(monster.EquippedType == Equipment.Weapon, "monster.EquippedType",
           Convert.ToString(monster.EquippedType), Convert.ToString(Equipment.Weapon));
        var equipped = (Weapon)monster.GetEquipped(new Weapon());
        Assert(equipped.Name.Equals("Axe", StringComparison.Ordinal), "equipped.Name", equipped.Name,
           "Axe");
        Assert(equipped.Damage == 5, "equipped.Damage", Convert.ToString(equipped.Damage),
           Convert.ToString(5));

        Console.WriteLine("The FlatBuffer was successfully created and verified!");
    }
开发者ID:CadeLaRen,项目名称:flatbuffers,代码行数:100,代码来源:SampleBinary.cs

示例9: FinishrootDataBuffer

 public static void FinishrootDataBuffer(FlatBufferBuilder builder, Offset<rootData> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:kestrelm,项目名称:CreatureTools,代码行数:4,代码来源:rootData.cs

示例10: FinishImoveisBuffer

 public static void FinishImoveisBuffer(FlatBufferBuilder builder, Offset<Imoveis> offset)
 {
     builder.Finish(offset.Value, "IMV3");
 }
开发者ID:talkitbr,项目名称:FlatBuffers,代码行数:4,代码来源:Imoveis.cs

示例11: FinishSynchronizeSceneDataBuffer

 public static void FinishSynchronizeSceneDataBuffer(FlatBufferBuilder builder, Offset<SynchronizeSceneData> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:wuyuntao,项目名称:Synchronica,代码行数:4,代码来源:SynchronizeSceneData.cs

示例12: FinishSyncFrameBuffer

 public static void FinishSyncFrameBuffer(FlatBufferBuilder builder, Offset<SyncFrame> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:wuyuntao,项目名称:DeterministicLockstepNetworking,代码行数:4,代码来源:SyncFrame.cs

示例13: FinishMonsterBuffer

 public static void FinishMonsterBuffer(FlatBufferBuilder builder, int offset)
 {
     builder.Finish(offset, "MONS");
 }
开发者ID:holvonix,项目名称:flatbuffers,代码行数:4,代码来源:Monster.cs

示例14: FinishInputRequestBuffer

 public static void FinishInputRequestBuffer(FlatBufferBuilder builder, Offset<InputRequest> offset)
 {
     builder.Finish(offset.Value);
 }
开发者ID:wuyuntao,项目名称:Synchronica,代码行数:4,代码来源:InputRequest.cs


注:本文中的FlatBuffers.FlatBufferBuilder.Finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。