Search in sources :

Example 51 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project fastFFI by alibaba.

the class FlatBuffersMonsterBuilder method newBuilder.

static FlatBufferBuilder newBuilder() {
    FlatBufferBuilder builder = new FlatBufferBuilder(0);
    // Create some weapons for our Monster ('Sword' and 'Axe').
    int weaponOneName = builder.createString("Sword");
    short weaponOneDamage = 3;
    int weaponTwoName = builder.createString("Axe");
    short weaponTwoDamage = 5;
    // Use the `createWeapon()` helper function to create the weapons, since we set every field.
    int[] weaps = new int[2];
    weaps[0] = Weapon.createWeapon(builder, weaponOneName, weaponOneDamage);
    weaps[1] = Weapon.createWeapon(builder, weaponTwoName, weaponTwoDamage);
    // Serialize the FlatBuffer data.
    int name = builder.createString("Orc");
    byte[] treasure = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    int inv = Monster.createInventoryVector(builder, treasure);
    int weapons = Monster.createWeaponsVector(builder, weaps);
    int pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f);
    Monster.startMonster(builder);
    Monster.addPos(builder, pos);
    Monster.addName(builder, name);
    Monster.addColor(builder, Color.Red);
    Monster.addHp(builder, (short) 300);
    Monster.addInventory(builder, inv);
    Monster.addWeapons(builder, weapons);
    Monster.addEquippedType(builder, Equipment.Weapon);
    Monster.addEquipped(builder, weaps[1]);
    int orc = Monster.endMonster(builder);
    // You could also call `Monster.finishMonsterBuffer(builder, orc);`.
    builder.finish(orc);
    return builder;
}
Also used : FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder)

Aggregations

FlatBufferBuilder (com.google.flatbuffers.FlatBufferBuilder)51 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 BigInteger (java.math.BigInteger)10 A6ConfigRequest (org.apache.apisix.plugin.runner.A6ConfigRequest)9 HttpRequest (org.apache.apisix.plugin.runner.HttpRequest)9 ByteBuffer (java.nio.ByteBuffer)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 A6ConfigResponse (org.apache.apisix.plugin.runner.A6ConfigResponse)7 Test (org.junit.Test)7 Req (io.github.api7.A6.PrepareConf.Req)5 A6Conf (org.apache.apisix.plugin.runner.A6Conf)5 ByteStringAccess (com.google.protobuf.ByteStringAccess)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 UncheckedDeephavenException (io.deephaven.UncheckedDeephavenException)3 ChunkType (io.deephaven.chunk.ChunkType)3 Map (java.util.Map)3 lombok.val (lombok.val)3 ExtraInfoRequest (org.apache.apisix.plugin.runner.ExtraInfoRequest)3 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)3