Support for required fields.

Change-Id: I560c7ca11b3d665eecafb528f3737b7e139ca9b0
Tested: on Linux and Windows.
This commit is contained in:
Wouter van Oortmerssen
2014-09-19 16:51:36 -07:00
parent 3f8700b296
commit 517c964fe2
21 changed files with 137 additions and 45 deletions

View File

@@ -335,6 +335,19 @@ namespace FlatBuffers
return vtableloc;
}
// This checks a required field has been set in a given table that has
// just been constructed.
public void Required(int table, int field)
{
int table_start = _bb.Length - table;
int vtable_start = table_start - _bb.GetInt(table_start);
bool ok = _bb.GetShort(vtable_start + field) != 0;
// If this fails, the caller will show what field needs to be set.
if (!ok)
throw new InvalidOperationException("FlatBuffers: field " + field +
" must be set");
}
public void Finish(int rootTable)
{
Prep(_minAlign, sizeof(int));