mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
File identifier feature.
Allows you to add, and test for the presence of a magic 4-char string in a FlatBuffer. Tested: on OS X. Change-Id: I090692a9e4fb53bed3543279a28563e67132cba0
This commit is contained in:
@@ -466,18 +466,36 @@ std::string GenerateCPP(const Parser &parser, const std::string &include_guard_i
|
||||
code += decl_code;
|
||||
code += enum_code_post;
|
||||
|
||||
// Generate convenient root datatype accessor, and root verifier.
|
||||
// Generate convenient global helper functions:
|
||||
if (parser.root_struct_def) {
|
||||
// The root datatype accessor:
|
||||
code += "inline const " + parser.root_struct_def->name + " *Get";
|
||||
code += parser.root_struct_def->name;
|
||||
code += "(const void *buf) { return flatbuffers::GetRoot<";
|
||||
code += parser.root_struct_def->name + ">(buf); }\n\n";
|
||||
|
||||
// The root verifier:
|
||||
code += "inline bool Verify";
|
||||
code += parser.root_struct_def->name;
|
||||
code += "Buffer(const flatbuffers::Verifier &verifier) { "
|
||||
"return verifier.VerifyBuffer<";
|
||||
code += parser.root_struct_def->name + ">(); }\n\n";
|
||||
|
||||
// Finish a buffer with a given root object:
|
||||
code += "inline void Finish" + parser.root_struct_def->name;
|
||||
code += "Buffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<";
|
||||
code += parser.root_struct_def->name + "> root) { fbb.Finish(root";
|
||||
if (parser.file_identifier_.length())
|
||||
code += ", \"" + parser.file_identifier_ + "\"";
|
||||
code += "); }\n\n";
|
||||
|
||||
if (parser.file_identifier_.length()) {
|
||||
// Check if a buffer has the identifier.
|
||||
code += "inline bool " + parser.root_struct_def->name;
|
||||
code += "BufferHasIdentifier(const void *buf) { return flatbuffers::";
|
||||
code += "BufferHasIdentifier(buf, \"" + parser.file_identifier_;
|
||||
code += "\"); }\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Close the namespaces.
|
||||
|
||||
Reference in New Issue
Block a user