chronoxor / FastBinaryEncoding

Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift
https://chronoxor.github.io/FastBinaryEncoding
MIT License
827 stars 86 forks source link

Receiver is unable to find message size despite parsing correctly #79

Closed M0n7y5 closed 1 year ago

M0n7y5 commented 1 year ago

Hi, for some reason when i send some message from my server to client, client will receive it, parse it and invoke OnReceive(myType msg) correctly. After going out of scope, it throws assert error.
obrazek

After some investigation. i found out it that it tries to get message size like this: obrazek

offset2 is 58 in this case: obrazek

resulted message size is 0;

This is the content of the buffer obrazek

This is called only once: obrazek

obrazek

For some reason it tries to invalidate this message after invoking OnReceive(myType msg) and data inside that struct are correct. So i don't quite understand the callgraph here. Here is callstack: obrazek

chronoxor commented 1 year ago

First of all please check that you call Reset() for each time, you client is connected:

        void OnConnected()
        {
            // Reset FBE protocol buffers
            Reset();
            ....
        }
chronoxor commented 1 year ago

If you have your own Server & Client implementation, I suggest starting from ProtoServer/ProtoClient examples to get everything works fine and replace TcpServer/TcpSession/TcpClient with your own transport layer.

M0n7y5 commented 1 year ago

If you have your own Server & Client implementation, I suggest starting from ProtoServer/ProtoClient examples to get everything works fine and replace TcpServer/TcpSession/TcpClient with your own transport layer.

That's what i am trying to do. But the documentation here is outdated and the fact that i need to go to completely different repository in order to get proper info about how to use this project is kinda red flag for me... For transport i am using Asp.Net websockets with custom encryption. I tested it all before i tried to plug in FBE for some actual protocol. It works flawlessly. But now am getting confusing crashes when i am trying to use FBE;

First of all please check that you call Reset() for each time, you client is connected:

        void OnConnected()
        {
            // Reset FBE protocol buffers
            Reset();
            ....
        }

I am already doing that.

Fun fact... Setting this to 0 here makes it work without crash but it is printing this infinitely obrazek

remedybg_Avwa9Y8MNR

So that means it correctly get message size. But still why is it able to print that message and the after printing its get validated? Shouldn't be this other way? Invalidate message -> Parse -> Invoke handlers?

M0n7y5 commented 1 year ago

I found the issue... The issue was additional message byte padding created by encryption algorithm. Since FBE tries to parse entire provided buffer. It was parsing first message correctly and then it tried to parse rest of the buffer. Since excess bytes are null, static assert with invalid message size is triggered. I made some additional changes and now it seems to be working fine. I was under the impression that FBE will ignore those padding bytes which DOES but not in Debug mode.