Hi,
did i something wrong?or why i'am not able to read out the byte array correctly?creation of the flatbuffer:
FlatBufferBuilder fbb = new FlatBufferBuilder(1); int coloroffset = XFBType.Colour.CreateColour(fbb, m_ColourAmbient.R, m_ColourAmbient.G, m_ColourAmbient.B, m_ColourAmbient.A); int sceneoffset = XFBType.Scene.CreateScene(fbb, coloroffset); fbb.Finish(sceneoffset);
if i try to read out only the byte array it doesn't work (this should work or?):
ByteBuffer byteBuffer = new ByteBuffer(fbb.DataBuffer().Data); var m_FBDataNOT = XFBType.Scene.GetRootAsScene(byteBuffer); // read //error NULL XFBType.Colour colourNOT = m_FBDataNOT.ColourAmbient();
if i read the flatbuffer directly after creation it works:
var m_FBData = XFBType.Scene.GetRootAsScene(fbb.DataBuffer()); // read //data OK XFBType.Colour colour = m_FBData.ColourAmbient()
and Byte[] test2 = fbb.SizedByteArray(); //error index out of bounds
is chrashing with index out of bounds...
fbb.dataBuffer().position()
(this is because the data was built backwards in memory). It ends at fbb.capacity()
."In my little test app I created a byte[bb.Length - bb.position ()] foo then used System.Buffer.BlockCopy (bb.Data(), bb.position (), foo, 0, bb.Length - bb.position ()). I was then able to feed foo into a new ByteBuffer, which I then fed to my object's GetRootAsObject method.
so... in the current state it's not possible to get the byte data(without a set position method)?....
i could swear " Byte[] test = fbb.DataBuffer().Data;" worked before the newly added "Create" functions (that i realy needed).
--
You received this message because you are subscribed to a topic in the Google Groups "FlatBuffers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flatbuffers/-TAa87iDyCg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
public static void SaveGameData(string path, Dictionary<string, GameInfo> games) { int[] gamesVector = new int[games.Count]; FlatBufferBuilder fbb = new FlatBufferBuilder(1); int i = 0; foreach (GameInfo game in games.Values) { gamesVector[i++] = game.ToFlatBuff(fbb); } int saveData = SaveData.CreateGamesVector(fbb, gamesVector); fbb.Finish(saveData); File.WriteAllBytes(path, fbb.SizedByteArray()); }
public static Dictionary<string, GameInfo> LoadGameData(string path) { Dictionary<string, GameInfo> games = new Dictionary<string, GameInfo>(); if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ByteBuffer bb = new ByteBuffer(data); SaveData save = SaveData.GetRootAsSaveData(bb); for (int i = 0; i < save.GamesLength; i++) { // ArgumentOutOfRange games.Add(save.GetGames(i).GameId, GameInfo.GetFromFlatBuff(save.GetGames(i))); } } return games; }