[Python/JS/TS] Codegen SizeOf method for structs (#6136)

* [Python] Codegen SizeOf classmethod for structs

This codegens a `SizeOf()` classmethod for all structs since we can't
determine the size of a FlatBuffer generated struct from Python otherwise.

* [JS/TS] Codegen sizeOf static method for structs

This codegens a `sizeOf()` static method for all structs since we can't
determine the size of a FlatBuffer generated struct from JavaScript or
TypeScript otherwise.
This commit is contained in:
Anass Al
2020-09-28 08:54:50 -07:00
committed by GitHub
parent 641309a5bf
commit 689bfafa7e
14 changed files with 133 additions and 0 deletions

View File

@@ -342,6 +342,13 @@ MyGame.Example.Test.prototype.mutate_b = function(value) {
return true;
};
/**
* @returns {number}
*/
MyGame.Example.Test.sizeOf = function() {
return 4;
}
/**
* @param {flatbuffers.Builder} builder
* @param {number} a
@@ -573,6 +580,13 @@ MyGame.Example.Vec3.prototype.test3 = function(obj) {
return (obj || new MyGame.Example.Test).__init(this.bb_pos + 26, this.bb);
};
/**
* @returns {number}
*/
MyGame.Example.Vec3.sizeOf = function() {
return 32;
}
/**
* @param {flatbuffers.Builder} builder
* @param {number} x
@@ -659,6 +673,13 @@ MyGame.Example.Ability.prototype.mutate_distance = function(value) {
return true;
};
/**
* @returns {number}
*/
MyGame.Example.Ability.sizeOf = function() {
return 8;
}
/**
* @param {flatbuffers.Builder} builder
* @param {number} id