From ba20d9bff39c71912399746d8711b9868afa0dd7 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Thu, 20 Apr 2017 02:06:33 +0200 Subject: [PATCH] Added a clear function for purging all data that is holded by the FlatBuffer. (#4259) --- .../google/flatbuffers/FlatBufferBuilder.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/java/com/google/flatbuffers/FlatBufferBuilder.java b/java/com/google/flatbuffers/FlatBufferBuilder.java index fd4b729e6..a138ed5f7 100644 --- a/java/com/google/flatbuffers/FlatBufferBuilder.java +++ b/java/com/google/flatbuffers/FlatBufferBuilder.java @@ -106,6 +106,22 @@ public class FlatBufferBuilder { return this; } + /** + * Reset the FlatBufferBuilder by purging all data that it holds. + */ + public void clear(){ + space = bb.capacity(); + bb.clear(); + minalign = 1; + while(vtable_in_use > 0) vtable[--vtable_in_use] = 0; + vtable_in_use = 0; + nested = false; + finished = false; + object_start = 0; + num_vtables = 0; + vector_num_elems = 0; + } + /// @cond FLATBUFFERS_INTERNAL /** * Create a `ByteBuffer` with a given capacity.