Merge pull request #32160 from unintellisense/master

[flatbuffers] support clear method on flatbuffer builder and bytebuffer
This commit is contained in:
Benjamin Lichtman
2019-01-23 15:11:10 -08:00
committed by GitHub
2 changed files with 29 additions and 0 deletions
+21
View File
@@ -86,6 +86,27 @@ class Test {
builder.writeInt16(a);
return builder.offset();
}
static testClear(builder: flatbuffers.Builder, a: number, b: number) {
const offsets: number[] = [];
const iterations = 100;
for (let i = 0; i < iterations; i++) {
const offset = Test.createTest(builder, a, b);
offsets.push(offset);
builder.clear();
}
let lastOffsetValue = offsets[0];
let sameValue = true;
for (let i = 1; i < offsets.length; i++) {
if (lastOffsetValue !== offsets[i]) {
sameValue = false;
return sameValue;
}
lastOffsetValue = offsets[i];
}
return sameValue;
}
}
class TestSimpleTableWithEnum {
+8
View File
@@ -42,6 +42,12 @@ declare global {
class Builder {
constructor(initial_size?: number);
/**
* Reset all the state in this FlatBufferBuilder
* so it can be reused to construct another buffer.
*/
clear(): void;
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
@@ -211,6 +217,8 @@ declare global {
static allocate(byte_size: number): ByteBuffer;
clear(): void;
bytes(): Uint8Array;
position(): number;