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

@@ -242,6 +242,17 @@ public class FlatBufferBuilder {
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.capacity() - table;
int vtable_start = table_start - bb.getInt(table_start);
boolean ok = bb.getShort(vtable_start + field) != 0;
// If this fails, the caller will show what field needs to be set.
if (!ok)
throw new AssertionError("FlatBuffers: field " + field + " must be set");
}
public void finish(int root_table) {
prep(minalign, SIZEOF_INT);
addOffset(root_table);