Search code examples
c++flatbuffers

Flatbuffers didn't generate a Get* method, but did generate *Builder (in c++)?


I recently started experimenting with flatbuffers and am facing a very strange problem. I am able to translate the flatb schema to c++ and compile my c++ code (which includes the generated c++) without errors. I am even able to encode a object using flatbuffers MyEventBuilder(...). However, there isn't a corresponding GetMyEvent(...) method!

I grepped for GetMyEvent in the .h file generated by flatc and nothing of relevance shows up. Clearly I'm doing something wrong, this is too big of an issue for it to just be a bug. However, I've followed the docs pretty closely. I also posted this issue in the flatbuffers google group, no response yet.

Has anyone else seen this? Any ideas what could cause this (I'm hoping and assuming this is just a silly error on my end and not an issue with flatbuffers)?

TLDR: flatb generate a method to encode my c++ object to a byte array, but not a method to convert a byte array back to a c++ object!


Solution

  • Do you have root_type defined in your Flatbuffer definition? I've discovered, that Get methon is only generated for table with this defined.