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

Some bug in receiver when parsing final model #12

Closed misha1sh closed 5 years ago

misha1sh commented 5 years ago

Hello. Minimal size of final model struct is 8 bytes, but this assert is checking that message_size is larger than 16 bytes https://github.com/chronoxor/FastBinaryEncoding/blob/393e6ee2528b9b53da8b0dc28d347ebb7cd5cd13/source/generator_cpp.cpp#L4513 Is this kind of bug or I am just using wrong compilation options?

chronoxor commented 5 years ago

8 bytes (4 byte size & 4 bytes offset) is minimal struct size, which could be included into another struct. For root structs which are send / received we need two more fields - 4 bytes total size and 4 bytes offset. See FBE spec for details - https://chronoxor.github.io/FastBinaryEncoding/documents/FBE.html#structs

Root struct

misha1sh commented 5 years ago

In specification said that minimal size of FINAL struct is 8 bytes:

Final model struct properties:

Root struct size = 8 + sizeof(fileds) Inner struct size = sizeof(fileds)

image

And this assert is working for Final model too. If you pass empty struct to FinalSender and then will try to pass buffer to FinalReceiver, this assert will fail. (model should be compiled with --final and --sender flags). Tested on java

chronoxor commented 5 years ago

Reproduced! Fix will be available soon.

chronoxor commented 5 years ago

Fixed!