diff options
author | Robert Nix <mischanix@gmail.com> | 2016-02-12 12:27:28 -0600 |
---|---|---|
committer | Robert Nix <mischanix@gmail.com> | 2016-02-12 12:41:28 -0600 |
commit | 9d92aeb182527989cd943fd1998d8669eea7d70d (patch) | |
tree | 0c2a001df04c149a82a1ac1d7a3766a7a9d615ad /tests | |
parent | 2f5d7ae64580c016f66a4c442b3bafb6e31a926d (diff) | |
download | flatbuffers-9d92aeb182527989cd943fd1998d8669eea7d70d.tar.gz flatbuffers-9d92aeb182527989cd943fd1998d8669eea7d70d.tar.bz2 flatbuffers-9d92aeb182527989cd943fd1998d8669eea7d70d.zip |
Add helper for javascript typed arrays
For scalar vector fields, emit an Array helper that
returns a typed array view of the underlying bytes buffer.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/JavaScriptTest.js | 7 | ||||
-rw-r--r-- | tests/monster_test_generated.js | 24 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/JavaScriptTest.js b/tests/JavaScriptTest.js index 0f4f2335..4661f870 100644 --- a/tests/JavaScriptTest.js +++ b/tests/JavaScriptTest.js @@ -105,6 +105,13 @@ function testBuffer(bb) { } assert.strictEqual(invsum, 10); + var invsum2 = 0; + var invArr = monster.inventoryArray(); + for (var i = 0; i < invArr.length; i++) { + invsum2 += invArr[i]; + } + assert.strictEqual(invsum2, 10); + var test_0 = monster.test4(0); var test_1 = monster.test4(1); assert.strictEqual(monster.test4Length(), 2); diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 9d0f48b0..bafc1eb8 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -448,6 +448,14 @@ MyGame.Example.Monster.prototype.inventoryLength = function() { }; /** + * @returns {Uint8Array} + */ +MyGame.Example.Monster.prototype.inventoryArray = function() { + var offset = this.bb.__offset(this.bb_pos, 14); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; +}; + +/** * @returns {MyGame.Example.Color} */ MyGame.Example.Monster.prototype.color = function() { @@ -556,6 +564,14 @@ MyGame.Example.Monster.prototype.testnestedflatbufferLength = function() { }; /** + * @returns {Uint8Array} + */ +MyGame.Example.Monster.prototype.testnestedflatbufferArray = function() { + var offset = this.bb.__offset(this.bb_pos, 30); + return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; +}; + +/** * @param {MyGame.Example.Stat=} obj * @returns {MyGame.Example.Stat} */ @@ -654,6 +670,14 @@ MyGame.Example.Monster.prototype.testarrayofboolsLength = function() { }; /** + * @returns {Int8Array} + */ +MyGame.Example.Monster.prototype.testarrayofboolsArray = function() { + var offset = this.bb.__offset(this.bb_pos, 52); + return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; +}; + +/** * @param {flatbuffers.Builder} builder */ MyGame.Example.Monster.startMonster = function(builder) { |