mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Support for required fields.
Change-Id: I560c7ca11b3d665eecafb528f3737b7e139ca9b0 Tested: on Linux and Windows.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user