I noticed the following issue
https://github.com/google/flatbuffers/issues/3826 which now allows fully qualified type identifiers to be provided in the generated C++ code.
The use case is to assign a unique hashed identifier either before a flatbuffer in transmission, or as a replacement of the file identifier which isn't standardized on a per table type.
So I was thinking: rather than having everyone inventing their own hash scheme, wouldn't it make sense to define an official hash of each type name and make this available as a pre-calculated GetTypeHash() or something similar to that. The input to the hash is already well-defined. What remains is to choose an endian stable 32-bit hash function and define that it must be encoded as little endian in transmission, and define a strategy such as any hash that result in a 0 hash should instead hash to hash("").
From the following: FNV-1 32-bit seems to be a strong candidate based on speed, few english word collisions, and simplicity:
hash = FNV_offset_basis
for each byte_of_data to be hashed
hash = hash × FNV_prime
hash = hash XOR byte_of_data
return hash
32 bit FNV_prime = 224 + 28 + 0x93 = 16777619
32 bit offset_basis = 2166136261
The above would be stable if converted to little endian after computation and stored in a 4 character array or string.
In the C-api it is currently possible to create buffers with `MyTable_create_as_root` which uses the last seen file_identifier in the schema, or `MyTable_create_as_root_with_identifier` which takes an extra user supplied 4 character identifier string. This string could be derived from the hash mentioned above.
One could also define that the hash is used instead of the file identifier in `MyTable_create_as_root` unless the table is the root_type and there is a file_identifier defined.
The above also solves and issue in the C verifier implementation: it doesn't verify the file identifier of any nested buffer because it is ambigous. The verifier could have two versions, one that continue to ignore nested file identifiers, and one that uses the hash schema.