feat: Support union underlying type for TS/JS (#7961)

This commit is contained in:
sssooonnnggg
2023-05-16 04:18:49 +08:00
committed by GitHub
parent 1d3afb90c5
commit b128b802d9
6 changed files with 58 additions and 8 deletions

View File

@@ -0,0 +1,26 @@
import assert from 'assert'
import * as flatbuffers from 'flatbuffers'
import {UnionUnderlyingType as Test} from './union_underlying_type_test.js'
function main() {
let a = new Test.AT();
a.a = 1;
let b = new Test.BT();
b.b = "foo";
let c = new Test.CT();
c.c = true;
let d = new Test.DT();
d.testUnionType = Test.ABC.A;
d.testUnion = a;
d.testVectorOfUnionType = [Test.ABC.A, Test.ABC.B, Test.ABC.C];
d.testVectorOfUnion = [a, b, c];
let fbb = new flatbuffers.Builder();
let offset = d.pack(fbb);
fbb.finish(offset);
let unpacked = Test.D.getRootAsD(fbb.dataBuffer()).unpack();
assert.equal(JSON.stringify(unpacked), JSON.stringify(d));
}
main()