-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++: mini_reflect: Add DefaultTypeTable #4614
Conversation
Currently it's very easy to make a mistake when it comes to instantiating the TypeTable to print a buffer because it is not type safe. This will allow us to write safer cpp code: flatbuffers::FlatBufferToString(reinterpret_cast<const uint8_t *>(&t), decltype(t)::DefaultTypeTable());
@gwvo I had a file that was like this:
I had a few core_dumps and then realize it was a typo on the name. I can write a type safe quick wrapper with this change. |
All the unit tests are passing now test 1 1: Test command: /home/agallego/workspace/flatbuffers/build/flattests 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 0.06 sec |
one can then create a simple helper like this
|
samples/monster_generated.h
Outdated
@@ -185,6 +191,9 @@ struct MonsterT : public flatbuffers::NativeTable { | |||
|
|||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { | |||
typedef MonsterT NativeTableType; | |||
static flatbuffers::TypeTable* DefaultTypeTable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure the *
goes next to the name. Also, Default
doesn't sound quite right, since there are no alternatives. Just TypeTable
would be too prone to clashes. Maybe.. ThisTypeTable
? GetTypeTable
? TheTypeTable
? Or go verbose and say MiniReflectTypeTable
..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will submit fix. Thanks!
Sounds good, I fixed it, let me know if you want me to do any other edits. |
Thanks! |
* mini_reflect: Add DefaultTypeTable Currently it's very easy to make a mistake when it comes to instantiating the TypeTable to print a buffer because it is not type safe. This will allow us to write safer cpp code: flatbuffers::FlatBufferToString(reinterpret_cast<const uint8_t *>(&t), decltype(t)::DefaultTypeTable()); * c++: mini_reflect: update generated code * Ensure types and names are set for mini_reflect * c++: mini_refelct: update unit tests with new typed TypeTable * Adding PR feedback of sylte and naming convention
Currently it's very easy to make a mistake when it comes to
instantiating the TypeTable to print a buffer because it is not type
safe.
This will allow us to write safer cpp code:
flatbuffers::FlatBufferToString(reinterpret_cast<const uint8_t *>(&t),
decltype(t)::DefaultTypeTable());