Added the hash attribute to ints and longs.

FlatBuffer schema files can now optionally specify a hash attribute that
will allow someone writing json files to enter a string to be hashed
rather than a specific value. The hashing algorithm to use is specified
by the schema.

Currently the only algorithms are fnv1 and fnv1a. There are 32 bit and
64 variatns for each. Additionally, a hashing command line tool was
added so that you can see what a string will hash to without needing to
inspect the flatbuffer binary blob.

Change-Id: I0cb359d0e2dc7d2dc1874b446dc19a17cc77109d
This commit is contained in:
Alex Ames
2015-02-13 15:58:29 -08:00
parent 620fe1c5cf
commit d575321eba
11 changed files with 333 additions and 6 deletions

View File

@@ -24,6 +24,7 @@
#include <functional>
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/hash.h"
// This file defines the data types representing a parsed IDL (Interface
// Definition Language) / schema file.
@@ -280,6 +281,7 @@ class Parser {
known_attributes_.insert("deprecated");
known_attributes_.insert("required");
known_attributes_.insert("key");
known_attributes_.insert("hash");
known_attributes_.insert("id");
known_attributes_.insert("force_align");
known_attributes_.insert("bit_flags");
@@ -334,6 +336,7 @@ class Parser {
uoffset_t ParseVector(const Type &type);
void ParseMetaData(Definition &def);
bool TryTypedValue(int dtoken, bool check, Value &e, BaseType req);
void ParseHash(Value &e, FieldDef* field);
void ParseSingleValue(Value &e);
int64_t ParseIntegerFromString(Type &type);
StructDef *LookupCreateStruct(const std::string &name);