summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2014-09-19 16:51:36 -0700
committerWouter van Oortmerssen <wvo@google.com>2014-09-22 15:53:19 -0700
commit517c964fe2099ecc0810db33cfd45b406b3f3132 (patch)
tree4b646dbde5cd5b70d4ef92c07d4cbbb27a594c50 /net
parent3f8700b29669855ae440ad67180742ede82b3fb2 (diff)
downloadflatbuffers-517c964fe2099ecc0810db33cfd45b406b3f3132.tar.gz
flatbuffers-517c964fe2099ecc0810db33cfd45b406b3f3132.tar.bz2
flatbuffers-517c964fe2099ecc0810db33cfd45b406b3f3132.zip
Support for required fields.
Change-Id: I560c7ca11b3d665eecafb528f3737b7e139ca9b0 Tested: on Linux and Windows.
Diffstat (limited to 'net')
-rw-r--r--net/FlatBuffers/FlatBufferBuilder.cs13
1 files changed, 13 insertions, 0 deletions
diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs
index f4a6ca42..68225f93 100644
--- a/net/FlatBuffers/FlatBufferBuilder.cs
+++ b/net/FlatBuffers/FlatBufferBuilder.cs
@@ -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));