mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 17:22:21 +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:
@@ -36,3 +36,6 @@ table Monster {
|
||||
}
|
||||
|
||||
root_type Monster;
|
||||
|
||||
file_identifier "MONS";
|
||||
file_extension "mon";
|
||||
|
||||
@@ -187,6 +187,10 @@ inline const Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot<
|
||||
|
||||
inline bool VerifyMonsterBuffer(const flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<Monster>(); }
|
||||
|
||||
inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<Monster> root) { fbb.Finish(root, "MONS"); }
|
||||
|
||||
inline bool MonsterBufferHasIdentifier(const void *buf) { return flatbuffers::BufferHasIdentifier(buf, "MONS"); }
|
||||
|
||||
} // namespace Example
|
||||
} // namespace MyGame
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ std::string CreateFlatBufferTest() {
|
||||
Any_Monster, mloc2.Union(), // Store a union.
|
||||
testv, vecofstrings, vecoftables, 0);
|
||||
|
||||
builder.Finish(mloc);
|
||||
FinishMonsterBuffer(builder, mloc);
|
||||
|
||||
#ifdef FLATBUFFERS_TEST_VERBOSE
|
||||
// print byte data for debugging:
|
||||
@@ -116,6 +116,8 @@ void AccessFlatBufferTest(const std::string &flatbuf) {
|
||||
flatbuf.length());
|
||||
TEST_EQ(VerifyMonsterBuffer(verifier), true);
|
||||
|
||||
TEST_EQ(MonsterBufferHasIdentifier(flatbuf.c_str()), true);
|
||||
|
||||
// Access the buffer from the root.
|
||||
auto monster = GetMonster(flatbuf.c_str());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user