mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
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:
committed by
Wouter van Oortmerssen
parent
b99332efd7
commit
46208b1e91
@@ -21,7 +21,28 @@ function main() {
|
||||
// normally a size larger than the typical FlatBuffer you generate would be
|
||||
// better for performance.
|
||||
var fbb = new flatbuffers.Builder(1);
|
||||
createMonster(fbb);
|
||||
serializeAndTest(fbb);
|
||||
|
||||
// clear the builder, repeat tests
|
||||
var clearIterations = 100;
|
||||
var startingCapacity = fbb.bb.capacity();
|
||||
for (var i = 0; i < clearIterations; i++) {
|
||||
fbb.clear();
|
||||
createMonster(fbb);
|
||||
serializeAndTest(fbb);
|
||||
}
|
||||
// the capacity of our buffer shouldn't increase with the same size payload
|
||||
assert.strictEqual(fbb.bb.capacity(), startingCapacity);
|
||||
|
||||
test64bit();
|
||||
testUnicode();
|
||||
fuzzTest1();
|
||||
|
||||
console.log('FlatBuffers test: completed successfully');
|
||||
}
|
||||
|
||||
function createMonster(fbb) {
|
||||
// We set up the same values as monsterdata.json:
|
||||
|
||||
var str = fbb.createString('MyMonster');
|
||||
@@ -56,7 +77,9 @@ function main() {
|
||||
var mon = MyGame.Example.Monster.endMonster(fbb);
|
||||
|
||||
MyGame.Example.Monster.finishMonsterBuffer(fbb, mon);
|
||||
}
|
||||
|
||||
function serializeAndTest(fbb) {
|
||||
// Write the result to a file for debugging purposes:
|
||||
// Note that the binaries are not necessarily identical, since the JSON
|
||||
// parser may serialize in a slightly different order than the above
|
||||
@@ -69,12 +92,6 @@ function main() {
|
||||
testMutation(fbb.dataBuffer());
|
||||
|
||||
testBuffer(fbb.dataBuffer());
|
||||
|
||||
test64bit();
|
||||
testUnicode();
|
||||
fuzzTest1();
|
||||
|
||||
console.log('FlatBuffers test: completed successfully');
|
||||
}
|
||||
|
||||
function testMutation(bb) {
|
||||
|
||||
Reference in New Issue
Block a user