JS- support clear() method on builder (#5109)

* support clearing flatBuffer builder in js

* remove unused member
 reset force_defaults
dont actually need to clear data in bytebuffer
This commit is contained in:
unintellisense
2019-01-14 09:21:42 -08:00
committed by Wouter van Oortmerssen
parent b99332efd7
commit 46208b1e91
2 changed files with 41 additions and 6 deletions

View File

@@ -226,6 +226,19 @@ flatbuffers.Builder = function(opt_initial_size) {
this.force_defaults = false;
};
flatbuffers.Builder.prototype.clear = function() {
this.bb.clear();
this.space = this.bb.capacity();
this.minalign = 1;
this.vtable = null;
this.vtable_in_use = 0;
this.isNested = false;
this.object_start = 0;
this.vtables = [];
this.vector_num_elems = 0;
this.force_defaults = false;
};
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
@@ -816,6 +829,7 @@ flatbuffers.ByteBuffer = function(bytes) {
* @private
*/
this.position_ = 0;
};
/**
@@ -828,6 +842,10 @@ flatbuffers.ByteBuffer.allocate = function(byte_size) {
return new flatbuffers.ByteBuffer(new Uint8Array(byte_size));
};
flatbuffers.ByteBuffer.prototype.clear = function() {
this.position_ = 0;
};
/**
* Get the underlying `Uint8Array`.
*