Closed Gompangs closed 8 years ago
Note what it says here: http://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html
// This must be called after `Finish()`.
var buf = builder.DataBuffer; // Of type `FlatBuffers.ByteBuffer`.
// The data in this ByteBuffer does NOT start at 0, but at buf.Position.
// The end of the data is marked by buf.Length, so the size is
// buf.Length - buf.Position.
// Alternatively this copies the above data out of the ByteBuffer for you:
bytes[] buf = builder.SizedByteArray();
I changed from fbb.DataBuffer.Data to fbb.SizedByteArray() and it's perpectly working now ! Thanks for your reply.
Hi, I'm using flatbuffer for my sample game.
Client : C#(Unity) Server : JAVA(netty)
Protocol Schema is `table EchoMsg{ ProtocolId:short; Msg:string; }
table TestMsg{ Msg:string; }`
So, I tried on Client(C#) object serialize like below `var fbb = new FlatBufferBuilder(1); string testStr = "FlatBuffer~ Flatbuffer Test !@#"; var strOffset = fbb.CreateString(testStr); EchoMsg.StartEchoMsg(fbb); EchoMsg.AddProtocolId(fbb, (short)1234); EchoMsg.AddMsg(fbb, strOffset); var endOffset = EchoMsg.EndEchoMsg(fbb); fbb.Finish(endOffset.Value);
sendToServer(fbb.DataBuffer.Data, SendOption.Reliable); ` = 128 Bytes
and Server side receive those data with ByteBuf(netty based buffer)
Server(Java) Receive and deserialize code is below @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
but it printed just string ->"null" and short ->"0".. I'm wondering which part was wrong.
On Java side just simple way to check data is append byte and print it. So , I tried that and Raw Data is exist! but it doesn't Deserialized in flatbuffers.
Received Bytes => 000000000000000000000000000000000000000000000000000000001200080120100408000800000-46442000-19-108-116-21-98-85-21-78-124-19-115-6832-19-123-116-20-118-92-19-118-723270108971169811710210210111432841011151163233
To String like this=>
I was tried almost things.. but I didn't found mistake. I guess it's Netty(NIO TCP Server) problem cause it using own buffer(ByteBuf).
Please give me some idea to solve this problem. Thanks!