You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
virtualvoidtext_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 useconst flatbuffers::String* str = flatbuffers::GetFieldS( *fb, *field );
// There's already a string in the table, modify itif ( 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( (constchar*)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?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:
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.
All reactions