mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-19 19:45:43 +00:00
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.
This commit is contained in:
@@ -447,6 +447,14 @@ MyGame.Example.Monster.prototype.inventoryLength = function() {
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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}
|
||||
*/
|
||||
@@ -555,6 +563,14 @@ MyGame.Example.Monster.prototype.testnestedflatbufferLength = function() {
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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}
|
||||
@@ -653,6 +669,14 @@ MyGame.Example.Monster.prototype.testarrayofboolsLength = function() {
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user