本文整理汇总了C#中FlatBuffers.FlatBufferBuilder.CreateString方法的典型用法代码示例。如果您正苦于以下问题:C# FlatBufferBuilder.CreateString方法的具体用法?C# FlatBufferBuilder.CreateString怎么用?C# FlatBufferBuilder.CreateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FlatBuffers.FlatBufferBuilder
的用法示例。
在下文中一共展示了FlatBufferBuilder.CreateString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunSerialize
void RunSerialize()
{
for (int i = 0; i < N; i++)
{
FlatBufferBuilder messageBuffer = new FlatBufferBuilder(100);
var text = messageBuffer.CreateString(@"Test message included");
int embeddedOffset = EmbeddedMessage.CreateEmbeddedMessage(messageBuffer, i);
TestMessage.StartTestMessage(messageBuffer);
TestMessage.AddText(messageBuffer, text.Value);
TestMessage.AddEmbedded(messageBuffer, embeddedOffset);
TestMessage.AddId(messageBuffer, i);
int testMessage = TestMessage.EndTestMessage(messageBuffer);
TestMessage.FinishTestMessageBuffer(messageBuffer, testMessage);
string s = "";
for (int j = 0; j < messageBuffer.DataBuffer.Data.Length; j++) s += messageBuffer.DataBuffer.Data[i].ToString() + ", ";
Debug.Log(s);
using (MemoryStream ms = new MemoryStream(messageBuffer.DataBuffer.Data,
0,
messageBuffer.DataBuffer.Data.Length))
{
ByteBuffer byteBuffer = new ByteBuffer(ms.ToArray());
TestMessage parsed = TestMessage.GetRootAsTestMessage(byteBuffer);
if (parsed.Embedded().Id() != i) throw new Exception("Invalid embedded value");
}
}
}
示例2: Login
public void Login()
{
var fbb = new FlatBufferBuilder(1024);
var oName = fbb.CreateString(this.name);
var oLogin = LoginRequest.CreateLoginRequest(fbb, oName);
LoginRequest.FinishLoginRequestBuffer(fbb, oLogin);
WriteBytes(FlatBufferExtensions.ToProtocolMessage(fbb, ClientMessageIds.LoginRequest));
Debug.Log("Login");
}
示例3: createCurrentQuests
VectorOffset createCurrentQuests(FlatBufferBuilder fbb)
{
Entity[] entities = metaPool.GetGroup(Matcher.AllOf(MetaGameMatcher.Quest, MetaGameMatcher.QuestTaskAmount)).GetEntities();
int count = entities.Length;
Offset<CurrentQuest>[] quests = new Offset<CurrentQuest>[count];
for (int i = 0; i < count; i++) {
var e = entities[i];
StringOffset questName = fbb.CreateString(e.quest.id);
quests[i] = CurrentQuest.CreateCurrentQuest(fbb, questName, e.questTaskAmount.toComplete, e.questTaskAmount.done, e.isQuestDone);
}
return GameData.CreateCurrentQuestsVector(fbb, quests);
}
示例4: createDefences
VectorOffset createDefences(FlatBufferBuilder fbb)
{
Entity[] entities = corePool.GetGroup(CoreGameMatcher.Defence).GetEntities();
int count = entities.Length;
Offset<CityDefences>[] defences = new Offset<CityDefences>[count];
for (int i = 0; i < count; i++) {
var e = entities[i];
StringOffset type = fbb.CreateString(e.type.value);
Offset<TimeInterval> production = e.hasStartEndTime ? TimeInterval.CreateTimeInterval (fbb, e.startEndTime.start.GetMicrosecondsFromEpoch (), e.startEndTime.end.GetMicrosecondsFromEpoch ()) : default(Offset<TimeInterval>);
defences[i] = CityDefences.CreateCityDefences(fbb, type, (sbyte)e.level.value, e.isDefenceUpgrading, production);
}
return GameData.CreateDefencesVector(fbb, defences);
}
示例5: createCompletedQuests
VectorOffset createCompletedQuests(FlatBufferBuilder fbb)
{
if(!metaPool.hasQuestsCompleted){
return default(VectorOffset);
}
int count = metaPool.questsCompleted.ids.Count;
StringOffset[] questArray = new StringOffset[count];
int index = 0;
foreach (var quests in metaPool.questsCompleted.ids) {
questArray[index] = fbb.CreateString(quests);
index++;
}
return GameData.CreateCompletedQuestsVector(fbb, questArray);
}
示例6: createBuildings
VectorOffset createBuildings(FlatBufferBuilder fbb)
{
Entity[] entities = corePool.GetGroup(CoreGameMatcher.Building).GetEntities();
int count = entities.Length;
Offset<Building>[] buildings = new Offset<Building>[count];
for (int i = 0; i < count; i++) {
var e = entities[i];
var production = Production (fbb, e);
StringOffset buildingType = fbb.CreateString (e.type.value);
Offset<Position> position = Position.CreatePosition(fbb, (short)e.position.x, (short)e.position.y);
VectorOffset storage = e.hasBuildingStorage ? TypeAmountVector(fbb, e.buildingStorage.items) : default(VectorOffset);;
buildings[i] = Building.CreateBuilding(fbb, buildingType, (sbyte)e.level.value, position, e.isProductionPaused, production, storage);
}
return GameData.CreateBuildingsVector(fbb, buildings);
}
示例7: createIslands
VectorOffset createIslands(FlatBufferBuilder fbb)
{
Entity[] entities = corePool.GetGroup(CoreGameMatcher.Island).GetEntities();
int count = entities.Length;
Offset<Island>[] islands = new Offset<Island>[count];
for (int i = 0; i < count; i++) {
var e = entities[i];
var defences = IslandDefences (fbb, e);
Offset<TimeInterval> production = Production(fbb, e);
islands[i] = Island.CreateIsland (fbb, fbb.CreateString (entities [i].islandID.value), fbb.CreateString (entities [i].islandOwner.value), (sbyte)e.level.value, production, defences);
}
return GameData.CreateIslandsVector(fbb, islands);
}
示例8: TypeLevelVector
VectorOffset TypeLevelVector(FlatBufferBuilder fbb, System.Collections.Generic.Dictionary<string, int> items)
{
var quantities = metaPool.unitLevels.values;
int count = quantities.Count;
Offset<TypeLevel>[] resources = new Offset<TypeLevel>[count];
int index = 0;
foreach (var type in quantities.Keys) {
StringOffset typeStringOffset = fbb.CreateString(type);
resources[index] = TypeLevel.CreateTypeLevel(fbb,typeStringOffset, (sbyte)quantities[type]);
index++;
}
fbb.StartVector(4, resources.Length, 4);
for (int i = resources.Length - 1; i >= 0; i--) fbb.AddOffset(resources[i].Value);
return fbb.EndVector();
}
示例9: TypeAmountVector
VectorOffset TypeAmountVector(FlatBufferBuilder fbb, System.Collections.Generic.Dictionary<string, int> items)
{
if(items == null || items.Count == 0){
return default(VectorOffset);
}
int count = items.Count;
Offset<TypeAmount>[] resources = new Offset<TypeAmount>[count];
int index = 0;
foreach (var type in items.Keys) {
StringOffset typeStringOffset = fbb.CreateString(type);
resources[index] = TypeAmount.CreateTypeAmount(fbb,typeStringOffset, items[type]);
index++;
}
fbb.StartVector(4, resources.Length, 4);
for (int i = resources.Length - 1; i >= 0; i--) fbb.AddOffset(resources[i].Value);
return fbb.EndVector();
}
示例10: IslandDefences
VectorOffset IslandDefences(FlatBufferBuilder fbb, Entity e)
{
VectorOffset defences = default(VectorOffset);
if (e.hasIslandDefence) {
int defencesCount = e.islandDefence.defences.Count;
Offset<Defence>[] defenceArray = new Offset<Defence>[defencesCount];
for (int j = 0; j < defencesCount; j++) {
var defenceType = fbb.CreateString (e.islandDefence.defences [j].type);
defenceArray [j] = Defence.CreateDefence (fbb, defenceType, (sbyte)e.islandDefence.defences [j].level, e.islandDefence.defences [j].hp);
}
defences = Island.CreateDefencesVector (fbb, defenceArray);
}
return defences;
}
示例11: createTechnologies
VectorOffset createTechnologies(FlatBufferBuilder fbb)
{
if(!metaPool.hasTechnologies){
return default(VectorOffset);
}
int count = metaPool.technologies.values.Count;
StringOffset[] technologies = new StringOffset[count];
int index = 0;
foreach (var tech in metaPool.technologies.values) {
technologies[index] = fbb.CreateString(tech);
index++;
}
return GameData.CreateTechnologiesVector(fbb, technologies);
}
示例12: createShips
VectorOffset createShips(FlatBufferBuilder fbb)
{
Entity[] entities = corePool.GetGroup(CoreGameMatcher.Ship).GetEntities();
int count = entities.Length;
Offset<Ship>[] ships = new Offset<Ship>[count];
for (int i = 0; i < count; i++) {
var e = entities[i];
StringOffset typeStringOffset = fbb.CreateString(e.type.value);
VectorOffset cargo = e.hasShipCargo ? TypeAmountVector(fbb, e.shipCargo.items) : default(VectorOffset);
VectorOffset armyCargo = e.hasShipArmyCargo ? TypeAmountVector(fbb, e.shipArmyCargo.troops) : default(VectorOffset);
ships[i] = Ship.CreateShip(fbb, typeStringOffset, e.shipStatus.value, (sbyte)e.order.value, (sbyte)e.level.value, cargo, armyCargo);
}
return GameData.CreateShipsVector(fbb, ships);
}
示例13: createPlayerName
StringOffset createPlayerName(FlatBufferBuilder fbb)
{
return fbb.CreateString("Caterina Spadari");//fbb.CreateString(GameSetupBehaviour.credentials.credentials.name);
}
示例14: 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!");
}
示例15: sendChatMessage
/// <summary>
/// Sends a chat message.
/// </summary>
/// <param name="message">Message.</param>
public static void sendChatMessage(string message)
{
FlatBufferBuilder fbb = new FlatBufferBuilder (1);
var mon = NetMessage.CreateNetMessage (fbb,
NetID.Chat,
Chat.CreateChat (fbb,
fbb.CreateString (userName),
fbb.CreateString (message)).Value);
NetMessage.FinishNetMessageBuffer (fbb, mon);
peer.Send (0, fbb.SizedByteArray (), PacketFlags.Reliable);
}