Feature request: Support key on character arrays in structs
In the same vein as https://github.com/google/flatbuffers/issues/4195, it would be nice if it were possible to easily use fixed-length character buffers in structs alongside the automatic sorting and LookupByKey code gen provided by (key).
In other words, it would be cool if this schema were valid:
struct UserAccount {
username:[uint8:32] (key);
password:[uint8:32];
}
Currently, it throws the error:
error: 'username' field must be string or scalar type
I'm working around this by using this schema instead:
table UserAccount {
username:string (key);
password:string;
}
along with the CreateString overload that takes an explicit length (e.g. fbb.CreateString("dbechrd", 32)) in order to pre-allocate enough storage to allow me to mutate the username later, but then it becomes very tedious to copy UserAccounts around in C++ since they're now tables instead of structs, and there doesn't seem to be any straightforward way to get the data() and size() of a table (it's probably possible via reflection, but that's not ideal).
Dunno if this is feasible; just a thought.
I would be supportive of this. A fixed-size array is a scalar IMO, and anything else you can place in a struct is technically a scalar type as well. So other structs could also be keys as well.
I created a PR #7623, this one only enables using an array of scalar type as key, will have follow up PRs for using struct and array of struct as key.
This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.
This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.