mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-15 08:48:52 +00:00
[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:
@@ -9,6 +9,10 @@ np = import_numpy()
|
||||
class StructInNestedNS(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def SizeOf(cls):
|
||||
return 8
|
||||
|
||||
# StructInNestedNS
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
@@ -205,6 +205,13 @@ NamespaceA.NamespaceB.StructInNestedNS.getFullyQualifiedName = function() {
|
||||
return 'NamespaceA.NamespaceB.StructInNestedNS';
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
NamespaceA.NamespaceB.StructInNestedNS.sizeOf = function() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} a
|
||||
|
||||
@@ -204,6 +204,13 @@ static getFullyQualifiedName():string {
|
||||
return 'NamespaceA.NamespaceB.StructInNestedNS';
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns number
|
||||
*/
|
||||
static sizeOf():number {
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @param number a
|
||||
|
||||
Reference in New Issue
Block a user