forked from google/flatbuffers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support union underlying type for TS/JS (google#7961)
- Loading branch information
1 parent
6c5e3c4
commit 82bead0
Showing
6 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters