-
Notifications
You must be signed in to change notification settings - Fork 3.4k
-
Hi, I am trying to generate a reflection-based ui so I can edit flatbuffers. I don't care if the performance isnt ideal when im BUILDING them in this case, as its a GUI tool, and I understand as strings and other optional tables are added by the user, that the underlying vector has to be resized.
Ive gone through ReflectionTest in test.cpp, and am using a resizing vector with a PIV just like the test.
I can set a struct member just fine, but I cant set an optional string, even with the AddFlatBuffer function.
It goes something like this:
virtual void text_changed( const String& p_str ) override { // fb // "fb" is simply a wrapper object that holds a vector data, and the "piv" to the root inside of it // it can be coerced to both Table* and Table* via operator() casts for ease of use const flatbuffers::String* str = flatbuffers::GetFieldS( *fb, *field ); // There's already a string in the table, modify it if ( str ) { flatbuffers::SetString( *schema, std::string( p_str.ascii() ), flatbuffers::GetFieldS( *fb, *field ), &fb->data ); print_line("MODIFIED FB STRING"); return; } // we need to add a new one flatbuffers::FlatBufferBuilder s_fbb; s_fbb.Finish( s_fbb.CreateString( (const char*)p_str.ascii() ) ); auto string_ptr = flatbuffers::AddFlatBuffer( fb->data, s_fbb.GetBufferPointer(), s_fbb.GetSize() ); bool ret_val = flatbuffers::SetFieldT( *fb, *field, string_ptr ); print_line("ADDED FB STRING"); }
In this case, ret_val is always false. It seems to fail in SetFieldT >>> table->SetPointer() >>> GetOptionalFieldOffset(field)
which returns 0, causing it to fail.
I notice the test example uses a vector of strings, and manually resizes the vector to add in a new string offset, which is different. I do not see a test case that simply adds in a string by itself.
Is there a different way of doing this? Or is it a bug?
Beta Was this translation helpful? Give feedback.