2

I'm using flatbuffers, in its' schema, some field can set as hash. Eg:

table Person {
  age: int (hash:"fnv1_32" );
}

what is this for ? I'm using

flatc --cpp --gen-object-api Person_KeyHashTest.fbs

How to set 'rehash' and 'resolver' in the generate function ? Could someone give me an easy example ?

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
NeoLiu
  • 212
  • 3
  • 11

1 Answers1

1

See hash in https://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html

It allows you to turn strings into integers in the binary representation. The resolver function allows you to specify a way to lookup such a hash to an object you have created elsewhere. This allows you to do things like having objects in one buffer refer to ones in another. The actual implementation of these functions is up to you, it can be whatever you want.

Aardappel
  • 5,559
  • 1
  • 19
  • 22
  • Can you please give an example/ use case. I see we can avoid multiple strings in buffer with this, but aren't strings already referred in table?? – Shivendra Agarwal May 28 '18 at 21:00
  • 2
    You don't need hashes to avoid having multiple copies of a string: you can simply serialize a string and use its offset multiple times in parent objects to do sting sharing. In C++ you can even turn on automatic string pooling. Hashes are for when the code that uses the buffer is going to use the string as hashes anyway, so you can save space in the buffer. – Aardappel May 29 '18 at 15:46